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 $validSortFields = ['labelID', 'label', 'groupName', 'showOrder'];
44 public $neededPermissions = ['admin.content.label.canManageLabel'];
49 public $objectListClassName = LabelList
::class;
52 * filter for css class name
55 public $cssClassName = '';
58 * if of the label group to which the displayed labels belong
64 * filter for label name
70 * label group to which the displayed labels belong
76 * list with available label groups
79 public $labelGroupList;
84 public function assignVariables() {
85 parent
::assignVariables();
87 WCF
::getTPL()->assign([
88 'cssClassName' => $this->cssClassName
,
89 'groupID' => $this->groupID
,
90 'labelSearch' => $this->label
,
91 'labelGroup' => $this->labelGroup
,
92 'labelGroupList' => $this->labelGroupList
99 protected function initObjectList() {
100 parent
::initObjectList();
102 $this->objectList
->sqlSelects
= "label_group.groupName, label_group.groupDescription";
103 $this->objectList
->sqlJoins
= "LEFT JOIN wcf".WCF_N
."_label_group label_group ON (label_group.groupID = label.groupID)";
104 if ($this->labelGroup
) {
105 $this->objectList
->getConditionBuilder()->add('label.groupID = ?', [$this->labelGroup
->groupID
]);
107 // Ramp up the limit to display all labels at once for easier
108 // drag & drop sorting. This isn't exactly infinite, but if
109 // you have a label group with more than 1k labels, being able
110 // to sort them is the least of your problems.
111 $this->itemsPerPage
= 1000;
113 if ($this->cssClassName
) {
114 $this->objectList
->getConditionBuilder()->add('label.cssClassName LIKE ?', ['%'.addcslashes($this->cssClassName
, '_%').'%']);
118 $languageItemList = new LanguageItemList();
119 $languageItemList->getConditionBuilder()->add('languageCategoryID = ?', [LanguageFactory
::getInstance()->getCategory('wcf.acp.label')->languageCategoryID
]);
120 $languageItemList->getConditionBuilder()->add('languageID = ?', [WCF
::getLanguage()->languageID
]);
121 $languageItemList->getConditionBuilder()->add('languageItem LIKE ?', ['wcf.acp.label.label%']);
122 $languageItemList->getConditionBuilder()->add('languageItemValue LIKE ?', ['%'.addcslashes($this->label
, '_%').'%']);
123 $languageItemList->readObjects();
126 foreach ($languageItemList as $languageItem) {
127 $labelIDs[] = str_replace('wcf.acp.label.label', '', $languageItem->languageItem
);
130 if (!empty($labelIDs)) {
131 $this->objectList
->getConditionBuilder()->add('(label LIKE ? OR labelID IN (?))', ['%'.addcslashes($this->label
, '_%').'%', $labelIDs]);
134 $this->objectList
->getConditionBuilder()->add('label LIKE ?', ['%'.addcslashes($this->label
, '_%').'%']);
142 public function readData() {
145 $this->labelGroupList
= new LabelGroupList();
146 $this->labelGroupList
->readObjects();
152 public function readParameters() {
153 parent
::readParameters();
155 if (!empty($_POST)) {
157 if (!empty($_POST['groupID'])) $parameters['id'] = intval($_POST['groupID']);
158 if (!empty($_POST['label'])) $parameters['label'] = StringUtil
::trim($_POST['label']);
159 if (!empty($_POST['cssClassName'])) $parameters['cssClassName'] = StringUtil
::trim($_POST['cssClassName']);
161 if (!empty($parameters)) {
162 HeaderUtil
::redirect(LinkHandler
::getInstance()->getLink('LabelList', $parameters));
167 if (isset($_REQUEST['id'])) $this->groupID
= intval($_REQUEST['id']);
168 if (isset($_REQUEST['label'])) $this->label
= StringUtil
::trim($_REQUEST['label']);
169 if (isset($_REQUEST['cssClassName'])) $this->cssClassName
= StringUtil
::trim($_REQUEST['cssClassName']);
171 if ($this->groupID
) {
172 $this->labelGroup
= new LabelGroup($this->groupID
);
173 if (!$this->labelGroup
->groupID
) {
174 throw new IllegalLinkException();
177 $this->defaultSortField
= 'showOrder';