2 namespace wcf\acp\page
;
3 use wcf\data\label\group\LabelGroup
;
4 use wcf\data\label\group\LabelGroupList
;
5 use wcf\data\label\LabelList
;
6 use wcf\data\language\item\LanguageItemList
;
7 use wcf\page\SortablePage
;
8 use wcf\system\exception\IllegalLinkException
;
9 use wcf\system\language\LanguageFactory
;
10 use wcf\system\request\LinkHandler
;
12 use wcf\util\HeaderUtil
;
13 use wcf\util\StringUtil
;
16 * Lists available labels
18 * @author Alexander Ebert
19 * @copyright 2001-2019 WoltLab GmbH
20 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
21 * @package WoltLabSuite\Core\Acp\Page
23 * @property LabelList $objectList
25 class LabelListPage
extends SortablePage
{
29 public $activeMenuItem = 'wcf.acp.menu.link.label.list';
34 public $defaultSortField = 'label';
39 public $itemsPerPage = 50;
44 public $validSortFields = ['labelID', 'label', 'groupName', 'showOrder'];
49 public $neededPermissions = ['admin.content.label.canManageLabel'];
54 public $objectListClassName = LabelList
::class;
57 * filter for css class name
60 public $cssClassName = '';
63 * if of the label group to which the displayed labels belong
69 * filter for label name
75 * label group to which the displayed labels belong
81 * list with available label groups
84 public $labelGroupList;
89 public function assignVariables() {
90 parent
::assignVariables();
92 WCF
::getTPL()->assign([
93 'cssClassName' => $this->cssClassName
,
94 'groupID' => $this->groupID
,
95 'labelSearch' => $this->label
,
96 'labelGroup' => $this->labelGroup
,
97 'labelGroupList' => $this->labelGroupList
104 protected function initObjectList() {
105 parent
::initObjectList();
107 $this->objectList
->sqlSelects
= "label_group.groupName, label_group.groupDescription";
108 $this->objectList
->sqlJoins
= "LEFT JOIN wcf".WCF_N
."_label_group label_group ON (label_group.groupID = label.groupID)";
109 if ($this->labelGroup
) {
110 $this->objectList
->getConditionBuilder()->add('label.groupID = ?', [$this->labelGroup
->groupID
]);
112 // Ramp up the limit to display all labels at once for easier
113 // drag & drop sorting. This isn't exactly infinite, but if
114 // you have a label group with more than 1k labels, being able
115 // to sort them is the least of your problems.
116 $this->itemsPerPage
= 1000;
118 if ($this->cssClassName
) {
119 $this->objectList
->getConditionBuilder()->add('label.cssClassName LIKE ?', ['%'.addcslashes($this->cssClassName
, '_%').'%']);
123 $languageItemList = new LanguageItemList();
124 $languageItemList->getConditionBuilder()->add('languageCategoryID = ?', [LanguageFactory
::getInstance()->getCategory('wcf.acp.label')->languageCategoryID
]);
125 $languageItemList->getConditionBuilder()->add('languageID = ?', [WCF
::getLanguage()->languageID
]);
126 $languageItemList->getConditionBuilder()->add('languageItem LIKE ?', ['wcf.acp.label.label%']);
127 $languageItemList->getConditionBuilder()->add('languageItemValue LIKE ?', ['%'.addcslashes($this->label
, '_%').'%']);
128 $languageItemList->readObjects();
131 foreach ($languageItemList as $languageItem) {
132 $labelIDs[] = str_replace('wcf.acp.label.label', '', $languageItem->languageItem
);
135 if (!empty($labelIDs)) {
136 $this->objectList
->getConditionBuilder()->add('(label LIKE ? OR labelID IN (?))', ['%'.addcslashes($this->label
, '_%').'%', $labelIDs]);
139 $this->objectList
->getConditionBuilder()->add('label LIKE ?', ['%'.addcslashes($this->label
, '_%').'%']);
147 public function readData() {
150 $this->labelGroupList
= new LabelGroupList();
151 $this->labelGroupList
->readObjects();
157 public function readParameters() {
158 parent
::readParameters();
160 if (!empty($_POST)) {
162 if (!empty($_POST['groupID'])) $parameters['id'] = intval($_POST['groupID']);
163 if (!empty($_POST['label'])) $parameters['label'] = StringUtil
::trim($_POST['label']);
164 if (!empty($_POST['cssClassName'])) $parameters['cssClassName'] = StringUtil
::trim($_POST['cssClassName']);
166 if (!empty($parameters)) {
167 HeaderUtil
::redirect(LinkHandler
::getInstance()->getLink('LabelList', $parameters));
172 if (isset($_REQUEST['id'])) $this->groupID
= intval($_REQUEST['id']);
173 if (isset($_REQUEST['label'])) $this->label
= StringUtil
::trim($_REQUEST['label']);
174 if (isset($_REQUEST['cssClassName'])) $this->cssClassName
= StringUtil
::trim($_REQUEST['cssClassName']);
176 if ($this->groupID
) {
177 $this->labelGroup
= new LabelGroup($this->groupID
);
178 if (!$this->labelGroup
->groupID
) {
179 throw new IllegalLinkException();
182 $this->defaultSortField
= 'showOrder';