Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AjaxMarkAsRead.php
Go to the documentation of this file.
1 <?php
8 
11 
13 {
17  private $notificationService;
18 
24  public function __construct(
25  Action\Context $context,
26  \Magento\AdminNotification\Model\NotificationService $notificationService = null
27  ) {
28  parent::__construct($context);
29  $this->notificationService = $notificationService?: \Magento\Framework\App\ObjectManager::getInstance()
30  ->get(\Magento\AdminNotification\Model\NotificationService::class);
31  }
32 
39  public function execute()
40  {
41  if (!$this->getRequest()->getPostValue()) {
42  return;
43  }
44  $notificationId = (int)$this->getRequest()->getPost('id');
45  $responseData = [];
46  try {
47  $this->notificationService->markAsRead($notificationId);
48  $responseData['success'] = true;
49  } catch (\Exception $e) {
50  $responseData['success'] = false;
51  }
52 
54  $resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON);
55  $resultJson->setData($responseData);
56  return $resultJson;
57  }
58 }
__construct(Action\Context $context, \Magento\AdminNotification\Model\NotificationService $notificationService=null)