|
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
|
|
|
|