Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
MassMarkAsRead.php
Go to the documentation of this file.
1 <?php
8 
10 {
11 
17  const ADMIN_RESOURCE = 'Magento_AdminNotification::mark_as_read';
18 
22  public function execute()
23  {
24  $ids = $this->getRequest()->getParam('notification');
25  if (!is_array($ids)) {
26  $this->messageManager->addErrorMessage(__('Please select messages.'));
27  } else {
28  try {
29  foreach ($ids as $id) {
30  $model = $this->_objectManager->create(\Magento\AdminNotification\Model\Inbox::class)->load($id);
31  if ($model->getId()) {
32  $model->setIsRead(1)->save();
33  }
34  }
35  $this->messageManager->addSuccessMessage(
36  __('A total of %1 record(s) have been marked as Read.', count($ids))
37  );
38  } catch (\Magento\Framework\Exception\LocalizedException $e) {
39  $this->messageManager->addErrorMessage($e->getMessage());
40  } catch (\Exception $e) {
41  $this->messageManager->addExceptionMessage(
42  $e,
43  __("We couldn't mark the notification as Read because of an error.")
44  );
45  }
46  }
47  $this->_redirect('adminhtml/*/');
48  }
49 }
$id
Definition: fieldset.phtml:14
__()
Definition: __.php:13