Source of file ItemWatch.php
Size: 1,740 Bytes - Last Modified: 2021-12-23T10:50:27+00:00
/var/www/docs.ssmods.com/process/src/src/ItemWatch.php
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 | <?php namespace Symbiote\Watch; use SilverStripe\ORM\DataObject; use SilverStripe\ORM\DataList; use SilverStripe\Security\Member; /** * @author marcus */ class ItemWatch extends DataObject { private static $table_name = 'ItemWatch'; private static $db = [ 'Title' => 'Varchar(255)', 'Type' => 'Varchar', 'WatchData' => 'Text', ]; private static $has_one = [ 'Watched' => DataObject::class, 'Owner' => Member::class, ]; protected $watchedItem = null; public function getWatchedItem() { if (!$this->watchedItem) { $this->watchedItem = $this->Watched(); } return $this->watchedItem; } public function watch($item, $type = 'watch', $member = null) { if (!$member) { $member = Member::currentUser(); } $filter = array( 'WatchedClass' => $item->ClassName, 'WatchedID' => $item->ID, 'OwnerID' => $member->ID, 'Type' => $type, ); $existing = ItemWatch::get()->filter($filter)->first(); if ($existing) { return $existing; } if (!$item->canView()) { return null; } $this->update($filter); $this->Title = $item->Title . ' watched by ' . $member->getTitle(); return $this; } public function summaryFields() { $fields = parent::summaryFields(); $fields['ItemOverview'] = 'ItemOverview'; return $fields; } public function getItemOverview() { return $this->renderWith([ $this->WatchedClass . '_watchoverview', 'ItemWatch_watchoverview' ]); } } |