2 namespace wcf\acp\page
;
3 use wcf\data\category\CategoryNodeTree
;
4 use wcf\data\
object\type\ObjectType
;
5 use wcf\page\AbstractPage
;
6 use wcf\system\category\CategoryHandler
;
7 use wcf\system\exception\InvalidObjectTypeException
;
8 use wcf\system\exception\PermissionDeniedException
;
9 use wcf\system\user\collapsible\content\UserCollapsibleContentHandler
;
13 * Abstract implementation of a page with lists all categories of a certain object
16 * @author Matthias Schmidt
17 * @copyright 2001-2017 WoltLab GmbH
18 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
19 * @package WoltLabSuite\Core\Acp\Page
21 abstract class AbstractCategoryListPage
extends AbstractPage
{
23 * name of the controller used to add new categories
26 public $addController = '';
30 * @var CategoryNodeTree
32 public $categoryNodeTree = null;
35 * ids of collapsed categories
38 public $collapsedCategoryIDs = null;
41 * id of the collapsible category object type
44 public $collapsibleObjectTypeID = 0;
47 * name of the controller used to edit categories
50 public $editController = '';
53 * language item with the page title
56 public $pageTitle = 'wcf.category.list';
59 * category object type object
62 public $objectType = null;
65 * name of the category object type
68 public $objectTypeName = '';
73 public $templateName = 'categoryList';
78 public function __run() {
79 $classNameParts = explode('\\', get_called_class());
80 $className = array_pop($classNameParts);
82 // autoset controllers
83 if (empty($this->addController
)) {
84 $this->addController
= str_replace('ListPage', 'Add', $className);
86 if (empty($this->editController
)) {
87 $this->editController
= str_replace('ListPage', 'Edit', $className);
96 public function assignVariables() {
97 parent
::assignVariables();
99 WCF
::getTPL()->assign([
100 'addController' => $this->addController
,
101 'categoryNodeList' => $this->categoryNodeTree
->getIterator(),
102 'collapsedCategoryIDs' => $this->collapsedCategoryIDs
,
103 'collapsibleObjectTypeID' => $this->collapsibleObjectTypeID
,
104 'editController' => $this->editController
,
105 'objectType' => $this->objectType
108 if ($this->pageTitle
) {
109 WCF
::getTPL()->assign('pageTitle', $this->pageTitle
);
114 * Checks if the active user has the needed permissions to view this list.
116 protected function checkCategoryPermissions() {
117 if (!$this->objectType
->getProcessor()->canDeleteCategory() && !$this->objectType
->getProcessor()->canEditCategory()) {
118 throw new PermissionDeniedException();
123 * Reads the categories.
125 protected function readCategories() {
126 $this->categoryNodeTree
= new CategoryNodeTree($this->objectType
->objectType
, 0, true);
132 public function readData() {
133 $this->objectType
= CategoryHandler
::getInstance()->getObjectTypeByName($this->objectTypeName
);
134 if ($this->objectType
=== null) {
135 throw new InvalidObjectTypeException($this->objectTypeName
, 'com.woltlab.wcf.category');
139 $this->checkCategoryPermissions();
141 $this->readCategories();
143 // note that the implementation of wcf\system\category\ICategoryType
144 // needs to support a object type of the pseudo definition
145 // 'com.woltlab.wcf.collapsibleContent.acp' which has to be registered
146 // during package installation as a 'com.woltlab.wcf.collapsibleContent'
147 // object type if you want to support collapsible categories in the
148 // acp; the pseudo object type is used to distinguish between
149 // collapsible categories in the frontend and the acp
150 $collapsibleObjectTypeName = $this->objectType
->getProcessor()->getObjectTypeName('com.woltlab.wcf.collapsibleContent.acp');
151 if ($collapsibleObjectTypeName) {
152 $this->collapsibleObjectTypeID
= UserCollapsibleContentHandler
::getInstance()->getObjectTypeID($collapsibleObjectTypeName);
153 // get ids of collapsed category
154 if ($this->collapsibleObjectTypeID
!== null) {
155 $this->collapsedCategoryIDs
= UserCollapsibleContentHandler
::getInstance()->getCollapsedContent($this->collapsibleObjectTypeID
);
156 $this->collapsedCategoryIDs
= array_flip($this->collapsedCategoryIDs
);