2 declare(strict_types
=1);
3 namespace wcf\acp\page
;
4 use wcf\data\category\CategoryNodeTree
;
5 use wcf\data\
object\type\ObjectType
;
6 use wcf\page\AbstractPage
;
7 use wcf\system\category\CategoryHandler
;
8 use wcf\system\exception\InvalidObjectTypeException
;
9 use wcf\system\exception\PermissionDeniedException
;
10 use wcf\system\user\collapsible\content\UserCollapsibleContentHandler
;
14 * Abstract implementation of a page with lists all categories of a certain object
17 * @author Matthias Schmidt
18 * @copyright 2001-2018 WoltLab GmbH
19 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
20 * @package WoltLabSuite\Core\Acp\Page
22 abstract class AbstractCategoryListPage
extends AbstractPage
{
24 * name of the controller used to add new categories
27 public $addController = '';
31 * @var CategoryNodeTree
33 public $categoryNodeTree = null;
36 * ids of collapsed categories
39 public $collapsedCategoryIDs = null;
42 * id of the collapsible category object type
45 public $collapsibleObjectTypeID = 0;
48 * name of the controller used to edit categories
51 public $editController = '';
54 * language item with the page title
57 public $pageTitle = 'wcf.category.list';
60 * category object type object
63 public $objectType = null;
66 * name of the category object type
69 public $objectTypeName = '';
74 public $templateName = 'categoryList';
79 public function __run() {
80 $classNameParts = explode('\\', get_called_class());
81 $className = array_pop($classNameParts);
83 // autoset controllers
84 if (empty($this->addController
)) {
85 $this->addController
= str_replace('ListPage', 'Add', $className);
87 if (empty($this->editController
)) {
88 $this->editController
= str_replace('ListPage', 'Edit', $className);
97 public function assignVariables() {
98 parent
::assignVariables();
100 WCF
::getTPL()->assign([
101 'addController' => $this->addController
,
102 'categoryNodeList' => $this->categoryNodeTree
->getIterator(),
103 'collapsedCategoryIDs' => $this->collapsedCategoryIDs
,
104 'collapsibleObjectTypeID' => $this->collapsibleObjectTypeID
,
105 'editController' => $this->editController
,
106 'objectType' => $this->objectType
109 if ($this->pageTitle
) {
110 WCF
::getTPL()->assign('pageTitle', $this->pageTitle
);
115 * Checks if the active user has the needed permissions to view this list.
117 protected function checkCategoryPermissions() {
118 if (!$this->objectType
->getProcessor()->canDeleteCategory() && !$this->objectType
->getProcessor()->canEditCategory()) {
119 throw new PermissionDeniedException();
124 * Reads the categories.
126 protected function readCategories() {
127 $this->categoryNodeTree
= new CategoryNodeTree($this->objectType
->objectType
, 0, true);
133 public function readData() {
134 $this->objectType
= CategoryHandler
::getInstance()->getObjectTypeByName($this->objectTypeName
);
135 if ($this->objectType
=== null) {
136 throw new InvalidObjectTypeException($this->objectTypeName
, 'com.woltlab.wcf.category');
140 $this->checkCategoryPermissions();
142 $this->readCategories();
144 // note that the implementation of wcf\system\category\ICategoryType
145 // needs to support a object type of the pseudo definition
146 // 'com.woltlab.wcf.collapsibleContent.acp' which has to be registered
147 // during package installation as a 'com.woltlab.wcf.collapsibleContent'
148 // object type if you want to support collapsible categories in the
149 // acp; the pseudo object type is used to distinguish between
150 // collapsible categories in the frontend and the acp
151 $collapsibleObjectTypeName = $this->objectType
->getProcessor()->getObjectTypeName('com.woltlab.wcf.collapsibleContent.acp');
152 if ($collapsibleObjectTypeName) {
153 $this->collapsibleObjectTypeID
= UserCollapsibleContentHandler
::getInstance()->getObjectTypeID($collapsibleObjectTypeName);
154 // get ids of collapsed category
155 if ($this->collapsibleObjectTypeID
!== null) {
156 $this->collapsedCategoryIDs
= UserCollapsibleContentHandler
::getInstance()->getCollapsedContent($this->collapsibleObjectTypeID
);
157 $this->collapsedCategoryIDs
= array_flip($this->collapsedCategoryIDs
);