]> Raphaël G. Git Repositories - airbundle/blobdiff - Entity/Application.php
Pass google client and default markdown to constructor
[airbundle] / Entity / Application.php
index a31aa92e966d0205b70f8c08398c14764ee1375d..b2672a19aa898ff58a383fed4bb273c27fe7e957 100644 (file)
@@ -1,51 +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;
 
+use Doctrine\ORM\Event\PreUpdateEventArgs;
+
 /**
  * Application
  */
 class Application {
        /**
-        * @var integer
+        * Primary key
         */
-       private $id;
+       private ?int $id = null;
 
        /**
-        * @var \DateTime
+        * Dance instance
         */
-       private $created;
+       private Dance $dance;
 
        /**
-        * @var \DateTime
+        * Score
         */
-       private $updated;
+       private ?float $score = null;
 
+       /**
+        * Cancel datetime
+        */
+       private ?\DateTime $canceled = null;
 
-       //TODO: ajouter un champ score à replir lors de l'attribution d'une session
-       //XXX: champ float avec une bonne capacité en décimale
-
+       /**
+        * Create datetime
+        */
+       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() {
-               $this->votes = new \Doctrine\Common\Collections\ArrayCollection();
+               //Set defaults
+               $this->created = new \DateTime('now');
+               $this->updated = new \DateTime('now');
        }
 
        /**
@@ -53,93 +71,128 @@ class Application {
         *
         * @return integer
         */
-       public function getId() {
+       public function getId(): ?int {
                return $this->id;
        }
 
        /**
-        * Set created
+        * Set dance
         *
-        * @param \DateTime $created
+        * @param Dance $dance
         *
         * @return Application
         */
-       public function setCreated($created) {
-               $this->created = $created;
+       public function setDance(Dance $dance): Application {
+               $this->dance = $dance;
 
                return $this;
        }
 
        /**
-        * Get created
+        * Get dance
         *
-        * @return \DateTime
+        * @return Dance
         */
-       public function getCreated() {
-               return $this->created;
+       public function getDance(): Dance {
+               return $this->dance;
        }
 
        /**
-        * Set updated
+        * Set score
         *
-        * @param \DateTime $updated
+        * @param float $score
         *
         * @return Application
         */
-       public function setUpdated($updated) {
-               $this->updated = $updated;
+       public function setScore(?float $score): Application {
+               $this->score = $score;
 
                return $this;
        }
 
        /**
-        * Get updated
+        * Get score
+        *
+        * @return float
+        */
+       public function getScore(): ?float {
+               return $this->score;
+       }
+
+       /**
+        * Set canceled
+        *
+        * @param \DateTime $canceled
+        *
+        * @return Application
+        */
+       public function setCanceled(?\DateTime $canceled): Application {
+               $this->canceled = $canceled;
+
+               return $this;
+       }
+
+       /**
+        * Get canceled
         *
         * @return \DateTime
         */
-       public function getUpdated() {
-               return $this->updated;
+       public function getCanceled(): ?\DateTime {
+               return $this->canceled;
        }
 
        /**
-        * Add vote
+        * Set created
         *
-        * @param \Rapsys\AirBundle\Entity\Vote $vote
+        * @param \DateTime $created
         *
         * @return Application
         */
-       public function addVote(\Rapsys\AirBundle\Entity\Vote $vote) {
-               $this->votes[] = $vote;
+       public function setCreated(\DateTime $created): Application {
+               $this->created = $created;
 
                return $this;
        }
 
        /**
-        * Remove vote
+        * Get created
+        *
+        * @return \DateTime
+        */
+       public function getCreated(): \DateTime {
+               return $this->created;
+       }
+
+       /**
+        * Set updated
+        *
+        * @param \DateTime $updated
         *
-        * @param \Rapsys\AirBundle\Entity\Vote $vote
+        * @return Application
         */
-       public function removeVote(\Rapsys\AirBundle\Entity\Vote $vote) {
-               $this->votes->removeElement($vote);
+       public function setUpdated(\DateTime $updated): Application {
+               $this->updated = $updated;
+
+               return $this;
        }
 
        /**
-        * Get votes
+        * Get updated
         *
-        * @return \Doctrine\Common\Collections\Collection
+        * @return \DateTime
         */
-       public function getVotes() {
-               return $this->votes;
+       public function getUpdated(): \DateTime {
+               return $this->updated;
        }
 
        /**
         * Set session
         *
-        * @param \Rapsys\AirBundle\Entity\Session $session
+        * @param Session $session
         *
         * @return Application
         */
-       public function setSession(\Rapsys\AirBundle\Entity\Session $session = null) {
+       public function setSession(Session $session): Application {
                $this->session = $session;
 
                return $this;
@@ -148,20 +201,20 @@ class Application {
        /**
         * Get session
         *
-        * @return \Rapsys\AirBundle\Entity\Session
+        * @return Session
         */
-       public function getSession() {
+       public function getSession(): Session {
                return $this->session;
        }
 
        /**
         * Set user
         *
-        * @param \Rapsys\AirBundle\Entity\User $user
+        * @param User $user
         *
         * @return Application
         */
-       public function setUser(\Rapsys\AirBundle\Entity\User $user = null) {
+       public function setUser(User $user): Application {
                $this->user = $user;
 
                return $this;
@@ -170,9 +223,20 @@ class Application {
        /**
         * Get user
         *
-        * @return \Rapsys\AirBundle\Entity\User
+        * @return User
         */
-       public function getUser() {
+       public function getUser(): 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'));
+               }
+       }
 }