]> Raphaël G. Git Repositories - airbundle/blobdiff - Entity/Location.php
Add location default values
[airbundle] / Entity / Location.php
index 57af698c4ced30112a6c7fcd7d67939ffe248967..f0e1a179dd9cc6969b407edc51a6d574f89e3053 100644 (file)
@@ -1,16 +1,17 @@
 <?php declare(strict_types=1);
 
 /*
 <?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;
 
  * 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;
 
 use Doctrine\Common\Collections\ArrayCollection;
 use Doctrine\ORM\Event\PreUpdateEventArgs;
 
@@ -19,77 +20,49 @@ use Doctrine\ORM\Event\PreUpdateEventArgs;
  */
 class Location {
        /**
  */
 class Location {
        /**
-        * @var integer
+        * Primary key
         */
         */
-       private $id;
+       private ?int $id = null;
 
        /**
         * @var string
         */
 
        /**
         * @var string
         */
-       private $title;
+       private ?string $description = null;
 
        /**
 
        /**
-        * @var string
-        */
-       private $address;
-
-       /**
-        * @var string
+        * Create datetime
         */
         */
-       private $zipcode;
+       private \DateTime $created;
 
        /**
 
        /**
-        * @var string
+        * Update datetime
         */
         */
-       private $city;
+       private \DateTime $updated;
 
        /**
 
        /**
-        * @var string
+        * Sessions collection
         */
         */
-       private $latitude;
+       private Collection $sessions;
 
        /**
 
        /**
-        * @var string
+        * Snippets collection
         */
         */
-       private $longitude;
+       private Collection $snippets;
 
        /**
 
        /**
-        * @var boolean
+        * Users collection
         */
         */
-       private $hotspot;
-
-       /**
-        * @var \DateTime
-        */
-       private $created;
-
-       /**
-        * @var \DateTime
-        */
-       private $updated;
-
-       /**
-        * @var ArrayCollection
-        */
-       private $sessions;
-
-       /**
-        * @var ArrayCollection
-        */
-       private $snippets;
-
-       /**
-        * @var ArrayCollection
-        */
-       private $users;
+       private Collection $users;
 
        /**
         * Constructor
         */
 
        /**
         * Constructor
         */
-       public function __construct() {
+       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) {
                //Set defaults
                $this->created = new \DateTime('now');
                $this->updated = new \DateTime('now');
                //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();
                $this->sessions = new ArrayCollection();
                $this->snippets = new ArrayCollection();
                $this->users = new ArrayCollection();
@@ -100,7 +73,7 @@ class Location {
         *
         * @return integer
         */
         *
         * @return integer
         */
-       public function getId(): int {
+       public function getId(): ?int {
                return $this->id;
        }
 
                return $this->id;
        }
 
@@ -126,6 +99,28 @@ class Location {
                return $this->title;
        }
 
                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
         *
        /**
         * Set address
         *
@@ -236,10 +231,32 @@ class Location {
                return $this->longitude;
        }
 
                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
         *
        /**
         * Set hotspot
         *
-        * @param boolean $hotspot
+        * @param bool $hotspot
         *
         * @return Session
         */
         *
         * @return Session
         */
@@ -252,7 +269,7 @@ class Location {
        /**
         * Get hotspot
         *
        /**
         * Get hotspot
         *
-        * @return boolean
+        * @return bool
         */
        public function getHotspot(): bool {
                return $this->hotspot;
         */
        public function getHotspot(): bool {
                return $this->hotspot;
@@ -319,7 +336,7 @@ class Location {
         * Remove session
         *
         * @param Session $session
         * Remove session
         *
         * @param Session $session
-        * @return boolean
+        * @return bool
         */
        public function removeSession(Session $session): bool {
                return $this->sessions->removeElement($session);
         */
        public function removeSession(Session $session): bool {
                return $this->sessions->removeElement($session);
@@ -351,7 +368,7 @@ class Location {
         * Remove snippet
         *
         * @param Snippet $snippet
         * Remove snippet
         *
         * @param Snippet $snippet
-        * @return boolean
+        * @return bool
         */
        public function removeSnippet(Snippet $snippet): bool {
                return $this->snippets->removeElement($snippet);
         */
        public function removeSnippet(Snippet $snippet): bool {
                return $this->snippets->removeElement($snippet);
@@ -374,6 +391,9 @@ class Location {
         * @return Location
         */
        public function addUser(User $user): Location {
         * @return Location
         */
        public function addUser(User $user): Location {
+               //Add from owning side
+               $user->addLocation($this);
+
                $this->users[] = $user;
 
                return $this;
                $this->users[] = $user;
 
                return $this;
@@ -383,9 +403,16 @@ class Location {
         * Remove user
         *
         * @param User $user
         * Remove user
         *
         * @param User $user
-        * @return boolean
+        * @return bool
         */
        public function removeUser(User $user): 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);
        }
 
                return $this->users->removeElement($user);
        }
 
@@ -403,7 +430,7 @@ class Location {
         */
        public function preUpdate(PreUpdateEventArgs $eventArgs) {
                //Check that we have a location instance
         */
        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'));
                }
                        //Set updated value
                        $location->setUpdated(new \DateTime('now'));
                }