Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
MassRemove.php
Go to the documentation of this file.
1 <?php
8 
10 {
11 
17  const ADMIN_RESOURCE = 'Magento_AdminNotification::adminnotification_remove';
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->setIsRemove(1)->save();
33  }
34  }
35  $this->messageManager->addSuccessMessage(__('Total of %1 record(s) have been removed.', count($ids)));
36  } catch (\Magento\Framework\Exception\LocalizedException $e) {
37  $this->messageManager->addErrorMessage($e->getMessage());
38  } catch (\Exception $e) {
39  $this->messageManager->addExceptionMessage(
40  $e,
41  __("We couldn't remove the messages because of an error.")
42  );
43  }
44  }
45  $this->_redirect('adminhtml/*/');
46  }
47 }
$id
Definition: fieldset.phtml:14
__()
Definition: __.php:13