]> Raphaël G. Git Repositories - airbundle/blobdiff - Entity/Application.php
Add default values to class member variables
[airbundle] / Entity / Application.php
index 2e8cca52177315e2eec06f0ad32bc1d0fcdb6116..b2672a19aa898ff58a383fed4bb273c27fe7e957 100644 (file)
@@ -1,56 +1,69 @@
-<?php
+<?php declare(strict_types=1);
+
+/*
+ * This file is part of the Rapsys AirBundle 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;
 
 
 namespace Rapsys\AirBundle\Entity;
 
+use Doctrine\ORM\Event\PreUpdateEventArgs;
+
 /**
  * Application
  */
 class Application {
        /**
 /**
  * Application
  */
 class Application {
        /**
-        * @var integer
+        * Primary key
         */
         */
-       private $id;
+       private ?int $id = null;
 
        /**
 
        /**
-        * @var float
+        * Dance instance
         */
         */
-       private $score;
+       private Dance $dance;
 
        /**
 
        /**
-        * @var \DateTime
+        * Score
         */
         */
-       private $canceled;
+       private ?float $score = null;
 
        /**
 
        /**
-        * @var \DateTime
+        * Cancel datetime
         */
         */
-       private $created;
+       private ?\DateTime $canceled = null;
 
        /**
 
        /**
-        * @var \DateTime
+        * Create datetime
         */
         */
-       private $updated;
+       private \DateTime $created;
 
        /**
 
        /**
-        * @var \Doctrine\Common\Collections\Collection
+        * Update datetime
         */
         */
-       private $votes;
+       private \DateTime $updated;
 
        /**
 
        /**
-        * @var \Rapsys\AirBundle\Entity\Session
+        * Session instance
         */
         */
-       private $session;
+       private $session = null;
 
        /**
 
        /**
-        * @var \Rapsys\AirBundle\Entity\User
+        * User instance
         */
         */
-       private $user;
+       private $user = null;
 
        /**
         * Constructor
         */
        public function __construct() {
 
        /**
         * Constructor
         */
        public function __construct() {
-               $this->votes = new \Doctrine\Common\Collections\ArrayCollection();
+               //Set defaults
+               $this->created = new \DateTime('now');
+               $this->updated = new \DateTime('now');
        }
 
        /**
        }
 
        /**
@@ -58,10 +71,32 @@ class Application {
         *
         * @return integer
         */
         *
         * @return integer
         */
-       public function getId() {
+       public function getId(): ?int {
                return $this->id;
        }
 
                return $this->id;
        }
 
+       /**
+        * Set dance
+        *
+        * @param Dance $dance
+        *
+        * @return Application
+        */
+       public function setDance(Dance $dance): Application {
+               $this->dance = $dance;
+
+               return $this;
+       }
+
+       /**
+        * Get dance
+        *
+        * @return Dance
+        */
+       public function getDance(): Dance {
+               return $this->dance;
+       }
+
        /**
         * Set score
         *
        /**
         * Set score
         *
@@ -69,7 +104,7 @@ class Application {
         *
         * @return Application
         */
         *
         * @return Application
         */
-       public function setScore($score) {
+       public function setScore(?float $score): Application {
                $this->score = $score;
 
                return $this;
                $this->score = $score;
 
                return $this;
@@ -80,7 +115,7 @@ class Application {
         *
         * @return float
         */
         *
         * @return float
         */
-       public function getScore() {
+       public function getScore(): ?float {
                return $this->score;
        }
 
                return $this->score;
        }
 
@@ -91,7 +126,7 @@ class Application {
         *
         * @return Application
         */
         *
         * @return Application
         */
-       public function setCanceled($canceled) {
+       public function setCanceled(?\DateTime $canceled): Application {
                $this->canceled = $canceled;
 
                return $this;
                $this->canceled = $canceled;
 
                return $this;
@@ -102,7 +137,7 @@ class Application {
         *
         * @return \DateTime
         */
         *
         * @return \DateTime
         */
-       public function getCanceled() {
+       public function getCanceled(): ?\DateTime {
                return $this->canceled;
        }
 
                return $this->canceled;
        }
 
@@ -113,7 +148,7 @@ class Application {
         *
         * @return Application
         */
         *
         * @return Application
         */
-       public function setCreated($created) {
+       public function setCreated(\DateTime $created): Application {
                $this->created = $created;
 
                return $this;
                $this->created = $created;
 
                return $this;
@@ -124,7 +159,7 @@ class Application {
         *
         * @return \DateTime
         */
         *
         * @return \DateTime
         */
-       public function getCreated() {
+       public function getCreated(): \DateTime {
                return $this->created;
        }
 
                return $this->created;
        }
 
@@ -135,7 +170,7 @@ class Application {
         *
         * @return Application
         */
         *
         * @return Application
         */
-       public function setUpdated($updated) {
+       public function setUpdated(\DateTime $updated): Application {
                $this->updated = $updated;
 
                return $this;
                $this->updated = $updated;
 
                return $this;
@@ -146,49 +181,18 @@ class Application {
         *
         * @return \DateTime
         */
         *
         * @return \DateTime
         */
-       public function getUpdated() {
+       public function getUpdated(): \DateTime {
                return $this->updated;
        }
 
                return $this->updated;
        }
 
-       /**
-        * Add vote
-        *
-        * @param \Rapsys\AirBundle\Entity\Vote $vote
-        *
-        * @return Application
-        */
-       public function addVote(\Rapsys\AirBundle\Entity\Vote $vote) {
-               $this->votes[] = $vote;
-
-               return $this;
-       }
-
-       /**
-        * Remove vote
-        *
-        * @param \Rapsys\AirBundle\Entity\Vote $vote
-        */
-       public function removeVote(\Rapsys\AirBundle\Entity\Vote $vote) {
-               $this->votes->removeElement($vote);
-       }
-
-       /**
-        * Get votes
-        *
-        * @return \Doctrine\Common\Collections\Collection
-        */
-       public function getVotes() {
-               return $this->votes;
-       }
-
        /**
         * Set session
         *
        /**
         * Set session
         *
-        * @param \Rapsys\AirBundle\Entity\Session $session
+        * @param Session $session
         *
         * @return Application
         */
         *
         * @return Application
         */
-       public function setSession(\Rapsys\AirBundle\Entity\Session $session = null) {
+       public function setSession(Session $session): Application {
                $this->session = $session;
 
                return $this;
                $this->session = $session;
 
                return $this;
@@ -197,20 +201,20 @@ class Application {
        /**
         * Get session
         *
        /**
         * Get session
         *
-        * @return \Rapsys\AirBundle\Entity\Session
+        * @return Session
         */
         */
-       public function getSession() {
+       public function getSession(): Session {
                return $this->session;
        }
 
        /**
         * Set user
         *
                return $this->session;
        }
 
        /**
         * Set user
         *
-        * @param \Rapsys\AirBundle\Entity\User $user
+        * @param User $user
         *
         * @return Application
         */
         *
         * @return Application
         */
-       public function setUser(\Rapsys\AirBundle\Entity\User $user = null) {
+       public function setUser(User $user): Application {
                $this->user = $user;
 
                return $this;
                $this->user = $user;
 
                return $this;
@@ -219,9 +223,20 @@ class Application {
        /**
         * Get user
         *
        /**
         * Get user
         *
-        * @return \Rapsys\AirBundle\Entity\User
+        * @return User
         */
         */
-       public function getUser() {
+       public function getUser(): User {
                return $this->user;
        }
                return $this->user;
        }
+
+       /**
+        * {@inheritdoc}
+        */
+       public function preUpdate(PreUpdateEventArgs $eventArgs) {
+               //Check that we have an application instance
+               if (($application = $eventArgs->getObject()) instanceof Application) {
+                       //Set updated value
+                       $application->setUpdated(new \DateTime('now'));
+               }
+       }
 }
 }