src/Entity/BookingConstraint.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\BookingConstraintRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface;
  8. use Knp\DoctrineBehaviors\Model\Translatable\TranslatableTrait;
  9. #[ORM\Entity(repositoryClassBookingConstraintRepository::class)]
  10. #[ORM\HasLifecycleCallbacks]
  11. class BookingConstraint implements TranslatableInterface
  12. {
  13.     use TranslatableTrait;
  14.     #[ORM\Id]
  15.     #[ORM\GeneratedValue]
  16.     #[ORM\Column(type"integer")]
  17.     private $id;
  18.     #[ORM\Column(type"boolean")]
  19.     private $status;
  20.     #[ORM\Column(type"integer")]
  21.     private $maxNumber;
  22.     #[ORM\Column(type"integer")]
  23.     private $minDuration;
  24.     #[ORM\Column(type"integer")]
  25.     private $maxDuration;
  26.     #[ORM\OneToMany(targetEntityBookingConstraintPeriod::class, mappedBy"bookingConstraint"orphanRemovaltruecascade: ["persist""remove"])]
  27.     private $unavailablePeriods;
  28.     #[ORM\OneToMany(targetEntityBooking::class, mappedBy"bookingConstraint")]
  29.     private $bookings;
  30.     #[ORM\Column(type"float"nullabletrue)]
  31.     private $advancePayment;
  32.     #[ORM\Column(type"integer")]
  33.     private $deposit;
  34.     #[ORM\OneToMany(targetEntityBookingPaymentMethod::class, mappedBy"bookingConstraint"cascade: ["persist""remove"])]
  35.     private $paymentMethods;
  36.     #[ORM\Column(type"float")]
  37.     private $longStayDiscount;
  38.     #[ORM\OneToMany(targetEntityBookingConstraintSaison::class, mappedBy"bookingConstraint"orphanRemovaltruecascade: ["persist""remove"])]
  39.     private $saisons;
  40.     #[ORM\Column(type"integer")]
  41.     private $balancePaymentDeadline;
  42.     #[ORM\Column(type"integer")]
  43.     private $advancePaymentDeadline;
  44.     #[ORM\Column(type"integer")]
  45.     private $offDuration;
  46.     #[ORM\Column(type"integer")]
  47.     private $blockedDaysAfterNow;
  48.     #[ORM\Column(type"integer")]
  49.     private $soonBookingPaymentDelay;
  50.     #[ORM\Column(type"time")]
  51.     private $startHour;
  52.     #[ORM\Column(type"time")]
  53.     private $endHour;
  54.     #[ORM\Column(type"integer")]
  55.     private $surface;
  56.     #[ORM\Column(type"integer"nullabletrue)]
  57.     private $housework;
  58.     #[ORM\Column(type"integer")]
  59.     private $cautionPaymentDelay;
  60.     #[ORM\Column(type"float")]
  61.     private $stayTax;
  62.     /**
  63.      * Permet d'obtenir un tableau des jours qui ne sont pas disponibles pour annonce
  64.      *
  65.      * @return array un tableau d'objets DateTime representant les jours d'occupation
  66.      */
  67.     public function getNotAvailableDays()
  68.     {
  69.         $notAvailableDays = [];
  70.         foreach ($this->bookings as $booking) {
  71.             $startDate = clone $booking->getStartDate();
  72.             $endDate = clone $booking->getEndDate();
  73.             //Calculer les jours qui se trouvent entre la date d'arriver et de départ
  74.             $resultat range(
  75.                 $startDate->modify('-' $this->offDuration ' day')->getTimestamp(),
  76.                 $endDate->modify('+' $this->offDuration ' day')->getTimestamp(),
  77.                 24 60 60
  78.             );
  79.             $days array_map(function ($dayTimestamp) {
  80.                 return new \DateTime(date('Y-m-d'$dayTimestamp));
  81.             }, $resultat);
  82.             $notAvailableDays array_merge($notAvailableDays$days);
  83.         }
  84.         foreach ($this->unavailablePeriods as $period) {
  85.             //Calculer les jours qui se trouvent entre le debut et la fin de chaque periode
  86.             $resultat range(
  87.                 $period->getStartDate()->getTimestamp(),
  88.                 $period->getEndDate()->getTimestamp(),
  89.                 24 60 60
  90.             );
  91.             $days array_map(function ($dayTimestamp) {
  92.                 return new \DateTime(date('Y-m-d'$dayTimestamp));
  93.             }, $resultat);
  94.             $notAvailableDays array_merge($notAvailableDays$days);
  95.         }
  96.         return $notAvailableDays;
  97.     }
  98.     public function __construct()
  99.     {
  100.         $this->unavailablePeriods = new ArrayCollection();
  101.         $this->bookings = new ArrayCollection();
  102.         $this->paymentMethods = new ArrayCollection();
  103.         $this->saisons = new ArrayCollection();
  104.     }
  105.     public function getId(): ?int
  106.     {
  107.         return $this->id;
  108.     }
  109.     public function getStatus(): ?bool
  110.     {
  111.         return $this->status;
  112.     }
  113.     public function setStatus(bool $status): self
  114.     {
  115.         $this->status $status;
  116.         return $this;
  117.     }
  118.     public function getMaxNumber(): ?int
  119.     {
  120.         return $this->maxNumber;
  121.     }
  122.     public function setMaxNumber(int $maxNumber): self
  123.     {
  124.         $this->maxNumber $maxNumber;
  125.         return $this;
  126.     }
  127.     public function getMinDuration(): ?int
  128.     {
  129.         return $this->minDuration;
  130.     }
  131.     public function setMinDuration(int $minDuration): self
  132.     {
  133.         $this->minDuration $minDuration;
  134.         return $this;
  135.     }
  136.     public function getMaxDuration(): ?int
  137.     {
  138.         return $this->maxDuration;
  139.     }
  140.     public function setMaxDuration(int $maxDuration): self
  141.     {
  142.         $this->maxDuration $maxDuration;
  143.         return $this;
  144.     }
  145.     /**
  146.      * @return Collection|BookingConstraintPeriod[]
  147.      */
  148.     public function getUnavailablePeriods(): Collection
  149.     {
  150.         return $this->unavailablePeriods;
  151.     }
  152.     public function addUnavailablePeriod(BookingConstraintPeriod $unavailablePeriod): self
  153.     {
  154.         if (!$this->unavailablePeriods->contains($unavailablePeriod)) {
  155.             $this->unavailablePeriods[] = $unavailablePeriod;
  156.             $unavailablePeriod->setBookingConstraint($this);
  157.         }
  158.         return $this;
  159.     }
  160.     public function removeUnavailablePeriod(BookingConstraintPeriod $unavailablePeriod): self
  161.     {
  162.         if ($this->unavailablePeriods->removeElement($unavailablePeriod)) {
  163.             // set the owning side to null (unless already changed)
  164.             if ($unavailablePeriod->getBookingConstraint() === $this) {
  165.                 $unavailablePeriod->setBookingConstraint(null);
  166.             }
  167.         }
  168.         return $this;
  169.     }
  170.     /**
  171.      * @return Collection|Booking[]
  172.      */
  173.     public function getBookings(): Collection
  174.     {
  175.         return $this->bookings;
  176.     }
  177.     public function addBooking(Booking $booking): self
  178.     {
  179.         if (!$this->bookings->contains($booking)) {
  180.             $this->bookings[] = $booking;
  181.             $booking->setBookingConstraint($this);
  182.         }
  183.         return $this;
  184.     }
  185.     public function removeBooking(Booking $booking): self
  186.     {
  187.         if ($this->bookings->removeElement($booking)) {
  188.             // set the owning side to null (unless already changed)
  189.             if ($booking->getBookingConstraint() === $this) {
  190.                 $booking->setBookingConstraint(null);
  191.             }
  192.         }
  193.         return $this;
  194.     }
  195.     public function getAdvancePayment(): ?float
  196.     {
  197.         return $this->advancePayment;
  198.     }
  199.     public function setAdvancePayment(?float $advancePayment): self
  200.     {
  201.         $this->advancePayment $advancePayment;
  202.         return $this;
  203.     }
  204.     public function getDeposit(): ?int
  205.     {
  206.         return $this->deposit;
  207.     }
  208.     public function setDeposit(int $deposit): self
  209.     {
  210.         $this->deposit $deposit;
  211.         return $this;
  212.     }
  213.     /**
  214.      * @return Collection|BookingPaymentMethod[]
  215.      */
  216.     public function getPaymentMethods(): Collection
  217.     {
  218.         return $this->paymentMethods;
  219.     }
  220.     public function addPaymentMethod(BookingPaymentMethod $paymentMethod): self
  221.     {
  222.         if (!$this->paymentMethods->contains($paymentMethod)) {
  223.             $this->paymentMethods[] = $paymentMethod;
  224.             $paymentMethod->setBookingConstraint($this);
  225.         }
  226.         return $this;
  227.     }
  228.     public function removePaymentMethod(BookingPaymentMethod $paymentMethod): self
  229.     {
  230.         if ($this->paymentMethods->removeElement($paymentMethod)) {
  231.             // set the owning side to null (unless already changed)
  232.             if ($paymentMethod->getBookingConstraint() === $this) {
  233.                 $paymentMethod->setBookingConstraint(null);
  234.             }
  235.         }
  236.         return $this;
  237.     }
  238.     public function getLongStayDiscount(): ?float
  239.     {
  240.         return $this->longStayDiscount;
  241.     }
  242.     public function setLongStayDiscount(?float $longStayDiscount): self
  243.     {
  244.         $this->longStayDiscount $longStayDiscount;
  245.         return $this;
  246.     }
  247.     /**
  248.      * @return Collection|BookingConstraintSaison[]
  249.      */
  250.     public function getSaisons(): Collection
  251.     {
  252.         return $this->saisons;
  253.     }
  254.     public function addSaison(BookingConstraintSaison $saison): self
  255.     {
  256.         if (!$this->saisons->contains($saison)) {
  257.             $this->saisons[] = $saison;
  258.             $saison->setBookingConstraint($this);
  259.         }
  260.         return $this;
  261.     }
  262.     public function removeSaison(BookingConstraintSaison $saison): self
  263.     {
  264.         if ($this->saisons->removeElement($saison)) {
  265.             // set the owning side to null (unless already changed)
  266.             if ($saison->getBookingConstraint() === $this) {
  267.                 $saison->setBookingConstraint(null);
  268.             }
  269.         }
  270.         return $this;
  271.     }
  272.     public function getBalancePaymentDeadline(): ?int
  273.     {
  274.         return $this->balancePaymentDeadline;
  275.     }
  276.     public function setBalancePaymentDeadline(int $balancePaymentDeadline): self
  277.     {
  278.         $this->balancePaymentDeadline $balancePaymentDeadline;
  279.         return $this;
  280.     }
  281.     public function getAdvancePaymentDeadline(): ?int
  282.     {
  283.         return $this->advancePaymentDeadline;
  284.     }
  285.     public function setAdvancePaymentDeadline(int $advancePaymentDeadline): self
  286.     {
  287.         $this->advancePaymentDeadline $advancePaymentDeadline;
  288.         return $this;
  289.     }
  290.     public function getOffDuration(): ?int
  291.     {
  292.         return $this->offDuration;
  293.     }
  294.     public function setOffDuration(int $offDuration): self
  295.     {
  296.         $this->offDuration $offDuration;
  297.         return $this;
  298.     }
  299.     public function getBlockedDaysAfterNow(): ?int
  300.     {
  301.         return $this->blockedDaysAfterNow;
  302.     }
  303.     public function setBlockedDaysAfterNow(int $blockedDaysAfterNow): self
  304.     {
  305.         $this->blockedDaysAfterNow $blockedDaysAfterNow;
  306.         return $this;
  307.     }
  308.     public function getSoonBookingPaymentDelay(): ?int
  309.     {
  310.         return $this->soonBookingPaymentDelay;
  311.     }
  312.     public function setSoonBookingPaymentDelay(int $soonBookingPaymentDelay): self
  313.     {
  314.         $this->soonBookingPaymentDelay $soonBookingPaymentDelay;
  315.         return $this;
  316.     }
  317.     public function getStartHour(): ?\DateTimeInterface
  318.     {
  319.         return $this->startHour;
  320.     }
  321.     public function setStartHour(\DateTimeInterface $startHour): self
  322.     {
  323.         $this->startHour $startHour;
  324.         return $this;
  325.     }
  326.     public function getEndHour(): ?\DateTimeInterface
  327.     {
  328.         return $this->endHour;
  329.     }
  330.     public function setEndHour(\DateTimeInterface $endHour): self
  331.     {
  332.         $this->endHour $endHour;
  333.         return $this;
  334.     }
  335.     public function getSurface(): ?int
  336.     {
  337.         return $this->surface;
  338.     }
  339.     public function setSurface(int $surface): self
  340.     {
  341.         $this->surface $surface;
  342.         return $this;
  343.     }
  344.     public function getHousework(): ?int
  345.     {
  346.         return $this->housework;
  347.     }
  348.     public function setHousework(?int $housework): self
  349.     {
  350.         $this->housework $housework;
  351.         return $this;
  352.     }
  353.     public function getCautionPaymentDelay(): ?int
  354.     {
  355.         return $this->cautionPaymentDelay;
  356.     }
  357.     public function setCautionPaymentDelay(int $cautionPaymentDelay): self
  358.     {
  359.         $this->cautionPaymentDelay $cautionPaymentDelay;
  360.         return $this;
  361.     }
  362.     public function getStayTax(): ?float
  363.     {
  364.         return $this->stayTax;
  365.     }
  366.     public function setStayTax(float $stayTax): self
  367.     {
  368.         $this->stayTax $stayTax;
  369.         return $this;
  370.     }
  371. }