<?php
namespace wcf\data\category;
+use wcf\data\user\User;
use wcf\data\IPermissionObject;
use wcf\data\ProcessibleDatabaseObject;
use wcf\system\category\CategoryHandler;
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
/**
* @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) {