/**
  * Retrieve popup title
  *
  * @return \Magento\Framework\Phrase
  */
 public function getPopupTitle()
 {
     $messageCount = count($this->_messages->getUnread());
     if ($messageCount > 1) {
         return __('You have %1 new system messages', $messageCount);
     } else {
         return __('You have %1 new system message', $messageCount);
     }
 }
Example #2
0
 /**
  * @return void
  */
 public function execute()
 {
     $severity = $this->getRequest()->getParam('severity');
     if ($severity) {
         $this->messageCollection->setSeverity($severity);
     }
     $result = [];
     foreach ($this->messageCollection->getItems() as $item) {
         $result[] = ['severity' => $item->getSeverity(), 'text' => $item->getText()];
     }
     if (empty($result)) {
         $result[] = ['severity' => (string) \Magento\Framework\Notification\MessageInterface::SEVERITY_NOTICE, 'text' => 'You have viewed and resolved all recent system notices. ' . 'Please refresh the web page to clear the notice alert.'];
     }
     $this->getResponse()->representJson($this->jsonHelper->jsonEncode($result));
 }
 /**
  * Store new messages in database and remove outdated messages
  *
  * @return $this|\Magento\Framework\Model\ModelResource\Db\AbstractDb
  */
 public function _afterLoad()
 {
     $messages = $this->_messageList->asArray();
     $persisted = [];
     $unread = [];
     foreach ($messages as $message) {
         if ($message->isDisplayed()) {
             foreach ($this->_items as $persistedKey => $persistedMessage) {
                 if ($message->getIdentity() == $persistedMessage->getIdentity()) {
                     $persisted[$persistedKey] = $persistedMessage;
                     continue 2;
                 }
             }
             $unread[] = $message;
         }
     }
     $removed = array_diff_key($this->_items, $persisted);
     foreach ($removed as $removedItem) {
         $removedItem->delete();
     }
     foreach ($unread as $unreadItem) {
         $item = $this->getNewEmptyItem();
         $item->setIdentity($unreadItem->getIdentity())->setSeverity($unreadItem->getSeverity())->save();
     }
     if (count($removed) || count($unread)) {
         $this->_unreadMessages = $unread;
         $this->clear();
         $this->load();
     } else {
         parent::_afterLoad();
     }
     return $this;
 }