<?php declare(strict_types=1);
/*
- * this file is part of the rapsys packbundle package.
+ * This file is part of the Rapsys AirBundle package.
*
- * (c) raphaël gertz <symfony@rapsys.eu>
+ * (c) Raphaël Gertz <symfony@rapsys.eu>
*
- * for the full copyright and license information, please view the license
+ * For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Rapsys\AirBundle\Entity;
+use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Event\PreUpdateEventArgs;
*/
class Location {
/**
- * @var integer
+ * Primary key
*/
- private $id;
+ private ?int $id = null;
/**
* @var string
*/
- private $title;
+ private ?string $description = null;
/**
- * @var string
- */
- private $short;
-
- /**
- * @var string
- */
- private $address;
-
- /**
- * @var string
- */
- private $zipcode;
-
- /**
- * @var string
- */
- private $city;
-
- /**
- * @var string
- */
- private $latitude;
-
- /**
- * @var string
- */
- private $longitude;
-
- /**
- * @var boolean
- */
- private $hotspot;
-
- /**
- * @var \DateTime
+ * Create datetime
*/
- private $created;
+ private \DateTime $created;
/**
- * @var \DateTime
+ * Update datetime
*/
- private $updated;
+ private \DateTime $updated;
/**
- * @var ArrayCollection
+ * Sessions collection
*/
- private $sessions;
+ private Collection $sessions;
/**
- * @var ArrayCollection
+ * Snippets collection
*/
- private $snippets;
+ private Collection $snippets;
/**
- * @var ArrayCollection
+ * Users collection
*/
- private $users;
+ private Collection $users;
/**
* Constructor
*/
- public function __construct() {
+ 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) {
+ //Set defaults
+ $this->created = new \DateTime('now');
+ $this->updated = new \DateTime('now');
+
+ //Set collections
$this->sessions = new ArrayCollection();
$this->snippets = new ArrayCollection();
$this->users = new ArrayCollection();
*
* @return integer
*/
- public function getId(): int {
+ public function getId(): ?int {
return $this->id;
}
}
/**
- * Set short
+ * Set description
*
- * @param string $short
+ * @param string $description
*
* @return Location
*/
- public function setShort(string $short): Location {
- $this->short = $short;
+ public function setDescription(?string $description): Location {
+ $this->description = $description;
return $this;
}
/**
- * Get short
+ * Get description
*
* @return string
*/
- public function getShort(): string {
- return $this->short;
+ public function getDescription(): ?string {
+ return $this->description;
}
/**
return $this->longitude;
}
+ /**
+ * Set indoor
+ *
+ * @param bool $indoor
+ *
+ * @return Session
+ */
+ public function setIndoor(bool $indoor): Location {
+ $this->indoor = $indoor;
+
+ return $this;
+ }
+
+ /**
+ * Get indoor
+ *
+ * @return bool
+ */
+ public function getIndoor(): bool {
+ return $this->indoor;
+ }
+
/**
* Set hotspot
*
- * @param boolean $hotspot
+ * @param bool $hotspot
*
* @return Session
*/
/**
* Get hotspot
*
- * @return boolean
+ * @return bool
*/
public function getHotspot(): bool {
return $this->hotspot;
* Remove session
*
* @param Session $session
- * @return boolean
+ * @return bool
*/
public function removeSession(Session $session): bool {
return $this->sessions->removeElement($session);
* Remove snippet
*
* @param Snippet $snippet
- * @return boolean
+ * @return bool
*/
public function removeSnippet(Snippet $snippet): bool {
return $this->snippets->removeElement($snippet);
* @return Location
*/
public function addUser(User $user): Location {
+ //Add from owning side
+ $user->addLocation($this);
+
$this->users[] = $user;
return $this;
* Remove user
*
* @param User $user
- * @return boolean
+ * @return bool
*/
public function removeUser(User $user): bool {
+ if (!$this->locations->contains($user)) {
+ return true;
+ }
+
+ //Remove from owning side
+ $user->removeLocation($this);
+
return $this->users->removeElement($user);
}
*/
public function preUpdate(PreUpdateEventArgs $eventArgs) {
//Check that we have a location instance
- if (($location = $eventArgs->getEntity()) instanceof Location) {
+ if (($location = $eventArgs->getObject()) instanceof Location) {
//Set updated value
$location->setUpdated(new \DateTime('now'));
}