NotificationHelper.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. namespace MGModule\DNSManager2\mgLibs\custom\manager;
  3. use MGModule\DNSManager2\models\custom\notification;
  4. class NotificationHelper {
  5. public static function addProblemNotification($message) {
  6. self::addNotification(notification\NotificationTypeEnum::ERROR, $message);
  7. }
  8. public static function addInfoNotification($message, $name = notification\NotificationNameEnum::OTHER) {
  9. self::addNotification(notification\NotificationTypeEnum::INFO, $message, $name);
  10. }
  11. private static function addNotification($type, $message, $name = notification\NotificationNameEnum::OTHER) {
  12. $notification = new notification\Notification();
  13. $notification->name = $name;
  14. $notification->date = date('Y-m-d H:i:s');
  15. $notification->read = 0;
  16. $notification->type = $type;
  17. $notification->value = $message;
  18. $notification->save();
  19. }
  20. public static function readNotificationByID($notification_id) {
  21. self::readNotification(new notification\Notification($notification_id));
  22. }
  23. public static function readNotification($notification) {
  24. $notification->read = 1;
  25. $notification->save();
  26. }
  27. }