Add optional User parameter to Category::getPermission()
authorMatthias Schmidt <gravatronics@live.com>
Tue, 2 Sep 2014 15:50:21 +0000 (17:50 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Tue, 2 Sep 2014 15:50:21 +0000 (17:50 +0200)
wcfsetup/install/files/lib/data/category/Category.class.php

index bf42a494c0c231a1b02c16e53fb770de9cdfcc5b..16fc69422d7cd73ddc7cb2e231dc6a02a29a67e3 100644 (file)
@@ -1,5 +1,6 @@
 <?php
 namespace wcf\data\category;
+use wcf\data\user\User;
 use wcf\data\IPermissionObject;
 use wcf\data\ProcessibleDatabaseObject;
 use wcf\system\category\CategoryHandler;
@@ -38,11 +39,19 @@ class Category extends ProcessibleDatabaseObject implements IPermissionObject, I
        protected $parentCategory = null;
        
        /**
-        * acl permissions for the active user of this category
+        * acl permissions of this category for the active user
+        * @deprecated
         * @var array<boolean>
         */
        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) {