Skip to content
Snippets Groups Projects
Select Git revision
  • e74bb796c3efbe9b6bedfa0e5f257189e6d830d7
  • master default
2 results

NotificationOnDeviceRepository.php

Blame
  • NotificationOnDeviceRepository.php 1.48 KiB
    <?php
    /**
     * Created by PhpStorm.
     * User: jeremyguiselin
     * Date: 01/11/2016
     * Time: 17:31
     */
    
    namespace BackendBundle\Repository;
    
    
    use BackendBundle\Entity\Device;
    use BackendBundle\Entity\Notification;
    use BackendBundle\Entity\NotificationOnDevice;
    use Doctrine\ORM\EntityRepository;
    
    class NotificationOnDeviceRepository extends EntityRepository
    {
        public function findNotificationsByDevice(array $notifications, Device $device)
        {
            return $this->createQueryBuilder('s')
                ->where('s.notification IN (:notifications)')
                ->andWhere('s.device = :device')
                ->setParameters([
                    'device' => $device,
                    'notifications' => $notifications
                ])
                ->getQuery()
                ->getResult();
        }
    
        public function updateStatusOnAllDevices(array $devices, Notification $notification)
        {
            foreach ($devices as $device) {
                $notifOnDevice = new NotificationOnDevice();
                $notifOnDevice->setDevice($device);
                $notifOnDevice->setNotification($notification);
                $this->getEntityManager()->persist($notifOnDevice);
            }
    
            $this->getEntityManager()->flush();
        }
    
        public function readAllNotifications(Device $device)
        {
            $qb = $this->createQueryBuilder('n');
            $qb
                ->update('n')
                ->set('n.status', NotificationOnDevice::STATUS_READ)
                ->where('n.device = :device')
                ->setParameter('device', $device);
        }
    }