Passed
Push — master ( 228bb8...761423 )
by
unknown
17:12 queued 07:28
created

ConferenceActivityRepository::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
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\ConferenceActivity;
10
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
11
use Doctrine\Persistence\ManagerRegistry;
12
13
/**
14
 * Repository for the ConferenceActivity entity.
15
 */
16
class ConferenceActivityRepository extends ServiceEntityRepository
17
{
18
    public function __construct(ManagerRegistry $registry)
19
    {
20
        parent::__construct($registry, ConferenceActivity::class);
21
    }
22
23
    public function findOpenWithSameInAndOutTime(int $meetingId): array
24
    {
25
        return $this->createQueryBuilder('a')
26
            ->where('a.meeting = :meetingId')
27
            ->andWhere('a.inAt = a.outAt')
28
            ->andWhere('a.close = :open')
29
            ->setParameter('meetingId', $meetingId)
30
            ->setParameter('open', \BBBPlugin::ROOM_OPEN)
31
            ->getQuery()
32
            ->getResult();
33
    }
34
35
    public function closeAllByMeetingId(int $meetingId): void
36
    {
37
        $this->createQueryBuilder('a')
38
            ->update()
39
            ->set('a.close', ':closed')
40
            ->where('a.meeting = :meetingId')
41
            ->setParameter('closed', \BBBPlugin::ROOM_CLOSE)
42
            ->setParameter('meetingId', $meetingId)
43
            ->getQuery()
44
            ->execute();
45
    }
46
47
    public function findOneArrayByMeetingAndParticipant(int $meetingId, int $participantId): ?array
48
    {
49
        $qb = $this->createQueryBuilder('a')
50
            ->where('a.meeting = :meetingId')
51
            ->andWhere('a.participant = :participantId')
52
            ->orderBy('a.id', 'DESC')
53
            ->setMaxResults(1)
54
            ->setParameters([
55
                'meetingId' => $meetingId,
56
                'participantId' => $participantId,
57
            ]);
58
59
        $result = $qb->getQuery()->getResult();
60
61
        if (empty($result)) {
62
            return null;
63
        }
64
65
        $entity = $result[0];
66
67
        return [
68
            'id' => $entity->getId(),
69
            'meeting_id' => $entity->getMeeting()?->getId(),
70
            'participant_id' => $entity->getParticipant()?->getId(),
71
            'in_at' => $entity->getInAt()?->format('Y-m-d H:i:s'),
72
            'out_at' => $entity->getOutAt()?->format('Y-m-d H:i:s'),
73
            'close' => $entity->isClose(),
74
            'type' => $entity->getType(),
75
            'event' => $entity->getEvent(),
76
            'activity_data' => $entity->getActivityData(),
77
            'signature_file' => $entity->getSignatureFile(),
78
            'signed_at' => $entity->getSignedAt()?->format('Y-m-d H:i:s'),
79
        ];
80
    }
81
}
82