src/Entity/ExtraReservation.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Privatisation;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Doctrine\Common\Collections\Collection;
  6. use App\Repository\ExtraReservationRepository;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. /**
  9.  * @ORM\Entity(repositoryClass=ExtraReservationRepository::class)
  10.  */
  11. class ExtraReservation
  12. {
  13.     /**
  14.      * @ORM\Id
  15.      * @ORM\GeneratedValue
  16.      * @ORM\Column(type="integer")
  17.      */
  18.     private $id;
  19.     /**
  20.      * @ORM\Column(type="integer", nullable=true)
  21.      */
  22.     private $quantity;
  23.     /**
  24.      * @ORM\Column(type="text", nullable=true)
  25.      */
  26.     private $commentary;
  27.     /**
  28.      * @ORM\ManyToOne(targetEntity=Extra::class, inversedBy="extraReservations")
  29.      * @ORM\JoinColumn(nullable=false)
  30.      */
  31.     private $extra;
  32.     /**
  33.      * @ORM\ManyToOne(targetEntity=Privatisation::class, inversedBy="extraReservations")
  34.      * @ORM\JoinColumn(nullable=true)
  35.      */
  36.     private $privatisation;
  37.     /**
  38.      * @ORM\OneToMany(targetEntity=OptionQuantityReservation::class, mappedBy="extraReservation", orphanRemoval=true, cascade={"persist"})
  39.      */
  40.     private $optionQuantityReservations;
  41.     /**
  42.      * @ORM\OneToMany(targetEntity=OptionSelectReservation::class, mappedBy="extraReservation", orphanRemoval=true, cascade={"persist"})
  43.      */
  44.     private $optionSelectReservations;
  45.     /**
  46.      * @ORM\ManyToOne(targetEntity=Token::class, inversedBy="extraReservations")
  47.      * @ORM\JoinColumn(nullable=true)
  48.      */
  49.     private $token;
  50.     /**
  51.      * @ORM\ManyToOne(targetEntity=Reservation::class, inversedBy="extraReservations")
  52.      * @ORM\JoinColumn(nullable=true)
  53.      */
  54.     private $reservation;
  55.     public function __construct()
  56.     {
  57.         $this->optionQuantityReservations = new ArrayCollection();
  58.         $this->optionSelectReservations = new ArrayCollection();
  59.     }
  60.     public function __clone()
  61.     {
  62.         $optionQuantityReservations = new ArrayCollection();
  63.         foreach($this->getOptionQuantityReservations() as $optionQuantityReservation) {
  64.             $newOptionQuantityReservation = clone $optionQuantityReservation;
  65.             $newOptionQuantityReservation->setExtraReservation($this);
  66.             $optionQuantityReservations->add($newOptionQuantityReservation);
  67.         }
  68.         $this->optionQuantityReservations $optionQuantityReservations;
  69.         $optionSelectReservations = new ArrayCollection();
  70.         foreach($this->getOptionSelectReservations() as $optionSelectReservation) {
  71.             $newOptionSelectReservation = clone $optionSelectReservation;
  72.             $newOptionSelectReservation->setExtraReservation($this);
  73.             $optionSelectReservations->add($newOptionSelectReservation);
  74.         }
  75.         $this->optionSelectReservations $optionSelectReservations;
  76.     }
  77.     public function getId(): ?int
  78.     {
  79.         return $this->id;
  80.     }
  81.     public function getQuantity(): ?int
  82.     {
  83.         return $this->quantity;
  84.     }
  85.     public function setQuantity(int $quantity): self
  86.     {
  87.         $this->quantity $quantity;
  88.         return $this;
  89.     }
  90.     public function getCommentary(): ?string
  91.     {
  92.         return $this->commentary;
  93.     }
  94.     public function setCommentary(?string $commentary): self
  95.     {
  96.         $this->commentary $commentary;
  97.         return $this;
  98.     }
  99.     public function getExtra(): ?Extra
  100.     {
  101.         return $this->extra;
  102.     }
  103.     public function setExtra(?Extra $extra): self
  104.     {
  105.         $this->extra $extra;
  106.         return $this;
  107.     }
  108.     public function getPrivatisation(): ?Privatisation
  109.     {
  110.         return $this->privatisation;
  111.     }
  112.     public function setPrivatisation(?Privatisation $privatisation): self
  113.     {
  114.         $this->privatisation $privatisation;
  115.         return $this;
  116.     }
  117.     /**
  118.      * @return Collection<int, OptionQuantityReservation>
  119.      */
  120.     public function getOptionQuantityReservations(): Collection
  121.     {
  122.         $reservations $this->optionQuantityReservations->toArray();
  123.         usort($reservations, function ($a$b) {
  124.             return $a->getOptionQuantity()->getId() <=> $b->getOptionQuantity()->getId();
  125.         });
  126.         
  127.         return new ArrayCollection($reservations);
  128.     }
  129.     public function addOptionQuantityReservation(OptionQuantityReservation $optionQuantityReservation): self
  130.     {
  131.         if (!$this->optionQuantityReservations->contains($optionQuantityReservation)) {
  132.             $this->optionQuantityReservations[] = $optionQuantityReservation;
  133.             $optionQuantityReservation->setExtraReservation($this);
  134.         }
  135.         return $this;
  136.     }
  137.     public function removeOptionQuantityReservation(OptionQuantityReservation $optionQuantityReservation): self
  138.     {
  139.         if ($this->optionQuantityReservations->removeElement($optionQuantityReservation)) {
  140.             // set the owning side to null (unless already changed)
  141.             if ($optionQuantityReservation->getExtraReservation() === $this) {
  142.                 $optionQuantityReservation->setExtraReservation(null);
  143.             }
  144.         }
  145.         return $this;
  146.     }
  147.     /**
  148.      * @return Collection<int, OptionSelectReservation>
  149.      */
  150.     public function getOptionSelectReservations(): Collection
  151.     {
  152.         return $this->optionSelectReservations;
  153.     }
  154.     public function addOptionSelectReservation(OptionSelectReservation $optionSelectReservation): self
  155.     {
  156.         if (!$this->optionSelectReservations->contains($optionSelectReservation)) {
  157.             $this->optionSelectReservations[] = $optionSelectReservation;
  158.             $optionSelectReservation->setExtraReservation($this);
  159.         }
  160.         return $this;
  161.     }
  162.     public function removeOptionSelectReservation(OptionSelectReservation $optionSelectReservation): self
  163.     {
  164.         if ($this->optionSelectReservations->removeElement($optionSelectReservation)) {
  165.             // set the owning side to null (unless already changed)
  166.             if ($optionSelectReservation->getExtraReservation() === $this) {
  167.                 $optionSelectReservation->setExtraReservation(null);
  168.             }
  169.         }
  170.         return $this;
  171.     }
  172.     public function isEmpty()
  173.     {
  174.         $isEmpty true;
  175.         foreach($this->getOptionQuantityReservations() as $optionQuantityReservation) {
  176.             if($optionQuantityReservation->getQuantity() > 0) {
  177.                 $isEmpty false;
  178.             }
  179.         }
  180.         foreach($this->getOptionSelectReservations() as $optionSelectReservation) {
  181.             if($optionSelectReservation->getOptionSelectItem()) {
  182.                 $isEmpty false;
  183.             }
  184.         }
  185.         return $isEmpty;
  186.     }
  187.     public function getToken(): ?Token
  188.     {
  189.         return $this->token;
  190.     }
  191.     public function setToken(?Token $token): self
  192.     {
  193.         $this->token $token;
  194.         return $this;
  195.     }
  196.     public function getReservation(): ?Reservation
  197.     {
  198.         return $this->reservation;
  199.     }
  200.     public function setReservation(?Reservation $reservation): self
  201.     {
  202.         $this->reservation $reservation;
  203.         return $this;
  204.     }
  205.     public function getDetails(): string
  206.     {
  207.         $details $this->getExtra()->getLabel();
  208.         $options = [];
  209.         foreach ($this->getOptionQuantityReservations() as $optionQuantityReservation) {
  210.             if($optionQuantityReservation->getQuantity() > 0) {
  211.                 $option $optionQuantityReservation->getOptionQuantity()->getLabel() . " x " $optionQuantityReservation->getQuantity();
  212.                 if($optionQuantityReservation->getCommentary()) {
  213.                     $option .= " " $optionQuantityReservation->getCommentary();
  214.                 }
  215.                 $options[] = $option;
  216.             }
  217.             
  218.         }
  219.         foreach($this->getOptionSelectReservations() as $optionSelectReservation) {
  220.             $option $optionSelectReservation->getOptionSelect()->getLabel() . " : ";
  221.             $option .= $optionSelectReservation->getOptionSelectItem()->getLabel();
  222.             if($optionSelectReservation->getCommentary()) {
  223.                 $option .= " " $optionQuantityReservation->getCommentary();
  224.             }
  225.             $options[] = $option;
  226.         }
  227.         if($options) {
  228.             $details .= "(s) : " implode(", "$options) . "";
  229.             
  230.         }
  231.         return $details;
  232.     }
  233.     public function getDetailsAsArray($showCategory true) : array
  234.     {
  235.         $extraCategory $this->getExtra()->getLabel();
  236.         $options = [];
  237.         foreach ($this->getOptionQuantityReservations() as $optionQuantityReservation) {
  238.             if($optionQuantityReservation->getQuantity() > 0) {
  239.                 if($showCategory) {
  240.                     $option $optionQuantityReservation->getQuantity() ." "$extraCategory ." "$optionQuantityReservation->getOptionQuantity()->getLabel();
  241.                 } else {
  242.                     $option $optionQuantityReservation->getQuantity() ." "$optionQuantityReservation->getOptionQuantity()->getLabel();
  243.                 }
  244.                 if($optionQuantityReservation->getCommentary()) {
  245.                     $option .= " " $optionQuantityReservation->getCommentary();
  246.                 }
  247.                 $options[] = strtolower($option);
  248.             }
  249.         }
  250. //        foreach($this->getOptionSelectReservations() as $optionSelectReservation) {
  251. //            $option = $optionSelectReservation->getOptionSelect()->getLabel() . " : ";
  252. //            $option .= $optionSelectReservation->getOptionSelectItem()->getLabel();
  253. //            if($optionSelectReservation->getCommentary()) {
  254. //                $option .= " " . $optionQuantityReservation->getCommentary();
  255. //            }
  256. //            $options[] = $option;
  257. //        }
  258.         return $options;
  259.     }
  260. }