Bonjour,
Je dois créer une fonction qui me permettra de retourner les chambre disponible en fonction des dates (entrée et sortie) fournies par l'utilisateur.
Voici ma requête:
dans RoomRepository
Mais cela me retourne une erreur:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 public function findByBookings($start, $leave): array { $qb = $this->createQueryBuilder('r'); $subquery = $qb->select('b.room') ->from('booking', 'b') ->where('b.startDate <= :startDate AND b.leaveDate >= :leaveDate') ->orWhere('b.startDate >= :startDate AND b.leaveDate <= :leaveDate') ->orWhere('b.startDate >= :startDate AND b.leaveDate >= :leaveDate') ->orWhere('b.startDate <= :startDate AND b.leaveDate <= :leaveDate') ->getDQL(); var_dump($qb->getDQL()); // automatically knows to select Rooms // the "r" is an alias you'll use in the rest of the query $query = $qb ->select('r') ->from('room', 'r') ->leftjoin('r.bookings', 'rb') ->where($qb->expr()->notIn('b.room', $subquery)) ->setParameter('startDate', $start) ->setParameter('leaveDate', $leave); $query = $qb->getQuery(); $results = $query->getResult(); return $results;Pourriez vous m'aider s'il vous plait.[Semantical Error] line 0, col 62 near 'booking b, room': Error: Class 'booking' is not defined.
et mes entité si ca peu aider:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220 <?php namespace App\Entity\Room; use App\Entity\Booking\Booking; use App\Repository\Room\RoomRepository; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity(repositoryClass=RoomRepository::class) */ class Room { /** * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") */ private $id; /** * @ORM\Column(type="string", length=255) */ private $name; /** * @ORM\Column(type="text") */ private $shortDescription; /** * @ORM\Column(type="text") */ private $description; /** * @ORM\Column(type="float") */ private $price; /** * @ORM\Column(type="string", length=255) */ private $livingSpace; /** * @ORM\Column(type="string", length=255) */ private $bed; /** * @ORM\Column(type="string", length=255) */ private $thumbnail; /** * @ORM\Column(type="datetime") */ private $createdAt; /** * @ORM\Column(type="datetime", nullable=true) */ private $updatedAt; /** * @ORM\OneToMany(targetEntity=Booking::class, mappedBy="room") */ private $bookings; public function __construct() { $this->bookings = new ArrayCollection(); } public function getId(): ?int { return $this->id; } public function getName(): ?string { return $this->name; } public function setName(string $name): self { $this->name = $name; return $this; } public function getShortDescription(): ?string { return $this->shortDescription; } public function setShortDescription(string $shortDescription): self { $this->shortDescription = $shortDescription; return $this; } public function getDescription(): ?string { return $this->description; } public function setDescription(string $description): self { $this->description = $description; return $this; } public function getPrice(): ?float { return $this->price; } public function setPrice(float $price): self { $this->price = $price; return $this; } public function getLivingSpace(): ?string { return $this->livingSpace; } public function setLivingSpace(string $livingSpace): self { $this->livingSpace = $livingSpace; return $this; } public function getBed(): ?string { return $this->bed; } public function setBed(string $bed): self { $this->bed = $bed; return $this; } public function getThumbnail(): ?string { return $this->thumbnail; } public function setThumbnail(string $thumbnail): self { $this->thumbnail = $thumbnail; return $this; } public function getCreatedAt(): ?\DateTimeInterface { return $this->createdAt; } public function setCreatedAt(\DateTimeInterface $createdAt): self { $this->createdAt = $createdAt; return $this; } public function getUpdatedAt(): ?\DateTimeInterface { return $this->updatedAt; } public function setUpdatedAt(?\DateTimeInterface $updatedAt): self { $this->updatedAt = $updatedAt; return $this; } /** * @return Collection|Booking[] */ public function getBookings(): Collection { return $this->bookings; } public function addBooking(Booking $booking): self { if (!$this->bookings->contains($booking)) { $this->bookings[] = $booking; $booking->setRoom($this); } return $this; } public function removeBooking(Booking $booking): self { if ($this->bookings->removeElement($booking)) { // set the owning side to null (unless already changed) if ($booking->getRoom() === $this) { $booking->setRoom(null); } } return $this; } }Merci à tous.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114 <?php namespace App\Entity\Booking; use Gedmo\Mapping\Annotation as Gedmo; use App\Entity\Room\Room; use App\Repository\Booking\BookingRepository; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity(repositoryClass=BookingRepository::class) */ class Booking { /** * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") */ private $id; /** * @ORM\Column(type="datetime") */ private $startDate; /** * @ORM\Column(type="datetime") */ private $leaveDate; /** * @Gedmo\Timestampable(on="create") * @ORM\Column(type="datetime") */ private $createdAt; /** * @Gedmo\Timestampable(on="create") * @ORM\Column(type="datetime", nullable=true) */ private $updatedAt; /** * @ORM\ManyToOne(targetEntity=Room::class, inversedBy="bookings") * @ORM\JoinColumn(nullable=false) */ private $room; public function getId(): ?int { return $this->id; } public function getStartDate(): ?\DateTimeInterface { return $this->startDate; } public function setStartDate(\DateTimeInterface $startDate): self { $this->startDate = $startDate; return $this; } public function getLeaveDate(): ?\DateTimeInterface { return $this->leaveDate; } public function setLeaveDate(\DateTimeInterface $leaveDate): self { $this->leaveDate = $leaveDate; return $this; } public function getCreatedAt(): ?\DateTimeInterface { return $this->createdAt; } public function setCreatedAt(\DateTimeInterface $createdAt): self { $this->createdAt = $createdAt; return $this; } public function getUpdatedAt(): ?\DateTimeInterface { return $this->updatedAt; } public function setUpdatedAt(?\DateTimeInterface $updatedAt): self { $this->updatedAt = $updatedAt; return $this; } public function getRoom(): ?Room { return $this->room; } public function setRoom(?Room $room): self { $this->room = $room; return $this; } }
Partager