src/Entity/Stage.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Eventable\EventableTrait;
  4. use App\Repository\StageRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Component\Uid\Uuid;
  9. /**
  10.  * @ORM\Entity(repositoryClass=StageRepository::class)
  11.  */
  12. class Stage
  13. {
  14.     /**
  15.      * @ORM\Id
  16.      * @ORM\Column(type="uuid", unique=true)
  17.      */
  18.     private $id;
  19.     /**
  20.      * @ORM\Column(type="string", length=255)
  21.      */
  22.     private $name;
  23.     /**
  24.      * @ORM\Column(type="text", nullable=true)
  25.      */
  26.     private $description;
  27.     /**
  28.      * @ORM\ManyToMany(targetEntity=Image::class, cascade={"persist", "remove"}, orphanRemoval=true)
  29.      */
  30.     private $images;
  31.     /**
  32.      * @ORM\OneToMany(targetEntity=Lineup::class, mappedBy="stage", orphanRemoval=true)
  33.      * @ORM\OrderBy({"startAt" = "ASC"})
  34.      */
  35.     private $lineups;
  36.     /**
  37.      * @ORM\Column(type="string", length=8, nullable=true)
  38.      */
  39.     private $colour;
  40.     /**
  41.      * @ORM\ManyToOne(targetEntity=Sponsor::class)
  42.      */
  43.     private $sponsoredBy;
  44.     /**
  45.      * @ORM\ManyToMany(targetEntity=Event::class, inversedBy="sponsors")
  46.      */
  47.     private $events;
  48.     public function __construct()
  49.     {
  50.         $this->id Uuid::v4();
  51.         $this->lineups = new ArrayCollection();
  52.         $this->images = new ArrayCollection();
  53.         $this->events = new ArrayCollection();
  54.     }
  55.     public function getId(): Uuid
  56.     {
  57.         return $this->id;
  58.     }
  59.     public function getName(): ?string
  60.     {
  61.         return $this->name;
  62.     }
  63.     public function setName(string $name): self
  64.     {
  65.         $this->name $name;
  66.         return $this;
  67.     }
  68.     public function getDescription(): ?string
  69.     {
  70.         return $this->description;
  71.     }
  72.     public function setDescription(?string $description): self
  73.     {
  74.         $this->description $description;
  75.         return $this;
  76.     }
  77.     /**
  78.      * @return Collection<int, Image>
  79.      */
  80.     public function getImages(): Collection
  81.     {
  82.         return $this->images;
  83.     }
  84.     public function addImage(Image $image): self
  85.     {
  86.         if (!$this->images->contains($image)) {
  87.             $this->images[] = $image;
  88.         }
  89.         return $this;
  90.     }
  91.     public function removeImage(Image $image): self
  92.     {
  93.         $this->images->removeElement($image);
  94.         return $this;
  95.     }
  96.     /**
  97.      * @return Collection<int, Lineup>
  98.      */
  99.     public function getLineups(): Collection
  100.     {
  101.         return $this->lineups;
  102.     }
  103.     public function addLineup(Lineup $lineup): self
  104.     {
  105.         if (!$this->lineups->contains($lineup)) {
  106.             $this->lineups[] = $lineup;
  107.             $lineup->setStage($this);
  108.         }
  109.         return $this;
  110.     }
  111.     public function removeLineup(Lineup $lineup): self
  112.     {
  113.         if ($this->lineups->removeElement($lineup)) {
  114.             // set the owning side to null (unless already changed)
  115.             if ($lineup->getStage() === $this) {
  116.                 $lineup->setStage(null);
  117.             }
  118.         }
  119.         return $this;
  120.     }
  121.     public function getUpcomingEvent(): ?Lineup
  122.     {
  123.         $now = new \DateTimeImmutable();
  124. //        $inOneHour = new \DateTimeImmutable('+1 hour');
  125.         foreach ($this->lineups as $lineup) {
  126.             if (
  127.                 $lineup->getStartAt()>$now
  128. //                && $lineup->getStartAt()<=$inOneHour
  129.             ) {
  130.                 return $lineup;
  131.             }
  132.         }
  133.         return null;
  134.     }
  135.     public function getColour(): ?string
  136.     {
  137.         if (empty($this->colour)) {
  138.             return 'inherited';
  139.         }
  140.         return $this->colour;
  141.     }
  142.     public function setColour(?string $colour): self
  143.     {
  144.         $this->colour $colour;
  145.         return $this;
  146.     }
  147.     public function getSponsoredBy(): ?Sponsor
  148.     {
  149.         return $this->sponsoredBy;
  150.     }
  151.     public function setSponsoredBy(?Sponsor $sponsoredBy): self
  152.     {
  153.         $this->sponsoredBy $sponsoredBy;
  154.         return $this;
  155.     }
  156.     /**
  157.      * @return Collection<int, Event>
  158.      */
  159.     public function getEvents(): Collection
  160.     {
  161.         return $this->events;
  162.     }
  163.     public function addEvent(Event $event): self
  164.     {
  165.         if (!$this->events->contains($event)) {
  166.             $this->events[] = $event;
  167.         }
  168.         return $this;
  169.     }
  170.     public function removeEvent(Event $event): self
  171.     {
  172.         $this->events->removeElement($event);
  173.         return $this;
  174.     }
  175. }