]> Raphaƫl G. Git Repositories - airbundle/blobdiff - Entity/Dance.php
Shorten air bundle route aliases
[airbundle] / Entity / Dance.php
index e3779da83fc03d8558dbaa0c4dead87b3aea33a8..0b132c8418cd76f59846514ffb62784aaa222743 100644 (file)
@@ -26,7 +26,12 @@ class Dance {
        /**
         * @var string
         */
        /**
         * @var string
         */
-       protected $title;
+       protected $name;
+
+       /**
+        * @var string
+        */
+       protected $type;
 
        /**
         * @var \DateTime
 
        /**
         * @var \DateTime
@@ -50,11 +55,18 @@ class Dance {
 
        /**
         * Constructor
 
        /**
         * Constructor
+        *
+        * @param string $name The dance name
+        * @param string $type The dance type
         */
         */
-       public function __construct() {
+       public function __construct(string $name, string $type) {
                //Set defaults
                //Set defaults
+               $this->name = $name;
+               $this->type = $type;
                $this->created = new \DateTime('now');
                $this->updated = new \DateTime('now');
                $this->created = new \DateTime('now');
                $this->updated = new \DateTime('now');
+
+               //Set collections
                $this->applications = new ArrayCollection();
                $this->users = new ArrayCollection();
        }
                $this->applications = new ArrayCollection();
                $this->users = new ArrayCollection();
        }
@@ -69,25 +81,47 @@ class Dance {
        }
 
        /**
        }
 
        /**
-        * 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;
        }
 
        /**
        }
 
        /**
@@ -175,6 +209,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;
@@ -188,6 +225,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);
        }
 
@@ -204,8 +248,8 @@ class Dance {
         * {@inheritdoc}
         */
        public function preUpdate(PreUpdateEventArgs $eventArgs) {
         * {@inheritdoc}
         */
        public function preUpdate(PreUpdateEventArgs $eventArgs) {
-               //Check that we have an session instance
-               if (($dance = $eventArgs->getEntity()) instanceof Dance) {
+               //Check that we have a dance instance
+               if (($dance = $eventArgs->getObject()) instanceof Dance) {
                        //Set updated value
                        $dance->setUpdated(new \DateTime('now'));
                }
                        //Set updated value
                        $dance->setUpdated(new \DateTime('now'));
                }
@@ -217,6 +261,6 @@ class Dance {
         * @return string
         */
        public function __toString(): string {
         * @return string
         */
        public function __toString(): string {
-               return $this->title;
+               return $this->name.' '.lcfirst($this->type);
        }
 }
        }
 }