src/Entity/Hotel.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\HotelRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\Validator\Constraints as Assert;
  8. use App\Trait\SearchEngineOptimization;
  9. use DateTime;
  10. use Gedmo\Mapping\Annotation as Gedmo;
  11. #[ORM\Entity(repositoryClassHotelRepository::class)]
  12. class Hotel extends Provider
  13. {
  14.     use SearchEngineOptimization;
  15.     #[Gedmo\Translatable]
  16.     #[ORM\Column(type'text'nullabletrue)]
  17.     private ?string $description;
  18.     #[ORM\Column(type'smallint'nullabletrue)]
  19.    // #[Assert\NotBlank(message: 'This value should not be blank')]
  20.     #[Assert\NotBlank]
  21.     private ?int $starRating;
  22.     #[ORM\Column(type'boolean')]
  23.     private bool $autoMail;
  24.     #[ORM\ManyToOne(targetEntityHotelChain::class, inversedBy'hotels')]
  25.     private ?HotelChain $chain;
  26.     #[ORM\ManyToOne(targetEntityHotelType::class, inversedBy'hotels')]
  27.     private ?HotelType $type;
  28.     #[ORM\OneToMany(mappedBy'hotel'targetEntityHotelRoomType::class)]
  29.     private Collection $hotelRoomTypes;
  30.     #[ORM\ManyToMany(targetEntityFacility::class)]
  31.     private Collection $facilities;
  32.     #[ORM\ManyToMany(targetEntityAccommodationOption::class)]
  33.     private Collection $options;
  34.     #[ORM\ManyToMany(targetEntityAccommodationCondition::class)]
  35.     private Collection $conditions;
  36.     #[ORM\OneToMany(mappedBy'hotel'targetEntityHotelContract::class)]
  37.     private Collection $hotelContracts;
  38.     #[ORM\ManyToMany(targetEntityFrontTheme::class)]
  39.     private Collection $themes;
  40.     #[ORM\OneToMany(mappedBy'hotel'targetEntityHotelBadge::class, orphanRemovaltrue)]
  41.     private Collection $badges;
  42.     #[ORM\Column(nullabletrue)]
  43.     private ?int $tripadvisorId null;
  44.     #[ORM\Column(length64nullabletrue)]
  45.     private ?string $customRating null;
  46.     public function __construct()
  47.     {
  48.         parent::__construct();
  49.         $this->hotelContracts = new ArrayCollection();
  50.         $this->hotelRoomTypes = new ArrayCollection();
  51.         $this->facilities = new ArrayCollection();
  52.         $this->options = new ArrayCollection();
  53.         $this->conditions = new ArrayCollection();
  54.         $this->themes = new ArrayCollection();
  55.         $this->badges = new ArrayCollection();
  56.     }
  57.     public function getDescription(): ?string
  58.     {
  59.         return $this->description;
  60.     }
  61.     public function setDescription(?string $description): self
  62.     {
  63.         $this->description $description;
  64.         return $this;
  65.     }
  66.     public function getStarRating(): ?int
  67.     {
  68.         return $this->starRating;
  69.     }
  70.     public function setStarRating(?int $starRating): self
  71.     {
  72.         $this->starRating $starRating;
  73.         return $this;
  74.     }
  75.     public function isAutoMail(): ?bool
  76.     {
  77.         return $this->autoMail;
  78.     }
  79.     public function setAutoMail(bool $autoMail): self
  80.     {
  81.         $this->autoMail $autoMail;
  82.         return $this;
  83.     }
  84.     public function getChain(): ?HotelChain
  85.     {
  86.         return $this->chain;
  87.     }
  88.     public function setChain(?HotelChain $chain): self
  89.     {
  90.         $this->chain $chain;
  91.         return $this;
  92.     }
  93.     public function getType(): ?HotelType
  94.     {
  95.         return $this->type;
  96.     }
  97.     public function setType(?HotelType $type): self
  98.     {
  99.         $this->type $type;
  100.         return $this;
  101.     }
  102.     /**
  103.      * @return Collection<int, HotelRoomType>
  104.      */
  105.     public function getHotelRoomTypes(): Collection
  106.     {
  107.         return $this->hotelRoomTypes;
  108.     }
  109.     public function addHotelRoomType(HotelRoomType $hotelRoomType): self
  110.     {
  111.         if (!$this->hotelRoomTypes->contains($hotelRoomType)) {
  112.             $this->hotelRoomTypes[] = $hotelRoomType;
  113.             $hotelRoomType->setHotel($this);
  114.         }
  115.         return $this;
  116.     }
  117.     public function removeHotelRoomType(HotelRoomType $hotelRoomType): self
  118.     {
  119.         if ($this->hotelRoomTypes->removeElement($hotelRoomType)) {
  120.             // set the owning side to null (unless already changed)
  121.             if ($hotelRoomType->getHotel() === $this) {
  122.                 $hotelRoomType->setHotel(null);
  123.             }
  124.         }
  125.         return $this;
  126.     }
  127.     /**
  128.      * @return Collection<int, Facility>
  129.      */
  130.     public function getFacilities(): Collection
  131.     {
  132.         return $this->facilities;
  133.     }
  134.     public function addFacility(Facility $facility): self
  135.     {
  136.         if (!$this->facilities->contains($facility)) {
  137.             $this->facilities[] = $facility;
  138.         }
  139.         return $this;
  140.     }
  141.     public function removeFacility(Facility $facility): self
  142.     {
  143.         $this->facilities->removeElement($facility);
  144.         return $this;
  145.     }
  146.     /**
  147.      * @return Collection<int, AccommodationOption>
  148.      */
  149.     public function getOptions(): Collection
  150.     {
  151.         return $this->options;
  152.     }
  153.     /**
  154.      * @return Collection<int, HotelContract>
  155.      */
  156.     public function getHotelContracts(): Collection
  157.     {
  158.         return $this->hotelContracts;
  159.     }
  160.     public function addHotelContract(HotelContract $hotelContract): self
  161.     {
  162.         if (!$this->hotelContracts->contains($hotelContract)) {
  163.             $this->hotelContracts[] = $hotelContract;
  164.             $hotelContract->setHotel($this);
  165.         }
  166.         return $this;
  167.     }
  168.     public function removeHotelContract(HotelContract $hotelContract): self
  169.     {
  170.         if ($this->hotelContracts->removeElement($hotelContract)) {
  171.             // set the owning side to null (unless already changed)
  172.             if ($hotelContract->getHotel() === $this) {
  173.                 $hotelContract->setHotel(null);
  174.             }
  175.         }
  176.         return $this;
  177.     }
  178.     /**
  179.      * @return Collection<int, AccommodationCondition>
  180.      */
  181.     public function getConditions(): Collection
  182.     {
  183.         return $this->conditions;
  184.     }
  185.     public function addCondition(AccommodationCondition $condition): self
  186.     {
  187.         if (!$this->conditions->contains($condition)) {
  188.             $this->conditions->add($condition);
  189.         }
  190.         return $this;
  191.     }
  192.     public function removeCondition(AccommodationCondition $condition): self
  193.     {
  194.         $this->conditions->removeElement($condition);
  195.         return $this;
  196.     }
  197.     /**
  198.      * @return Collection<int, FrontTheme>
  199.      */
  200.     public function getThemes(): Collection
  201.     {
  202.         return $this->themes;
  203.     }
  204.     public function addTheme(FrontTheme $theme): static
  205.     {
  206.         if (!$this->themes->contains($theme)) {
  207.             $this->themes->add($theme);
  208.         }
  209.         return $this;
  210.     }
  211.     public function removeTheme(FrontTheme $theme): static
  212.     {
  213.         $this->themes->removeElement($theme);
  214.         return $this;
  215.     }
  216.     /**
  217.      * @return Collection<int, HotelBadge>
  218.      */
  219.     public function getBadges(): Collection
  220.     {
  221.         return $this->badges;
  222.     }
  223.     public function addBadge(HotelBadge $badge): static
  224.     {
  225.         if (!$this->badges->contains($badge)) {
  226.             $this->badges->add($badge);
  227.             $badge->setHotel($this);
  228.         }
  229.         return $this;
  230.     }
  231.     public function removeBadge(HotelBadge $badge): static
  232.     {
  233.         if ($this->badges->removeElement($badge)) {
  234.             // set the owning side to null (unless already changed)
  235.             if ($badge->getHotel() === $this) {
  236.                 $badge->setHotel(null);
  237.             }
  238.         }
  239.         return $this;
  240.     }
  241.     public function getTripadvisorId(): ?int
  242.     {
  243.         return $this->tripadvisorId;
  244.     }
  245.     public function setTripadvisorId(?int $tripadvisorId): static
  246.     {
  247.         $this->tripadvisorId $tripadvisorId;
  248.         return $this;
  249.     }
  250.     public function getPromos(): array
  251.     {
  252.         $dateFrom = new DateTime();
  253.         $dateFrom->modify('+2 hours');
  254.         $promos = [];
  255.         foreach ($this->getBadges() as $badge ){
  256.             if($badge->getType() == 'Promo' && $badge->getExpireAt() >= $dateFrom){
  257.                 $promos[] = $badge;
  258.             }
  259.         }
  260.         return $promos;
  261.     }
  262.     public function getCustomRating(): ?string
  263.     {
  264.         return $this->customRating;
  265.     }
  266.     public function setCustomRating(?string $customRating): static
  267.     {
  268.         $this->customRating $customRating;
  269.         return $this;
  270.     }
  271. }