96ee59c802921e936ae3022792f167161b47dfd5
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / acp / page / TagListPage.class.php
1 <?php
2
3 namespace wcf\acp\page;
4
5 use wcf\data\tag\TagList;
6 use wcf\page\SortablePage;
7 use wcf\system\clipboard\ClipboardHandler;
8 use wcf\system\WCF;
9 use wcf\util\StringUtil;
10
11 /**
12 * Shows a list of tags.
13 *
14 * @author Tim Duesterhus
15 * @copyright 2001-2019 WoltLab GmbH
16 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
17 *
18 * @property TagList $objectList
19 */
20 class TagListPage extends SortablePage
21 {
22 /**
23 * @inheritDoc
24 */
25 public $activeMenuItem = 'wcf.acp.menu.link.tag.list';
26
27 /**
28 * @inheritDoc
29 */
30 public $neededPermissions = ['admin.content.tag.canManageTag'];
31
32 /**
33 * @inheritDoc
34 */
35 public $neededModules = ['MODULE_TAGGING'];
36
37 /**
38 * @inheritDoc
39 */
40 public $defaultSortField = 'name';
41
42 /**
43 * @inheritDoc
44 */
45 public $validSortFields = ['tagID', 'languageID', 'name', 'usageCount'];
46
47 /**
48 * @inheritDoc
49 */
50 public $objectListClassName = TagList::class;
51
52 /**
53 * search-query
54 * @var string
55 */
56 public $search = '';
57
58 /**
59 * @inheritDoc
60 */
61 public function assignVariables()
62 {
63 parent::assignVariables();
64
65 WCF::getTPL()->assign([
66 'hasMarkedItems' => ClipboardHandler::getInstance()->hasMarkedItems(ClipboardHandler::getInstance()->getObjectTypeID('com.woltlab.wcf.tag')),
67 'search' => $this->search,
68 ]);
69 }
70
71 /**
72 * @inheritDoc
73 */
74 public function readParameters()
75 {
76 parent::readParameters();
77
78 if (isset($_REQUEST['search'])) {
79 $this->search = StringUtil::trim($_REQUEST['search']);
80 }
81 }
82
83 /**
84 * @inheritDoc
85 */
86 protected function initObjectList()
87 {
88 parent::initObjectList();
89
90 $this->objectList->sqlSelects = "(
91 SELECT COUNT(*)
92 FROM wcf" . WCF_N . "_tag_to_object t2o
93 WHERE t2o.tagID = tag.tagID
94 ) AS usageCount";
95 $this->objectList->sqlSelects .= ", language.languageName, language.languageCode";
96 $this->objectList->sqlSelects .= ", synonym.name AS synonymName";
97
98 $this->objectList->sqlJoins = "
99 LEFT JOIN wcf" . WCF_N . "_language language
100 ON tag.languageID = language.languageID
101 LEFT JOIN wcf" . WCF_N . "_tag synonym
102 ON tag.synonymFor = synonym.tagID";
103
104 if ($this->search !== '') {
105 $this->objectList->getConditionBuilder()->add('tag.name LIKE ?', [$this->search . '%']);
106 }
107 }
108 }