NotificationService.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\AdminNotification\Model;
  7. /**
  8. * Notification service model
  9. *
  10. * @author Magento Core Team <core@magentocommerce.com>
  11. * @api
  12. * @since 100.0.2
  13. */
  14. class NotificationService
  15. {
  16. /**
  17. * @var \Magento\AdminNotification\Model\InboxFactory $notificationFactory
  18. */
  19. protected $_notificationFactory;
  20. /**
  21. * @param \Magento\AdminNotification\Model\InboxFactory $notificationFactory
  22. */
  23. public function __construct(\Magento\AdminNotification\Model\InboxFactory $notificationFactory)
  24. {
  25. $this->_notificationFactory = $notificationFactory;
  26. }
  27. /**
  28. * Mark notification as read
  29. *
  30. * @param int $notificationId
  31. * @return void
  32. * @throws \Magento\Framework\Exception\LocalizedException
  33. */
  34. public function markAsRead($notificationId)
  35. {
  36. $notification = $this->_notificationFactory->create();
  37. $notification->load($notificationId);
  38. if (!$notification->getId()) {
  39. throw new \Magento\Framework\Exception\LocalizedException(__('Wrong notification ID specified.'));
  40. }
  41. $notification->setIsRead(1);
  42. $notification->save();
  43. }
  44. }