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