]> Raphaël G. Git Repositories - airbundle/blob - Entity/Location.php
Add user cache to constructor arguments
[airbundle] / Entity / Location.php
1 <?php declare(strict_types=1);
2
3 /*
4 * This file is part of the Rapsys AirBundle package.
5 *
6 * (c) Raphaël Gertz <symfony@rapsys.eu>
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 Rapsys\AirBundle\Entity;
13
14 use Doctrine\Common\Collections\Collection;
15 use Doctrine\Common\Collections\ArrayCollection;
16 use Doctrine\ORM\Event\PreUpdateEventArgs;
17
18 /**
19 * Location
20 */
21 class Location {
22 /**
23 * Primary key
24 */
25 private ?int $id = null;
26
27 /**
28 * @var string
29 */
30 private ?string $description = null;
31
32 /**
33 * Create datetime
34 */
35 private \DateTime $created;
36
37 /**
38 * Update datetime
39 */
40 private \DateTime $updated;
41
42 /**
43 * Sessions collection
44 */
45 private Collection $sessions;
46
47 /**
48 * Snippets collection
49 */
50 private Collection $snippets;
51
52 /**
53 * Users collection
54 */
55 private Collection $users;
56
57 /**
58 * Constructor
59 */
60 public function __construct(private string $title = '', private string $address = '', private string $zipcode = '0', private string $city = '', private string $latitude = '0', private string $longitude = '0', private bool $hotspot = false, private bool $indoor = false) {
61 //Set defaults
62 $this->created = new \DateTime('now');
63 $this->updated = new \DateTime('now');
64
65 //Set collections
66 $this->sessions = new ArrayCollection();
67 $this->snippets = new ArrayCollection();
68 $this->users = new ArrayCollection();
69 }
70
71 /**
72 * Get id
73 *
74 * @return integer
75 */
76 public function getId(): ?int {
77 return $this->id;
78 }
79
80 /**
81 * Set title
82 *
83 * @param string $title
84 *
85 * @return Location
86 */
87 public function setTitle(string $title): Location {
88 $this->title = $title;
89
90 return $this;
91 }
92
93 /**
94 * Get title
95 *
96 * @return string
97 */
98 public function getTitle(): string {
99 return $this->title;
100 }
101
102 /**
103 * Set description
104 *
105 * @param string $description
106 *
107 * @return Location
108 */
109 public function setDescription(?string $description): Location {
110 $this->description = $description;
111
112 return $this;
113 }
114
115 /**
116 * Get description
117 *
118 * @return string
119 */
120 public function getDescription(): ?string {
121 return $this->description;
122 }
123
124 /**
125 * Set address
126 *
127 * @param string $address
128 *
129 * @return Location
130 */
131 public function setAddress(string $address): Location {
132 $this->address = $address;
133
134 return $this;
135 }
136
137 /**
138 * Get address
139 *
140 * @return string
141 */
142 public function getAddress(): string {
143 return $this->address;
144 }
145
146 /**
147 * Set zipcode
148 *
149 * @param string $zipcode
150 *
151 * @return Location
152 */
153 public function setZipcode(string $zipcode): Location {
154 $this->zipcode = $zipcode;
155
156 return $this;
157 }
158
159 /**
160 * Get zipcode
161 *
162 * @return string
163 */
164 public function getZipcode(): string {
165 return $this->zipcode;
166 }
167
168 /**
169 * Set city
170 *
171 * @param string $city
172 *
173 * @return Location
174 */
175 public function setCity(string $city): Location {
176 $this->city = $city;
177
178 return $this;
179 }
180
181 /**
182 * Get city
183 *
184 * @return string
185 */
186 public function getCity(): string {
187 return $this->city;
188 }
189
190 /**
191 * Set latitude
192 *
193 * @param string $latitude
194 *
195 * @return Location
196 */
197 public function setLatitude(string $latitude): Location {
198 $this->latitude = $latitude;
199
200 return $this;
201 }
202
203 /**
204 * Get latitude
205 *
206 * @return string
207 */
208 public function getLatitude(): string {
209 return $this->latitude;
210 }
211
212 /**
213 * Set longitude
214 *
215 * @param string $longitude
216 *
217 * @return Location
218 */
219 public function setLongitude(string $longitude): Location {
220 $this->longitude = $longitude;
221
222 return $this;
223 }
224
225 /**
226 * Get longitude
227 *
228 * @return string
229 */
230 public function getLongitude(): string {
231 return $this->longitude;
232 }
233
234 /**
235 * Set indoor
236 *
237 * @param bool $indoor
238 *
239 * @return Session
240 */
241 public function setIndoor(bool $indoor): Location {
242 $this->indoor = $indoor;
243
244 return $this;
245 }
246
247 /**
248 * Get indoor
249 *
250 * @return bool
251 */
252 public function getIndoor(): bool {
253 return $this->indoor;
254 }
255
256 /**
257 * Set hotspot
258 *
259 * @param bool $hotspot
260 *
261 * @return Session
262 */
263 public function setHotspot(bool $hotspot): Location {
264 $this->hotspot = $hotspot;
265
266 return $this;
267 }
268
269 /**
270 * Get hotspot
271 *
272 * @return bool
273 */
274 public function getHotspot(): bool {
275 return $this->hotspot;
276 }
277
278 /**
279 * Set created
280 *
281 * @param \DateTime $created
282 *
283 * @return Location
284 */
285 public function setCreated(\DateTime $created): Location {
286 $this->created = $created;
287
288 return $this;
289 }
290
291 /**
292 * Get created
293 *
294 * @return \DateTime
295 */
296 public function getCreated(): \DateTime {
297 return $this->created;
298 }
299
300 /**
301 * Set updated
302 *
303 * @param \DateTime $updated
304 *
305 * @return Location
306 */
307 public function setUpdated(\DateTime $updated): Location {
308 $this->updated = $updated;
309
310 return $this;
311 }
312
313 /**
314 * Get updated
315 *
316 * @return \DateTime
317 */
318 public function getUpdated(): \DateTime {
319 return $this->updated;
320 }
321
322 /**
323 * Add session
324 *
325 * @param Session $session
326 *
327 * @return Location
328 */
329 public function addSession(Session $session): Location {
330 $this->sessions[] = $session;
331
332 return $this;
333 }
334
335 /**
336 * Remove session
337 *
338 * @param Session $session
339 * @return bool
340 */
341 public function removeSession(Session $session): bool {
342 return $this->sessions->removeElement($session);
343 }
344
345 /**
346 * Get sessions
347 *
348 * @return ArrayCollection
349 */
350 public function getSessions(): ArrayCollection {
351 return $this->sessions;
352 }
353
354 /**
355 * Add snippet
356 *
357 * @param Snippet $snippet
358 *
359 * @return Location
360 */
361 public function addSnippet(Snippet $snippet): Location {
362 $this->snippets[] = $snippet;
363
364 return $this;
365 }
366
367 /**
368 * Remove snippet
369 *
370 * @param Snippet $snippet
371 * @return bool
372 */
373 public function removeSnippet(Snippet $snippet): bool {
374 return $this->snippets->removeElement($snippet);
375 }
376
377 /**
378 * Get snippets
379 *
380 * @return ArrayCollection
381 */
382 public function getSnippets(): ArrayCollection {
383 return $this->snippets;
384 }
385
386 /**
387 * Add user
388 *
389 * @param User $user
390 *
391 * @return Location
392 */
393 public function addUser(User $user): Location {
394 //Add from owning side
395 $user->addLocation($this);
396
397 $this->users[] = $user;
398
399 return $this;
400 }
401
402 /**
403 * Remove user
404 *
405 * @param User $user
406 * @return bool
407 */
408 public function removeUser(User $user): bool {
409 if (!$this->locations->contains($user)) {
410 return true;
411 }
412
413 //Remove from owning side
414 $user->removeLocation($this);
415
416 return $this->users->removeElement($user);
417 }
418
419 /**
420 * Get users
421 *
422 * @return ArrayCollection
423 */
424 public function getUsers(): ArrayCollection {
425 return $this->users;
426 }
427
428 /**
429 * {@inheritdoc}
430 */
431 public function preUpdate(PreUpdateEventArgs $eventArgs) {
432 //Check that we have a location instance
433 if (($location = $eventArgs->getObject()) instanceof Location) {
434 //Set updated value
435 $location->setUpdated(new \DateTime('now'));
436 }
437 }
438
439 /**
440 * Returns a string representation of the location
441 *
442 * @return string
443 */
444 public function __toString(): string {
445 return $this->title;
446 }
447 }