示例#1
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;
 }
示例#2
0
 /**
  * @return \Zend\Http\Response|ViewModel
  */
 public function loginAction()
 {
     $data = $this->getRequest()->getPost();
     $form = new Form\LoginForm(null, $this->getServiceLocator());
     $flashMessenger = new FlashMessenger();
     if ($this->getRequest()->isPost()) {
         // If you used another name for the authentication service, change it here
         $form->setData($this->getRequest()->getPost());
         if ($form->isValid()) {
             /**
              * @var \User\Service\Auth $userAuth
              */
             $userAuth = $this->getServiceLocator()->get('\\User\\Service\\Auth');
             try {
                 $userAuth->authenticateEquals($data['email'], $data['password']);
                 $flashMessenger->addSuccessMessage('You\'re successfully logged in');
                 $session = new Container('location');
                 $location = $session->location;
                 if ($location) {
                     $session->getManager()->getStorage()->clear('location');
                     return $this->redirect()->toUrl($location);
                 }
                 return $this->redirect()->toRoute('home');
             } catch (AuthException $exception) {
                 $flashMessenger->addErrorMessage($exception->getMessage());
             }
         }
     }
     return new ViewModel(array('form' => $form, 'serviceLocator' => $this->getServiceLocator()));
 }
示例#3
0
 public function testInvoke_WithIncludeCurrentMessages()
 {
     $this->flashMessenger->addErrorMessage('ErrorMessage1')->addInfoMessage('InfoMessage2')->addSuccessMessage('SuccessMessage3')->addWarningMessage('WarningMessage4')->addMessage('Message5');
     $result = $this->testedObject->__invoke(true);
     $expected = [FlashMessenger::NAMESPACE_ERROR => ['ErrorMessage1'], FlashMessenger::NAMESPACE_SUCCESS => ['SuccessMessage3'], FlashMessenger::NAMESPACE_INFO => ['InfoMessage2'], FlashMessenger::NAMESPACE_WARNING => ['WarningMessage4'], FlashMessenger::NAMESPACE_DEFAULT => ['Message5']];
     $this->assertSame($expected, $result);
 }
 /**
  * @test
  * @covers \Authentication\Controller\IndexController::indexAction()
  * @dataProvider getListPostInValid2
  */
 public function indexActionValidPost1($arrMessage, $arrDataPost)
 {
     $this->dispatch('/authentication', HttpRequest::METHOD_POST, $arrDataPost);
     $flashMessager = new FlashMessenger();
     $arrMessages = $flashMessager->getMessages();
     $this->assertSame($arrMessages[0]['danger'][0], $arrMessage[0]);
     $this->assertSame($arrMessages[1]['danger'][0], $arrMessage[1]);
 }
 /**
  * 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;
 }
 /**
  *
  * @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;
 }
 /**
  * Get messages
  *
  * @param boolean $includeCurrentMessages
  * @return array
  */
 public function __invoke($includeCurrentMessages = false)
 {
     $messages = [FlashMessenger::NAMESPACE_ERROR => [], FlashMessenger::NAMESPACE_SUCCESS => [], FlashMessenger::NAMESPACE_INFO => [], FlashMessenger::NAMESPACE_DEFAULT => []];
     foreach ($messages as $ns => &$m) {
         $m = $this->flashMessenger->getMessagesFromNamespace($ns);
         if ($includeCurrentMessages) {
             $m = array_merge($m, $this->flashMessenger->getCurrentMessagesFromNamespace($ns));
         }
     }
     return $messages;
 }
示例#8
0
 public function __invoke($includeCurrentMessages = false)
 {
     $messages = array(FlashMessenger::NAMESPACE_ERROR => [], FlashMessenger::NAMESPACE_SUCCESS => [], FlashMessenger::NAMESPACE_INFO => [], FlashMessenger::NAMESPACE_WARNING => [], FlashMessenger::NAMESPACE_DEFAULT => []);
     foreach ($messages as $namespace => &$message) {
         $message = $this->flashMessenger->getMessagesFromNamespace($namespace);
         if ($includeCurrentMessages) {
             $message = array_merge($message, $this->flashMessenger->getCurrentMessagesFromNamespace($namespace));
             $this->flashMessenger->clearCurrentMessagesFromNamespace($namespace);
         }
     }
     return $messages;
 }
示例#9
0
 public function __invoke($includeCurrentMessages = false)
 {
     $messages = array_combine(array_keys($this->_nsMap), array(array(), array(), array(), array()));
     foreach ($messages as $className => &$m) {
         $ns = $this->_mapNameSpace($className);
         $m = $this->flashMessenger->getMessagesFromNamespace($ns);
         if ($includeCurrentMessages) {
             $m = array_merge($m, $this->flashMessenger->getCurrentMessagesFromNamespace($ns));
             $this->flashMessenger->clearCurrentMessagesFromNamespace($ns);
         }
     }
     return $messages;
 }
示例#10
0
 public function __invoke($includeCurrentMessages = false)
 {
     $messages = array(FlashMessenger::NAMESPACE_ERROR => array(), FlashMessenger::NAMESPACE_SUCCESS => array(), FlashMessenger::NAMESPACE_INFO => array(), FlashMessenger::NAMESPACE_DEFAULT => array());
     foreach ($messages as $ns => &$m) {
         $m = $this->flashMessenger->getMessagesFromNamespace($ns);
         if ($includeCurrentMessages) {
             $m = array_merge($m, $this->flashMessenger->getCurrentMessagesFromNamespace($ns));
             $this->flashMessenger->clearCurrentMessagesFromNamespace($ns);
         }
     }
     // Fix Twitter Bootstrap 3
     $messages['danger'] =& $messages[FlashMessenger::NAMESPACE_ERROR];
     $messages['warning'] =& $messages[FlashMessenger::NAMESPACE_DEFAULT];
     return $messages;
 }
示例#11
0
 protected function addSpecificMessage($type, $title, $description = null, array $messages = null)
 {
     $className = '\\Application\\Common\\Message\\' . ucfirst($type) . 'Message';
     if (!class_exists($className)) {
         throw new \InvalidArgumentException('Class "' . $className . '" is undefined.');
     }
     $message = new $className($title, $description, $messages);
     return parent::addMessage($message);
 }
示例#12
0
 public function handleErrorMessages($messages, FlashMessenger $messenger, $parentEl = null, $prefix = '')
 {
     if ($parentEl === null) {
         $parentEl = $this;
     }
     foreach ($messages as $name => $message) {
         if (is_string($message)) {
             $messenger->addErrorMessage($message);
         } else {
             $targetEl = $parentEl->get($name);
             if ($targetEl instanceof Fieldset) {
                 $this->handleErrorMessages($message, $messenger, $targetEl, $prefix . $targetEl->getName() . ", ");
             } else {
                 if ($targetEl instanceof Element) {
                     $messenger->addErrorMessage($prefix . $targetEl->getLabel() . ": " . implode(", ", $message));
                 }
             }
         }
     }
 }
 /**
  * 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";
 }
示例#14
0
 /**
  * This method represents an exception flashing system for backend without access to
  * rendering the template
  *
  * Just add an array value to $_ENV['exceptions'] inside any Backend class to flash it later ..
  *
  * If the key of appended array value will match any of User's registered institutions, it'll be
  * shown as related to that institution.
  *
  * @param \Zend\Mvc\Controller\Plugin\FlashMessenger $flashMessenger
  *
  * @return void
  */
 protected function flashExceptions(\Zend\Mvc\Controller\Plugin\FlashMessenger $flashMessenger)
 {
     if (isset($_ENV['exceptions'])) {
         foreach ($_ENV['exceptions'] as $source => $exception) {
             // We actually cannot print multi-lined exception -> divide it into separate ones ..
             $exceptions = explode("\n", $exception);
             if ($exceptions == null) {
                 // It is probably an array
                 $exceptions = $exception;
             }
             foreach ($exceptions as $exception) {
                 if (!is_numeric($source)) {
                     $exception = $source . ':' . $exception;
                 }
                 $flashMessenger->addErrorMessage($exception);
             }
         }
         unset($_ENV['exceptions']);
     }
 }
 /**
  * Render a namespace
  * @param string $namespace
  * @param bool $includeCurrentMessages
  * @param bool $forceClearMessages
  * @param array $attr
  * @return string 
  */
 public function renderNamespace($namespace, $includeCurrentMessages = false, $forceClearMessages = true, $attr = array())
 {
     // init : messages
     $messagesHTML = "";
     $messages = $this->flashMessenger->getMessagesFromNamespace($namespace);
     if ($includeCurrentMessages) {
         $messages = array_merge($messages, $this->flashMessenger->getCurrentMessagesFromNamespace($namespace));
     }
     $messages = array_unique($messages);
     foreach ($messages as $message) {
         $messagesHTML .= $this->renderMessage($message, $namespace, $attr);
     }
     // clear messages
     if ($forceClearMessages) {
         $this->flashMessenger->clearMessagesFromNamespace($namespace);
         if ($includeCurrentMessages) {
             $this->flashMessenger->clearCurrentMessagesFromNamespace($namespace);
         }
     }
     return $messagesHTML;
 }
示例#16
0
文件: NewItems.php 项目: tillk/vufind
 /**
  * Figure out which bib IDs to load from the ILS.
  *
  * @param \VuFind\ILS\Connection                     $catalog ILS connection
  * @param \VuFind\Search\Solr\Params                 $params  Solr parameters
  * @param string                                     $range   Range setting
  * @param string                                     $dept    Department setting
  * @param \Zend\Mvc\Controller\Plugin\FlashMessenger $flash   Flash messenger
  *
  * @return array
  */
 public function getBibIDsFromCatalog($catalog, $params, $range, $dept, $flash)
 {
     // The code always pulls in enough catalog results to get a fixed number
     // of pages worth of Solr results.  Note that if the Solr index is out of
     // sync with the ILS, we may see fewer results than expected.
     $resultPages = $this->getResultPages();
     $perPage = $params->getLimit();
     $newItems = $catalog->getNewItems(1, $perPage * $resultPages, $range, $dept);
     // Build a list of unique IDs
     $bibIDs = [];
     for ($i = 0; $i < count($newItems['results']); $i++) {
         $bibIDs[] = $newItems['results'][$i]['id'];
     }
     // Truncate the list if it is too long:
     $limit = $params->getQueryIDLimit();
     if (count($bibIDs) > $limit) {
         $bibIDs = array_slice($bibIDs, 0, $limit);
         $flash->setNamespace('info')->addMessage('too_many_new_items');
     }
     return $bibIDs;
 }
示例#17
0
 public function checkAuthentication(MvcEvent $event)
 {
     $auth = $event->getApplication()->getServiceManager()->get("Authentication\\AuthenticationService");
     $target = $event->getTarget();
     $match = $event->getRouteMatch();
     if (!$auth->hasIdentity()) {
         $strController = $match->getParam('controller');
         $arrConfigAcl = $event->getApplication()->getServiceManager()->get('config')['acl']['public'];
         $flashMessenger = new FlashMessenger();
         $strAction = $match->getParam('action');
         $arrMessage = array('danger' => array('É preciso está autenticado para acessar esta funcionalidade.'));
         if (!array_key_exists($strController, $arrConfigAcl)) {
             $flashMessenger->addMessage($arrMessage);
             return $target->redirect()->toUrl('/authentication');
         }
         if (!in_array($strAction, $arrConfigAcl[$strController])) {
             $flashMessenger->addMessage($arrMessage);
             return $target->redirect()->toUrl('/authentication');
         }
     }
 }
 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();
 }
示例#19
0
 /**
  * @return \Zend\Http\Response|ViewModel
  */
 public function changePasswordAction()
 {
     $currentPasswordElement = false;
     if ($this->identity()->getUser()->getEmail()) {
         $form = new ChangePasswordForm(null, ['serviceLocator' => $this->getServiceLocator()]);
         $currentPasswordElement = true;
     } else {
         $form = new ChangePasswordAndEmailForm(null, ['serviceLocator' => $this->getServiceLocator()]);
     }
     $request = $this->getRequest();
     if ($request->isPost()) {
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $flashMessenger = new FlashMessenger();
             /** @var \User\Service\Auth $userAuth */
             $userAuth = $this->getServiceLocator()->get('\\User\\Service\\Auth');
             try {
                 $objectManager = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager');
                 /** @var \User\Entity\User $user */
                 $user = $objectManager->getRepository('User\\Entity\\User')->find($this->identity()->getUser()->getId());
                 if ($this->identity()->getUser()->getEmail()) {
                     $userAuth->checkCredentials($this->identity()->getUser()->getEmail(), $form->getData()['currentPassword']);
                 } else {
                     $user->setEmail($form->getData()['email']);
                 }
                 $objectManager->persist($user);
                 $objectManager->flush();
                 $userAuth->generateEquals($user, $form->getData()['password']);
                 $flashMessenger->addSuccessMessage("You have successfully changed your password!");
                 return $this->redirect()->toRoute('home');
             } catch (AuthException $exception) {
                 $flashMessenger->addErrorMessage($exception->getMessage());
             }
         }
     }
     return new ViewModel(['form' => $form, 'currentPasswordElement' => $currentPasswordElement]);
 }
示例#20
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";
 }
示例#21
0
 /**
  * @param string $to
  * @param string $toName
  * @param string $subject
  * @param string $message
  * @param string $from
  * @param string $fromName
  *
  * @return bool|FlashMessenger
  */
 public function sendMail($to, $toName, $subject, $message, $from, $fromName)
 {
     $transport = new SmtpTransport();
     $options = new SmtpOptions(['host' => $this->settings->__invoke('mail', 'host'), 'name' => $this->settings->__invoke('mail', 'name'), 'connection_class' => $this->settings->__invoke('mail', 'connection_class'), 'connection_config' => ['username' => $this->settings->__invoke('mail', 'username'), 'password' => $this->settings->__invoke('mail', 'password'), 'ssl' => $this->settings->__invoke('mail', 'ssl')], 'port' => $this->settings->__invoke('mail', 'port')]);
     $htmlPart = new MimePart($message);
     $htmlPart->type = 'text/html';
     $body = new MimeMessage();
     $body->setParts([$htmlPart]);
     $mail = new Message();
     $mail->setFrom($from, $fromName);
     $mail->addTo($to, $toName);
     $mail->setSubject($subject);
     $mail->setEncoding('UTF-8');
     $mail->setBody($body);
     $mail->getHeaders()->addHeaderLine('MIME-Version: 1.0');
     $mail->getHeaders()->addHeaderLine('Content-Type', 'text/html; charset=UTF-8');
     try {
         $transport->setOptions($options);
         $transport->send($mail);
         return true;
     } catch (\Exception $e) {
         return $this->flashMessenger->addMessage('Email not send', 'error');
     }
 }
示例#22
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 : '';
 }
示例#23
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);
 }
示例#24
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;
 }
示例#25
0
 public function recordAction()
 {
     $id = $this->request->getParam('id');
     $sid = $_SESSION[$this->id]['sid'];
     $offset = $this->request->getParam('offset', null, true);
     $targets = $this->query->fillTargetInfo();
     try {
         // get the record
         $results = $this->engine->getRawRecord($sid, $id, $offset, $targets);
     } catch (\Exception $e) {
         // Exception probably a session timeout; go back to front page
         $fm = new FlashMessenger();
         $fm->addMessage('Session timeout: ' . $e->getMessage());
         $params = $this->query->getAllSearchParams();
         $params['lang'] = $this->request->getParam('lang');
         $params['controller'] = $this->request->getParam('controller');
         $params['action'] = 'index';
         $url = $this->request->url_for($params);
         return $this->redirect()->toUrl($url);
     }
     // set links
     $this->helper->addRecordLinks($results);
     $this->helper->addExternalRecordLinks($results, $this->config);
     // add to response
     //var_dump($results);
     $this->data["results"] = $results;
     return $this->data;
 }
 /**
  * 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";
 }
示例#27
0
 public function testComposesSessionManagerByDefault()
 {
     $helper  = new FlashMessenger();
     $session = $helper->getSessionManager();
     $this->assertInstanceOf('Zend\Session\SessionManager', $session);
 }
示例#28
0
 /**
  * @return \Zend\Http\Response|ViewModel
  * @throws \Exception
  */
 public function addAction()
 {
     $form = $this->getServiceLocator()->get('Comment\\Service\\Comment')->createForm();
     // for POST data
     if ($this->getRequest()->isPost()) {
         $data = $this->getRequest()->getPost();
         // for GET (or query string) data
         if ($this->getRequest()->getQuery('alias') && ($entityId = intval($this->getRequest()->getQuery('id')))) {
             $data->set('alias', $this->getRequest()->getQuery('alias'));
             $data->set('entityId', $this->getRequest()->getQuery('id'));
         }
         if (!isset($data['alias']) || !isset($data['entityId'])) {
             $this->getResponse()->setStatusCode(400);
             throw new \Exception('Bad request');
         }
         $comment = $this->getServiceLocator()->get('Comment\\Service\\Comment')->add($form, $data);
         $flashMessenger = new FlashMessenger();
         if ($comment) {
             $flashMessenger->addSuccessMessage('Comment created');
             if (!$this->getRequest()->isXmlHttpRequest()) {
                 if ($this->getRequest()->getHeader('Referer')) {
                     return $this->redirect()->toUrl($this->getRequest()->getHeader('Referer')->getUri());
                 } else {
                     return $this->redirect()->toUrl('/');
                 }
             }
             return;
         } else {
             $flashMessenger->addErrorMessage('Comment is not created');
         }
     }
     $viewModel = new ViewModel(['form' => $form, 'title' => 'Add comment']);
     $viewModel->setTerminal($this->getRequest()->isXmlHttpRequest());
     return $viewModel;
 }
示例#29
0
 public function recordAction()
 {
     $uo = new UserOptions($this->request);
     $sid = $uo->getSessionData('pz2session');
     $targets = new Targets($uo->getSessionData('source_type'), $uo->getSessionData('targets'));
     $id = $this->request->getParam('id');
     $offset = $this->request->getParam('offset', null, true);
     try {
         // get the record
         $results = $this->engine->getRawRecord($sid, $id, $offset, $targets);
     } catch (\Exception $e) {
         // Exception probably a session timeout; go back to front page
         $fm = new FlashMessenger();
         $fm->addMessage('Session timeout: ' . $e->getMessage());
         $params = $this->query->getAllSearchParams();
         $params['lang'] = $this->request->getParam('lang');
         $params['controller'] = $this->request->getParam('controller');
         $params['action'] = 'index';
         $url = $this->request->url_for($params);
         return $this->redirect()->toUrl($url);
     }
     // set links
     $this->helper->addRecordLinks($results);
     $this->helper->addExternalRecordLinks($results, $this->config);
     // add to response
     $this->data->setVariable('results', $results);
     return $this->data;
 }
示例#30
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;
 }