Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Inbox.php
Go to the documentation of this file.
1 <?php
7 
13 {
19  protected function _construct()
20  {
21  $this->_init('adminnotification_inbox', 'notification_id');
22  }
23 
30  public function loadLatestNotice(\Magento\AdminNotification\Model\Inbox $object)
31  {
32  $connection = $this->getConnection();
33  $select = $connection->select()->from(
34  $this->getMainTable()
35  )->order(
36  $this->getIdFieldName() . ' DESC'
37  )->where(
38  'is_read != 1'
39  )->where(
40  'is_remove != 1'
41  )->limit(
42  1
43  );
44  $data = $connection->fetchRow($select);
45 
46  if ($data) {
47  $object->setData($data);
48  }
49 
50  $this->_afterLoad($object);
51 
52  return $this;
53  }
54 
62  public function getNoticeStatus(\Magento\AdminNotification\Model\Inbox $object)
63  {
64  $connection = $this->getConnection();
65  $select = $connection->select()->from(
66  $this->getMainTable(),
67  [
68  'severity' => 'severity',
69  'count_notice' => new \Zend_Db_Expr('COUNT(' . $this->getIdFieldName() . ')')
70  ]
71  )->group(
72  'severity'
73  )->where(
74  'is_remove=?',
75  0
76  )->where(
77  'is_read=?',
78  0
79  );
80  $return = $connection->fetchPairs($select);
81  return $return;
82  }
83 
92  public function parse(\Magento\AdminNotification\Model\Inbox $object, array $data)
93  {
94  $connection = $this->getConnection();
95  foreach ($data as $item) {
96  $select = $connection->select()->from($this->getMainTable())->where('title = ?', $item['title']);
97 
98  if (empty($item['url'])) {
99  $select->where('url IS NULL');
100  } else {
101  $select->where('url = ?', $item['url']);
102  }
103 
104  if (isset($item['internal'])) {
105  $row = false;
106  unset($item['internal']);
107  } else {
108  $row = $connection->fetchRow($select);
109  }
110 
111  if (!$row) {
112  $connection->insert($this->getMainTable(), $item);
113  }
114  }
115  }
116 }
loadLatestNotice(\Magento\AdminNotification\Model\Inbox $object)
Definition: Inbox.php:30
parse(\Magento\AdminNotification\Model\Inbox $object, array $data)
Definition: Inbox.php:92
getNoticeStatus(\Magento\AdminNotification\Model\Inbox $object)
Definition: Inbox.php:62
$connection
Definition: bulk.php:13
_afterLoad(\Magento\Framework\Model\AbstractModel $object)
Definition: AbstractDb.php:641