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');
if(!$this->owner->exists()) {
if (!$this->owner->exists()) {
$tab->push(LiteralField::create(
'NotificationsNotice',
'<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(
HeaderField::create('NotificationsHeader','Notifications'),
HeaderField::create('NotificationsHeader', 'Notifications'),
LiteralField::create(
'CurrentNotifications',
'<b>Current:</b>'
@ -83,9 +83,6 @@ class NotificationsExtension extends DataExtension
$items = $this->owner->Notifications();
$time = time();
return $items->filter([
'DateOn:LessThanOrEqual' => date('Y-m-d', $time),
'DateOff:GreaterThanOrEqual' => date('Y-m-d', $time),
]);
return $items->where("AlwaysOn='1' OR (DateOn <= '".date('Y-m-d', $time)."' AND DateOff >= '".date('Y-m-d', $time)."')");
}
}

View File

@ -36,6 +36,7 @@ class Notification extends DataObject
'Content' => 'Text',
'DateOn' => 'Date',
'DateOff' => 'Date',
'AlwaysOn' => 'Boolean(0)',
'Area' => 'Enum("Site","Site")',
];
@ -52,6 +53,7 @@ class Notification extends DataObject
private static $summary_fields = [
'Title' => 'Title',
'Content' => 'Text',
'AlwaysOn' => 'Always On',
'DateOn' => 'Turn on date',
'DateOff' => 'Turn off date',
];
@ -73,13 +75,6 @@ class Notification extends DataObject
{
$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')) {
return $result->addError(
'Text field required.',