/**
  * 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";
 }
Esempio n. 2
0
 public function __invoke()
 {
     $messages = array();
     if ($this->flashMessenger->hasMessages()) {
         $messages['common'] = $this->flashMessenger->getMessages();
     }
     if ($this->flashMessenger->hasSuccessMessages()) {
         $messages['success'] = $this->flashMessenger->getSuccessMessages();
     }
     if ($this->flashMessenger->hasInfoMessages()) {
         $messages['info'] = $this->flashMessenger->getInfoMessages();
     }
     if ($this->flashMessenger->hasErrorMessages()) {
         $messages['danger'] = $this->flashMessenger->getErrorMessages();
     }
     if ($this->flashMessenger->hasWarningMessages()) {
         $messages['warning'] = $this->flashMessenger->getWarningMessages();
     }
     return $messages;
 }
Esempio n. 3
0
 public function onBootstrap(MvcEvent $e)
 {
     $eventManager = $e->getApplication()->getEventManager();
     $moduleRouteListener = new ModuleRouteListener();
     $eventManager->attach(MvcEvent::EVENT_RENDER, function ($e) {
         $flashMessenger = new FlashMessenger();
         $messages = array_merge($flashMessenger->getSuccessMessages(), $flashMessenger->getInfoMessages(), $flashMessenger->getErrorMessages(), $flashMessenger->getMessages());
         if ($flashMessenger->hasMessages()) {
             $e->getViewModel()->setVariable('flashMessages', $messages);
         }
     });
     $eventManager->attach('route', array($this, 'onPreRoute'), 100);
     $moduleRouteListener->attach($eventManager);
 }