-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNotificationRepository.php
More file actions
37 lines (30 loc) · 1.01 KB
/
NotificationRepository.php
File metadata and controls
37 lines (30 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
namespace IrishDan\NotificationBundle\Repository;
use Doctrine\ORM\EntityRepository;
use IrishDan\NotificationBundle\DatabaseNotifiableInterface;
class NotificationRepository extends EntityRepository implements DatabaseNotificationRepositoryInterface
{
public function getNotificationsCount(DatabaseNotifiableInterface $user, $status = '')
{
$dq = $this->createQueryBuilder('n')
->select('count(n.id)')
->andWhere('n.notifiable = ' . $user->getId());
switch ($status) {
case 'read':
$dq->andWhere('n.readAt IS NOT NULL');
break;
case 'unread':
$dq->andWhere('n.readAt IS NULL');
break;
}
$count = $dq->getQuery()->getSingleScalarResult();
return $count;
}
public function getUnreadNotifications(DatabaseNotifiableInterface $user)
{
return $this->findBy([
'notifiable' => $user,
'readAt' => null,
]);
}
}