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