Source of file InternalNotification.php
Size: 2,142 Bytes - Last Modified: 2021-12-23T10:25:43+00:00
/var/www/docs.ssmods.com/process/src/src/Model/InternalNotification.php
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 | <?php namespace Symbiote\Notifications\Model; use SilverStripe\ORM\DataObject; use SilverStripe\Security\Member; use SilverStripe\Security\Security; use Symbiote\MultiValueField\ORM\FieldType\MultiValueField; use Symbiote\MultiValueField\Fields\KeyValueField; use SilverStripe\Security\Permission; class InternalNotification extends DataObject { private static $table_name = 'InternalNotification'; private static $db = [ 'Title' => 'Varchar(255)', 'Message' => 'Text', 'SentOn' => 'Datetime', 'IsRead' => 'Boolean', 'IsSeen' => 'Boolean', 'Context' => MultiValueField::class, ]; private static $has_one = [ 'To' => Member::class, 'From' => Member::class, 'SourceObject' => DataObject::class, 'SourceNotification' => SystemNotification::class, ]; private static $summary_fields = [ 'Title' => 'Title', 'To.Name' => 'To', 'SentOn' => 'Sent on', 'IsSeen.Nice' => 'Seen?', 'IsRead.Nice' => 'Read?' ]; private static $default_sort = 'ID DESC'; public function onBeforeWrite() { parent::onBeforeWrite(); if ($this->IsRead) { $this->IsSeen = true; } } public function getCMSFields() { $fields = parent::getCMSFields(); $fields->replaceField('Context', KeyValueField::create('Context')); return $fields; } public function canView($member = null) { $member = $member ?: Security::getCurrentUser(); if (!$member) { return false; } if (Permission::check('ADMIN')) { return true; } return $member && (!$this->ID || $this->ToID == $member->ID || $this->FromID == $member->ID); } public function canEdit($member = null) { $member = $member ?: Security::getCurrentUser(); if (!$member) { return false; } if (Permission::check('ADMIN')) { return true; } return $member && (!$this->ID || $this->ToID == $member->ID); } } |