Completed
Push — master ( 038cb8...f2d1b9 )
by FX
13:23
created

EventRepository   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 3
dl 0
loc 28
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A findPlannedEventByBuildingType4UserBetween() 0 16 1
1
<?php
2
3
/**
4
 * Copyright (c) 2016 Francois-Xavier Soubirou.
5
 *
6
 * This file is part of eco4.
7
 *
8
 * eco4 is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU General Public License as published by
10
 * the Free Software Foundation, either version 3 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * eco4 is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with eco4. If not, see <http://www.gnu.org/licenses/>.
20
 */
21
declare(strict_types=1);
22
23
namespace AppBundle\Repository;
24
25
use AppBundle\Entity\User;
26
use AppBundle\Util\Period;
27
use Doctrine\ORM\EntityRepository;
28
29
/**
30
 * Event repository class.
31
 *
32
 * @category  Eco4 App
33
 *
34
 * @author    Francois-Xavier Soubirou <[email protected]>
35
 * @copyright 2016 Francois-Xavier Soubirou
36
 * @license   http://www.gnu.org/licenses/   GPLv3
37
 *
38
 * @link      https://www.eco4.io
39
 */
40
class EventRepository extends EntityRepository
41
{
42
    /**
43
     * Get all events for an object.
44
     *
45
     * @param User   $user       The owner of the building
46
     * @param int    $objectType The building type
47
     * @param Period $period     The period of events
48
     *
49
     * @return array List of events
50
     */
51
    public function findPlannedEventByBuildingType4UserBetween(User $user, int $objectType, Period $period)
52
    {
53
        $qb = $this->createQueryBuilder('e')
54
            ->where('e.objectType = :objectType')
55
            ->andWhere('e.user = :user')
56
            ->andWhere('e.eventDatetime between :from and :to')
57
            ->setParameter('objectType', $objectType)
58
            ->setParameter('user', $user)
59
            ->setParameter('from', $period->getStartDate())
60
            ->setParameter('to', $period->getEndDate())
61
            ->orderBy('e.eventDatetime', 'ASC');
62
63
        $results = $qb->getQuery()->getResult();
64
65
        return $results;
66
    }
67
}
68