Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Window.php
Go to the documentation of this file.
1 <?php
9 
15 {
19  const XML_SEVERITY_ICONS_URL_PATH = 'system/adminnotification/severity_icons_url';
20 
26  protected $_severityIconsUrl;
27 
33  protected $_authSession;
34 
41 
45  protected $_latestItem;
46 
53  protected $_isScopePrivate;
54 
61  public function __construct(
62  \Magento\Backend\Block\Template\Context $context,
63  \Magento\Backend\Model\Auth\Session $authSession,
64  \Magento\AdminNotification\Model\ResourceModel\Inbox\Collection\Critical $criticalCollection,
65  array $data = []
66  ) {
67  parent::__construct($context, $data);
68  $this->_authSession = $authSession;
69  $this->_criticalCollection = $criticalCollection;
70  $this->_isScopePrivate = true;
71  }
72 
78  protected function _toHtml()
79  {
80  if ($this->canShow()) {
81  $this->setHeaderText($this->escapeHtml(__('Incoming Message')));
82  $this->setCloseText($this->escapeHtml(__('close')));
83  $this->setReadDetailsText($this->escapeHtml(__('Read Details')));
84  $this->setNoticeMessageText($this->escapeHtml($this->_getLatestItem()->getTitle()));
85  $this->setNoticeMessageUrl($this->escapeUrl($this->_getLatestItem()->getUrl()));
86  $this->setSeverityText('critical');
87  return parent::_toHtml();
88  }
89  return '';
90  }
91 
97  protected function _getLatestItem()
98  {
99  if ($this->_latestItem == null) {
100  $items = array_values($this->_criticalCollection->getItems());
101  $this->_latestItem = false;
102  if (count($items)) {
103  $this->_latestItem = $items[0];
104  }
105  }
106  return $this->_latestItem;
107  }
108 
114  public function canShow()
115  {
116  return $this->_authSession->isFirstPageAfterLogin() && $this->_getLatestItem();
117  }
118 }
__()
Definition: __.php:13
__construct(\Magento\Backend\Block\Template\Context $context, \Magento\Backend\Model\Auth\Session $authSession, \Magento\AdminNotification\Model\ResourceModel\Inbox\Collection\Critical $criticalCollection, array $data=[])
Definition: Window.php:61
$items