[FEATURE] Add wincache as a cache backend
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_flashmessage.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009-2011 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 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28
29 /**
30 * A class representing flash messages.
31 *
32 * @author Ingo Renner <ingo@typo3.org>
33 * @package TYPO3
34 * @subpackage t3lib
35 */
36 class t3lib_FlashMessage extends t3lib_message_AbstractMessage {
37
38 /**
39 * defines whether the message should be stored in the session (to survive redirects) or only for one request (default)
40 *
41 * @var boolean
42 */
43 protected $storeInSession = FALSE;
44
45 /**
46 * @var string The message severity class names
47 */
48 protected $classes = array(
49 self::NOTICE => 'notice',
50 self::INFO => 'information',
51 self::OK => 'ok',
52 self::WARNING => 'warning',
53 self::ERROR => 'error',
54 );
55
56 /**
57 * Constructor for a flash message
58 *
59 * @param string $message The message.
60 * @param string $title Optional message title.
61 * @param integer $severity Optional severity, must be either of t3lib_FlashMessage::INFO, t3lib_FlashMessage::OK,
62 * t3lib_FlashMessage::WARNING or t3lib_FlashMessage::ERROR. Default is t3lib_FlashMessage::OK.
63 * @param boolean $storeInSession Optional, defines whether the message should be stored in the session or only for one request (default)
64 * @return void
65 */
66 public function __construct($message, $title = '', $severity = self::OK, $storeInSession = FALSE) {
67 $this->setMessage($message);
68 $this->setTitle($title);
69 $this->setSeverity($severity);
70 $this->setStoreInSession($storeInSession);
71 }
72
73 /**
74 * Gets the message's storeInSession flag.
75 *
76 * @return boolean TRUE if message should be stored in the session, otherwise FALSE.
77 */
78 public function isSessionMessage() {
79 return $this->storeInSession;
80 }
81
82 /**
83 * Sets the message's storeInSession flag
84 *
85 * @param boolean The persistence flag
86 * @return void
87 */
88 public function setStoreInSession($storeInSession) {
89 $this->storeInSession = (bool) $storeInSession;
90 }
91
92 /**
93 * Gets the message severity class name
94 *
95 * @return string The message severity class name
96 */
97 public function getClass() {
98 return 'message-' . $this->classes[$this->severity];
99 }
100
101 /**
102 * Renders the flash message.
103 *
104 * @return string The flash message as HTML.
105 */
106 public function render() {
107 $title = '';
108 if (!empty($this->title)) {
109 $title = '<div class="message-header">' . $this->title . '</div>';
110 }
111
112 $message = '<div class="typo3-message ' . $this->getClass() . '">'
113 . $title
114 . '<div class="message-body">' . $this->message . '</div>'
115 . '</div>';
116
117 return $message;
118 }
119 }
120
121 ?>