]> Raphaël G. Git Repositories - airbundle/blobdiff - Entity/Dance.php
Use google client id and secret env variables
[airbundle] / Entity / Dance.php
index c269f32d196a33dc200c32ad9e75e3809e6595aa..6ae5f1bb14dcd72bd7e7e47b4a3f94ba44cc3887 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,39 +20,37 @@ use Doctrine\ORM\Event\PreUpdateEventArgs;
  */
 class Dance {
        /**
  */
 class Dance {
        /**
-        * @var integer
+        * Primary key
         */
         */
-       private $id;
+       private ?int $id = null;
 
        /**
 
        /**
-        * @var string
+        * Create datetime
         */
         */
-       protected $title;
+       private \DateTime $created;
 
        /**
 
        /**
-        * @var \DateTime
+        * Update datetime
         */
         */
-       private $created;
+       private \DateTime $updated;
 
        /**
 
        /**
-        * @var \DateTime
+        * Applications collection
         */
         */
-       private $updated;
+       private Collection $applications;
 
        /**
 
        /**
-        * @var ArrayCollection
+        * Users collection
         */
         */
-       private $applications;
-
-       /**
-        * @var ArrayCollection
-        */
-       private $users;
+       private Collection $users;
 
        /**
         * Constructor
 
        /**
         * Constructor
+        *
+        * @param string $name The dance name
+        * @param string $type The dance type
         */
         */
-       public function __construct() {
+       public function __construct(private string $name, private string $type) {
                //Set defaults
                $this->created = new \DateTime('now');
                $this->updated = new \DateTime('now');
                //Set defaults
                $this->created = new \DateTime('now');
                $this->updated = new \DateTime('now');
@@ -66,30 +65,52 @@ class Dance {
         *
         * @return integer
         */
         *
         * @return integer
         */
-       public function getId(): int {
+       public function getId(): ?int {
                return $this->id;
        }
 
        /**
                return $this->id;
        }
 
        /**
-        * Set title
+        * Set name
         *
         *
-        * @param string $title
+        * @param string $name
         *
         * @return Dance
         */
         *
         * @return Dance
         */
-       public function setTitle(string $title): Dance {
-               $this->title = $title;
+       public function setName(string $name): Dance {
+               $this->name = $name;
 
                return $this;
        }
 
        /**
 
                return $this;
        }
 
        /**
-        * Get title
+        * Get name
         *
         * @return string
         */
         *
         * @return string
         */
-       public function getTitle(): string {
-               return $this->title;
+       public function getName(): string {
+               return $this->name;
+       }
+
+       /**
+        * Set type
+        *
+        * @param string $type
+        *
+        * @return Dance
+        */
+       public function setType(string $type): Dance {
+               $this->type = $type;
+
+               return $this;
+       }
+
+       /**
+        * Get type
+        *
+        * @return string
+        */
+       public function getType(): string {
+               return $this->type;
        }
 
        /**
        }
 
        /**
@@ -177,6 +198,9 @@ class Dance {
         * @return Dance
         */
        public function addUser(User $user): Dance {
         * @return Dance
         */
        public function addUser(User $user): Dance {
+               //Add from owning side
+               $user->addDance($this);
+
                $this->users[] = $user;
 
                return $this;
                $this->users[] = $user;
 
                return $this;
@@ -190,6 +214,13 @@ class Dance {
         * @return bool
         */
        public function removeUser(User $user): bool {
         * @return bool
         */
        public function removeUser(User $user): bool {
+               if (!$this->dances->contains($user)) {
+                       return true;
+               }
+
+               //Remove from owning side
+               $user->removeDance($this);
+
                return $this->users->removeElement($user);
        }
 
                return $this->users->removeElement($user);
        }
 
@@ -207,7 +238,7 @@ class Dance {
         */
        public function preUpdate(PreUpdateEventArgs $eventArgs) {
                //Check that we have a dance instance
         */
        public function preUpdate(PreUpdateEventArgs $eventArgs) {
                //Check that we have a dance instance
-               if (($dance = $eventArgs->getEntity()) instanceof Dance) {
+               if (($dance = $eventArgs->getObject()) instanceof Dance) {
                        //Set updated value
                        $dance->setUpdated(new \DateTime('now'));
                }
                        //Set updated value
                        $dance->setUpdated(new \DateTime('now'));
                }
@@ -219,6 +250,6 @@ class Dance {
         * @return string
         */
        public function __toString(): string {
         * @return string
         */
        public function __toString(): string {
-               return $this->title;
+               return $this->name.' '.lcfirst($this->type);
        }
 }
        }
 }