Exemplo n.º 1
0
 /**
  *
  * @return string
  */
 public function __invoke()
 {
     if ($this->request->getQuery('msg', false) && $this->flashMessenger->hasMessages()) {
         $messages = $this->flashMessenger->getMessages();
         foreach ($messages as $message) {
             $this->flashMessenger->addInfoMessage($message);
         }
     }
     $messageString = '';
     foreach ($this->namespaces as $class => $ns) {
         $this->flashMessenger->setNamespace($ns);
         $messages = $this->flashMessenger->getMessages();
         if ($this->flashMessenger->hasCurrentMessages()) {
             $messages += $this->flashMessenger->getCurrentMessages();
             $this->flashMessenger->clearCurrentMessages();
         }
         if (count($messages) > 0) {
             // Twitter bootstrap message box
             $messageString .= sprintf('<div class="container-fluid">
                     <div class="alert alert-%s alert-dismissable fade in">
                         <button data-dismiss="alert" class="close" aria-hidden="true" type="button">x</button>
                         %s
                     </div>
                 </div>', $class, implode('<br />', $messages));
         }
     }
     return $messageString;
 }
 /**
  * Outputs message depending on flag
  *
  * @return string
  */
 public function render()
 {
     // get messages
     $allMessages = ['danger' => array_unique(array_merge($this->flashMessenger->getErrorMessages(), $this->flashMessenger->getCurrentErrorMessages())), 'success' => array_unique(array_merge($this->flashMessenger->getSuccessMessages(), $this->flashMessenger->getCurrentSuccessMessages())), 'warning' => array_unique(array_merge($this->flashMessenger->getWarningMessages(), $this->flashMessenger->getCurrentWarningMessages())), 'info' => array_unique(array_merge($this->flashMessenger->getInfoMessages(), $this->flashMessenger->getCurrentInfoMessages())), 'default' => array_unique(array_merge($this->flashMessenger->getMessages(), $this->flashMessenger->getCurrentMessages()))];
     // clear messages
     $this->flashMessenger->clearMessagesFromContainer();
     $this->flashMessenger->clearCurrentMessagesFromContainer();
     // initialize output
     $output = '';
     // loop through messages
     foreach ($allMessages as $groupKey => $groupMessages) {
         foreach ($groupMessages as $message) {
             $addClass = $groupKey == 'default' ? '' : 'alert-' . $groupKey;
             // setup view model
             $viewModel = new ViewModel();
             $viewModel->setVariable('alertClass', $addClass);
             $viewModel->setVariable('alertMessage', $message);
             $viewModel->setTemplate('zf2rapid-library/widget/bootstrap-alert');
             // add rendered output
             $output .= $this->getView()->render($viewModel);
         }
     }
     // return output
     return $output . "\n";
 }
Exemplo n.º 3
0
 /**
  * Generate flash message <div>'s with appropriate classes based on message type.
  *
  * @return string $html
  */
 public function __invoke()
 {
     $html = '';
     $namespaces = ['error', 'info', 'success'];
     foreach ($namespaces as $ns) {
         $this->fm->setNamespace($ns);
         $messages = array_merge($this->fm->getMessages(), $this->fm->getCurrentMessages());
         foreach (array_unique($messages, SORT_REGULAR) as $msg) {
             $html .= '<div class="' . $this->getClassForNamespace($ns) . '">';
             // Advanced form:
             if (is_array($msg)) {
                 // Use a different translate helper depending on whether
                 // or not we're in HTML mode.
                 if (!isset($msg['translate']) || $msg['translate']) {
                     $helper = isset($msg['html']) && $msg['html'] ? 'translate' : 'transEsc';
                 } else {
                     $helper = isset($msg['html']) && $msg['html'] ? false : 'escapeHtml';
                 }
                 $helper = $helper ? $this->getView()->plugin($helper) : false;
                 $tokens = isset($msg['tokens']) ? $msg['tokens'] : [];
                 $default = isset($msg['default']) ? $msg['default'] : null;
                 $html .= $helper ? $helper($msg['msg'], $tokens, $default) : $msg['msg'];
             } else {
                 // Basic default string:
                 $transEsc = $this->getView()->plugin('transEsc');
                 $html .= $transEsc($msg);
             }
             $html .= '</div>';
         }
         $this->fm->clearMessages();
         $this->fm->clearCurrentMessages();
     }
     return $html;
 }
 /**
  * Gets messages and removes them from storage
  *
  * @param string $type
  * @return array
  **/
 public function getMessages($type = self::MSG_ERROR)
 {
     $this->getFlashMessenger()->setNamespace($type);
     $messages = $this->_flashMessenger->getMessages();
     $currentMessages = $this->_flashMessenger->getCurrentMessages();
     $this->_flashMessenger->clearMessages();
     $this->_flashMessenger->clearCurrentMessages();
     $messages = array_merge($messages, $currentMessages);
     return $messages;
 }
 /**
  * Outputs message depending on flag
  *
  * @return string
  */
 public function __invoke()
 {
     // get messages
     $messages = array_unique(array_merge($this->flashMessenger->getMessages(), $this->flashMessenger->getCurrentMessages()));
     // initialize output
     $output = '';
     // loop through messages
     foreach ($messages as $message) {
         // create output
         $output .= '<div class="alert alert-success">';
         $output .= '<button class="close" data-dismiss="alert" type="button">×</button>';
         $output .= '<h2>' . $message . '</h2>';
         $output .= '</div>';
     }
     // clear messages
     $this->flashMessenger->clearMessages();
     $this->flashMessenger->clearCurrentMessages();
     // return output
     return $output . "\n";
 }
Exemplo n.º 6
0
 /**
  * @return  string
  */
 public function __invoke()
 {
     $messageString = '';
     foreach ($this->namespaces as $ns) {
         $this->flashMessenger->setNamespace($ns);
         $messages = $this->flashMessenger->getMessages();
         if ($this->flashMessenger->hasCurrentMessages()) {
             $messages += $this->flashMessenger->getCurrentMessages();
             $this->flashMessenger->clearCurrentMessages();
         }
         if (count($messages) > 0) {
             // Twitter bootstrap message box
             $messageString .= sprintf('<div class="messagebox alert-%s">
                     <a class="messagebox-closer" href="#close" style="display: inline;" title="Close"></a>
                     <div class="messagebox-text">%s</div>
                 </div>', $ns, implode('<br />', $messages));
         }
     }
     return $messageString;
 }
Exemplo n.º 7
0
 /**
  * Outputs message depending on flag
  *
  * @return string 
  */
 public function __invoke()
 {
     // get messages
     $messages = array_unique(array_merge($this->flashMessenger->getMessages(), $this->flashMessenger->getCurrentMessages()));
     $warning_messages = array_unique(array_merge($this->flashMessenger->getWarningMessages(), $this->flashMessenger->getCurrentWarningMessages()));
     $error_messages = array_unique(array_merge($this->flashMessenger->getErrorMessages(), $this->flashMessenger->getCurrentErrorMessages()));
     $success_messages = array_unique(array_merge($this->flashMessenger->getSuccessMessages(), $this->flashMessenger->getCurrentSuccessMessages()));
     $this->flashMessenger->getSuccessMessages();
     // initialize output
     $output = '';
     // loop through messages
     foreach ($messages as $message) {
         // create output
         $output .= '<div class="alert" role="alert">';
         $output .= $message;
         $output .= '</div>';
     }
     foreach ($error_messages as $error_message) {
         // create output
         $output .= '<div class="alert alert-danger" role="alert">';
         $output .= $error_message;
         $output .= '</div>';
     }
     foreach ($warning_messages as $warning_message) {
         // create output
         $output .= '<div class="alert alert-warning" role="alert">';
         $output .= $warning_message;
         $output .= '</div>';
     }
     foreach ($success_messages as $success_message) {
         // create output
         $output .= '<div class="alert alert-success" role="alert">';
         $output .= $success_message;
         $output .= '</div>';
     }
     // clear messages
     $this->flashMessenger->clearMessages();
     $this->flashMessenger->clearCurrentMessages();
     // return output
     return $output . "\n";
 }
 public function getCurrentMessages($type = null)
 {
     if ($type === null) {
         return parent::getCurrentMessages();
     }
     $this->setNamespace($type);
     if ($this->hasCurrentMessages()) {
         $container = $this->getContainer();
         return $container->{$this->namespace};
     }
     return array();
 }
Exemplo n.º 9
0
 /**
  * Outputs message depending on flag
  *
  * @return string 
  */
 public function __invoke()
 {
     // get messages
     $messages = array_unique(array_merge($this->flashMessenger->getMessages(), $this->flashMessenger->getCurrentMessages()));
     // initialize output
     $output = '';
     // loop through messages
     foreach ($messages as $message) {
         // split into parts to identify $class and $textDomain
         $parts = explode('_', $message);
         $class = $parts[2];
         $textDomain = $parts[0];
         // create output
         $output .= '<div class="alert alert-' . $class . '">';
         $output .= '<button class="close" data-dismiss="alert" type="button">×</button>';
         $output .= $this->getView()->translate($message, $textDomain);
         $output .= '</div>';
     }
     // clear messages
     $this->flashMessenger->clearMessages();
     $this->flashMessenger->clearCurrentMessages();
     // return output
     return $output . "\n";
 }
Exemplo n.º 10
0
 /**
  * @param bool $admin
  * @param bool $current
  * @return string
  */
 public function __invoke($admin = false, $current = false)
 {
     $prefix = $this->getHTMLPrefix($admin);
     $html = '';
     $flashMessenger = new FlashMessenger();
     foreach ($current ? $flashMessenger->getCurrentErrorMessages() : $flashMessenger->getErrorMessages() as $message) {
         $html .= $admin ? $this->renderAdminMessage($message, 'alert-error') : $this->renderAppMessage($message);
     }
     foreach ($current ? $flashMessenger->getCurrentSuccessMessages() : $flashMessenger->getSuccessMessages() as $message) {
         $html .= $admin ? $this->renderAdminMessage($message, 'alert-success') : $this->renderAppMessage($message);
     }
     foreach ($current ? $flashMessenger->getCurrentMessages() : $flashMessenger->getMessages() as $message) {
         $html .= $admin ? $this->renderAdminMessage($message, 'alert-info') : $this->renderAppMessage($message);
     }
     $postfix = $this->getHTMLPostfix($admin);
     return !empty($html) ? $prefix . $html . $postfix : '';
 }