[BUGFIX][reports] Missing check for SOAP extension
[Packages/TYPO3.CMS.git] / typo3 / sysext / reports / reports / class.tx_reports_reports_status.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009-2011 Ingo Renner <ingo@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 /**
27 * The status report
28 *
29 * @author Ingo Renner <ingo@typo3.org>
30 * @package TYPO3
31 * @subpackage reports
32 */
33 class tx_reports_reports_Status implements tx_reports_Report {
34
35 protected $statusProviders = array();
36
37 /**
38 * Constructor for class tx_reports_report_Status
39 */
40 public function __construct() {
41 $this->getStatusProviders();
42
43 $GLOBALS['LANG']->includeLLFile('EXT:reports/reports/locallang.xml');
44 }
45
46 /**
47 * Takes care of creating / rendering the status report
48 *
49 * @return string The status report as HTML
50 */
51 public function getReport() {
52 $content = '';
53
54 foreach ($this->statusProviders as $statusProviderId => $statusProvidersList) {
55 $status[$statusProviderId] = array();
56 foreach ($statusProvidersList as $statusProvider) {
57 $statuses = $statusProvider->getStatus();
58 $status[$statusProviderId] = array_merge($status[$statusProviderId], $statuses);
59 }
60 }
61
62 $status = $this->getSystemStatus();
63 $highestSeverity = $this->getHighestSeverity($status);
64
65 // updating the registry
66 $registry = t3lib_div::makeInstance('t3lib_Registry');
67 $registry->set('tx_reports', 'status.highestSeverity', $highestSeverity);
68
69 $content .= '<p class="help">'
70 . $GLOBALS['LANG']->getLL('status_report_explanation')
71 . '</p>';
72
73 return $content . $this->renderStatus($status);
74 }
75
76 /**
77 * Gets all registered status providers and creates instances of them.
78 *
79 */
80 protected function getStatusProviders() {
81 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports']['tx_reports']['status']['providers'] as $key => $statusProvidersList) {
82 $this->statusProviders[$key] = array();
83
84 foreach ($statusProvidersList as $statusProvider) {
85 $statusProviderInstance = t3lib_div::makeInstance($statusProvider);
86
87 if ($statusProviderInstance instanceof tx_reports_StatusProvider) {
88 $this->statusProviders[$key][] = $statusProviderInstance;
89 }
90 }
91 }
92 }
93
94 /**
95 * Runs through all status providers and returns all statuses collected.
96 *
97 * @return array An array of tx_reports_reports_status_Status objects
98 */
99 public function getSystemStatus() {
100 $status = array();
101
102 foreach ($this->statusProviders as $statusProviderId => $statusProviderList) {
103 $status[$statusProviderId] = array();
104
105 foreach ($statusProviderList as $statusProvider) {
106 $statuses = $statusProvider->getStatus();
107 $status[$statusProviderId] = array_merge($status[$statusProviderId], $statuses);
108 }
109 }
110
111 return $status;
112 }
113
114 /**
115 * Determines the highest severity from the given statuses.
116 *
117 * @param array An array of tx_reports_reports_status_Status objects.
118 * @return integer The highest severity found from the statuses.
119 */
120 public function getHighestSeverity(array $statusCollection) {
121 $highestSeverity = tx_reports_reports_status_Status::NOTICE;
122
123 foreach ($statusCollection as $statusProvider => $providerStatuses) {
124 foreach ($providerStatuses as $status) {
125 if ($status->getSeverity() > $highestSeverity) {
126 $highestSeverity = $status->getSeverity();
127 }
128
129 // reached the highest severity level, no need to go on
130 if ($highestSeverity == tx_reports_reports_status_Status::ERROR) {
131 break;
132 }
133 }
134 }
135
136 return $highestSeverity;
137 }
138
139 /**
140 * Renders the system's status
141 *
142 * @param array An array of statuses as returned by the available status providers
143 * @return string The system status as an HTML table
144 */
145 protected function renderStatus(array $statusCollection) {
146
147 // TODO refactor into separate methods, status list and single status
148
149 $content = '';
150 $template = '
151 <div class="typo3-message message-###CLASS###">
152 <div class="header-container">
153 <div class="message-header message-left">###HEADER###</div>
154 <div class="message-header message-right">###STATUS###</div>
155 </div>
156 <div class="message-body">###CONTENT###</div>
157 </div>';
158
159 $statuses = $this->sortStatusProviders($statusCollection);
160
161 foreach($statuses as $provider => $providerStatus) {
162 $providerState = $this->sortStatuses($providerStatus);
163
164 $id = str_replace(' ', '-', $provider);
165 $classes = array(
166 tx_reports_reports_status_Status::NOTICE => 'notice',
167 tx_reports_reports_status_Status::INFO => 'information',
168 tx_reports_reports_status_Status::OK => 'ok',
169 tx_reports_reports_status_Status::WARNING => 'warning',
170 tx_reports_reports_status_Status::ERROR => 'error',
171 );
172
173 $icon[tx_reports_reports_status_Status::WARNING] = t3lib_iconWorks::getSpriteIcon('status-dialog-warning');
174 $icon[tx_reports_reports_status_Status::ERROR] = t3lib_iconWorks::getSpriteIcon('status-dialog-error');
175 $messages = '';
176 $headerIcon = '';
177 $sectionSeverity = 0;
178
179 foreach ($providerState as $status) {
180 $severity = $status->getSeverity();
181 $sectionSeverity = $severity > $sectionSeverity ? $severity : $sectionSeverity;
182 $messages .= strtr($template, array(
183 '###CLASS###' => $classes[$severity],
184 '###HEADER###' => $status->getTitle(),
185 '###STATUS###' => $status->getValue(),
186 '###CONTENT###' => $status->getMessage(),
187 ));
188 }
189 if ($sectionSeverity > 0) {
190 $headerIcon = $icon[$sectionSeverity];
191 }
192 $content .= $GLOBALS['TBE_TEMPLATE']->collapseableSection($headerIcon . $provider, $messages, $id, 'reports.states');
193 }
194
195 return $content;
196 }
197
198 /**
199 * Sorts the status providers (alphabetically and puts primary status providers at the beginning)
200 *
201 * @param array A collection of statuses (with providers)
202 * @return array The collection of statuses sorted by provider (beginning with provider "_install")
203 */
204 protected function sortStatusProviders(array $statusCollection) {
205 // Extract the primary status collections, i.e. the status groups
206 // that must appear on top of the status report
207 // Change their keys to localized collection titles
208 $primaryStatuses = array(
209 $GLOBALS['LANG']->getLL('status_typo3') => $statusCollection['typo3'],
210 $GLOBALS['LANG']->getLL('status_system') => $statusCollection['system'],
211 $GLOBALS['LANG']->getLL('status_security') => $statusCollection['security'],
212 $GLOBALS['LANG']->getLL('status_configuration') => $statusCollection['configuration']
213 );
214 unset(
215 $statusCollection['typo3'],
216 $statusCollection['system'],
217 $statusCollection['security'],
218 $statusCollection['configuration']
219 );
220
221 // Assemble list of secondary status collections with left-over collections
222 // Change their keys using localized labels if available
223 // TODO extract into getLabel() method
224 $secondaryStatuses = array();
225 foreach ($statusCollection as $statusProviderId => $collection) {
226 $label = '';
227
228 if (strpos($statusProviderId, 'LLL:') === 0) {
229 // Label provided by extension
230 $label = $GLOBALS['LANG']->sL($statusProviderId);
231 } else {
232 // Generic label
233 $label = $GLOBALS['LANG']->getLL('status_' . $statusProviderId);
234 }
235
236 $providerLabel = (empty($label)) ? $statusProviderId : $label;
237 $secondaryStatuses[$providerLabel] = $collection;
238 }
239 // Sort the secondary status collections alphabetically
240 ksort($secondaryStatuses);
241 $orderedStatusCollection = array_merge($primaryStatuses, $secondaryStatuses);
242
243 return $orderedStatusCollection;
244 }
245
246 /**
247 * Sorts the statuses by severity
248 *
249 * @param array A collection of statuses per provider
250 * @return array The collection of statuses sorted by severity
251 */
252 protected function sortStatuses(array $statusCollection) {
253 $statuses = array();
254 $sortTitle = array();
255
256 foreach ($statusCollection as $status) {
257 if ($status->getTitle() === 'TYPO3') {
258 $header = $status;
259 continue;
260 }
261
262 $statuses[] = $status;
263 $sortTitle[] = $status->getSeverity();
264 }
265 array_multisort($sortTitle, SORT_DESC, $statuses);
266
267 // making sure that the core version information is always on the top
268 if (is_object($header)) {
269 array_unshift($statuses, $header);
270 }
271 return $statuses;
272 }
273
274 }
275
276
277 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/reports/reports/class.tx_reports_reports_status.php'])) {
278 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/reports/reports/class.tx_reports_reports_status.php']);
279 }
280
281 ?>