[TASK] Move and Namespace classes
[Packages/TYPO3.CMS.git] / typo3 / sysext / reports / Classes / Status.php
1 <?php
2 namespace TYPO3\CMS\Reports;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2009-2011 Ingo Renner <ingo@typo3.org>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26 /**
27 * A class representing a certain status
28 *
29 * @author Ingo Renner <ingo@typo3.org>
30 * @package TYPO3
31 * @subpackage reports
32 */
33 class Status {
34
35 const NOTICE = -2;
36 const INFO = -1;
37 const OK = 0;
38 const WARNING = 1;
39 const ERROR = 2;
40 /**
41 * @var string
42 */
43 protected $title;
44
45 /**
46 * @var string
47 */
48 protected $value;
49
50 /**
51 * @var string
52 */
53 protected $message;
54
55 /**
56 * @var integer
57 */
58 protected $severity;
59
60 /**
61 * constructor for class tx_reports_report_status_Status
62 *
63 * @param string $title The status' title
64 * @param string $value The status' value
65 * @param string $message An optional message further describing the status
66 * @param integer $severity A severity level, one of
67 */
68 public function __construct($title, $value, $message = '', $severity = self::OK) {
69 $this->title = (string) $title;
70 $this->value = (string) $value;
71 $this->message = (string) $message;
72 $this->severity = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($severity, self::NOTICE, self::ERROR, self::OK);
73 }
74
75 /**
76 * Gets the status' title
77 *
78 * @return string
79 */
80 public function getTitle() {
81 return $this->title;
82 }
83
84 /**
85 * Gets the status' value
86 *
87 * @return string
88 */
89 public function getValue() {
90 return $this->value;
91 }
92
93 /**
94 * Gets the status' message (if any)
95 *
96 * @return string
97 */
98 public function getMessage() {
99 return $this->message;
100 }
101
102 /**
103 * Gets the status' severity
104 *
105 * @return integer
106 */
107 public function getSeverity() {
108 return $this->severity;
109 }
110
111 /**
112 * Creates a string representation of a status.
113 *
114 * @return string String representation of this status.
115 */
116 public function __toString() {
117 $severity = array(
118 self::NOTICE => 'NOTE',
119 self::INFO => 'INFO',
120 self::OK => 'OK',
121 self::WARNING => 'WARN',
122 self::ERROR => 'ERR'
123 );
124 // Max length 80 characters
125 $stringRepresentation = ((str_pad((('[' . $severity[$this->severity]) . ']'), 7) . str_pad($this->title, 40)) . ' - ') . substr($this->value, 0, 30);
126 return $stringRepresentation;
127 }
128
129 }
130
131
132 ?>