<?php
namespace App\Entity;
use App\Entity\Eventable\EventableTrait;
use App\Repository\StageRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Uid\Uuid;
/**
* @ORM\Entity(repositoryClass=StageRepository::class)
*/
class Stage
{
/**
* @ORM\Id
* @ORM\Column(type="uuid", unique=true)
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $description;
/**
* @ORM\ManyToMany(targetEntity=Image::class, cascade={"persist", "remove"}, orphanRemoval=true)
*/
private $images;
/**
* @ORM\OneToMany(targetEntity=Lineup::class, mappedBy="stage", orphanRemoval=true)
* @ORM\OrderBy({"startAt" = "ASC"})
*/
private $lineups;
/**
* @ORM\Column(type="string", length=8, nullable=true)
*/
private $colour;
/**
* @ORM\ManyToOne(targetEntity=Sponsor::class)
*/
private $sponsoredBy;
/**
* @ORM\ManyToMany(targetEntity=Event::class, inversedBy="sponsors")
*/
private $events;
public function __construct()
{
$this->id = Uuid::v4();
$this->lineups = new ArrayCollection();
$this->images = new ArrayCollection();
$this->events = new ArrayCollection();
}
public function getId(): Uuid
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
/**
* @return Collection<int, Image>
*/
public function getImages(): Collection
{
return $this->images;
}
public function addImage(Image $image): self
{
if (!$this->images->contains($image)) {
$this->images[] = $image;
}
return $this;
}
public function removeImage(Image $image): self
{
$this->images->removeElement($image);
return $this;
}
/**
* @return Collection<int, Lineup>
*/
public function getLineups(): Collection
{
return $this->lineups;
}
public function addLineup(Lineup $lineup): self
{
if (!$this->lineups->contains($lineup)) {
$this->lineups[] = $lineup;
$lineup->setStage($this);
}
return $this;
}
public function removeLineup(Lineup $lineup): self
{
if ($this->lineups->removeElement($lineup)) {
// set the owning side to null (unless already changed)
if ($lineup->getStage() === $this) {
$lineup->setStage(null);
}
}
return $this;
}
public function getUpcomingEvent(): ?Lineup
{
$now = new \DateTimeImmutable();
// $inOneHour = new \DateTimeImmutable('+1 hour');
foreach ($this->lineups as $lineup) {
if (
$lineup->getStartAt()>$now
// && $lineup->getStartAt()<=$inOneHour
) {
return $lineup;
}
}
return null;
}
public function getColour(): ?string
{
if (empty($this->colour)) {
return 'inherited';
}
return $this->colour;
}
public function setColour(?string $colour): self
{
$this->colour = $colour;
return $this;
}
public function getSponsoredBy(): ?Sponsor
{
return $this->sponsoredBy;
}
public function setSponsoredBy(?Sponsor $sponsoredBy): self
{
$this->sponsoredBy = $sponsoredBy;
return $this;
}
/**
* @return Collection<int, Event>
*/
public function getEvents(): Collection
{
return $this->events;
}
public function addEvent(Event $event): self
{
if (!$this->events->contains($event)) {
$this->events[] = $event;
}
return $this;
}
public function removeEvent(Event $event): self
{
$this->events->removeElement($event);
return $this;
}
}