2 /***************************************************************
5 * (c) 2009-2010 Ingo Renner <ingo@typo3.org>
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.
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
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.
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
29 * @author Ingo Renner <ingo@typo3.org>
35 class tx_reports_reports_Status
implements tx_reports_Report
{
37 protected $statusProviders = array();
40 * Constructor for class tx_reports_report_Status
42 public function __construct() {
43 $this->getStatusProviders();
45 $GLOBALS['LANG']->includeLLFile('EXT:reports/reports/locallang.xml');
49 * Takes care of creating / rendering the status report
51 * @return string The status report as HTML
53 public function getReport() {
56 foreach ($this->statusProviders
as $statusProviderId => $statusProvidersList) {
57 $status[$statusProviderId] = array();
58 foreach ($statusProvidersList as $statusProvider) {
59 $statuses = $statusProvider->getStatus();
60 $status[$statusProviderId] = array_merge($status[$statusProviderId], $statuses);
64 $status = $this->getSystemStatus();
65 $highestSeverity = $this->getHighestSeverity($status);
67 // updating the registry
68 $registry = t3lib_div
::makeInstance('t3lib_Registry');
69 $registry->set('tx_reports', 'status.highestSeverity', $highestSeverity);
71 $content .= '<p class="help">'
72 . $GLOBALS['LANG']->getLL('status_report_explanation')
75 return $content . $this->renderStatus($status);
79 * Gets all registered status providers and creates instances of them.
82 protected function getStatusProviders() {
83 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports']['tx_reports']['status']['providers'] as $key => $statusProvidersList) {
84 $this->statusProviders
[$key] = array();
86 foreach ($statusProvidersList as $statusProvider) {
87 $statusProviderInstance = t3lib_div
::makeInstance($statusProvider);
89 if ($statusProviderInstance instanceof tx_reports_StatusProvider
) {
90 $this->statusProviders
[$key][] = $statusProviderInstance;
97 * Runs through all status providers and returns all statuses collected.
99 * @return array An array of tx_reports_reports_status_Status objects
101 public function getSystemStatus() {
104 foreach ($this->statusProviders
as $statusProviderId => $statusProviderList) {
105 $status[$statusProviderId] = array();
107 foreach ($statusProviderList as $statusProvider) {
108 $statuses = $statusProvider->getStatus();
109 $status[$statusProviderId] = array_merge($status[$statusProviderId], $statuses);
117 * Determines the highest severity from the given statuses.
119 * @param array An array of tx_reports_reports_status_Status objects.
120 * @return integer The highest severity found from the statuses.
122 public function getHighestSeverity(array $statusCollection) {
123 $highestSeverity = tx_reports_reports_status_Status
::NOTICE
;
125 foreach ($statusCollection as $statusProvider => $providerStatuses) {
126 foreach ($providerStatuses as $status) {
127 if ($status->getSeverity() > $highestSeverity) {
128 $highestSeverity = $status->getSeverity();
131 // reached the highest severity level, no need to go on
132 if ($highestSeverity == tx_reports_reports_status_Status
::ERROR
) {
138 return $highestSeverity;
142 * Renders the system's status
144 * @param array An array of statuses as returned by the available status providers
145 * @return string The system status as an HTML table
147 protected function renderStatus(array $statusCollection) {
149 // TODO refactor into separate methods, status list and single status
153 <div class="typo3-message message-###CLASS###">
154 <div class="header-container">
155 <div class="message-header message-left">###HEADER###</div>
156 <div class="message-header message-right">###STATUS###</div>
158 <div class="message-body">###CONTENT###</div>
161 $statuses = $this->sortStatusProviders($statusCollection);
163 foreach($statuses as $provider => $providerStatus) {
164 $providerState = $this->sortStatuses($providerStatus);
166 $id = str_replace(' ', '-', $provider);
167 if (isset($GLOBALS['BE_USER']->uc
['reports']['states'][$id]) && $GLOBALS['BE_USER']->uc
['reports']['states'][$id]) {
168 $collapsedStyle = 'style="display: none"';
169 $collapsedClass = 'collapsed';
171 $collapsedStyle = '';
172 $collapsedClass = 'expanded';
176 tx_reports_reports_status_Status
::NOTICE
=> 'notice',
177 tx_reports_reports_status_Status
::INFO
=> 'information',
178 tx_reports_reports_status_Status
::OK
=> 'ok',
179 tx_reports_reports_status_Status
::WARNING
=> 'warning',
180 tx_reports_reports_status_Status
::ERROR
=> 'error',
183 $icon[tx_reports_reports_status_Status
::WARNING
] = t3lib_iconWorks
::getSpriteIcon('status-dialog-warning');
184 $icon[tx_reports_reports_status_Status
::ERROR
] = t3lib_iconWorks
::getSpriteIcon('status-dialog-error');
187 $sectionSeverity = 0;
189 foreach ($providerState as $status) {
190 $severity = $status->getSeverity();
191 $sectionSeverity = $severity > $sectionSeverity ?
$severity : $sectionSeverity;
192 $messages .= strtr($template, array(
193 '###CLASS###' => $classes[$severity],
194 '###HEADER###' => $status->getTitle(),
195 '###STATUS###' => $status->getValue(),
196 '###CONTENT###' => $status->getMessage(),
199 if ($sectionSeverity > 0) {
200 $headerIcon = $icon[$sectionSeverity];
202 $content .= '<h2 id="' . $id . '" class="section-header ' . $collapsedClass . '">' . $headerIcon . $provider . '</h2>
203 <div ' . $collapsedStyle . '>' . $messages . '</div>';
209 * Sorts the status providers (alphabetically and puts primary status providers at the beginning)
211 * @param array A collection of statuses (with providers)
212 * @return array The collection of statuses sorted by provider (beginning with provider "_install")
214 protected function sortStatusProviders(array $statusCollection) {
215 // Extract the primary status collections, i.e. the status groups
216 // that must appear on top of the status report
217 // Change their keys to localized collection titles
218 $primaryStatuses = array(
219 $GLOBALS['LANG']->getLL('status_typo3') => $statusCollection['typo3'],
220 $GLOBALS['LANG']->getLL('status_system') => $statusCollection['system'],
221 $GLOBALS['LANG']->getLL('status_security') => $statusCollection['security'],
222 $GLOBALS['LANG']->getLL('status_configuration') => $statusCollection['configuration']
225 $statusCollection['typo3'],
226 $statusCollection['system'],
227 $statusCollection['security'],
228 $statusCollection['configuration']
231 // Assemble list of secondary status collections with left-over collections
232 // Change their keys using localized labels if available
233 // TODO extract into getLabel() method
234 $secondaryStatuses = array();
235 foreach ($statusCollection as $statusProviderId => $collection) {
238 if (strpos($statusProviderId, 'LLL:') === 0) {
239 // Label provided by extension
240 $label = $GLOBALS['LANG']->sL($statusProviderId);
243 $label = $GLOBALS['LANG']->getLL('status_' . $statusProviderId);
246 $providerLabel = (empty($label)) ?
$statusProviderId : $label;
247 $secondaryStatuses[$providerLabel] = $collection;
249 // Sort the secondary status collections alphabetically
250 ksort($secondaryStatuses);
251 $orderedStatusCollection = array_merge($primaryStatuses, $secondaryStatuses);
253 return $orderedStatusCollection;
257 * Sorts the statuses by severity
259 * @param array A collection of statuses per provider
260 * @return array The collection of statuses sorted by severity
262 protected function sortStatuses(array $statusCollection) {
264 $sortTitle = array();
266 foreach ($statusCollection as $status) {
267 if ($status->getTitle() === 'TYPO3') {
272 $statuses[] = $status;
273 $sortTitle[] = $status->getSeverity();
275 array_multisort($sortTitle, SORT_DESC
, $statuses);
277 // making sure that the core version information is always on the top
278 if (is_object($header)) {
279 array_unshift($statuses, $header);
285 * Saves the section toggle state in the backend user's uc.
287 * @param array Array of parameters from the AJAX interface, currently unused
288 * @param TYPO3AJAX Object of type TYPO3AJAX
291 public function saveCollapseState(array $params, TYPO3AJAX
$ajaxObj) {
292 $item = t3lib_div
::_POST('item');
293 $state = (bool)t3lib_div
::_POST('state');
295 $GLOBALS['BE_USER']->uc
['reports']['states'][$item] = $state;
296 $GLOBALS['BE_USER']->writeUC();
301 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['ext/reports/reports/class.tx_reports_reports_status.php']) {
302 include_once($TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['ext/reports/reports/class.tx_reports_reports_status.php']);