]> Raphaël G. Git Repositories - airbundle/blobdiff - Entity/Slot.php
Use google client id and secret env variables
[airbundle] / Entity / Slot.php
index 12a0acad74ba48c232f8067ba93bd2c3fb6f0cc6..25ef3e8427e642693c058eba7b2cd75d1575f7cf 100644 (file)
-<?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
  */
 /**
  * Slot
  */
-class Slot
-{
-    /**
-     * @var integer
-     */
-    private $id;
-
-    /**
-     * @var \DateTime
-     */
-    private $begin;
-
-    /**
-     * @var \DateTime
-     */
-    private $length;
-
-    /**
-     * @var \DateTime
-     */
-    private $created;
-
-    /**
-     * @var \DateTime
-     */
-    private $updated;
-
-    /**
-     * @var \Doctrine\Common\Collections\Collection
-     */
-    private $sessions;
-
-    /**
-     * Constructor
-     */
-    public function __construct()
-    {
-        $this->sessions = new \Doctrine\Common\Collections\ArrayCollection();
-    }
-
-    /**
-     * Get id
-     *
-     * @return integer
-     */
-    public function getId()
-    {
-        return $this->id;
-    }
-
-    /**
-     * Set begin
-     *
-     * @param \DateTime $begin
-     *
-     * @return Slot
-     */
-    public function setBegin($begin)
-    {
-        $this->begin = $begin;
-
-        return $this;
-    }
-
-    /**
-     * Get begin
-     *
-     * @return \DateTime
-     */
-    public function getBegin()
-    {
-        return $this->begin;
-    }
-
-    /**
-     * Set length
-     *
-     * @param \DateTime $length
-     *
-     * @return Slot
-     */
-    public function setLength($length)
-    {
-        $this->length = $length;
-
-        return $this;
-    }
-
-    /**
-     * Get length
-     *
-     * @return \DateTime
-     */
-    public function getLength()
-    {
-        return $this->length;
-    }
-
-    /**
-     * Set created
-     *
-     * @param \DateTime $created
-     *
-     * @return Slot
-     */
-    public function setCreated($created)
-    {
-        $this->created = $created;
-
-        return $this;
-    }
-
-    /**
-     * Get created
-     *
-     * @return \DateTime
-     */
-    public function getCreated()
-    {
-        return $this->created;
-    }
-
-    /**
-     * Set updated
-     *
-     * @param \DateTime $updated
-     *
-     * @return Slot
-     */
-    public function setUpdated($updated)
-    {
-        $this->updated = $updated;
-
-        return $this;
-    }
-
-    /**
-     * Get updated
-     *
-     * @return \DateTime
-     */
-    public function getUpdated()
-    {
-        return $this->updated;
-    }
-
-    /**
-     * Add session
-     *
-     * @param \Rapsys\AirBundle\Entity\Session $session
-     *
-     * @return Slot
-     */
-    public function addSession(\Rapsys\AirBundle\Entity\Session $session)
-    {
-        $this->sessions[] = $session;
-
-        return $this;
-    }
-
-    /**
-     * Remove session
-     *
-     * @param \Rapsys\AirBundle\Entity\Session $session
-     */
-    public function removeSession(\Rapsys\AirBundle\Entity\Session $session)
-    {
-        $this->sessions->removeElement($session);
-    }
-
-    /**
-     * Get sessions
-     *
-     * @return \Doctrine\Common\Collections\Collection
-     */
-    public function getSessions()
-    {
-        return $this->sessions;
-    }
-
-    public function getTitle() {
-           //TODO: replace that with computed time
-           return $this->begin->format('H:i').'+'.$this->length->format('H:i');
-    }
+class Slot {
+       /**
+        * Primary key
+        */
+       private ?int $id = null;
+
+       /**
+        * Create datetime
+        */
+       private \DateTime $created;
+
+       /**
+        * Update datetime
+        */
+       private \DateTime $updated;
+
+       /**
+        * Sessions collection
+        */
+       private Collection $sessions;
+
+       /**
+        * Constructor
+        */
+       public function __construct(private string $title) {
+               //Set defaults
+               $this->created = new \DateTime('now');
+               $this->updated = new \DateTime('now');
+
+               //Set collections
+               $this->sessions = new ArrayCollection();
+       }
+
+       /**
+        * Get id
+        *
+        * @return integer
+        */
+       public function getId(): ?int {
+               return $this->id;
+       }
+
+       /**
+        * Set title
+        *
+        * @param string $title
+        *
+        * @return Title
+        */
+       public function setTitle(string $title) {
+               $this->title = $title;
+
+               return $this;
+       }
+
+       /**
+        * Get title
+        *
+        * @return string
+        */
+       public function getTitle(): string {
+               return $this->title;
+       }
+
+       /**
+        * Set created
+        *
+        * @param \DateTime $created
+        *
+        * @return Slot
+        */
+       public function setCreated(\DateTime $created) {
+               $this->created = $created;
+
+               return $this;
+       }
+
+       /**
+        * Get created
+        *
+        * @return \DateTime
+        */
+       public function getCreated(): \DateTime {
+               return $this->created;
+       }
+
+       /**
+        * Set updated
+        *
+        * @param \DateTime $updated
+        *
+        * @return Slot
+        */
+       public function setUpdated(\DateTime $updated) {
+               $this->updated = $updated;
+
+               return $this;
+       }
+
+       /**
+        * Get updated
+        *
+        * @return \DateTime
+        */
+       public function getUpdated(): \DateTime {
+               return $this->updated;
+       }
+
+       /**
+        * Add session
+        *
+        * @param Session $session
+        *
+        * @return Slot
+        */
+       public function addSession(Session $session): Slot {
+               $this->sessions[] = $session;
+
+               return $this;
+       }
+
+       /**
+        * Remove session
+        *
+        * @param Session $session
+        */
+       public function removeSession(Session $session): bool {
+               return $this->sessions->removeElement($session);
+       }
+
+       /**
+        * Get sessions
+        *
+        * @return ArrayCollection
+        */
+       public function getSessions(): ArrayCollection {
+               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
+        *
+        * @return string
+        */
+       public function __toString(): string {
+               return $this->title;
+       }
 }
 }