src/Entity/HotelContract.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\HotelContractRepository;
  4. use DateTime;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. #[ORM\Entity(repositoryClassHotelContractRepository::class)]
  9. class HotelContract extends Product
  10. {
  11.     #[ORM\ManyToOne(targetEntityHotel::class, cascade: ['persist'], inversedBy'hotelContracts')]
  12.     #[ORM\JoinColumn(nullablefalse)]
  13.     private Hotel $hotel;
  14.     #[ORM\OneToMany(mappedBy'hotelContract'targetEntityContractSeason::class)]
  15.     private Collection $contractSeasons;
  16.     #[ORM\OneToMany(mappedBy'hotelContract'targetEntityStopsale::class, orphanRemovaltrue)]
  17.     private Collection $stopsales;
  18.     #[ORM\OneToMany(mappedBy'hotelContract'targetEntityPromo::class, orphanRemovaltrue)]
  19.     private Collection $promos;
  20.     #[ORM\OneToMany(mappedBy'hotelContract'targetEntityCancellationPolicy::class, orphanRemovaltrue)]
  21.     private Collection $cancellationPolicies;
  22.     public function __construct()
  23.     {
  24.         parent::__construct();
  25.         $this->contractSeasons = new ArrayCollection();
  26.         $this->stopsales = new ArrayCollection();
  27.         $this->promos = new ArrayCollection();
  28.         $this->cancellationPolicies = new ArrayCollection();
  29.     }
  30.     public function getHotel(): ?Hotel
  31.     {
  32.         return $this->hotel;
  33.     }
  34.     public function setHotel(?Hotel $hotel): self
  35.     {
  36.         $this->hotel $hotel;
  37.         return $this;
  38.     }
  39.     /**
  40.      * @return Collection<int, ContractSeason>
  41.      */
  42.     public function getContractSeasons(): Collection
  43.     {
  44.         return $this->contractSeasons;
  45.     }
  46.     public function addContractSeason(ContractSeason $contractSeason): self
  47.     {
  48.         if (!$this->contractSeasons->contains($contractSeason)) {
  49.             $this->contractSeasons[] = $contractSeason;
  50.             $contractSeason->setHotelContract($this);
  51.         }
  52.         return $this;
  53.     }
  54.     public function removeContractSeason(ContractSeason $contractSeason): self
  55.     {
  56.         if ($this->contractSeasons->removeElement($contractSeason)) {
  57.             // set the owning side to null (unless already changed)
  58.             if ($contractSeason->getHotelContract() === $this) {
  59.                 $contractSeason->setHotelContract(null);
  60.             }
  61.         }
  62.         return $this;
  63.     }
  64.     public function __toString(): string
  65.     {
  66.         $hotel_name $this->getHotel()->getName();
  67.         $provider_name $this->getProvider()->getName();
  68.         if($hotel_name === $provider_name){
  69.             return $hotel_name;
  70.         }
  71.         return  $hotel_name." (".$provider_name.")";
  72.     }
  73.     /**
  74.      * @return Collection<int, Stopsale>
  75.      */
  76.     public function getStopsales(): Collection
  77.     {
  78.         return $this->stopsales;
  79.     }
  80.     public function addStopsale(Stopsale $stopsale): self
  81.     {
  82.         if (!$this->stopsales->contains($stopsale)) {
  83.             $this->stopsales->add($stopsale);
  84.             $stopsale->setHotelContract($this);
  85.         }
  86.         return $this;
  87.     }
  88.     public function removeStopsale(Stopsale $stopsale): self
  89.     {
  90.         if ($this->stopsales->removeElement($stopsale)) {
  91.             // set the owning side to null (unless already changed)
  92.             if ($stopsale->getHotelContract() === $this) {
  93.                 $stopsale->setHotelContract(null);
  94.             }
  95.         }
  96.         return $this;
  97.     }
  98.     /**
  99.      * @return Collection<int, Promo>
  100.      */
  101.     public function getPromos(): Collection
  102.     {
  103.         return $this->promos;
  104.     }
  105.     public function addPromo(Promo $promo): self
  106.     {
  107.         if (!$this->promos->contains($promo)) {
  108.             $this->promos->add($promo);
  109.             $promo->setHotelContract($this);
  110.         }
  111.         return $this;
  112.     }
  113.     public function removePromo(Promo $promo): self
  114.     {
  115.         if ($this->promos->removeElement($promo)) {
  116.             // set the owning side to null (unless already changed)
  117.             if ($promo->getHotelContract() === $this) {
  118.                 $promo->setHotelContract(null);
  119.             }
  120.         }
  121.         return $this;
  122.     }
  123.     /**
  124.      * @return Collection<int, CancellationPolicy>
  125.      */
  126.     public function getCancellationPolicies(): Collection
  127.     {
  128.         return $this->cancellationPolicies;
  129.     }
  130.     public function addCancellationPolicy(CancellationPolicy $cancellationPolicy): self
  131.     {
  132.         if (!$this->cancellationPolicies->contains($cancellationPolicy)) {
  133.             $this->cancellationPolicies->add($cancellationPolicy);
  134.             $cancellationPolicy->setHotelContract($this);
  135.         }
  136.         return $this;
  137.     }
  138.     public function removeCancellationPolicy(CancellationPolicy $cancellationPolicy): self
  139.     {
  140.         if ($this->cancellationPolicies->removeElement($cancellationPolicy)) {
  141.             // set the owning side to null (unless already changed)
  142.             if ($cancellationPolicy->getHotelContract() === $this) {
  143.                 $cancellationPolicy->setHotelContract(null);
  144.             }
  145.         }
  146.         return $this;
  147.     }
  148.     public function getActiveSeasonsByMarket() : array{
  149.         $activeSeasons = [];
  150.         foreach ($this->contractSeasons as $season) {
  151.             $endDate $season->getEndDate();
  152.             if ($endDate >= new DateTime()) {
  153.                 $marketName $season->getMarket()->getName();
  154.                 $activeSeasons[$marketName][] = $season;
  155.             }
  156.         }
  157.         return $activeSeasons;
  158.     }
  159.     public function getClass()  : string {
  160.         return "HotelContract";
  161.     }
  162.     public function getIcon() : string{
  163.         return "fas fa-hotel";
  164.     }
  165. }