]> Raphaël G. Git Repositories - airbundle/blobdiff - Entity/Location.php
Fix header comment
[airbundle] / Entity / Location.php
index fd619698cbf4ff8b455f70f728bfec446bca5737..75f6f45e29774f85ca6187d48aa56cea97666aef 100644 (file)
@@ -1,15 +1,28 @@
-<?php
+<?php declare(strict_types=1);
+
+/*
+ * This file is part of the Rapsys AirBundle package.
+ *
+ * (c) Raphaël Gertz <symfony@rapsys.eu>
+ *
+ * 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;
+
 /**
  * Location
  */
 class Location {
        /**
-        * @var integer
+        * Primary key
         */
-       private $id;
+       private ?int $id = null;
 
        /**
         * @var string
@@ -19,7 +32,7 @@ class Location {
        /**
         * @var string
         */
-       private $short;
+       private ?string $description = null;
 
        /**
         * @var string
@@ -47,42 +60,52 @@ 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 \Doctrine\Common\Collections\Collection
+        * Sessions collection
         */
-       private $sessions;
+       private Collection $sessions;
 
        /**
-        * @var \Doctrine\Common\Collections\Collection
+        * Snippets collection
         */
-       private $snippets;
+       private Collection $snippets;
 
        /**
-        * @var \Doctrine\Common\Collections\Collection
+        * Users collection
         */
-       private $users;
+       private Collection $users;
 
        /**
         * Constructor
         */
        public function __construct() {
-               $this->sessions = new \Doctrine\Common\Collections\ArrayCollection();
-               $this->snippets = new \Doctrine\Common\Collections\ArrayCollection();
-               $this->users = new \Doctrine\Common\Collections\ArrayCollection();
+               //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();
        }
 
        /**
@@ -90,7 +113,7 @@ class Location {
         *
         * @return integer
         */
-       public function getId() {
+       public function getId(): ?int {
                return $this->id;
        }
 
@@ -101,7 +124,7 @@ class Location {
         *
         * @return Location
         */
-       public function setTitle($title) {
+       public function setTitle(string $title): Location {
                $this->title = $title;
 
                return $this;
@@ -112,30 +135,30 @@ class Location {
         *
         * @return string
         */
-       public function getTitle() {
+       public function getTitle(): string {
                return $this->title;
        }
 
        /**
-        * Set short
+        * Set description
         *
-        * @param string $short
+        * @param string $description
         *
         * @return Location
         */
-       public function setShort($short) {
-               $this->short = $short;
+       public function setDescription(?string $description): Location {
+               $this->description = $description;
 
                return $this;
        }
 
        /**
-        * Get short
+        * Get description
         *
         * @return string
         */
-       public function getShort() {
-               return $this->short;
+       public function getDescription(): ?string {
+               return $this->description;
        }
 
        /**
@@ -145,7 +168,7 @@ class Location {
         *
         * @return Location
         */
-       public function setAddress($address) {
+       public function setAddress(string $address): Location {
                $this->address = $address;
 
                return $this;
@@ -156,7 +179,7 @@ class Location {
         *
         * @return string
         */
-       public function getAddress() {
+       public function getAddress(): string {
                return $this->address;
        }
 
@@ -167,7 +190,7 @@ class Location {
         *
         * @return Location
         */
-       public function setZipcode($zipcode) {
+       public function setZipcode(string $zipcode): Location {
                $this->zipcode = $zipcode;
 
                return $this;
@@ -178,7 +201,7 @@ class Location {
         *
         * @return string
         */
-       public function getZipcode() {
+       public function getZipcode(): string {
                return $this->zipcode;
        }
 
@@ -189,7 +212,7 @@ class Location {
         *
         * @return Location
         */
-       public function setCity($city) {
+       public function setCity(string $city): Location {
                $this->city = $city;
 
                return $this;
@@ -200,7 +223,7 @@ class Location {
         *
         * @return string
         */
-       public function getCity() {
+       public function getCity(): string {
                return $this->city;
        }
 
@@ -211,7 +234,7 @@ class Location {
         *
         * @return Location
         */
-       public function setLatitude($latitude) {
+       public function setLatitude(string $latitude): Location {
                $this->latitude = $latitude;
 
                return $this;
@@ -222,7 +245,7 @@ class Location {
         *
         * @return string
         */
-       public function getLatitude() {
+       public function getLatitude(): string {
                return $this->latitude;
        }
 
@@ -233,7 +256,7 @@ class Location {
         *
         * @return Location
         */
-       public function setLongitude($longitude) {
+       public function setLongitude(string $longitude): Location {
                $this->longitude = $longitude;
 
                return $this;
@@ -244,18 +267,40 @@ class Location {
         *
         * @return string
         */
-       public function getLongitude() {
+       public function getLongitude(): string {
                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
         */
-       public function setHotspot($hotspot) {
+       public function setHotspot(bool $hotspot): Location {
                $this->hotspot = $hotspot;
 
                return $this;
@@ -264,9 +309,9 @@ class Location {
        /**
         * Get hotspot
         *
-        * @return boolean
+        * @return bool
         */
-       public function getHotspot() {
+       public function getHotspot(): bool {
                return $this->hotspot;
        }
 
@@ -277,7 +322,7 @@ class Location {
         *
         * @return Location
         */
-       public function setCreated($created) {
+       public function setCreated(\DateTime $created): Location {
                $this->created = $created;
 
                return $this;
@@ -288,7 +333,7 @@ class Location {
         *
         * @return \DateTime
         */
-       public function getCreated() {
+       public function getCreated(): \DateTime {
                return $this->created;
        }
 
@@ -299,7 +344,7 @@ class Location {
         *
         * @return Location
         */
-       public function setUpdated($updated) {
+       public function setUpdated(\DateTime $updated): Location {
                $this->updated = $updated;
 
                return $this;
@@ -310,18 +355,18 @@ class Location {
         *
         * @return \DateTime
         */
-       public function getUpdated() {
+       public function getUpdated(): \DateTime {
                return $this->updated;
        }
 
        /**
         * Add session
         *
-        * @param \Rapsys\AirBundle\Entity\Session $session
+        * @param Session $session
         *
         * @return Location
         */
-       public function addSession(\Rapsys\AirBundle\Entity\Session $session) {
+       public function addSession(Session $session): Location {
                $this->sessions[] = $session;
 
                return $this;
@@ -330,29 +375,30 @@ class Location {
        /**
         * Remove session
         *
-        * @param \Rapsys\AirBundle\Entity\Session $session
+        * @param Session $session
+        * @return bool
         */
-       public function removeSession(\Rapsys\AirBundle\Entity\Session $session) {
-               $this->sessions->removeElement($session);
+       public function removeSession(Session $session): bool {
+               return $this->sessions->removeElement($session);
        }
 
        /**
         * Get sessions
         *
-        * @return \Doctrine\Common\Collections\Collection
+        * @return ArrayCollection
         */
-       public function getSessions() {
+       public function getSessions(): ArrayCollection {
                return $this->sessions;
        }
 
        /**
         * Add snippet
         *
-        * @param \Rapsys\AirBundle\Entity\Snippet $snippet
+        * @param Snippet $snippet
         *
         * @return Location
         */
-       public function addSnippet(\Rapsys\AirBundle\Entity\Snippet $snippet) {
+       public function addSnippet(Snippet $snippet): Location {
                $this->snippets[] = $snippet;
 
                return $this;
@@ -361,29 +407,33 @@ class Location {
        /**
         * Remove snippet
         *
-        * @param \Rapsys\AirBundle\Entity\Snippet $snippet
+        * @param Snippet $snippet
+        * @return bool
         */
-       public function removeSnippet(\Rapsys\AirBundle\Entity\Snippet $snippet) {
-               $this->snippets->removeElement($snippet);
+       public function removeSnippet(Snippet $snippet): bool {
+               return $this->snippets->removeElement($snippet);
        }
 
        /**
         * Get snippets
         *
-        * @return \Doctrine\Common\Collections\Collection
+        * @return ArrayCollection
         */
-       public function getSnippets() {
+       public function getSnippets(): ArrayCollection {
                return $this->snippets;
        }
 
        /**
         * Add user
         *
-        * @param \Rapsys\AirBundle\Entity\User $user
+        * @param User $user
         *
         * @return Location
         */
-       public function addUser(\Rapsys\AirBundle\Entity\User $user) {
+       public function addUser(User $user): Location {
+               //Add from owning side
+               $user->addLocation($this);
+
                $this->users[] = $user;
 
                return $this;
@@ -392,21 +442,40 @@ class Location {
        /**
         * Remove user
         *
-        * @param \Rapsys\AirBundle\Entity\User $user
+        * @param User $user
+        * @return bool
         */
-       public function removeUser(\Rapsys\AirBundle\Entity\User $user) {
-               $this->users->removeElement($user);
+       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);
        }
 
        /**
         * Get users
         *
-        * @return \Doctrine\Common\Collections\Collection
+        * @return ArrayCollection
         */
-       public function getUsers() {
+       public function getUsers(): ArrayCollection {
                return $this->users;
        }
 
+       /**
+        * {@inheritdoc}
+        */
+       public function preUpdate(PreUpdateEventArgs $eventArgs) {
+               //Check that we have a location instance
+               if (($location = $eventArgs->getObject()) instanceof Location) {
+                       //Set updated value
+                       $location->setUpdated(new \DateTime('now'));
+               }
+       }
+
        /**
         * Returns a string representation of the location
         *