src/Helpers/System/NotificationHelper.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Helpers\System;
  3. use Symfony\Component\DependencyInjection\ContainerInterface as Container;
  4. use Symfony\Component\Yaml\Parser;
  5. use Doctrine\ORM\EntityManagerInterface;
  6. use Symfony\Component\HttpFoundation\RequestStack;
  7. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  8. class NotificationHelper
  9. {
  10. public function __construct(TokenStorageInterface $tokenStorage, EntityManagerInterface $entityManager, RequestStack $requestStack)
  11. {
  12. $this->token_storage = $tokenStorage;
  13. $this->em = $entityManager;
  14. $this->request = $requestStack;
  15. }
  16. public function getNotifications() : array
  17. {
  18. // Get notifications for this user
  19. $notifications = $this->em->getRepository('\App\Entity\System\Notification')->findFiltered(array(
  20. 'recipients' => array("has_all", [$this->token_storage->getToken()->getUser()]),
  21. 'scheduledDate' => array("lte", new \DateTime(date("Y-m-d 23:59:59"))),
  22. ), array(
  23. "n.scheduledDate" => "ASC"
  24. ));
  25. if(!count($notifications))
  26. return array();
  27. // Get dismissed notification notices
  28. $dismissedNotifications = $this->em->getRepository('\App\Entity\System\DismissedNotification')->findFiltered(array(
  29. 'notification' => array("in", $notifications),
  30. 'user' => $this->token_storage->getToken()->getUser(),
  31. ));
  32. // Loop dismissals
  33. foreach($dismissedNotifications AS $someDismissal)
  34. {
  35. if(in_array($someDismissal->getNotification(), $notifications))
  36. {
  37. // Find key, and remove it if found
  38. if(false !== $key = array_search($someDismissal->getNotification(), $notifications))
  39. unset($notifications[$key]);
  40. }
  41. }
  42. return $notifications;
  43. }
  44. public function getUsers(): array
  45. {
  46. return $this->em->getRepository('\App\Entity\Users\User')->findFiltered(array(
  47. 'isSuspended' => array("in", [false, null]),
  48. ), array(
  49. "u.name" => "ASC"
  50. ));
  51. }
  52. }