From: Matthias Schmidt Date: Tue, 2 Sep 2014 15:50:21 +0000 (+0200) Subject: Add optional User parameter to Category::getPermission() X-Git-Tag: 2.1.0_Alpha_1~361^2~1 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=2b59736b2592a01ee880f0cc4439622b437acd85;p=GitHub%2FWoltLab%2FWCF.git Add optional User parameter to Category::getPermission() --- diff --git a/wcfsetup/install/files/lib/data/category/Category.class.php b/wcfsetup/install/files/lib/data/category/Category.class.php index bf42a494c0..16fc69422d 100644 --- a/wcfsetup/install/files/lib/data/category/Category.class.php +++ b/wcfsetup/install/files/lib/data/category/Category.class.php @@ -1,5 +1,6 @@ */ protected $permissions = null; + /** + * acl permissions of this category grouped by the id of the user they + * belong to + * @var array + */ + protected $userPermissions = array(); + /** * fallback return value used in Category::getPermission() * @var boolean @@ -153,17 +162,25 @@ class Category extends ProcessibleDatabaseObject implements IPermissionObject, I /** * @see \wcf\data\IPermissionObject::getPermission() */ - public function getPermission($permission) { - if ($this->permissions === null) { - $this->permissions = CategoryPermissionHandler::getInstance()->getPermissions($this); + public function getPermission($permission, User $user = null) { + if ($user === null) { + $user = WCF::getUser(); + } + + if (!isset($this->userPermissions[$user->userID])) { + $this->userPermissions[$user->userID] = CategoryPermissionHandler::getInstance()->getPermissions($this, $user); + + if ($user->userID == WCF::getUser()->userID) { + $this->permissions = $this->userPermissions[$user->userID]; + } } - if (isset($this->permissions[$permission])) { - return $this->permissions[$permission]; + if (isset($this->userPermissions[$user->userID][$permission])) { + return $this->userPermissions[$user->userID][$permission]; } if ($this->getParentCategory()) { - return $this->getParentCategory()->getPermission($permission); + return $this->getParentCategory()->getPermission($permission, $user); } if ($this->getObjectType()->defaultpermission !== null) {