X-Git-Url: https://git.rapsys.eu/airbundle/blobdiff_plain/89206adbc7af13fc281d31dabcc416d973982428..2884b5c8b4514b0e1c0dd0449db2af5be32382b6:/Entity/Location.php?ds=sidebyside

diff --git a/Entity/Location.php b/Entity/Location.php
index c379b56..d70bddf 100644
--- a/Entity/Location.php
+++ b/Entity/Location.php
@@ -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
+	 * Create datetime
 	 */
-	private $zipcode;
+	private \DateTime $created;
 
 	/**
-	 * @var string
-	 */
-	private $city;
-
-	/**
-	 * @var string
-	 */
-	private $latitude;
-
-	/**
-	 * @var string
+	 * Update datetime
 	 */
-	private $longitude;
+	private \DateTime $updated;
 
 	/**
-	 * @var bool
+	 * Sessions collection
 	 */
-	private $indoor;
+	private Collection $sessions;
 
 	/**
-	 * @var bool
+	 * Snippets collection
 	 */
-	private $hotspot;
+	private Collection $snippets;
 
 	/**
-	 * @var \DateTime
+	 * Users collection
 	 */
-	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');
+
+		//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;
 	}
 
@@ -429,6 +391,9 @@ class Location {
 	 * @return Location
 	 */
 	public function addUser(User $user): Location {
+		//Add from owning side
+		$user->addLocation($this);
+
 		$this->users[] = $user;
 
 		return $this;
@@ -441,6 +406,13 @@ class Location {
 	 * @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);
 	}
 
@@ -458,7 +430,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'));
 		}