1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* For licensing terms, see /license.txt */ |
6
|
|
|
|
7
|
|
|
namespace Chamilo\CoreBundle\Repository; |
8
|
|
|
|
9
|
|
|
use Chamilo\CoreBundle\Entity\PushSubscription; |
10
|
|
|
use Chamilo\CoreBundle\Entity\User; |
11
|
|
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; |
12
|
|
|
use Doctrine\Persistence\ManagerRegistry; |
13
|
|
|
|
14
|
|
|
class PushSubscriptionRepository extends ServiceEntityRepository |
15
|
|
|
{ |
16
|
|
|
public function __construct(ManagerRegistry $registry) |
17
|
|
|
{ |
18
|
|
|
parent::__construct($registry, PushSubscription::class); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Find all subscriptions for a specific user. |
23
|
|
|
* |
24
|
|
|
* @return PushSubscription[] |
25
|
|
|
*/ |
26
|
|
|
public function findByUser(User $user): array |
27
|
|
|
{ |
28
|
|
|
return $this->createQueryBuilder('p') |
29
|
|
|
->where('p.user = :user') |
30
|
|
|
->setParameter('user', $user) |
31
|
|
|
->orderBy('p.createdAt', 'DESC') |
32
|
|
|
->getQuery() |
33
|
|
|
->getResult(); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Find a subscription by its endpoint. |
38
|
|
|
*/ |
39
|
|
|
public function findOneByEndpoint(string $endpoint): ?PushSubscription |
40
|
|
|
{ |
41
|
|
|
return $this->createQueryBuilder('p') |
42
|
|
|
->where('p.endpoint = :endpoint') |
43
|
|
|
->setParameter('endpoint', $endpoint) |
44
|
|
|
->getQuery() |
45
|
|
|
->getOneOrNullResult(); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Remove all subscriptions for a user (e.g. on logout). |
50
|
|
|
*/ |
51
|
|
|
public function removeAllByUser(User $user): void |
52
|
|
|
{ |
53
|
|
|
$qb = $this->createQueryBuilder('p'); |
54
|
|
|
$qb->delete() |
55
|
|
|
->where('p.user = :user') |
56
|
|
|
->setParameter('user', $user) |
57
|
|
|
->getQuery() |
58
|
|
|
->execute(); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Remove a subscription by endpoint. |
63
|
|
|
*/ |
64
|
|
|
public function removeByEndpoint(string $endpoint): void |
65
|
|
|
{ |
66
|
|
|
$qb = $this->createQueryBuilder('p'); |
67
|
|
|
$qb->delete() |
68
|
|
|
->where('p.endpoint = :endpoint') |
69
|
|
|
->setParameter('endpoint', $endpoint) |
70
|
|
|
->getQuery() |
71
|
|
|
->execute(); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|