X-Git-Url: https://git.rapsys.eu/airbundle/blobdiff_plain/f0ed7af138b95f31354f8d5a37cb4cd27b902a75..aecd79b0af016492323465e0526dbbbd94178976:/Entity/Location.php?ds=inline diff --git a/Entity/Location.php b/Entity/Location.php index 57af698..75f6f45 100644 --- a/Entity/Location.php +++ b/Entity/Location.php @@ -1,16 +1,17 @@ + * (c) Raphaël Gertz * - * 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; @@ -19,15 +20,20 @@ use Doctrine\ORM\Event\PreUpdateEventArgs; */ class Location { /** - * @var integer + * Primary key */ - private $id; + private ?int $id = null; /** * @var string */ private $title; + /** + * @var string + */ + private ?string $description = null; + /** * @var string */ @@ -54,34 +60,39 @@ class Location { private $longitude; /** - * @var boolean + * @var bool + */ + private $indoor; + + /** + * @var bool */ 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 @@ -90,6 +101,8 @@ class Location { //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(); @@ -100,7 +113,7 @@ class Location { * * @return integer */ - public function getId(): int { + public function getId(): ?int { return $this->id; } @@ -126,6 +139,28 @@ class Location { return $this->title; } + /** + * Set description + * + * @param string $description + * + * @return Location + */ + public function setDescription(?string $description): Location { + $this->description = $description; + + return $this; + } + + /** + * Get description + * + * @return string + */ + public function getDescription(): ?string { + return $this->description; + } + /** * Set address * @@ -236,10 +271,32 @@ class Location { 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 */ @@ -252,7 +309,7 @@ class Location { /** * Get hotspot * - * @return boolean + * @return bool */ public function getHotspot(): bool { return $this->hotspot; @@ -319,7 +376,7 @@ class Location { * Remove session * * @param Session $session - * @return boolean + * @return bool */ public function removeSession(Session $session): bool { return $this->sessions->removeElement($session); @@ -351,7 +408,7 @@ class Location { * Remove snippet * * @param Snippet $snippet - * @return boolean + * @return bool */ public function removeSnippet(Snippet $snippet): bool { return $this->snippets->removeElement($snippet); @@ -374,6 +431,9 @@ class Location { * @return Location */ public function addUser(User $user): Location { + //Add from owning side + $user->addLocation($this); + $this->users[] = $user; return $this; @@ -383,9 +443,16 @@ class Location { * 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); } @@ -403,7 +470,7 @@ class Location { */ 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')); }