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

RegistrationRepository   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
eloc 14
c 1
b 0
f 1
dl 0
loc 27
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A save() 0 14 2
A findAllWithAttendance() 0 9 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