Fixed bug #12025: Make statuses in the status report sorted and grouped
[Packages/TYPO3.CMS.git] / typo3 / sysext / reports / reports / class.tx_reports_reports_status.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009 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 $status = array();
53 $content = '';
54
55 foreach ($this->statusProviders as $statusProviderId => $statusProvider) {
56 if (strcmp(substr($statusProviderId, 0, 4), 'LLL:')) {
57 $providerLabel = $GLOBALS['LANG']->getLL('status_' . $statusProviderId);
58 } else {
59 // label from extension
60 $providerLabel = $GLOBALS['LANG']->sL($statusProviderId);
61 }
62 $provider = $providerLabel ? $providerLabel : $statusProviderId;
63 $status[$provider] = $statusProvider->getStatus();
64 }
65
66 $content .= '<p class="help">'
67 . $GLOBALS['LANG']->getLL('status_report_explanation')
68 . '</p>';
69
70 return $content . $this->renderStatus($status);
71 }
72
73 /**
74 * Gets all registered status providers and creates instances of them.
75 *
76 * @return void
77 */
78 protected function getStatusProviders() {
79 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports']['tx_reports']['status'] as $key => $statusProvider) {
80 if (t3lib_div::inList('title,description,report', $key)) {
81 continue; // skip (for this report) unneccessary data
82 }
83
84 $statusProviderInstance = t3lib_div::makeInstance($statusProvider);
85 if ($statusProviderInstance instanceof tx_reports_StatusProvider) {
86 $this->statusProviders[$key] = $statusProviderInstance;
87 }
88 }
89 }
90
91 /**
92 * Renders the system's status
93 *
94 * @param array An array of statuses as returned by the available status providers
95 * @return string The system status as an HTML table
96 */
97 protected function renderStatus(array $statusCollection) {
98 $content = '';
99
100 $statuses = $this->sortStatusProviders($statusCollection);
101
102 foreach($statuses as $provider => $providerStatus) {
103 $providerState = $this->sortStatuses($providerStatus);
104
105 $content .= '<h2>' . $provider . '</h2>';
106 $content .= '<table class="system-status-report">';
107 $classes = array(
108 tx_reports_reports_status_Status::NOTICE => 'notice',
109 tx_reports_reports_status_Status::INFO => 'information',
110 tx_reports_reports_status_Status::OK => 'ok',
111 tx_reports_reports_status_Status::WARNING => 'warning',
112 tx_reports_reports_status_Status::ERROR => 'error',
113 );
114
115 foreach ($providerState as $status) {
116 $class = 'typo3-message message-' . $classes[$status->getSeverity()];
117 $description = $status->getMessage();
118
119 if (empty($description)) {
120 $content .= '<tr><th class="'. $class .' statusTitle">'. $status->getTitle() .'</th><td class="'. $class .'">'. $status->getValue() .'</td></tr>';
121 } else {
122 $content .= '<tr><th class="'. $class .' merge-down">'. $status->getTitle() .'</th><td class="'. $class .' merge-down">'. $status->getValue() .'</td></tr>';
123 $content .= '<tr><td class="'. $class .' merge-up" colspan="2">'. $description .'</td></tr>';
124 }
125 }
126
127 $content .= '</table>';
128 }
129 return $content;
130 }
131
132 /**
133 * sorts the status providers (alphabetically and adds "_install" provider at the beginning)
134 *
135 * @param array A collection of statuses (with providers)
136 * @return array The collection of statuses sorted by provider (beginning with provider "_install")
137 */
138 protected function sortStatusProviders(array $statusCollection) {
139 $systemStatus = array(
140 'TYPO3 System' => $statusCollection['Installation'],
141 'System' => $statusCollection['System'],
142 'Security' => $statusCollection['security'],
143 'Configuration' => $statusCollection['configuration'],
144 );
145 unset(
146 $statusCollection['Installation'],
147 $statusCollection['System'],
148 $statusCollection['security'],
149 $statusCollection['configuration']
150 );
151 ksort($statusCollection);
152 $statusCollection = array_merge($systemStatus, $statusCollection);
153
154 return $statusCollection;
155 }
156
157 /**
158 * Sorts the statuses by severity
159 *
160 * @param array A collection of statuses per provider
161 * @return array The collection of statuses sorted by severity
162 */
163 protected function sortStatuses(array $statusCollection) {
164 $statuses = array();
165 $sortTitle = array();
166
167 foreach ($statusCollection as $status) {
168 if ($status->getTitle() === 'TYPO3') {
169 $header = $status;
170 continue;
171 }
172
173 $statuses[] = $status;
174 $sortTitle[] = $status->getSeverity();
175 }
176 array_multisort($sortTitle, SORT_DESC, $statuses);
177
178 // making sure that the core version information is always on the top
179 if(is_object($header)) {
180 array_unshift($statuses, $header);
181 }
182 return $statuses;
183 }
184 }
185
186
187 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/reports/reports/class.tx_reports_reports_status.php']) {
188 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/reports/reports/class.tx_reports_reports_status.php']);
189 }
190
191 ?>