]> Raphaël G. Git Repositories - airbundle/blobdiff - Entity/Location.php
Version 0.6.1
[airbundle] / Entity / Location.php
index 613e46281c3664f841ddbc86f8790c8bfb50f966..db76b03d73ce5da1bb2720c77346693c0bf81b5b 100644 (file)
@@ -1,16 +1,17 @@
 <?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;
 
@@ -19,88 +20,49 @@ 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
-        */
-       protected $description;
-
-       /**
-        * @var string
-        */
-       private $address;
-
-       /**
-        * @var string
-        */
-       private $zipcode;
-
-       /**
-        * @var string
+        * Create datetime
         */
-       private $city;
+       private \DateTimeImmutable $created;
 
        /**
-        * @var string
+        * Update datetime
         */
-       private $latitude;
+       private \DateTimeImmutable $updated;
 
        /**
-        * @var string
+        * Sessions collection
         */
-       private $longitude;
+       private Collection $sessions;
 
        /**
-        * @var bool
+        * Snippets collection
         */
-       private $indoor;
+       private Collection $snippets;
 
        /**
-        * @var bool
+        * 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
         */
-       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->description = null;
-               $this->created = new \DateTime('now');
-               $this->updated = new \DateTime('now');
+               $this->created = new \DateTimeImmutable('now');
+               $this->updated = new \DateTimeImmutable('now');
+
+               //Set collections
                $this->sessions = new ArrayCollection();
                $this->snippets = new ArrayCollection();
                $this->users = new ArrayCollection();
@@ -111,7 +73,7 @@ class Location {
         *
         * @return integer
         */
-       public function getId(): int {
+       public function getId(): ?int {
                return $this->id;
        }
 
@@ -316,11 +278,11 @@ class Location {
        /**
         * Set created
         *
-        * @param \DateTime $created
+        * @param \DateTimeImmutable $created
         *
         * @return Location
         */
-       public function setCreated(\DateTime $created): Location {
+       public function setCreated(\DateTimeImmutable $created): Location {
                $this->created = $created;
 
                return $this;
@@ -329,20 +291,20 @@ class Location {
        /**
         * Get created
         *
-        * @return \DateTime
+        * @return \DateTimeImmutable
         */
-       public function getCreated(): \DateTime {
+       public function getCreated(): \DateTimeImmutable {
                return $this->created;
        }
 
        /**
         * Set updated
         *
-        * @param \DateTime $updated
+        * @param \DateTimeImmutable $updated
         *
         * @return Location
         */
-       public function setUpdated(\DateTime $updated): Location {
+       public function setUpdated(\DateTimeImmutable $updated): Location {
                $this->updated = $updated;
 
                return $this;
@@ -351,9 +313,9 @@ class Location {
        /**
         * Get updated
         *
-        * @return \DateTime
+        * @return \DateTimeImmutable
         */
-       public function getUpdated(): \DateTime {
+       public function getUpdated(): \DateTimeImmutable {
                return $this->updated;
        }
 
@@ -430,7 +392,7 @@ class Location {
         */
        public function addUser(User $user): Location {
                //Add from owning side
-               $user->addSubscriber($this);
+               $user->addLocation($this);
 
                $this->users[] = $user;
 
@@ -444,12 +406,12 @@ class Location {
         * @return bool
         */
        public function removeUser(User $user): bool {
-               if (!$this->users->contains($user)) {
+               if (!$this->locations->contains($user)) {
                        return true;
                }
 
                //Remove from owning side
-               $user->removeSubscriber($this);
+               $user->removeLocation($this);
 
                return $this->users->removeElement($user);
        }
@@ -468,9 +430,9 @@ 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'));
+                       $location->setUpdated(new \DateTimeImmutable('now'));
                }
        }