* @category class * @package core * @subpackage business * @copyright 2005-2017 Titan Framework * @license http://www.titanframework.com/license/ BSD License (3 Clause) * @see Instance, Business, Action, Section */ class Message { static private $message = FALSE; private $array = array (); private $cont = 0; const TEXT = 0; const HTML = 1; const SUCCESS = 'SUCCESS'; const INFO = 'INFO'; const ALERT = 'ALERT'; const WARNING = 'WARNING'; // Legacy const MESSAGE = self::SUCCESS; private final function __construct () { $this->load (); } static public function singleton () { if (self::$message !== FALSE) return self::$message; $class = __CLASS__; self::$message = new $class (); return self::$message; } public function save () { $_SESSION['CACHE_MESSAGES'] = serialize ($this->array); } public function load () { if (isset ($_SESSION['CACHE_MESSAGES'])) $this->array = unserialize ($_SESSION['CACHE_MESSAGES']); } public function add ($type, $message) { if (trim ($message) != '' && in_array ($type, array (self::SUCCESS, self::INFO, self::ALERT, self::WARNING))) $this->array [] = array ($type, $message); } public function addMessage ($message) { if (trim ($message) != '') $this->array [] = array (self::SUCCESS, $message); } public function addWarning ($warning) { if (trim ($warning) != '') $this->array [] = array (self::WARNING, $warning); } public function get ($type = self::HTML) { if (!array_key_exists ($this->cont, $this->array)) return NULL; $key = $this->cont++; if ($type == self::TEXT) return $this->array [$key][1]; switch ($this->array [$key][0]) { case self::SUCCESS: return '
'. $this->array [$key][1] .'
'; case self::INFO: return '
'. $this->array [$key][1] .'
'; case self::WARNING: return '
'. $this->array [$key][1] .'array [$key][1])) .'\');">'. __ ('Technical issue?') .'
'; case self::ALERT: default: return '
'. $this->array [$key][1] .'
'; } } public function has () { return sizeof ($this->array); } public function clear () { $this->array = array (); unset ($_SESSION['CACHE_MESSAGES']); } }