1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AppBundle\Repository; |
4
|
|
|
|
5
|
|
|
use AppBundle\Entity\Seat; |
6
|
|
|
use AppBundle\Entity\Venue; |
7
|
|
|
use AppBundle\Entity\VenueSector; |
8
|
|
|
use AppBundle\Exception\NotFoundException; |
9
|
|
|
|
10
|
|
|
class SeatRepository extends AbstractRepository |
11
|
|
|
{ |
12
|
|
|
public function findByVenue(Venue $venue) |
13
|
|
|
{ |
14
|
|
|
$qb = $this->createQueryBuilder('s') |
15
|
|
|
->join('s.venueSector', 'vs') |
16
|
|
|
->andWhere('vs.venue = :venue') |
17
|
|
|
->setParameter('venue', $venue->getId()) |
18
|
|
|
; |
19
|
|
|
|
20
|
|
|
$query = $qb->getQuery(); |
21
|
|
|
|
22
|
|
|
return $query->execute(); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Get Seats for specific Venue |
27
|
|
|
* |
28
|
|
|
* @param Venue $venue |
29
|
|
|
* |
30
|
|
|
* @return Seat[] |
31
|
|
|
* @throws NotFoundException |
32
|
|
|
*/ |
33
|
|
|
public function getByVenue(Venue $venue): array |
34
|
|
|
{ |
35
|
|
|
$seats = $this->findByVenue($venue); |
36
|
|
|
|
37
|
|
|
if (empty($seats)) { |
38
|
|
|
throw new NotFoundException('No seats found for Venue ID: '.$venue->getId()); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
return $seats; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Get Seats for specific Venue |
46
|
|
|
* |
47
|
|
|
* @param VenueSector $venueSector |
48
|
|
|
* |
49
|
|
|
* @return Seat[] |
50
|
|
|
* @throws NotFoundException |
51
|
|
|
*/ |
52
|
|
View Code Duplication |
public function getByVenueSector(VenueSector $venueSector): array |
|
|
|
|
53
|
|
|
{ |
54
|
|
|
$seats = $this->findBy([ |
55
|
|
|
'venueSector' => $venueSector |
56
|
|
|
]); |
57
|
|
|
|
58
|
|
|
if (empty($seats)) { |
59
|
|
|
throw new NotFoundException( |
60
|
|
|
sprintf('No seats found for venue sector: %s', $venueSector) |
61
|
|
|
); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
return $seats; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Get Seats for specific Venue |
70
|
|
|
* |
71
|
|
|
* @param VenueSector $venueSector |
72
|
|
|
* @param int $row |
73
|
|
|
* |
74
|
|
|
* @return Seat[] |
75
|
|
|
* @throws NotFoundException |
76
|
|
|
*/ |
77
|
|
|
public function getByVenueSectorAndRow(VenueSector $venueSector, int $row): array |
78
|
|
|
{ |
79
|
|
|
$seats = $this->findBy([ |
80
|
|
|
'venueSector' => $venueSector, |
81
|
|
|
'row' => $row |
82
|
|
|
]); |
83
|
|
|
|
84
|
|
|
if (empty($seats)) { |
85
|
|
|
throw new NotFoundException( |
86
|
|
|
sprintf('No seats found for venue sector: %s row: %s ', $venueSector, $row) |
87
|
|
|
); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
return $seats; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Get Seats for specific Venue |
95
|
|
|
* |
96
|
|
|
* @param VenueSector $venueSector |
97
|
|
|
* @param int $row |
98
|
|
|
* @param int $place |
99
|
|
|
* |
100
|
|
|
* @return Seat |
101
|
|
|
* @throws NotFoundException |
102
|
|
|
*/ |
103
|
|
|
public function getByVenueSectorRowAndPlace(VenueSector $venueSector, int $row, int $place): Seat |
104
|
|
|
{ |
105
|
|
|
/** @var Seat $seat */ |
106
|
|
|
$seat = $this->findOneBy([ |
107
|
|
|
'venueSector' => $venueSector, |
108
|
|
|
'row' => $row, |
109
|
|
|
'place' => $place, |
110
|
|
|
]); |
111
|
|
|
|
112
|
|
|
if (empty($seat)) { |
113
|
|
|
throw new NotFoundException( |
114
|
|
|
sprintf('No Seat found for venue sector: %s, row: %s, place %s', $venueSector, $row, $place) |
115
|
|
|
); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
return $seat; |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.