Completed
Push — master ( 6f4e0b...12f334 )
by Florian
19s queued 16s
created

RegistrationRepository::findAllWithAttendance()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
c 0
b 0
f 0
dl 0
loc 9
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the TheAlternativeZurich/events project.
5
 *
6
 * (c) Florian Moser <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace App\Repository;
13
14
use App\Entity\Event;
15
use App\Entity\Registration;
16
use Doctrine\ORM\EntityRepository;
17
18
class RegistrationRepository extends EntityRepository
19
{
20
    public function save(Registration $registration)
21
    {
22
        $maxNumber = 0;
23
        foreach ($registration->getEvent()->getRegistrations() as $existingRegistration) {
24
            $maxNumber = max($existingRegistration->getNumber(), $maxNumber);
25
        }
26
27
        ++$maxNumber;
28
29
        $registration->setNumber($maxNumber);
30
31
        $manager = $this->getEntityManager();
32
        $manager->persist($registration);
33
        $manager->flush();
34
    }
35
36
    public function findAllWithAttendance(Event $event)
37
    {
38
        $qb = $this->createQueryBuilder('r')
39
            ->leftJoin('r.attendances', 'a')
40
            ->where('r.event = :event_id');
41
42
        $qb->setParameter(':event_id', $event->getId());
43
44
        return $qb->getQuery()->getResult();
45
    }
46
}
47