<?php
namespace App\Helpers\System;
use Symfony\Component\DependencyInjection\ContainerInterface as Container;
use Symfony\Component\Yaml\Parser;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
class NotificationHelper
{
public function __construct(TokenStorageInterface $tokenStorage, EntityManagerInterface $entityManager, RequestStack $requestStack)
{
$this->token_storage = $tokenStorage;
$this->em = $entityManager;
$this->request = $requestStack;
}
public function getNotifications() : array
{
// Get notifications for this user
$notifications = $this->em->getRepository('\App\Entity\System\Notification')->findFiltered(array(
'recipients' => array("has_all", [$this->token_storage->getToken()->getUser()]),
'scheduledDate' => array("lte", new \DateTime(date("Y-m-d 23:59:59"))),
), array(
"n.scheduledDate" => "ASC"
));
if(!count($notifications))
return array();
// Get dismissed notification notices
$dismissedNotifications = $this->em->getRepository('\App\Entity\System\DismissedNotification')->findFiltered(array(
'notification' => array("in", $notifications),
'user' => $this->token_storage->getToken()->getUser(),
));
// Loop dismissals
foreach($dismissedNotifications AS $someDismissal)
{
if(in_array($someDismissal->getNotification(), $notifications))
{
// Find key, and remove it if found
if(false !== $key = array_search($someDismissal->getNotification(), $notifications))
unset($notifications[$key]);
}
}
return $notifications;
}
public function getUsers(): array
{
return $this->em->getRepository('\App\Entity\Users\User')->findFiltered(array(
'isSuspended' => array("in", [false, null]),
), array(
"u.name" => "ASC"
));
}
}