TYPO3 API  SVNRelease
class.tx_reports_reports_status_status.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 2009-2011 Ingo Renner <ingo@typo3.org>
00006 *  All rights reserved
00007 *
00008 *  This script is part of the TYPO3 project. The TYPO3 project is
00009 *  free software; you can redistribute it and/or modify
00010 *  it under the terms of the GNU General Public License as published by
00011 *  the Free Software Foundation; either version 2 of the License, or
00012 *  (at your option) any later version.
00013 *
00014 *  The GNU General Public License can be found at
00015 *  http://www.gnu.org/copyleft/gpl.html.
00016 *
00017 *  This script is distributed in the hope that it will be useful,
00018 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 *  GNU General Public License for more details.
00021 *
00022 *  This copyright notice MUST APPEAR in all copies of the script!
00023 ***************************************************************/
00024 
00025 
00026 /**
00027  * A class representing a certain status
00028  *
00029  * @author      Ingo Renner <ingo@typo3.org>
00030  * @package     TYPO3
00031  * @subpackage  reports
00032  *
00033  * $Id: class.tx_reports_reports_status_status.php 10120 2011-01-18 20:03:36Z ohader $
00034  */
00035 class tx_reports_reports_status_Status {
00036 
00037     const NOTICE  = -2;
00038     const INFO    = -1;
00039     const OK      = 0;
00040     const WARNING = 1;
00041     const ERROR   = 2;
00042 
00043     protected $title;
00044     protected $value;
00045     protected $message;
00046     protected $severity;
00047 
00048     /**
00049      * constructor for class tx_reports_report_status_Status
00050      *
00051      * @param   string  the status' title
00052      * @param   string  the status' value
00053      * @param   string  an optional message further describing the status
00054      * @param   integer a severity level, one of
00055      */
00056     public function __construct($title, $value, $message = '', $severity = self::OK) {
00057         $this->title    = (string) $title;
00058         $this->value    = (string) $value;
00059         $this->message  = (string) $message;
00060 
00061         $this->severity = t3lib_div::intInRange(
00062             $severity,
00063             self::NOTICE, self::ERROR, self::OK
00064         );
00065     }
00066 
00067     /**
00068      * gets the status' title
00069      *
00070      * @return  string
00071      */
00072     public function getTitle() {
00073         return $this->title;
00074     }
00075 
00076     /**
00077      * gets the status' value
00078      *
00079      * @return  string
00080      */
00081     public function getValue() {
00082         return $this->value;
00083     }
00084 
00085     /**
00086      * gets the status' message (if any)
00087      *
00088      * @return  string
00089      */
00090     public function getMessage() {
00091         return $this->message;
00092     }
00093 
00094     /**
00095      * gets the status' severity
00096      *
00097      * @return  integer
00098      */
00099     public function getSeverity() {
00100         return $this->severity;
00101     }
00102 
00103     /**
00104      * Creates a string representation of a status.
00105      *
00106      * @return  string  String representation of this status.
00107      */
00108     public function __toString() {
00109         $severity = array(
00110             self::NOTICE  => 'NOTE',
00111             self::INFO    => 'INFO',
00112             self::OK      => 'OK',
00113             self::WARNING => 'WARN',
00114             self::ERROR   => 'ERR',
00115         );
00116 
00117             // max length 80 characters
00118         $stringRepresentation =
00119             str_pad('[' . $severity[$this->severity] . ']', 7) .
00120             str_pad($this->title, 40) . ' - ' .
00121             substr($this->value, 0, 30);
00122 
00123         return $stringRepresentation;
00124     }
00125 }
00126 
00127 
00128 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/reports/reports/status/class.tx_reports_reports_status_status.php'])) {
00129     include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/reports/reports/status/class.tx_reports_reports_status_status.php']);
00130 }
00131 
00132 ?>