public function __invoke()
 {
     $messenger = new FlashMessenger();
     $errorMessages = $messenger->getErrorMessages();
     $messages = $messenger->getMessages();
     $result = '';
     # create error messages
     if (count($errorMessages)) {
         $result .= '<div class="alert alert-danger"> ';
         $result .= '<ul>';
         foreach ($errorMessages as $message) {
             $result .= '<li>' . $message . '</li>';
         }
         $result .= '</ul>';
         $result .= '</div>';
     }
     #create successful messages
     if (count($messages)) {
         $result .= '<div class="alert alert-success">';
         $result .= '<ul>';
         foreach ($messages as $message) {
             $result .= '<li>' . $message . '</li>';
         }
         $result .= '</ul>';
         $result .= '</div>';
     }
     return $result;
 }
 /**
  * {@inheritdoc}
  */
 public function renderCurrent($namespace = PluginFlashMessenger::NAMESPACE_DEFAULT, array $classes = [], $autoEscape = null)
 {
     $renderer = function ($namespace, $classes, $autoEscape) {
         return parent::renderCurrent($namespace, $classes, $autoEscape);
     };
     return $this->doRender($renderer, $namespace, $classes, $autoEscape);
 }
 public function seedMessages()
 {
     $helper = new FlashMessenger();
     $helper->setSessionManager($this->session);
     $helper->addMessage('foo');
     $helper->addMessage('bar');
     $helper->addInfoMessage('bar-info');
     $helper->addSuccessMessage('bar-success');
     $helper->addErrorMessage('bar-error');
     unset($helper);
 }
 public function __invoke()
 {
     $messenger = new FlashMessenger();
     $namespaces = ['default', 'success', 'error', 'warning', 'info'];
     $result = '';
     foreach ($namespaces as $namespace) {
         $messenger->setNamespace($namespace);
         if ($namespace === 'default') {
             $namespace = 'info';
         }
         if ($namespace === 'error') {
             $namespace = 'danger';
         }
         foreach ($messenger->getMessages() as $message) {
             $result .= $this->getView()->partial('partial/message', compact('message', 'namespace'));
         }
     }
     return $result;
 }
 /**
  * Create service
  *
  * @param ContainerInterface $container
  * @param string $name
  * @param null|array $options
  * @return FlashMessenger
  */
 public function __invoke(ContainerInterface $container, $name, array $options = null)
 {
     // test if we are using Zend\ServiceManager v2 or v3
     if (!method_exists($container, 'configure')) {
         $container = $container->getServiceLocator();
     }
     $helper = new FlashMessenger();
     $controllerPluginManager = $container->get('ControllerPluginManager');
     $flashMessenger = $controllerPluginManager->get('flashmessenger');
     $helper->setPluginFlashMessenger($flashMessenger);
     $config = $container->get('config');
     if (isset($config['view_helper_config']['flashmessenger'])) {
         $configHelper = $config['view_helper_config']['flashmessenger'];
         if (isset($configHelper['message_open_format'])) {
             $helper->setMessageOpenFormat($configHelper['message_open_format']);
         }
         if (isset($configHelper['message_separator_string'])) {
             $helper->setMessageSeparatorString($configHelper['message_separator_string']);
         }
         if (isset($configHelper['message_close_string'])) {
             $helper->setMessageCloseString($configHelper['message_close_string']);
         }
     }
     return $helper;
 }
Exemple #6
0
 public function __invoke()
 {
     $messenger = new FlashMessenger();
     $error_messages = $messenger->getErrorMessages();
     $messages = $messenger->getMessages();
     $result = '';
     if (count($error_messages)) {
         $result .= '<ul class="error">';
         foreach ($error_messages as $message) {
             $result .= '<li>' . $message . '</li>';
         }
         $result .= '</ul>';
     }
     if (count($messages)) {
         $result .= '<ul>';
         foreach ($messages as $message) {
             $result .= '<li>' . $message . '</li>';
         }
         $result .= '</ul>';
     }
     return $result;
 }
 public function render($namespace = ZendControllerFlashMessenger::NAMESPACE_DEFAULT, array $classes = array(), $autoEscape = null)
 {
     $this->setDefaultFlashMessengerSettings();
     $this->setMessageOpenFormat('<div%s><h4>' . $this->getTranslator()->translate('Warning', $this->getTranslatorTextDomain()) . '</h4><ul><li>');
     $default = parent::render(ZendControllerFlashMessenger::NAMESPACE_DEFAULT);
     $this->setMessageOpenFormat('<div%s><h4>' . $this->getTranslator()->translate('Error', $this->getTranslatorTextDomain()) . '</h4><ul><li>');
     $error = parent::render(ZendControllerFlashMessenger::NAMESPACE_ERROR);
     $this->setMessageOpenFormat('<div%s><h4>' . $this->getTranslator()->translate('Information', $this->getTranslatorTextDomain()) . '</h4><ul><li>');
     $info = parent::render(ZendControllerFlashMessenger::NAMESPACE_INFO);
     $this->setMessageOpenFormat('<div%s><h4>' . $this->getTranslator()->translate('Success', $this->getTranslatorTextDomain()) . '</h4><ul><li>');
     $success = parent::render(ZendControllerFlashMessenger::NAMESPACE_SUCCESS);
     $messageContainer = $default . $error . $info . $success;
     return $messageContainer;
 }
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $serviceLocator = $serviceLocator->getServiceLocator();
     $helper = new FlashMessenger();
     $controllerPluginManager = $serviceLocator->get('ControllerPluginManager');
     $flashMessenger = $controllerPluginManager->get('flashmessenger');
     $helper->setPluginFlashMessenger($flashMessenger);
     $config = $serviceLocator->get('Config');
     if (isset($config['view_helper_config']['flashmessenger'])) {
         $configHelper = $config['view_helper_config']['flashmessenger'];
         if (isset($configHelper['message_open_format'])) {
             $helper->setMessageOpenFormat($configHelper['message_open_format']);
         }
         if (isset($configHelper['message_separator_string'])) {
             $helper->setMessageSeparatorString($configHelper['message_separator_string']);
         }
         if (isset($configHelper['message_close_string'])) {
             $helper->setMessageCloseString($configHelper['message_close_string']);
         }
     }
     return $helper;
 }
 /**
  * @return string
  */
 public function __invoke()
 {
     $view = new ViewModel(array('success' => $this->flashMessenger->getSuccessMessages(), 'errors' => $this->flashMessenger->getErrorMessages(), 'infos' => $this->flashMessenger->getInfoMessages()));
     $view->setTemplate('widget/messenger');
     return $this->getView()->render($view);
 }
Exemple #10
0
 public function onRoute(EventInterface $poEvent)
 {
     $loApplication = $poEvent->getApplication();
     $loRouteMatch = $poEvent->getRouteMatch();
     $loServiceManager = $loApplication->getServiceManager();
     $loEventManager = $loApplication->getEventManager();
     $loEvents = $loEventManager->getSharedManager();
     $loSession = new Session();
     $loUser = $loSession->getRegister('OnionAuth');
     $laMenu = Config::getAppOptions('menu');
     $lsRole = Acl::DEFAULT_ROLE;
     //guest
     if ($loUser !== null) {
         $lnGroup = $loUser->get('UserGroup_id');
         if (isset($laMenu['groups'][$lnGroup])) {
             $lsRole = $laMenu['groups'][$lnGroup];
         }
     }
     $laMenu = $laMenu[$lsRole];
     $loEvents->attach('Zend\\Mvc\\Controller\\AbstractActionController', 'dispatch', function ($event) use($laMenu, $loUser) {
         $loController = $event->getTarget();
         $loController->layout()->laMenu = $laMenu;
         $loController->layout()->loUser = $loUser;
         $loController->layout()->loController = $loController;
     }, 100);
     $lsController = $loRouteMatch->getParam('__CONTROLLER__');
     $lsAction = $loRouteMatch->getParam('action');
     if (empty($lsController)) {
         $lsController = 'Index';
     }
     if (empty($lsAction)) {
         $lsAction = 'index';
     }
     $laConfigAcl = Config::getAppOptions('acl');
     $loAcl = new Acl($laConfigAcl);
     if (!$loAcl->hasResource($lsController)) {
         throw new \Exception('Resource ' . $lsController . ' not defined');
     }
     Debug::debug("Route: {$lsController}/{$lsAction}");
     if (!$loAcl->isAllowed($lsRole, $lsController, $lsAction)) {
         if ($lsController != 'Index' && $lsAction != 'index') {
             $loFlashMessenger = new FlashMessenger();
             $loFlashMessenger->addMessage(array('id' => 'Access-' . microtime(true), 'hidden' => false, 'push' => false, 'type' => 'danger', 'msg' => Translator::i18n('Você não tem permissão para executar esta ação!')));
         }
         $lsUrl = $poEvent->getRouter()->assemble(array(), array('name' => 'access', 'query' => array('urlFrom' => base64_encode($_SERVER['REQUEST_URI']))));
         $loResponse = $poEvent->getResponse();
         $loResponse->getHeaders()->addHeaderLine('Location', $lsUrl);
         $loResponse->setStatusCode(302);
         $loResponse->sendHeaders();
         exit;
     }
 }
Exemple #11
0
 /**
  * @param $eventManager
  */
 public function attachFlashMessenger($eventManager)
 {
     $eventManager->attach(MvcEvent::EVENT_RENDER, function ($e) {
         $flashMessenger = new FlashMessenger();
         $messages = [];
         $flashMessenger->setNamespace('success');
         if ($flashMessenger->hasMessages()) {
             $messages['success'] = $flashMessenger->getMessages();
         }
         $flashMessenger->clearMessages();
         $flashMessenger->setNamespace('warning');
         if ($flashMessenger->hasMessages()) {
             $messages['warning'] = $flashMessenger->getMessages();
         }
         $flashMessenger->clearMessages();
         $flashMessenger->setNamespace('danger');
         if ($flashMessenger->hasMessages()) {
             $messages['danger'] = $flashMessenger->getMessages();
         }
         $flashMessenger->clearMessages();
         $e->getViewModel()->setVariable('flashMessages', $messages);
     });
 }
Exemple #12
0
 public function onBootstrap(MvcEvent $e)
 {
     $eventManager = $e->getApplication()->getEventManager();
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->attach($eventManager);
     // Show flashmessages in the view
     $eventManager->attach(MvcEvent::EVENT_RENDER, function ($e) {
         $flashMessenger = new FlashMessenger();
         $messages = array();
         $flashMessenger->setNamespace('success');
         if ($flashMessenger->hasMessages()) {
             $messages['success'] = $flashMessenger->getMessages();
         }
         $flashMessenger->clearMessages();
         $flashMessenger->setNamespace('warning');
         if ($flashMessenger->hasMessages()) {
             $messages['warning'] = $flashMessenger->getMessages();
         }
         $flashMessenger->clearMessages();
         $flashMessenger->setNamespace('danger');
         if ($flashMessenger->hasMessages()) {
             $messages['danger'] = $flashMessenger->getMessages();
         }
         $flashMessenger->clearMessages();
         $e->getViewModel()->setVariable('flashMessages', $messages);
     });
 }