]> Raphaël G. Git Repositories - airbundle/blobdiff - Entity/Location.php
Add strict
[airbundle] / Entity / Location.php
index 73fc6b980ff79370d14e6fb6103b4fc0e87cd752..1fdca93803149aa9a4c241536af7b21366d0d3e4 100644 (file)
@@ -1,7 +1,19 @@
-<?php
+<?php declare(strict_types=1);
+
+/*
+ * this file is part of the rapsys packbundle 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\ArrayCollection;
+use Doctrine\ORM\Event\PreUpdateEventArgs;
+
 /**
  * Location
  */
@@ -62,15 +74,27 @@ class Location {
        private $updated;
 
        /**
-        * @var \Doctrine\Common\Collections\Collection
+        * @var ArrayCollection
         */
        private $sessions;
 
+       /**
+        * @var ArrayCollection
+        */
+       private $snippets;
+
+       /**
+        * @var ArrayCollection
+        */
+       private $users;
+
        /**
         * Constructor
         */
        public function __construct() {
-               $this->sessions = new \Doctrine\Common\Collections\ArrayCollection();
+               $this->sessions = new ArrayCollection();
+               $this->snippets = new ArrayCollection();
+               $this->users = new ArrayCollection();
        }
 
        /**
@@ -78,7 +102,7 @@ class Location {
         *
         * @return integer
         */
-       public function getId() {
+       public function getId(): int {
                return $this->id;
        }
 
@@ -89,7 +113,7 @@ class Location {
         *
         * @return Location
         */
-       public function setTitle($title) {
+       public function setTitle(string $title): Location {
                $this->title = $title;
 
                return $this;
@@ -100,7 +124,7 @@ class Location {
         *
         * @return string
         */
-       public function getTitle() {
+       public function getTitle(): string {
                return $this->title;
        }
 
@@ -111,7 +135,7 @@ class Location {
         *
         * @return Location
         */
-       public function setShort($short) {
+       public function setShort(string $short): Location {
                $this->short = $short;
 
                return $this;
@@ -122,7 +146,7 @@ class Location {
         *
         * @return string
         */
-       public function getShort() {
+       public function getShort(): string {
                return $this->short;
        }
 
@@ -133,7 +157,7 @@ class Location {
         *
         * @return Location
         */
-       public function setAddress($address) {
+       public function setAddress(string $address): Location {
                $this->address = $address;
 
                return $this;
@@ -144,7 +168,7 @@ class Location {
         *
         * @return string
         */
-       public function getAddress() {
+       public function getAddress(): string {
                return $this->address;
        }
 
@@ -155,7 +179,7 @@ class Location {
         *
         * @return Location
         */
-       public function setZipcode($zipcode) {
+       public function setZipcode(string $zipcode): Location {
                $this->zipcode = $zipcode;
 
                return $this;
@@ -166,7 +190,7 @@ class Location {
         *
         * @return string
         */
-       public function getZipcode() {
+       public function getZipcode(): string {
                return $this->zipcode;
        }
 
@@ -177,7 +201,7 @@ class Location {
         *
         * @return Location
         */
-       public function setCity($city) {
+       public function setCity(string $city): Location {
                $this->city = $city;
 
                return $this;
@@ -188,7 +212,7 @@ class Location {
         *
         * @return string
         */
-       public function getCity() {
+       public function getCity(): string {
                return $this->city;
        }
 
@@ -199,7 +223,7 @@ class Location {
         *
         * @return Location
         */
-       public function setLatitude($latitude) {
+       public function setLatitude(string $latitude): Location {
                $this->latitude = $latitude;
 
                return $this;
@@ -210,7 +234,7 @@ class Location {
         *
         * @return string
         */
-       public function getLatitude() {
+       public function getLatitude(): string {
                return $this->latitude;
        }
 
@@ -221,7 +245,7 @@ class Location {
         *
         * @return Location
         */
-       public function setLongitude($longitude) {
+       public function setLongitude(string $longitude): Location {
                $this->longitude = $longitude;
 
                return $this;
@@ -232,7 +256,7 @@ class Location {
         *
         * @return string
         */
-       public function getLongitude() {
+       public function getLongitude(): string {
                return $this->longitude;
        }
 
@@ -243,7 +267,7 @@ class Location {
         *
         * @return Session
         */
-       public function setHotspot($hotspot) {
+       public function setHotspot(bool $hotspot): Location {
                $this->hotspot = $hotspot;
 
                return $this;
@@ -254,7 +278,7 @@ class Location {
         *
         * @return boolean
         */
-       public function getHotspot() {
+       public function getHotspot(): bool {
                return $this->hotspot;
        }
 
@@ -265,7 +289,7 @@ class Location {
         *
         * @return Location
         */
-       public function setCreated($created) {
+       public function setCreated(\DateTime $created): Location {
                $this->created = $created;
 
                return $this;
@@ -276,7 +300,7 @@ class Location {
         *
         * @return \DateTime
         */
-       public function getCreated() {
+       public function getCreated(): \DateTime {
                return $this->created;
        }
 
@@ -287,7 +311,7 @@ class Location {
         *
         * @return Location
         */
-       public function setUpdated($updated) {
+       public function setUpdated(\DateTime $updated): Location {
                $this->updated = $updated;
 
                return $this;
@@ -298,18 +322,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;
@@ -318,21 +342,97 @@ class Location {
        /**
         * Remove session
         *
-        * @param \Rapsys\AirBundle\Entity\Session $session
+        * @param Session $session
+        * @return boolean
         */
-       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 Snippet $snippet
+        *
+        * @return Location
+        */
+       public function addSnippet(Snippet $snippet): Location {
+               $this->snippets[] = $snippet;
+
+               return $this;
+       }
+
+       /**
+        * Remove snippet
+        *
+        * @param Snippet $snippet
+        * @return boolean
+        */
+       public function removeSnippet(Snippet $snippet): bool {
+               return $this->snippets->removeElement($snippet);
+       }
+
+       /**
+        * Get snippets
+        *
+        * @return ArrayCollection
+        */
+       public function getSnippets(): ArrayCollection {
+               return $this->snippets;
+       }
+
+       /**
+        * Add user
+        *
+        * @param User $user
+        *
+        * @return Location
+        */
+       public function addUser(User $user): Location {
+               $this->users[] = $user;
+
+               return $this;
+       }
+
+       /**
+        * Remove user
+        *
+        * @param User $user
+        * @return boolean
+        */
+       public function removeUser(User $user): bool {
+               return $this->users->removeElement($user);
+       }
+
+       /**
+        * Get users
+        *
+        * @return ArrayCollection
+        */
+       public function getUsers(): ArrayCollection {
+               return $this->users;
+       }
+
+       /**
+        * {@inheritdoc}
+        */
+       public function preUpdate(PreUpdateEventArgs $eventArgs) {
+               //Check that we have a location instance
+               if (($user = $eventArgs->getEntity()) instanceof Location) {
+                       //Set updated value
+                       $user->setUpdated(new \DateTime('now'));
+               }
+       }
+
        /**
         * Returns a string representation of the location
         *