* * 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\Common\Collections\Collection; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Event\PreUpdateEventArgs; /** * Slot */ class Slot { /** * Primary key */ private ?int $id = null; /** * Create datetime */ private \DateTimeImmutable $created; /** * Update datetime */ private \DateTimeImmutable $updated; /** * Sessions collection */ private Collection $sessions; /** * Constructor */ public function __construct(private string $title) { //Set defaults $this->created = new \DateTimeImmutable('now'); $this->updated = new \DateTimeImmutable('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 \DateTimeImmutable $created * * @return Slot */ public function setCreated(\DateTimeImmutable $created) { $this->created = $created; return $this; } /** * Get created * * @return \DateTimeImmutable */ public function getCreated(): \DateTimeImmutable { return $this->created; } /** * Set updated * * @param \DateTimeImmutable $updated * * @return Slot */ public function setUpdated(\DateTimeImmutable $updated) { $this->updated = $updated; return $this; } /** * Get updated * * @return \DateTimeImmutable */ public function getUpdated(): \DateTimeImmutable { 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 \DateTimeImmutable('now')); } } /** * Returns a string representation of the slot * * @return string */ public function __toString(): string { return $this->title; } }