user->getMessages(); $this->user->clearMessages(); Session::getSession()->write(); return $messages; } /** * The displayed alert messages * * @var array */ private $messages = array(); /** * The user to fetch the messages from * * @var User */ private $user; /** * The available states. * * @var array */ private $states = array( Zend_Log::INFO => array( 'state' => 'alert-success', 'icon' => 'success.png' ), Zend_Log::NOTICE => array( 'state' => 'alert-info', 'icon' => 'info.png' ), Zend_Log::WARN => array( 'state' => 'alert-warning', 'icon' => 'warning.png' ), Zend_Log::ERR => array( 'state' => 'alert-danger', 'icon' => 'error.png' ) ); /** * Create a new AlertBox * * @param boolean showUserMessages If the current user messages should be displayed * in this AlertMessageBox. Defaults to false */ public function __construct($showUserMessages = false) { if ($showUserMessages) { $this->user = AuthenticationManager::getInstance()->getUser(); } } /** * Add a new error * * @param $error */ public function addError($error) { $this->messages[] = new Message($error, Zend_Log::ERR); } /** * Add the error messages of the given Zend_Form */ public function addForm(Zend_Form $form) { foreach ($form->getErrorMessages() as $error) { $this->addError($error); } } /** * Output the HTML of the AlertBox * * @return string */ public function render(Zend_View_Abstract $view = null) { $html = ''; if (isset($this->user)) { $this->messages = array_merge($this->messages, $this->getAndClearMessages()); } foreach ($this->messages as $message) { $level = $message->getLevel(); if (!array_key_exists($level, $this->states)) { continue; } $alert = $this->states[$level]; $html .= '
' . $this->view()->icon($alert['icon']) . '' . htmlspecialchars($message->getMessage()) . '' . '
'; } return $html; } }