[TASK] Reports module based on extbase
[Packages/TYPO3.CMS.git] / typo3 / sysext / sv / reports / class.tx_sv_reports_serviceslist.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009-2011 Francois Suter <francois@typo3.org>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25 /**
26 * This class provides a report displaying a list of all installed services
27 * Code inspired by EXT:dam/lib/class.tx_dam_svlist.php by René Fritz
28 *
29 * @author Francois Suter <francois@typo3.org>
30 * @package TYPO3
31 * @subpackage sv
32 */
33 class tx_sv_reports_ServicesList implements tx_reports_Report {
34
35 /**
36 * Back-reference to the calling reports module
37 *
38 * @var Tx_Reports_Controller_ReportController
39 */
40 protected $reportsModule;
41
42 /**
43 * Constructor for class tx_sv_reports_ServicesList
44 *
45 * @param tx_reports_Module $reportsModule Back-reference to the calling reports module
46 */
47 public function __construct(Tx_Reports_Controller_ReportController $reportsModule) {
48 $this->reportsModule = $reportsModule;
49 $GLOBALS['LANG']->includeLLFile('EXT:sv/reports/locallang.xml');
50 }
51
52 /**
53 * This method renders the report
54 *
55 * @return string The status report as HTML
56 */
57 public function getReport() {
58 $content = '';
59
60 $content .= $this->renderHelp();
61 $content .= $this->renderServicesList();
62 $content .= $this->renderExecutablesSearchPathList();
63
64 return $content;
65 }
66
67 /**
68 * Renders the help comments at the top of the module.
69 *
70 * @return string The help content for this module.
71 */
72 protected function renderHelp() {
73 $help = '<p class="help">'
74 . $GLOBALS['LANG']->getLL('report_explanation')
75 . '</p>';
76 $help .= '<p class="help">'
77 . $GLOBALS['LANG']->getLL('externals_explanation')
78 . '</p><br />';
79
80 return $help;
81 }
82
83 /**
84 * This method assembles a list of all installed services
85 *
86 * @return string HTML to display
87 */
88 protected function renderServicesList() {
89 $servicesList = '';
90 $services = $this->getInstalledServices();
91
92 foreach ($services as $serviceType => $installedServices) {
93 $servicesList .= $this->renderServiceTypeList($serviceType, $installedServices);
94 }
95
96 return $servicesList;
97 }
98
99 /**
100 * Renders the services list for a single service type.
101 *
102 * @param string $serviceType The service type to render the installed services list for
103 * @param array $services List of services for the given type
104 * @return string Service list as HTML for one service type
105 */
106 protected function renderServiceTypeList($serviceType, $services) {
107 $header = '<h4>' . sprintf(
108 $GLOBALS['LANG']->getLL('service_type'),
109 $serviceType
110 ) . '</h4>';
111
112 $serviceList = '
113 <table cellspacing="1" cellpadding="2" border="0" class="tx_sv_reportlist services">
114 <tr class="t3-row-header">
115 <td style="width: 35%">' . $GLOBALS['LANG']->getLL('service') . '</td>
116 <td>' . $GLOBALS['LANG']->getLL('priority') . '</td>
117 <td>' . $GLOBALS['LANG']->getLL('quality') . '</td>
118 <td style="width: 35%">' . $GLOBALS['LANG']->getLL('subtypes') . '</td>
119 <td>' . $GLOBALS['LANG']->getLL('os') . '</td>
120 <td>' . $GLOBALS['LANG']->getLL('externals') . '</td>
121 <td>' . $GLOBALS['LANG']->getLL('available') . '</td>
122 </tr>';
123
124 foreach ($services as $serviceKey => $serviceInformation) {
125 $serviceList .= $this->renderServiceRow($serviceKey, $serviceInformation);
126 }
127
128 $serviceList .= '
129 </table>
130 ';
131
132 return $header . $serviceList;
133 }
134
135 /**
136 * Renders a single service's row.
137 *
138 * @param string $serviceKey The service key to access the service.
139 * @param array $serviceInformation registration information of the service.
140 * @return string HTML row for the service.
141 */
142 protected function renderServiceRow($serviceKey, $serviceInformation) {
143 $serviceDescription = '
144 <p class="service-header">
145 <span class="service-title">' . $serviceInformation['title'] . '</span> (' . $serviceInformation['extKey'] . ': ' . $serviceKey . ')
146 </p>';
147
148 if (!empty($serviceInformation['description'])) {
149 $serviceDescription .= '<p class="service-description">' . $serviceInformation['description']. '</p>';
150 }
151
152 $serviceSubtypes = empty($serviceInformation['serviceSubTypes']) ?
153 '-' :
154 implode(', ', $serviceInformation['serviceSubTypes']);
155
156 $serviceOperatingSystem = empty($serviceInformation['os']) ?
157 $GLOBALS['LANG']->getLL('any') :
158 $serviceInformation['os'];
159
160 $serviceRequiredExecutables = empty($serviceInformation['exec']) ?
161 '-' :
162 $serviceInformation['exec'];
163
164 $serviceAvailabilityClass = 'typo3-message message-error';
165 $serviceAvailable = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:no');
166 try {
167 $serviceDetails = t3lib_extmgm::findServiceByKey($serviceKey);
168 if ($serviceDetails['available']) {
169 $serviceAvailabilityClass = 'typo3-message message-ok';
170 $serviceAvailable = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:yes');
171 }
172 } catch (t3lib_exception $e) {
173 // Nothing to do, the default display is already not available
174 }
175
176 $serviceRow = '
177 <tr class="service">
178 <td class="first-cell ' . $serviceAvailabilityClass . '">' . $serviceDescription . '</td>
179 <td class="cell ' . $serviceAvailabilityClass . '">' . $serviceInformation['priority'] . '</td>
180 <td class="cell ' . $serviceAvailabilityClass . '">' . $serviceInformation['quality'] . '</td>
181 <td class="cell ' . $serviceAvailabilityClass . '">' . $serviceSubtypes . '</td>
182 <td class="cell ' . $serviceAvailabilityClass . '">' . $serviceOperatingSystem . '</td>
183 <td class="cell ' . $serviceAvailabilityClass . '">' . $serviceRequiredExecutables . '</td>
184 <td class="last-cell ' . $serviceAvailabilityClass . '">' . $serviceAvailable . '</td>
185 </tr>';
186
187 return $serviceRow;
188 }
189
190 /**
191 * This method assembles a list of all defined executables search paths
192 *
193 * @return string HTML to display
194 */
195 protected function renderExecutablesSearchPathList() {
196 $searchPaths = t3lib_exec::getPaths(TRUE);
197
198 $content = '<br /><h3 class="divider">' . $GLOBALS['LANG']->getLL('search_paths') . '</h3>';
199
200 if (count($searchPaths) == 0) {
201 $content .= '<p>' . $GLOBALS['LANG']->getLL('no_search_paths') . '</p>';
202 } else {
203 $content .= '
204 <table cellspacing="1" cellpadding="2" border="0" class="tx_sv_reportlist paths">
205 <thead>
206 <tr class="t3-row-header">
207 <td>' . $GLOBALS['LANG']->getLL('path') . '</td>
208 <td>' . $GLOBALS['LANG']->getLL('valid') . '</td>
209 </tr>
210 </thead>
211 <tbody>';
212
213 foreach ($searchPaths as $path => $isValid) {
214 $pathAccessibleClass = 'typo3-message message-error';
215 $pathAccessible = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:no');
216 if ($isValid) {
217 $pathAccessibleClass = 'typo3-message message-ok';
218 $pathAccessible = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:yes');
219 }
220
221 $content .= '
222 <tr>
223 <td class="first-cell ' . $pathAccessibleClass . '">' . t3lib_div::fixWindowsFilePath($path) . '</td>
224 <td class="last-cell ' . $pathAccessibleClass . '">' . $pathAccessible . '</td>
225 </tr>';
226 }
227
228 $content .= '
229 </tbody>
230 </table>';
231 }
232
233 return $content;
234 }
235
236 /**
237 * This method filters the $T3_SERVICES global array to return a relevant,
238 * ordered list of installed services.
239 *
240 * Every installed service appears twice in $T3_SERVICES: once as a service key
241 * for a given service type, and once a service type all by itself
242 * The list of services to display must avoid these duplicates
243 *
244 * Furthermore, inside each service type, installed services must be
245 * ordered by priority and quality
246 *
247 * @return array List of filtered and ordered services
248 */
249 protected function getInstalledServices() {
250 $filteredServices = array();
251
252 foreach ($GLOBALS['T3_SERVICES'] as $serviceType => $serviceList) {
253 // If the (first) key of the service list is not the same as the service type,
254 // it's a "true" service type. Keep it and sort it.
255 if (key($serviceList) !== $serviceType) {
256 uasort($serviceList, array($this, 'sortServices'));
257 $filteredServices[$serviceType] = $serviceList;
258 }
259 }
260
261 return $filteredServices;
262 }
263
264 /**
265 * Utility method used to sort services according to their priority and
266 * quality.
267 *
268 * @param array $a First service to compare
269 * @param array $b Second service to compare
270 *
271 * @return integer 1, 0 or -1 if a is smaller, equal or greater than b, respectively
272 */
273 protected function sortServices(array $a, array $b) {
274 $result = 0;
275
276 // If priorities are the same, test quality
277 if ($a['priority'] == $b['priority']) {
278 if ($a['quality'] != $b['quality']) {
279 // Service with highest quality should come first,
280 // thus it must be marked as smaller
281 $result = ($a['quality'] > $b['quality']) ? -1 : 1;
282 }
283 } else {
284 // Service with highest priority should come first,
285 // thus it must be marked as smaller
286 $result = ($a['priority'] > $b['priority']) ? -1 : 1;
287 }
288
289 return $result;
290 }
291 }
292 ?>