]> Raphaël G. Git Repositories - airbundle/blobdiff - Entity/Slot.php
Remove googleScopes const
[airbundle] / Entity / Slot.php
index a46fd0bedf5c42719d84ce19995e24f5e2676df3..25ef3e8427e642693c058eba7b2cd75d1575f7cf 100644 (file)
@@ -1,41 +1,54 @@
-<?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\Common\Collections\Collection;
+use Doctrine\Common\Collections\ArrayCollection;
+use Doctrine\ORM\Event\PreUpdateEventArgs;
+
 /**
  * Slot
  */
 class Slot {
        /**
 /**
  * Slot
  */
 class Slot {
        /**
-        * @var integer
-        */
-       private $id;
-
-       /**
-        * @var string
+        * Primary key
         */
         */
-       protected $title;
+       private ?int $id = null;
 
        /**
 
        /**
-        * @var \DateTime
+        * Create datetime
         */
         */
-       private $created;
+       private \DateTime $created;
 
        /**
 
        /**
-        * @var \DateTime
+        * Update datetime
         */
         */
-       private $updated;
+       private \DateTime $updated;
 
        /**
 
        /**
-        * @var \Doctrine\Common\Collections\Collection
+        * Sessions collection
         */
         */
-       private $sessions;
+       private Collection $sessions;
 
        /**
         * Constructor
         */
 
        /**
         * Constructor
         */
-       public function __construct() {
-               $this->sessions = new \Doctrine\Common\Collections\ArrayCollection();
+       public function __construct(private string $title) {
+               //Set defaults
+               $this->created = new \DateTime('now');
+               $this->updated = new \DateTime('now');
+
+               //Set collections
+               $this->sessions = new ArrayCollection();
        }
 
        /**
        }
 
        /**
@@ -43,7 +56,7 @@ class Slot {
         *
         * @return integer
         */
         *
         * @return integer
         */
-       public function getId() {
+       public function getId(): ?int {
                return $this->id;
        }
 
                return $this->id;
        }
 
@@ -54,7 +67,7 @@ class Slot {
         *
         * @return Title
         */
         *
         * @return Title
         */
-       public function setTitle($title) {
+       public function setTitle(string $title) {
                $this->title = $title;
 
                return $this;
                $this->title = $title;
 
                return $this;
@@ -76,7 +89,7 @@ class Slot {
         *
         * @return Slot
         */
         *
         * @return Slot
         */
-       public function setCreated($created) {
+       public function setCreated(\DateTime $created) {
                $this->created = $created;
 
                return $this;
                $this->created = $created;
 
                return $this;
@@ -87,7 +100,7 @@ class Slot {
         *
         * @return \DateTime
         */
         *
         * @return \DateTime
         */
-       public function getCreated() {
+       public function getCreated(): \DateTime {
                return $this->created;
        }
 
                return $this->created;
        }
 
@@ -98,7 +111,7 @@ class Slot {
         *
         * @return Slot
         */
         *
         * @return Slot
         */
-       public function setUpdated($updated) {
+       public function setUpdated(\DateTime $updated) {
                $this->updated = $updated;
 
                return $this;
                $this->updated = $updated;
 
                return $this;
@@ -109,18 +122,18 @@ class Slot {
         *
         * @return \DateTime
         */
         *
         * @return \DateTime
         */
-       public function getUpdated() {
+       public function getUpdated(): \DateTime {
                return $this->updated;
        }
 
        /**
         * Add session
         *
                return $this->updated;
        }
 
        /**
         * Add session
         *
-        * @param \Rapsys\AirBundle\Entity\Session $session
+        * @param Session $session
         *
         * @return Slot
         */
         *
         * @return Slot
         */
-       public function addSession(\Rapsys\AirBundle\Entity\Session $session) {
+       public function addSession(Session $session): Slot {
                $this->sessions[] = $session;
 
                return $this;
                $this->sessions[] = $session;
 
                return $this;
@@ -129,21 +142,32 @@ class Slot {
        /**
         * Remove session
         *
        /**
         * Remove session
         *
-        * @param \Rapsys\AirBundle\Entity\Session $session
+        * @param Session $session
         */
         */
-       public function removeSession(\Rapsys\AirBundle\Entity\Session $session) {
-               $this->sessions->removeElement($session);
+       public function removeSession(Session $session): bool {
+               return $this->sessions->removeElement($session);
        }
 
        /**
         * Get sessions
         *
        }
 
        /**
         * Get sessions
         *
-        * @return \Doctrine\Common\Collections\Collection
+        * @return ArrayCollection
         */
         */
-       public function getSessions() {
+       public function getSessions(): ArrayCollection {
                return $this->sessions;
        }
 
                return $this->sessions;
        }
 
+       /**
+        * {@inheritdoc}
+        */
+       public function preUpdate(PreUpdateEventArgs $eventArgs) {
+               //Check that we have a slot instance
+               if (($slot = $eventArgs->getObject()) instanceof Slot) {
+                       //Set updated value
+                       $slot->setUpdated(new \DateTime('now'));
+               }
+       }
+
        /**
         * Returns a string representation of the slot
         *
        /**
         * Returns a string representation of the slot
         *