Apply PSR-12 code style (#3886)
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / acp / page / DevtoolsProjectPipEntryListPage.class.php
CommitLineData
532a045a 1<?php
a9229942 2
532a045a 3namespace wcf\acp\page;
a9229942 4
532a045a
MS
5use wcf\data\devtools\project\DevtoolsProject;
6use wcf\page\AbstractPage;
7use wcf\system\devtools\pip\DevtoolsPip;
532a045a
MS
8use wcf\system\devtools\pip\IDevtoolsPipEntryList;
9use wcf\system\exception\IllegalLinkException;
87cf14f2 10use wcf\system\request\LinkHandler;
532a045a
MS
11use wcf\system\WCF;
12use wcf\util\StringUtil;
13
14/**
15 * Shows the list of entries of a specific pip for a specific project.
a9229942
TD
16 *
17 * @author Matthias Schmidt
18 * @copyright 2001-2019 WoltLab GmbH
19 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
20 * @package WoltLabSuite\Core\Acp\Page
21 * @since 5.2
532a045a 22 */
a9229942
TD
23class DevtoolsProjectPipEntryListPage extends AbstractPage
24{
25 /**
26 * @inheritDoc
27 */
28 public $activeMenuItem = 'wcf.acp.menu.link.devtools.project.list';
29
30 /**
31 * indicates the range of the listed items
32 * @var int
33 */
34 public $endIndex = 0;
35
36 /**
37 * entry filter string
38 * @var string
39 */
40 public $entryFilter;
41
42 /**
43 * pip entry list
44 * @var IDevtoolsPipEntryList
45 */
46 public $entryList;
47
48 /**
49 * type of the listed pip entries
50 * @var string
51 */
52 public $entryType;
53
54 /**
55 * @inheritDoc
56 */
57 public $forceCanonicalURL = true;
58
59 /**
60 * number of items shown per page
61 * @var int
62 */
63 public $itemsPerPage = 100;
64
65 /**
66 * number of all items
67 * @var int
68 */
69 public $items = 0;
70
71 /**
72 * pagination link parameters
73 * @var string
74 */
75 public $linkParameters = '';
76
77 /**
78 * @inheritDoc
79 */
80 public $neededModules = ['ENABLE_DEVELOPER_TOOLS'];
81
82 /**
83 * @inheritDoc
84 */
85 public $neededPermissions = ['admin.configuration.package.canInstallPackage'];
86
87 /**
88 * current page number
89 * @var int
90 */
91 public $pageNo = 0;
92
93 /**
94 * number of all pages
95 * @var int
96 */
97 public $pages = 0;
98
99 /**
100 * name of the requested pip
101 * @var string
102 */
103 public $pip = '';
104
105 /**
106 * requested pip
107 * @var DevtoolsPip
108 */
109 protected $pipObject;
110
111 /**
112 * devtools project
113 * @var DevtoolsProject
114 */
115 public $project;
116
117 /**
118 * project id
119 * @var int
120 */
121 public $projectID = 0;
122
123 /**
124 * indicates the range of the listed items
125 * @var int
126 */
127 public $startIndex = 0;
128
129 /**
130 * @inheritDoc
131 * @throws IllegalLinkException
132 */
133 public function readParameters()
134 {
135 parent::readParameters();
136
137 if (isset($_REQUEST['id'])) {
138 $this->projectID = \intval($_REQUEST['id']);
139 }
140 $this->project = new DevtoolsProject($this->projectID);
141 if (!$this->project->projectID) {
142 throw new IllegalLinkException();
143 }
144
145 if ($this->project->validatePackageXml() !== '') {
146 throw new IllegalLinkException();
147 }
148
149 if (isset($_REQUEST['pip'])) {
150 $this->pip = StringUtil::trim($_REQUEST['pip']);
151 }
152
153 $filteredPips = \array_filter($this->project->getPips(), function (DevtoolsPip $pip) {
154 return $pip->pluginName === $this->pip;
155 });
156 if (\count($filteredPips) === 1) {
157 $this->pipObject = \reset($filteredPips);
158 } else {
159 throw new IllegalLinkException();
160 }
161
162 if (!$this->pipObject->supportsGui()) {
163 throw new IllegalLinkException();
164 }
165
166 if (isset($_REQUEST['entryType'])) {
167 $this->entryType = StringUtil::trim($_REQUEST['entryType']);
168
169 try {
170 $this->pipObject->getPip()->setEntryType($this->entryType);
171 } catch (\InvalidArgumentException $e) {
172 throw new IllegalLinkException();
173 }
174 } elseif (!empty($this->pipObject->getPip()->getEntryTypes())) {
175 throw new IllegalLinkException();
176 }
177
178 if (isset($_REQUEST['pageNo'])) {
179 $this->pageNo = \intval($_REQUEST['pageNo']);
180 }
181
182 $this->linkParameters = 'pip=' . $this->pip;
183 if ($this->entryType !== null) {
184 $this->linkParameters .= '&entryType=' . $this->entryType;
185 }
186
187 if (isset($_REQUEST['entryFilter'])) {
188 $this->entryFilter = StringUtil::trim($_REQUEST['entryFilter']);
189 }
190
191 if ($this->entryFilter !== null && $this->entryFilter !== '') {
192 $this->linkParameters .= '&entryFilter=' . $this->entryFilter;
193 }
194
195 $this->canonicalURL = LinkHandler::getInstance()->getLink('DevtoolsProjectPipEntryList', [
196 'id' => $this->project->projectID,
197 ], $this->linkParameters);
198 }
199
200 /**
201 * @inheritDoc
202 */
203 public function readData()
204 {
205 parent::readData();
206
207 /** @var IDevtoolsPipEntryList entryList */
208 $this->entryList = $this->pipObject->getPip()->getEntryList();
209
210 if ($this->entryFilter !== null && $this->entryFilter !== '') {
211 $this->entryList->filterEntries($this->entryFilter);
212 }
213
214 $this->items = \count($this->entryList->getEntries());
215 $this->pages = \intval(\ceil($this->items / $this->itemsPerPage));
216
217 // correct active page number
218 if ($this->pageNo > $this->pages) {
219 $this->pageNo = $this->pages;
220 }
221 if ($this->pageNo < 1) {
222 $this->pageNo = 1;
223 }
224
225 // calculate start and end index
226 $this->startIndex = ($this->pageNo - 1) * $this->itemsPerPage;
227 $this->endIndex = $this->startIndex + $this->itemsPerPage;
228 $this->startIndex++;
229 if ($this->endIndex > $this->items) {
230 $this->endIndex = $this->items;
231 }
232 }
233
234 /**
235 * @inheritDoc
236 */
237 public function assignVariables()
238 {
239 parent::assignVariables();
240
241 WCF::getTPL()->assign([
242 'endIndex' => $this->endIndex,
243 'entryFilter' => $this->entryFilter,
244 'entryList' => $this->entryList,
245 'entryType' => $this->entryType,
246 'items' => $this->items,
247 'itemsPerPage' => $this->itemsPerPage,
248 'linkParameters' => $this->linkParameters,
249 'pageNo' => $this->pageNo,
250 'pages' => $this->pages,
251 'pip' => $this->pip,
252 'pipObject' => $this->pipObject,
253 'project' => $this->project,
254 'startIndex' => $this->startIndex,
255 ]);
256 }
532a045a 257}