|
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\Ticket; |
|
10
|
|
|
use Chamilo\CoreBundle\Entity\TicketRelUser; |
|
11
|
|
|
use Chamilo\CoreBundle\Entity\User; |
|
12
|
|
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; |
|
13
|
|
|
use Doctrine\Persistence\ManagerRegistry; |
|
14
|
|
|
|
|
15
|
|
|
class TicketRelUserRepository extends ServiceEntityRepository |
|
16
|
|
|
{ |
|
17
|
|
|
public function __construct(ManagerRegistry $registry) |
|
18
|
|
|
{ |
|
19
|
|
|
parent::__construct($registry, TicketRelUser::class); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function subscribeUserToTicket(User $user, Ticket $ticket): void |
|
23
|
|
|
{ |
|
24
|
|
|
$em = $this->getEntityManager(); |
|
25
|
|
|
|
|
26
|
|
|
$existingSubscription = $this->findOneBy(['user' => $user, 'ticket' => $ticket]); |
|
27
|
|
|
|
|
28
|
|
|
if (!$existingSubscription) { |
|
29
|
|
|
$subscription = new TicketRelUser($user, $ticket, true); |
|
30
|
|
|
$em->persist($subscription); |
|
31
|
|
|
$em->flush(); |
|
32
|
|
|
} |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function unsubscribeUserFromTicket(User $user, Ticket $ticket): void |
|
36
|
|
|
{ |
|
37
|
|
|
$em = $this->getEntityManager(); |
|
38
|
|
|
|
|
39
|
|
|
$subscription = $this->findOneBy(['user' => $user, 'ticket' => $ticket]); |
|
40
|
|
|
|
|
41
|
|
|
if ($subscription) { |
|
42
|
|
|
$em->remove($subscription); |
|
43
|
|
|
$em->flush(); |
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function isUserSubscribedToTicket(User $user, Ticket $ticket): bool |
|
48
|
|
|
{ |
|
49
|
|
|
return (bool) $this->findOneBy(['user' => $user, 'ticket' => $ticket]); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function getTicketFollowers(Ticket $ticket): array |
|
53
|
|
|
{ |
|
54
|
|
|
return $this->findBy(['ticket' => $ticket]); |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|