ed0f451f6df71bd8c8a61aecc0d4ccee31674b0c
[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 $statusProvider) {
56 $status += $statusProvider->getStatus();
57 }
58
59 $content .= '<p class="help">'
60 . $GLOBALS['LANG']->getLL('status_report_explanation')
61 . '</p>';
62
63 return $content . $this->renderStatus($status);
64 }
65
66 /**
67 * Gets all registered status providers and creates instances of them.
68 *
69 * @return void
70 */
71 protected function getStatusProviders() {
72 ksort($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports']['tx_reports']['status']);
73
74 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports']['tx_reports']['status'] as $key => $statusProvider) {
75 if (t3lib_div::inList('title,description,report', $key)) {
76 continue; // skip (for this report) unneccessary data
77 }
78
79 $statusProviderInstance = t3lib_div::makeInstance($statusProvider);
80 if ($statusProviderInstance instanceof tx_reports_StatusProvider) {
81 $this->statusProviders[$key] = $statusProviderInstance;
82 }
83 }
84 }
85
86 /**
87 * Renders a the system's status
88 *
89 * @param array An array of statuses as returned by the available status providers
90 * @return string The system status as an HTML table
91 */
92 protected function renderStatus(array $statusCollection) {
93 $content = '<table class="system-status-report">';
94 $classes = array(
95 tx_reports_reports_status_Status::NOTICE => 'notice',
96 tx_reports_reports_status_Status::INFO => 'information',
97 tx_reports_reports_status_Status::OK => 'ok',
98 tx_reports_reports_status_Status::WARNING => 'warning',
99 tx_reports_reports_status_Status::ERROR => 'error',
100 );
101
102 foreach ($statusCollection as $status) {
103 $class = 'typo3-message message-' . $classes[$status->getSeverity()];
104 $description = $status->getMessage();
105
106 if (empty($description)) {
107 $content .= '<tr><th class="'. $class .'">'. $status->getTitle() .'</th><td class="'. $class .'">'. $status->getValue() .'</td></tr>';
108 } else {
109 $content .= '<tr><th class="'. $class .' merge-down">'. $status->getTitle() .'</th><td class="'. $class .' merge-down">'. $status->getValue() .'</td></tr>';
110 $content .= '<tr><td class="'. $class .' merge-up" colspan="2">'. $description .'</td></tr>';
111 }
112 }
113
114 return $content . '</table>';
115 }
116 }
117
118
119 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/reports/reports/class.tx_reports_reports_status.php']) {
120 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/reports/reports/class.tx_reports_reports_status.php']);
121 }
122
123 ?>