Source of file RestrictedList.php
Size: 1,545 Bytes - Last Modified: 2021-12-23T10:34:03+00:00
/var/www/docs.ssmods.com/process/src/code/model/RestrictedList.php
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 | <?php /** * @author <marcus@silverstripe.com.au> * @license BSD License http://www.silverstripe.org/bsd-license */ class RestrictedList extends DataList { /** * The permission / role being checked for the data list items * * @var string */ private $requiredPermission = 'View'; /** * Set the required permission * * @param string $roleOrPerm * @return \RestrictedList */ public function requirePerm($roleOrPerm) { $this->requiredPermission = $roleOrPerm; return $this; } public function toArray() { $query = $this->dataQuery->query(); $rows = $query->execute(); $results = array(); foreach ($rows as $row) { $item = $this->createDataObject($row); if ($item->hasExtension('Restrictable') && $item->checkPerm($this->requiredPermission)) { $results[] = $item; } elseif ($item->canView()) { $results[] = $item; } } // TODO if we don't have enough, we need to query again, but // we'll look at that later... return $results; } public function byID($id) { $item = parent::byID($id); if (!$item) { return $item; } if ($item->hasExtension('Restrictable') && $item->checkPerm($this->requiredPermission)) { return $item; } elseif ($item->canView()) { return $item; } } } |