[TASK] Re-work/simplify copyright header in PHP files - Part 2
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Messaging / FlashMessage.php
1 <?php
2 namespace TYPO3\CMS\Core\Messaging;
3
4 /**
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16 /**
17 * A class representing flash messages.
18 *
19 * @author Ingo Renner <ingo@typo3.org>
20 */
21 class FlashMessage extends \TYPO3\CMS\Core\Messaging\AbstractMessage {
22
23 /**
24 * defines whether the message should be stored in the session (to survive redirects) or only for one request (default)
25 *
26 * @var boolean
27 */
28 protected $storeInSession = FALSE;
29
30 /**
31 * @var string The message severity class names
32 */
33 protected $classes = array(
34 self::NOTICE => 'notice',
35 self::INFO => 'information',
36 self::OK => 'ok',
37 self::WARNING => 'warning',
38 self::ERROR => 'error'
39 );
40
41 /**
42 * Constructor for a flash message
43 *
44 * @param string $message The message.
45 * @param string $title Optional message title.
46 * @param integer $severity Optional severity, must be either of one of \TYPO3\CMS\Core\Messaging\FlashMessage constants
47 * @param boolean $storeInSession Optional, defines whether the message should be stored in the session or only for one request (default)
48 * @return void
49 */
50 public function __construct($message, $title = '', $severity = self::OK, $storeInSession = FALSE) {
51 $this->setMessage($message);
52 $this->setTitle($title);
53 $this->setSeverity($severity);
54 $this->setStoreInSession($storeInSession);
55 }
56
57 /**
58 * Gets the message's storeInSession flag.
59 *
60 * @return boolean TRUE if message should be stored in the session, otherwise FALSE.
61 */
62 public function isSessionMessage() {
63 return $this->storeInSession;
64 }
65
66 /**
67 * Sets the message's storeInSession flag
68 *
69 * @param boolean $storeInSession The persistence flag
70 * @return void
71 */
72 public function setStoreInSession($storeInSession) {
73 $this->storeInSession = (bool)$storeInSession;
74 }
75
76 /**
77 * Gets the message severity class name
78 *
79 * @return string The message severity class name
80 */
81 public function getClass() {
82 return 'message-' . $this->classes[$this->severity];
83 }
84
85 /**
86 * Renders the flash message.
87 *
88 * @return string The flash message as HTML.
89 */
90 public function render() {
91 $title = '';
92 if (!empty($this->title)) {
93 $title = '<div class="message-header">' . $this->title . '</div>';
94 }
95 $message = '<div class="typo3-message ' . $this->getClass() . '">' . $title . '<div class="message-body">' . $this->message . '</div>' . '</div>';
96 return $message;
97 }
98
99 }