IMPR: Add always on for notifications

This commit is contained in:
Tony Air 2024-08-20 18:19:41 +02:00
parent ee24867435
commit 1a98f25c92
2 changed files with 5 additions and 13 deletions

View File

@ -39,7 +39,7 @@ class NotificationsExtension extends DataExtension
{ {
$tab = $fields->findOrMakeTab('Root.Notifications'); $tab = $fields->findOrMakeTab('Root.Notifications');
if(!$this->owner->exists()) { if (!$this->owner->exists()) {
$tab->push(LiteralField::create( $tab->push(LiteralField::create(
'NotificationsNotice', 'NotificationsNotice',
'<p class="message notice">The object must be saved before notifications can be added</p>' '<p class="message notice">The object must be saved before notifications can be added</p>'
@ -62,7 +62,7 @@ class NotificationsExtension extends DataExtension
]); ]);
$tab->setChildren(FieldList::create( $tab->setChildren(FieldList::create(
HeaderField::create('NotificationsHeader','Notifications'), HeaderField::create('NotificationsHeader', 'Notifications'),
LiteralField::create( LiteralField::create(
'CurrentNotifications', 'CurrentNotifications',
'<b>Current:</b>' '<b>Current:</b>'
@ -83,9 +83,6 @@ class NotificationsExtension extends DataExtension
$items = $this->owner->Notifications(); $items = $this->owner->Notifications();
$time = time(); $time = time();
return $items->filter([ return $items->where("AlwaysOn='1' OR (DateOn <= '".date('Y-m-d', $time)."' AND DateOff >= '".date('Y-m-d', $time)."')");
'DateOn:LessThanOrEqual' => date('Y-m-d', $time),
'DateOff:GreaterThanOrEqual' => date('Y-m-d', $time),
]);
} }
} }

View File

@ -36,6 +36,7 @@ class Notification extends DataObject
'Content' => 'Text', 'Content' => 'Text',
'DateOn' => 'Date', 'DateOn' => 'Date',
'DateOff' => 'Date', 'DateOff' => 'Date',
'AlwaysOn' => 'Boolean(0)',
'Area' => 'Enum("Site","Site")', 'Area' => 'Enum("Site","Site")',
]; ];
@ -52,6 +53,7 @@ class Notification extends DataObject
private static $summary_fields = [ private static $summary_fields = [
'Title' => 'Title', 'Title' => 'Title',
'Content' => 'Text', 'Content' => 'Text',
'AlwaysOn' => 'Always On',
'DateOn' => 'Turn on date', 'DateOn' => 'Turn on date',
'DateOff' => 'Turn off date', 'DateOff' => 'Turn off date',
]; ];
@ -73,13 +75,6 @@ class Notification extends DataObject
{ {
$result = parent::validate(); $result = parent::validate();
if (!$this->getField('DateOn') || !$this->getField('DateOff')) {
return $result->addError(
'Turn on and turn off dates are required.',
ValidationResult::TYPE_ERROR
);
}
if (!$this->getField('Content')) { if (!$this->getField('Content')) {
return $result->addError( return $result->addError(
'Text field required.', 'Text field required.',