Merge branch '5.2' into 5.3
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / acp / page / LabelGroupListPage.class.php
1 <?php
2 namespace wcf\acp\page;
3 use wcf\data\label\group\LabelGroupList;
4 use wcf\data\language\item\LanguageItemList;
5 use wcf\page\SortablePage;
6 use wcf\system\language\LanguageFactory;
7 use wcf\system\request\LinkHandler;
8 use wcf\system\WCF;
9 use wcf\util\HeaderUtil;
10 use wcf\util\StringUtil;
11
12 /**
13 * Lists available label groups.
14 *
15 * @author Alexander Ebert
16 * @copyright 2001-2019 WoltLab GmbH
17 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
18 * @package WoltLabSuite\Core\Acp\Page
19 *
20 * @property LabelGroupList $objectList
21 */
22 class LabelGroupListPage extends SortablePage {
23 /**
24 * @inheritDoc
25 */
26 public $activeMenuItem = 'wcf.acp.menu.link.label.group.list';
27
28 /**
29 * @inheritDoc
30 */
31 public $defaultSortField = 'showOrder';
32
33 /**
34 * @inheritDoc
35 */
36 public $itemsPerPage = 50;
37
38 /**
39 * @inheritDoc
40 */
41 public $validSortFields = ['groupID', 'groupName', 'groupDescription', 'showOrder', 'labels'];
42
43 /**
44 * @inheritDoc
45 */
46 public $neededPermissions = ['admin.content.label.canManageLabel'];
47
48 /**
49 * @inheritDoc
50 */
51 public $objectListClassName = LabelGroupList::class;
52
53 /**
54 * @var string
55 */
56 public $groupName = '';
57
58 /**
59 * @var string
60 */
61 public $groupDescription = '';
62
63 /**
64 * @inheritDoc
65 */
66 public function readParameters() {
67 parent::readParameters();
68
69 if (!empty($_POST)) {
70 $parameters = [];
71 if (!empty($_POST['groupName'])) $parameters['groupName'] = StringUtil::trim($_POST['groupName']);
72 if (!empty($_POST['groupDescription'])) $parameters['groupDescription'] = StringUtil::trim($_POST['groupDescription']);
73
74 if (!empty($parameters)) {
75 HeaderUtil::redirect(LinkHandler::getInstance()->getLink('LabelGroupList', $parameters));
76 exit;
77 }
78 }
79
80 if (isset($_REQUEST['groupName'])) $this->groupName = StringUtil::trim($_REQUEST['groupName']);
81 if (isset($_REQUEST['groupDescription'])) $this->groupDescription = StringUtil::trim($_REQUEST['groupDescription']);
82 }
83
84 /**
85 * @inheritDoc
86 */
87 protected function initObjectList() {
88 parent::initObjectList();
89
90 $this->objectList->sqlSelects .= '(SELECT COUNT(*) FROM wcf'.WCF_N.'_label WHERE groupID = label_group.groupID) AS labels';
91
92 if ($this->groupName) {
93 $languageItemList = new LanguageItemList();
94 $languageItemList->getConditionBuilder()->add('languageCategoryID = ?', [LanguageFactory::getInstance()->getCategory('wcf.acp.label')->languageCategoryID]);
95 $languageItemList->getConditionBuilder()->add('languageID = ?', [WCF::getLanguage()->languageID]);
96 $languageItemList->getConditionBuilder()->add('languageItem LIKE ?', ['wcf.acp.label.group%']);
97 $languageItemList->getConditionBuilder()->add('languageItemValue LIKE ?', ['%'.addcslashes($this->groupName, '_%').'%']);
98 $languageItemList->readObjects();
99
100 $labelIDs = [];
101 foreach ($languageItemList as $languageItem) {
102 $labelIDs[] = str_replace('wcf.acp.label.group', '', $languageItem->languageItem);
103 }
104
105 if (!empty($labelIDs)) {
106 $this->objectList->getConditionBuilder()->add('(groupName LIKE ? OR groupID IN (?))', ['%'.addcslashes($this->groupName, '_%').'%', $labelIDs]);
107 }
108 else {
109 $this->objectList->getConditionBuilder()->add('groupName LIKE ?', ['%'.addcslashes($this->groupName, '_%').'%']);
110 }
111 }
112
113 if ($this->groupDescription) {
114 $this->objectList->getConditionBuilder()->add('label_group.groupDescription LIKE ?', ['%'.addcslashes($this->groupDescription, '_%').'%']);
115 }
116 }
117
118 /**
119 * @inheritDoc
120 */
121 public function assignVariables() {
122 parent::assignVariables();
123
124 WCF::getTPL()->assign([
125 'groupName' => $this->groupName,
126 'groupDescription' => $this->groupDescription,
127 ]);
128 }
129 }