1 <?php
declare(strict_types
=1);
4 * This file is part of the Rapsys AirBundle package.
6 * (c) Raphaël Gertz <symfony@rapsys.eu>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Rapsys\AirBundle\Entity
;
14 use Doctrine\Common\Collections\Collection
;
15 use Doctrine\Common\Collections\ArrayCollection
;
16 use Doctrine\ORM\Event\PreUpdateEventArgs
;
25 private ?int $id = null;
30 private ?string $description = null;
35 private \DateTime
$created;
40 private \DateTime
$updated;
45 private Collection
$sessions;
50 private Collection
$snippets;
55 private Collection
$users;
60 public function __construct(private string $title = '', private string $address = '', private string $zipcode = '', private string $city = '', private float $latitude = 0, private float $longitude = 0, private bool $hotspot = false, private bool $indoor = false) {
62 $this->created
= new \
DateTime('now');
63 $this->updated
= new \
DateTime('now');
66 $this->sessions
= new ArrayCollection();
67 $this->snippets
= new ArrayCollection();
68 $this->users
= new ArrayCollection();
76 public function getId(): ?int {
83 * @param string $title
87 public function setTitle(string $title): Location
{
88 $this->title
= $title;
98 public function getTitle(): string {
105 * @param string $description
109 public function setDescription(?string $description): Location
{
110 $this->description
= $description;
120 public function getDescription(): ?string {
121 return $this->description
;
127 * @param string $address
131 public function setAddress(string $address): Location
{
132 $this->address
= $address;
142 public function getAddress(): string {
143 return $this->address
;
149 * @param string $zipcode
153 public function setZipcode(string $zipcode): Location
{
154 $this->zipcode
= $zipcode;
164 public function getZipcode(): string {
165 return $this->zipcode
;
171 * @param string $city
175 public function setCity(string $city): Location
{
186 public function getCity(): string {
193 * @param string $latitude
197 public function setLatitude(string $latitude): Location
{
198 $this->latitude
= $latitude;
208 public function getLatitude(): string {
209 return $this->latitude
;
215 * @param string $longitude
219 public function setLongitude(string $longitude): Location
{
220 $this->longitude
= $longitude;
230 public function getLongitude(): string {
231 return $this->longitude
;
237 * @param bool $indoor
241 public function setIndoor(bool $indoor): Location
{
242 $this->indoor
= $indoor;
252 public function getIndoor(): bool {
253 return $this->indoor
;
259 * @param bool $hotspot
263 public function setHotspot(bool $hotspot): Location
{
264 $this->hotspot
= $hotspot;
274 public function getHotspot(): bool {
275 return $this->hotspot
;
281 * @param \DateTime $created
285 public function setCreated(\DateTime
$created): Location
{
286 $this->created
= $created;
296 public function getCreated(): \DateTime
{
297 return $this->created
;
303 * @param \DateTime $updated
307 public function setUpdated(\DateTime
$updated): Location
{
308 $this->updated
= $updated;
318 public function getUpdated(): \DateTime
{
319 return $this->updated
;
325 * @param Session $session
329 public function addSession(Session
$session): Location
{
330 $this->sessions
[] = $session;
338 * @param Session $session
341 public function removeSession(Session
$session): bool {
342 return $this->sessions
->removeElement($session);
348 * @return ArrayCollection
350 public function getSessions(): ArrayCollection
{
351 return $this->sessions
;
357 * @param Snippet $snippet
361 public function addSnippet(Snippet
$snippet): Location
{
362 $this->snippets
[] = $snippet;
370 * @param Snippet $snippet
373 public function removeSnippet(Snippet
$snippet): bool {
374 return $this->snippets
->removeElement($snippet);
380 * @return ArrayCollection
382 public function getSnippets(): ArrayCollection
{
383 return $this->snippets
;
393 public function addUser(User
$user): Location
{
394 //Add from owning side
395 $user->addLocation($this);
397 $this->users
[] = $user;
408 public function removeUser(User
$user): bool {
409 if (!$this->locations
->contains($user)) {
413 //Remove from owning side
414 $user->removeLocation($this);
416 return $this->users
->removeElement($user);
422 * @return ArrayCollection
424 public function getUsers(): ArrayCollection
{
431 public function preUpdate(PreUpdateEventArgs
$eventArgs) {
432 //Check that we have a location instance
433 if (($location = $eventArgs->getObject()) instanceof Location
) {
435 $location->setUpdated(new \
DateTime('now'));
440 * Returns a string representation of the location
444 public function __toString(): string {