<?php
namespace App\Entity;
use App\Repository\HotelRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use App\Trait\SearchEngineOptimization;
use DateTime;
use Gedmo\Mapping\Annotation as Gedmo;
#[ORM\Entity(repositoryClass: HotelRepository::class)]
class Hotel extends Provider
{
use SearchEngineOptimization;
#[Gedmo\Translatable]
#[ORM\Column(type: 'text', nullable: true)]
private ?string $description;
#[ORM\Column(type: 'smallint', nullable: true)]
// #[Assert\NotBlank(message: 'This value should not be blank')]
#[Assert\NotBlank]
private ?int $starRating;
#[ORM\Column(type: 'boolean')]
private bool $autoMail;
#[ORM\ManyToOne(targetEntity: HotelChain::class, inversedBy: 'hotels')]
private ?HotelChain $chain;
#[ORM\ManyToOne(targetEntity: HotelType::class, inversedBy: 'hotels')]
private ?HotelType $type;
#[ORM\OneToMany(mappedBy: 'hotel', targetEntity: HotelRoomType::class)]
private Collection $hotelRoomTypes;
#[ORM\ManyToMany(targetEntity: Facility::class)]
private Collection $facilities;
#[ORM\ManyToMany(targetEntity: AccommodationOption::class)]
private Collection $options;
#[ORM\ManyToMany(targetEntity: AccommodationCondition::class)]
private Collection $conditions;
#[ORM\OneToMany(mappedBy: 'hotel', targetEntity: HotelContract::class)]
private Collection $hotelContracts;
#[ORM\ManyToMany(targetEntity: FrontTheme::class)]
private Collection $themes;
#[ORM\OneToMany(mappedBy: 'hotel', targetEntity: HotelBadge::class, orphanRemoval: true)]
private Collection $badges;
#[ORM\Column(nullable: true)]
private ?int $tripadvisorId = null;
#[ORM\Column(length: 64, nullable: true)]
private ?string $customRating = null;
public function __construct()
{
parent::__construct();
$this->hotelContracts = new ArrayCollection();
$this->hotelRoomTypes = new ArrayCollection();
$this->facilities = new ArrayCollection();
$this->options = new ArrayCollection();
$this->conditions = new ArrayCollection();
$this->themes = new ArrayCollection();
$this->badges = new ArrayCollection();
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getStarRating(): ?int
{
return $this->starRating;
}
public function setStarRating(?int $starRating): self
{
$this->starRating = $starRating;
return $this;
}
public function isAutoMail(): ?bool
{
return $this->autoMail;
}
public function setAutoMail(bool $autoMail): self
{
$this->autoMail = $autoMail;
return $this;
}
public function getChain(): ?HotelChain
{
return $this->chain;
}
public function setChain(?HotelChain $chain): self
{
$this->chain = $chain;
return $this;
}
public function getType(): ?HotelType
{
return $this->type;
}
public function setType(?HotelType $type): self
{
$this->type = $type;
return $this;
}
/**
* @return Collection<int, HotelRoomType>
*/
public function getHotelRoomTypes(): Collection
{
return $this->hotelRoomTypes;
}
public function addHotelRoomType(HotelRoomType $hotelRoomType): self
{
if (!$this->hotelRoomTypes->contains($hotelRoomType)) {
$this->hotelRoomTypes[] = $hotelRoomType;
$hotelRoomType->setHotel($this);
}
return $this;
}
public function removeHotelRoomType(HotelRoomType $hotelRoomType): self
{
if ($this->hotelRoomTypes->removeElement($hotelRoomType)) {
// set the owning side to null (unless already changed)
if ($hotelRoomType->getHotel() === $this) {
$hotelRoomType->setHotel(null);
}
}
return $this;
}
/**
* @return Collection<int, Facility>
*/
public function getFacilities(): Collection
{
return $this->facilities;
}
public function addFacility(Facility $facility): self
{
if (!$this->facilities->contains($facility)) {
$this->facilities[] = $facility;
}
return $this;
}
public function removeFacility(Facility $facility): self
{
$this->facilities->removeElement($facility);
return $this;
}
/**
* @return Collection<int, AccommodationOption>
*/
public function getOptions(): Collection
{
return $this->options;
}
/**
* @return Collection<int, HotelContract>
*/
public function getHotelContracts(): Collection
{
return $this->hotelContracts;
}
public function addHotelContract(HotelContract $hotelContract): self
{
if (!$this->hotelContracts->contains($hotelContract)) {
$this->hotelContracts[] = $hotelContract;
$hotelContract->setHotel($this);
}
return $this;
}
public function removeHotelContract(HotelContract $hotelContract): self
{
if ($this->hotelContracts->removeElement($hotelContract)) {
// set the owning side to null (unless already changed)
if ($hotelContract->getHotel() === $this) {
$hotelContract->setHotel(null);
}
}
return $this;
}
/**
* @return Collection<int, AccommodationCondition>
*/
public function getConditions(): Collection
{
return $this->conditions;
}
public function addCondition(AccommodationCondition $condition): self
{
if (!$this->conditions->contains($condition)) {
$this->conditions->add($condition);
}
return $this;
}
public function removeCondition(AccommodationCondition $condition): self
{
$this->conditions->removeElement($condition);
return $this;
}
/**
* @return Collection<int, FrontTheme>
*/
public function getThemes(): Collection
{
return $this->themes;
}
public function addTheme(FrontTheme $theme): static
{
if (!$this->themes->contains($theme)) {
$this->themes->add($theme);
}
return $this;
}
public function removeTheme(FrontTheme $theme): static
{
$this->themes->removeElement($theme);
return $this;
}
/**
* @return Collection<int, HotelBadge>
*/
public function getBadges(): Collection
{
return $this->badges;
}
public function addBadge(HotelBadge $badge): static
{
if (!$this->badges->contains($badge)) {
$this->badges->add($badge);
$badge->setHotel($this);
}
return $this;
}
public function removeBadge(HotelBadge $badge): static
{
if ($this->badges->removeElement($badge)) {
// set the owning side to null (unless already changed)
if ($badge->getHotel() === $this) {
$badge->setHotel(null);
}
}
return $this;
}
public function getTripadvisorId(): ?int
{
return $this->tripadvisorId;
}
public function setTripadvisorId(?int $tripadvisorId): static
{
$this->tripadvisorId = $tripadvisorId;
return $this;
}
public function getPromos(): array
{
$dateFrom = new DateTime();
$dateFrom->modify('+2 hours');
$promos = [];
foreach ($this->getBadges() as $badge ){
if($badge->getType() == 'Promo' && $badge->getExpireAt() >= $dateFrom){
$promos[] = $badge;
}
}
return $promos;
}
public function getCustomRating(): ?string
{
return $this->customRating;
}
public function setCustomRating(?string $customRating): static
{
$this->customRating = $customRating;
return $this;
}
}