mirror of
https://github.com/a2nt/cms-niceties.git
synced 2024-10-22 11:05:46 +02:00
58 lines
1.2 KiB
PHP
58 lines
1.2 KiB
PHP
|
<?php
|
||
|
/**
|
||
|
* Created by PhpStorm.
|
||
|
* User: tony
|
||
|
* Date: 9/12/18
|
||
|
* Time: 2:55 AM
|
||
|
*/
|
||
|
|
||
|
namespace A2nt\CMSNiceties\Models;
|
||
|
|
||
|
use Dynamic\FlexSlider\Model\SlideImage;
|
||
|
use Sheadawson\Linkable\Forms\LinkField;
|
||
|
use Sheadawson\Linkable\Models\Link;
|
||
|
use SilverStripe\ORM\DataObject;
|
||
|
use SilverStripe\ORM\ValidationResult;
|
||
|
use SilverStripe\SiteConfig\SiteConfig;
|
||
|
|
||
|
class Holiday extends DataObject
|
||
|
{
|
||
|
private static $table_name = 'Holiday';
|
||
|
|
||
|
private static $db = [
|
||
|
'Title' => 'Varchar(255)',
|
||
|
'Date' => 'Date',
|
||
|
];
|
||
|
|
||
|
private static $has_one = [
|
||
|
'Parent' => SiteConfig::class,
|
||
|
];
|
||
|
|
||
|
|
||
|
private static $summary_fields = [
|
||
|
'Title' => 'Title',
|
||
|
'Date' => 'Date',
|
||
|
];
|
||
|
|
||
|
private static $default_sort = 'Date ASC, Title ASC';
|
||
|
|
||
|
public function validate()
|
||
|
{
|
||
|
$result = parent::validate();
|
||
|
|
||
|
$exists = self::get()->filter([
|
||
|
'ID:not' => $this->ID,
|
||
|
'Date' => $this->getField('Date'),
|
||
|
])->exists();
|
||
|
|
||
|
if($exists) {
|
||
|
return $result->addError(
|
||
|
'Holiday was defined already.',
|
||
|
ValidationResult::TYPE_ERROR
|
||
|
);
|
||
|
}
|
||
|
|
||
|
return $result;
|
||
|
}
|
||
|
}
|