Source of file MerchantTreeDOD.php
Size: 1,800 Bytes - Last Modified: 2021-12-23T10:40:53+00:00
/var/www/docs.ssmods.com/process/src/code/decorator/MerchantTreeDOD.php
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 | <?php /** * Class implementing the canEdit function but for the frontend instead as canEdit is for the CMS. */ class MerchantTreeDOD extends DataObjectDecorator { public static $allowed_classes = array('MerchantPage', 'MerchantProduct', 'MerchantLocation'); public function canFrontEndEdit($member = null) { //we do this afterwards as we want to make sure that admins can edit all pages. if (! in_array($this->owner->class, self::$allowed_classes)) { return parent::canEdit($member); } if ($member instanceof Member) { $memberID = $member->ID; } elseif (is_numeric($member)) { $memberID = $member; } else { $memberID = Member::currentUserID(); } if ($memberID && Permission::checkMember($memberID, array("ADMIN", "SITETREE_EDIT_ALL", "SHOPADMIN"))) { return true; } if ($this->owner->ID) { if ($this->owner->CanEditType == 'LoggedInUsers') { return $memberID; } elseif ($this->owner->CanEditType == 'OnlyTheseUsers') { $groups = DB::query("SELECT GroupID FROM SiteTree_EditorGroups WHERE SiteTreeID = {$this->owner->ID}")->column(); if ($memberID && count($groups) > 0) { $groups = implode(',', $groups); return DB::query("SELECT COUNT(*) FROM Group_Members WHERE MemberID = $memberID AND GroupID IN ($groups)")->value(); } } // Inherit elseif ($this->owner->ParentID) { $parent = $this->owner->Parent(); if ($parent->exists()) { return $parent->canFrontEndEdit($memberID); } } } } } |