src/Entity/Offer.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\AbstractClass\AbstractOffer;
  4. use App\Repository\OfferRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Component\Validator\Constraints as Assert;;
  9. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  10. #[ORM\Entity(repositoryClassOfferRepository::class)]
  11. #[UniqueEntity("slug")]
  12. class Offer extends AbstractOffer
  13. {
  14.     const STATUS_IN_PROGRESS 0;
  15.     const STATUS_ACTIVE 1;
  16.     const STATUS_PAUSED 2;
  17.     const STATUS_FINISHED 3;
  18.     const STATUS_DELETED 4;
  19.     #[ORM\Id]
  20.     #[ORM\GeneratedValue]
  21.     #[ORM\Column(type'integer')]
  22.     private $id;
  23.     #[ORM\Column(type'string'length255)]
  24.     #[Assert\NotBlank(message:'Ce champ est obligatoire.')]
  25.     private $type;
  26.     #[ORM\Column(type'string'length255)]
  27.     #[Assert\NotBlank(message:'Ce champ est obligatoire.')]
  28.     private $title;
  29.     #[ORM\Column(type'string'length255uniquetrue)]
  30.     private $slug '';
  31.     #[ORM\Column(type'text'nullabletrue)]
  32.     private $gibierDescription;
  33.     #[ORM\Column(type'text'nullabletrue)]
  34.     private $teamExperienceDescription;
  35.     #[ORM\Column(type'text'nullabletrue)]
  36.     #[Assert\NotBlank(message:'Ce champ est obligatoire.')]
  37.     private $unfoldsDay;
  38.     #[ORM\Column(type'text'nullabletrue)]
  39.     private $huntingPlan;
  40.     #[ORM\Column(type'date'nullabletrue)]
  41.     private $startAt;
  42.     #[ORM\Column(type'date'nullabletrue)]
  43.     private $endAt;
  44.     #[ORM\Column(type'json'nullabletrue)]
  45.     private $recurrence;
  46.     #[ORM\Column(type'float'nullabletrue)]
  47.     #[Assert\Type(type'float'message'La valeur {{ value }} n\'est pas un nombre.')]
  48.     private $price;
  49.     #[ORM\Column(type'float'nullabletrue)]
  50.     #[Assert\Type(type'float'message'La valeur {{ value }} n\'est pas un nombre.')]
  51.     private $halfActionPrice;
  52.     #[ORM\Column(type'integer'nullabletrue)]
  53.     #[Assert\Type(type'integer'message'La valeur {{ value }} n\'est pas un entier.')]
  54.     private $halfActionNbDays;
  55.     #[ORM\Column(type'integer'nullabletrue)]
  56.     #[Assert\Type(type'integer'message'La valeur {{ value }} n\'est pas un entier.')]
  57.     private $nbActionsAvailable;
  58.     #[ORM\Column(type'integer'nullabletrue)]
  59.     #[Assert\Type(type'integer'message'La valeur {{ value }} n\'est pas un entier.')]
  60.     private $nbBraceletPersonMax;
  61.     #[ORM\Column(type'integer'nullabletrue)]
  62.     #[Assert\Type(type'integer'message'La valeur {{ value }} n\'est pas un entier.')]
  63.     private $nbBraceletsAvailable;
  64.     #[ORM\Column(type'integer'nullabletrue)]
  65.     #[Assert\Type(type'integer'message'La valeur {{ value }} n\'est pas un entier.')]
  66.     private $maxNbPersonsHuntingDay;
  67.     #[ORM\Column(type'integer'nullabletrue)]
  68.     #[Assert\Type(type'integer'message'La valeur {{ value }} n\'est pas un entier.')]
  69.     private $nbPlacesDay;
  70.     #[ORM\Column(type'text'nullabletrue)]
  71.     private $furtherInformation;
  72.     #[ORM\Column(type'boolean'nullabletrue)]
  73.     private $companions;
  74.     #[ORM\Column(type'boolean'nullabletrue)]
  75.     private $halfAction;
  76.     #[ORM\Column(type'integer'nullabletrue)]
  77.     private $status;
  78.     #[ORM\Column(type'boolean'nullabletrue)]
  79.     private $isPaused;
  80.     #[ORM\ManyToOne(targetEntityTerritory::class, inversedBy'offers')]
  81.     private $territory;
  82.     #[ORM\ManyToMany(targetEntityHuntingMode::class)]
  83.     private $huntingMode;
  84.     #[ORM\ManyToMany(targetEntityWeapon::class)]
  85.     private $weapons;
  86.     #[ORM\ManyToOne(targetEntityUser::class)]
  87.     #[ORM\JoinColumn(nullabletrue)]
  88.     private $createdBy;
  89.     #[ORM\OneToMany(mappedBy'offer'targetEntityBooking::class, orphanRemovaltrue)]
  90.     private $bookings;
  91.     #[ORM\Column(type'string'length255nullabletrue)]
  92.     private $equipement;
  93.     #[ORM\Column(type'text'nullabletrue)]
  94.     private $planningText;
  95.     #[ORM\Column(type'boolean'nullabletrue)]
  96.     private $isTuchassouSelected;
  97.     #[ORM\OneToMany(mappedBy'offer'targetEntityOfferAdditionalService::class, orphanRemovaltruecascade: ["persist"])]
  98.     private $offerAdditionalServices;
  99.     #[ORM\Column(type'json'nullabletrue)]
  100.     private $disponibilities = [];
  101.     #[ORM\Column(type'integer'nullabletrue)]
  102.     #[Assert\Type(type'integer'message'La valeur {{ value }} n\'est pas un entier.')]
  103.     private $quantityBooked;
  104.     #[ORM\Column(type'datetime'nullabletrue)]
  105.     private $createdAt;
  106.     #[ORM\ManyToMany(targetEntityAnimal::class)]
  107.     private $animals;
  108.     #[ORM\Column(type'string'length255nullabletrue)]
  109.     private $caractericGibier;
  110.     #[ORM\Column(type'string'length255nullabletrue)]
  111.     private $cover;
  112.     #[ORM\Column(type'float'nullabletrue)]
  113.     private $fraisChasseur;
  114.     #[ORM\Column(type'float'nullabletrue)]
  115.     private $fraisHote;
  116.     #[ORM\OneToMany(mappedBy'offer'targetEntityOfferCancellationRequest::class)]
  117.     private $offerCancellationRequests;
  118.     #[ORM\OneToMany(mappedBy'offer'targetEntityOfferImage::class, orphanRemovaltruecascade: ["persist"])]
  119.     private $offerImages;
  120.     #[ORM\ManyToMany(targetEntityGibier::class, inversedBy'allOffers')]
  121.     private $gibiers;
  122.     #[ORM\Column(type'text'nullabletrue)]
  123.     private $recurrenceException "[]";
  124.     #[ORM\Column(type'boolean'nullabletrue)]
  125.     private $isManagedByTuchassou;
  126.     public function __construct()
  127.     {
  128.         $this->weapons = new ArrayCollection();
  129.         $this->bookings = new ArrayCollection();
  130.         $this->offerAdditionalServices = new ArrayCollection();
  131.         $this->createdAt = new \DateTime();
  132.         $this->animals = new ArrayCollection();
  133.         $this->huntingMode = new ArrayCollection();
  134.         $this->offerCancellationRequests = new ArrayCollection();
  135.         $this->offerImages = new ArrayCollection();
  136.         $this->gibiers = new ArrayCollection();
  137.     }
  138.     public function getId(): ?int
  139.     {
  140.         return $this->id;
  141.     }
  142.     public function getType(): ?string
  143.     {
  144.         return $this->type;
  145.     }
  146.     public function setType(string $type): self
  147.     {
  148.         $this->type $type;
  149.         return $this;
  150.     }
  151.     public function getTitle(): ?string
  152.     {
  153.         return $this->title;
  154.     }
  155.     public function setTitle(string $title): self
  156.     {
  157.         $this->title $title;
  158.         return $this;
  159.     }
  160.     public function getGibierDescription(): ?string
  161.     {
  162.         return $this->gibierDescription;
  163.     }
  164.     public function setGibierDescription(?string $gibierDescription): self
  165.     {
  166.         $this->gibierDescription $gibierDescription;
  167.         return $this;
  168.     }
  169.     public function getTeamExperienceDescription(): ?string
  170.     {
  171.         return $this->teamExperienceDescription;
  172.     }
  173.     public function setTeamExperienceDescription(?string $teamExperienceDescription): self
  174.     {
  175.         $this->teamExperienceDescription $teamExperienceDescription;
  176.         return $this;
  177.     }
  178.     public function getUnfoldsDay(): ?string
  179.     {
  180.         return $this->unfoldsDay;
  181.     }
  182.     public function setUnfoldsDay(?string $unfoldsDay): self
  183.     {
  184.         $this->unfoldsDay $unfoldsDay;
  185.         return $this;
  186.     }
  187.     public function getHuntingPlan(): ?string
  188.     {
  189.         return $this->huntingPlan;
  190.     }
  191.     public function setHuntingPlan(?string $huntingPlan): self
  192.     {
  193.         $this->huntingPlan $huntingPlan;
  194.         return $this;
  195.     }
  196.     public function getStartAt(): ?\DateTimeInterface
  197.     {
  198.         return $this->startAt;
  199.     }
  200.     public function setStartAt(?\DateTimeInterface $startAt): self
  201.     {
  202.         $this->startAt $startAt;
  203.         return $this;
  204.     }
  205.     public function getEndAt(): ?\DateTimeInterface
  206.     {
  207.         return $this->endAt;
  208.     }
  209.     public function setEndAt(?\DateTimeInterface $endAt): self
  210.     {
  211.         $this->endAt $endAt;
  212.         return $this;
  213.     }
  214.     public function getRecurrence(): ?array
  215.     {
  216.         return $this->recurrence;
  217.     }
  218.     public function setRecurrence(?array $recurrence): self
  219.     {
  220.         $this->recurrence $recurrence;
  221.         return $this;
  222.     }
  223.     public function getHotePrice(): ?float
  224.     {
  225.         if(is_null($this->price) || $this->price === 0) return null;
  226.         return $this->price/(1+(floatval((is_null($this->fraisHote)) ? $this->getHoteParameters($this->type) : $this->fraisHote)/100));
  227.     }
  228.     public function getPrice(): ?float
  229.     {
  230.         return $this->price;
  231.     }
  232.     public function getBasePrice(): ?float
  233.     {
  234.         if(is_null($this->price) || $this->price === 0) return null;
  235.         $price $this->price;
  236.         $frais $price*floatval((is_null($this->fraisChasseur)) ? $this->getParameters($this->type)/100 $this->fraisChasseur/100);
  237.         $frais += $frais*0.2;
  238.         return $price+$frais;
  239.     }
  240.     public function setPrice(?float $price): self
  241.     {
  242.         $this->price $price;
  243.         return $this;
  244.     }
  245.     public function getBaseHalfActionPrice(): ?float
  246.     {
  247.         if(is_null($this->halfActionPrice) || $this->halfActionPrice === 0) return null;
  248.         $price $this->halfActionPrice;
  249.         $price += $price*floatval((is_null($this->fraisChasseur)) ? $this->getParameters($this->type)/100 $this->fraisChasseur/100);
  250.         return $price;
  251.     }
  252.     public function getBaseHalfActionHotePrice(): ?float
  253.     {
  254.         if(is_null($this->halfActionPrice) || $this->halfActionPrice === 0) return null;
  255.         return $this->halfActionPrice/(1+(floatval((is_null($this->fraisHote)) ? $this->getHoteParameters($this->type) : $this->fraisHote)/100));
  256.     }
  257.     public function getHalfActionPrice(): ?float
  258.     {
  259.         return $this->halfActionPrice;
  260.     }
  261.     public function setHalfActionPrice(?float $halfActionPrice): self
  262.     {
  263.         $this->halfActionPrice $halfActionPrice;
  264.         return $this;
  265.     }
  266.     public function getHalfActionNbDays(): ?int
  267.     {
  268.         return $this->halfActionNbDays;
  269.     }
  270.     public function setHalfActionNbDays(?int $halfActionNbDays): self
  271.     {
  272.         $this->halfActionNbDays $halfActionNbDays;
  273.         return $this;
  274.     }
  275.     public function getNbActionsAvailable(): ?int
  276.     {
  277.         $quantityBooked 0;
  278.         foreach ($this->getBookings() as $booking) {
  279.             if($booking->getStatus() === Booking::STATUS_ACCEPTED) {
  280.                 $quantityBooked += $booking->getQuantity();
  281.             }
  282.         }
  283.         return ($this->nbActionsAvailable $quantityBooked === 0) ? null $this->nbActionsAvailable $quantityBooked;
  284.     }
  285.     public function setNbActionsAvailable(?int $nbActionsAvailable): self
  286.     {
  287.         $this->nbActionsAvailable $nbActionsAvailable;
  288.         return $this;
  289.     }
  290.     public function getNbBraceletPersonMax(): ?int
  291.     {
  292.         return $this->nbBraceletPersonMax;
  293.     }
  294.     public function setNbBraceletPersonMax(?int $nbBraceletPersonMax): self
  295.     {
  296.         $this->nbBraceletPersonMax $nbBraceletPersonMax;
  297.         return $this;
  298.     }
  299.     public function getNbBraceletsAvailable(): ?int
  300.     {
  301.         return $this->nbBraceletsAvailable;
  302.     }
  303.     public function setNbBraceletsAvailable(?int $nbBraceletsAvailable): self
  304.     {
  305.         $this->nbBraceletsAvailable $nbBraceletsAvailable;
  306.         return $this;
  307.     }
  308.     public function getMaxNbPersonsHuntingDay(): ?int
  309.     {
  310.         return $this->maxNbPersonsHuntingDay;
  311.     }
  312.     public function setMaxNbPersonsHuntingDay(?int $maxNbPersonsHuntingDay): self
  313.     {
  314.         $this->maxNbPersonsHuntingDay $maxNbPersonsHuntingDay;
  315.         return $this;
  316.     }
  317.     public function getNbPlacesDay(): ?int
  318.     {
  319.         return $this->nbPlacesDay;
  320.     }
  321.     public function setNbPlacesDay(?int $nbPlacesDay): self
  322.     {
  323.         $this->nbPlacesDay $nbPlacesDay;
  324.         return $this;
  325.     }
  326.     public function getFurtherInformation(): ?string
  327.     {
  328.         return $this->furtherInformation;
  329.     }
  330.     public function setFurtherInformation(?string $furtherInformation): self
  331.     {
  332.         $this->furtherInformation $furtherInformation;
  333.         return $this;
  334.     }
  335.     public function getCompanions(): ?bool
  336.     {
  337.         return $this->companions;
  338.     }
  339.     public function setCompanions(?bool $companions): self
  340.     {
  341.         $this->companions $companions;
  342.         return $this;
  343.     }
  344.     public function getHalfAction(): ?bool
  345.     {
  346.         return $this->halfAction;
  347.     }
  348.     public function setHalfAction(?bool $halfAction): self
  349.     {
  350.         $this->halfAction $halfAction;
  351.         return $this;
  352.     }
  353.     public function getStatus(): ?int
  354.     {
  355.         if(!is_null($this->endAt)) {
  356.             $now = new \DateTime();
  357.             if($this->endAt $now) {
  358.                 return self::STATUS_FINISHED;
  359.             }
  360.         }
  361.         if(!is_null($this->disponibilities) && !empty($this->disponibilities)) {
  362.             usort($this->disponibilities, function($a$b) {
  363.                 $a \DateTime::createFromFormat('d/m/Y'$a['date']);
  364.                 $b \DateTime::createFromFormat('d/m/Y'$b['date']);
  365.                 return $a <=> $b;
  366.             });
  367.             $end \DateTime::createFromFormat('d/m/Y'$this->disponibilities[count($this->disponibilities) - 1]['date']);
  368.             if ($end) {
  369.                 $end->setTime(235959);
  370.             }
  371.             $now = new \DateTime();
  372.             if($end $now) {
  373.                 return self::STATUS_FINISHED;
  374.             }
  375.         }
  376.         return $this->status;
  377.     }
  378.     public function setStatus(?int $status): self
  379.     {
  380.         $this->status $status;
  381.         return $this;
  382.     }
  383.     public function getIsPaused(): ?bool
  384.     {
  385.         return $this->isPaused;
  386.     }
  387.     public function setIsPaused(?bool $isPaused): self
  388.     {
  389.         $this->isPaused $isPaused;
  390.         return $this;
  391.     }
  392.     public function getTerritory(): ?Territory
  393.     {
  394.         return $this->territory;
  395.     }
  396.     public function setTerritory(?Territory $territory): self
  397.     {
  398.         $this->territory $territory;
  399.         return $this;
  400.     }
  401.     /**
  402.      * @return Collection<int, Weapon>
  403.      */
  404.     public function getWeapons(): Collection
  405.     {
  406.         return $this->weapons;
  407.     }
  408.     public function addWeapon(Weapon $weapon): self
  409.     {
  410.         if (!$this->weapons->contains($weapon)) {
  411.             $this->weapons[] = $weapon;
  412.         }
  413.         return $this;
  414.     }
  415.     public function removeWeapon(Weapon $weapon): self
  416.     {
  417.         $this->weapons->removeElement($weapon);
  418.         return $this;
  419.     }
  420.     public function getCreatedBy(): ?User
  421.     {
  422.         return $this->createdBy;
  423.     }
  424.     public function setCreatedBy(?User $createdBy): self
  425.     {
  426.         $this->createdBy $createdBy;
  427.         return $this;
  428.     }
  429.     /**
  430.      * @return Collection<int, Booking>
  431.      */
  432.     public function getBookings(): Collection
  433.     {
  434.         return $this->bookings;
  435.     }
  436.     public function addBooking(Booking $booking): self
  437.     {
  438.         if (!$this->bookings->contains($booking)) {
  439.             $this->bookings[] = $booking;
  440.             $booking->setOffer($this);
  441.         }
  442.         return $this;
  443.     }
  444.     public function removeBooking(Booking $booking): self
  445.     {
  446.         if ($this->bookings->removeElement($booking)) {
  447.             // set the owning side to null (unless already changed)
  448.             if ($booking->getOffer() === $this) {
  449.                 $booking->setOffer(null);
  450.             }
  451.         }
  452.         return $this;
  453.     }
  454.     public function getNbReservation(): int
  455.     {
  456.         $count 0;
  457.         foreach ($this->bookings as $booking) {
  458.             if($booking->getStatus() === Booking::STATUS_ACCEPTED$count++;
  459.         }
  460.         return $count;
  461.     }
  462.     public function getCA(): float
  463.     {
  464.         $chiffre 0;
  465.         foreach ($this->bookings as $booking) {
  466.             if($booking->getStatus() === Booking::STATUS_ACCEPTED$chiffre += $booking->getTotalTtc();
  467.         }
  468.         return $chiffre;
  469.     }
  470.     public function getEquipement(): ?string
  471.     {
  472.         return $this->equipement;
  473.     }
  474.     public function setEquipement(?string $equipement): self
  475.     {
  476.         $this->equipement $equipement;
  477.         return $this;
  478.     }
  479.     public function getPlanningText(): ?string
  480.     {
  481.         return $this->planningText;
  482.     }
  483.     public function setPlanningText(?string $planningText): self
  484.     {
  485.         $this->planningText $planningText;
  486.         return $this;
  487.     }
  488.     public function getIsTuchassouSelected(): ?bool
  489.     {
  490.         return $this->isTuchassouSelected;
  491.     }
  492.     public function setIsTuchassouSelected(?bool $isTuchassouSelected): self
  493.     {
  494.         $this->isTuchassouSelected $isTuchassouSelected;
  495.         return $this;
  496.     }
  497.     /**
  498.      * @return Collection<int, OfferAdditionalService>
  499.      */
  500.     public function getOfferAdditionalServices(): Collection
  501.     {
  502.         return $this->offerAdditionalServices;
  503.     }
  504.     public function addOfferAdditionalService(OfferAdditionalService $offerAdditionalService): self
  505.     {
  506.         if (!$this->offerAdditionalServices->contains($offerAdditionalService)) {
  507.             $this->offerAdditionalServices[] = $offerAdditionalService;
  508.             $offerAdditionalService->setOffer($this);
  509.         }
  510.         return $this;
  511.     }
  512.     public function removeOfferAdditionalService(OfferAdditionalService $offerAdditionalService): self
  513.     {
  514.         if ($this->offerAdditionalServices->removeElement($offerAdditionalService)) {
  515.             // set the owning side to null (unless already changed)
  516.             if ($offerAdditionalService->getOffer() === $this) {
  517.                 $offerAdditionalService->setOffer(null);
  518.             }
  519.         }
  520.         return $this;
  521.     }
  522.     public function getDisponibilities(): ?array
  523.     {
  524.         $sorted $this->disponibilities;
  525.         sort($this->disponibilities);
  526.         return $sorted;
  527.     }
  528.     public function setDisponibilities(?array $disponibilities): self
  529.     {
  530.         $this->disponibilities $disponibilities;
  531.         return $this;
  532.     }
  533.     public function hasShowServices(): ?bool
  534.     {
  535.         foreach ($this->offerAdditionalServices as $service)
  536.             if ($service->getIsActive()) return true;
  537.         return false;
  538.     }
  539.     public function getValidDays(): ?array
  540.     {
  541.         $dates = [];
  542.         $recurrenceExceptions json_decode($this->getRecurrenceException());
  543.         $exceptions = [];
  544.         if ($recurrenceExceptions) {
  545.             foreach ($recurrenceExceptions as $recurrenceException) {
  546.                 $exceptions[] = $recurrenceException->date;
  547.             }
  548.         }
  549.         if($this->getDisponibilities() && !empty($this->getDisponibilities())) {
  550.             foreach ($this->getDisponibilities() as $disponibility) {
  551.                 if(!empty($disponibility) && !is_null($disponibility['date']) && !in_array($disponibility['date'], $exceptions))
  552.                     $dates[] = \DateTime::createFromFormat('d/m/Y'$disponibility['date'])->format('Y-m-d');
  553.             }
  554.         }
  555.         if (!is_null($this->startAt) && !is_null($this->endAt)){
  556.             $period = new \DatePeriod(
  557.                 $this->startAt,
  558.                 new \DateInterval('P1D'),
  559.                 $this->endAt->modify('+1 day')
  560.             );
  561.             if($this->getRecurrence() && !empty($this->getRecurrence())) {
  562.                 $days = [
  563.                     'dimanche',
  564.                     'lundi',
  565.                     'mardi',
  566.                     'mercredi',
  567.                     'jeudi',
  568.                     'vendredi',
  569.                     'samedi'
  570.                 ];
  571.                 foreach ($period as $key => $value) {
  572.                     if(in_array($days[$value->format('w')], $this->getRecurrence())) {
  573.                         $formatted $value->format('d/m/Y');
  574.                         if (!in_array($formatted$exceptions)) {
  575.                             $dates[] = $value->format('Y-m-d');
  576.                         }
  577.                     }
  578.                 }
  579.             } else {
  580.                 foreach ($period as $key => $value) {
  581.                     $dates[] = $value->format('Y-m-d');
  582.                 }
  583.             }
  584.         }
  585.         return array_unique(array_values(array_diff($dates$this->getFullBookedDays())));
  586.     }
  587.     public function getFullBookedDays(): array
  588.     {
  589.         $fullDays = [];
  590.         $booked $this->getBookingDays();
  591.         foreach ($booked as $day => $quantity) {
  592.             if($this->getNbPlacesDay() <= $quantity)
  593.                 $fullDays[] = $day;
  594.         }
  595.         return $fullDays;
  596.     }
  597.     public function getQuantityBooked(): ?int
  598.     {
  599.         return $this->quantityBooked;
  600.     }
  601.     public function setQuantityBooked(?int $quantityBooked): self
  602.     {
  603.         $this->quantityBooked $quantityBooked;
  604.         return $this;
  605.     }
  606.     public function getNbBraceletAvaibleToBooking(): ?int
  607.     {
  608.         return $this->nbBraceletsAvailable;
  609.     }
  610.     public function getIntialPrice(): ?float
  611.     {
  612.         return $this->price;
  613.     }
  614.     public function intialHalfPrice(): ?float
  615.     {
  616.         return $this->halfActionPrice;
  617.     }
  618.     public function getCreatedAt(): ?\DateTimeInterface
  619.     {
  620.         return $this->createdAt;
  621.     }
  622.     public function setCreatedAt(?\DateTimeInterface $createdAt): self
  623.     {
  624.         $this->createdAt $createdAt;
  625.         return $this;
  626.     }
  627.     public function getBookingDays(): array
  628.     {
  629.         $result = [];
  630.         /** @var Booking $booking */
  631.         foreach ($this->bookings as $booking) {
  632.             if($booking->getStatus() !== Booking::STATUS_ACCEPTED) continue;
  633.             if($booking->getDateStart() && $booking->getDateEnd() && $booking->getDateStart()->format('Y-m-d') !== $booking->getDateEnd()->format('Y-m-d')) {
  634.                 $interval \DateInterval::createFromDateString('1 day');
  635.                 $period = new \DatePeriod($booking->getDateStart(), $interval$booking->getDateEnd());
  636.                 foreach ($period as $day) {
  637.                     if(array_key_exists($day->format('Y-m-d'), $result)) {
  638.                         $result[$day->format('Y-m-d')] += $booking->getQuantity();
  639.                     } else {
  640.                         $result[$day->format('Y-m-d')] = $booking->getQuantity();
  641.                     }
  642.                 }
  643.             } elseif ($booking->getDateStart()) {
  644.                 if(array_key_exists($booking->getDateStart()->format('Y-m-d'), $result)) {
  645.                     $result[$booking->getDateStart()->format('Y-m-d')] += $booking->getQuantity();
  646.                 } else {
  647.                     $result[$booking->getDateStart()->format('Y-m-d')] = $booking->getQuantity();
  648.                 }
  649.             }
  650.         }
  651.         return $result;
  652.     }
  653.     /**
  654.      * @return Collection<int, Animal>
  655.      */
  656.     public function getAnimals(): Collection
  657.     {
  658.         return $this->animals;
  659.     }
  660.     public function addAnimal(Animal $animal): self
  661.     {
  662.         if (!$this->animals->contains($animal)) {
  663.             $this->animals[] = $animal;
  664.         }
  665.         return $this;
  666.     }
  667.     public function removeAnimal(Animal $animal): self
  668.     {
  669.         $this->animals->removeElement($animal);
  670.         return $this;
  671.     }
  672.     public function getCaractericGibier(): ?string
  673.     {
  674.         return $this->caractericGibier;
  675.     }
  676.     public function setCaractericGibier(?string $caractericGibier): self
  677.     {
  678.         $this->caractericGibier $caractericGibier;
  679.         return $this;
  680.     }
  681.     public function getFraisService(): ?float
  682.     {
  683.         return $this->getPrice() - $this->getIntialPrice();
  684.     }
  685.     public function getCover(): ?string
  686.     {
  687.         return $this->cover;
  688.     }
  689.     public function setCover(?string $cover): self
  690.     {
  691.         $this->cover $cover;
  692.         return $this;
  693.     }
  694.     public function getImages(): ?array
  695.     {
  696.         $images = [];
  697.         if($this->cover$images[] = $this->cover;
  698.         if(!empty($this->offerImages)) {
  699.             foreach ($this->offerImages as $image) {
  700.                 $images[] = $image->getPath();
  701.             }
  702.         }
  703.         return $images;
  704.     }
  705.     public function getFraisChasseur(): ?float
  706.     {
  707.         return $this->fraisChasseur;
  708.     }
  709.     public function setFraisChasseur(?float $fraisChasseur): self
  710.     {
  711.         $this->fraisChasseur $fraisChasseur;
  712.         return $this;
  713.     }
  714.     public function getFraisHote(): ?float
  715.     {
  716.         return $this->fraisHote;
  717.     }
  718.     public function setFraisHote(?float $fraisHote): self
  719.     {
  720.         $this->fraisHote $fraisHote;
  721.         return $this;
  722.     }
  723.     /**
  724.      * @return Collection<int, HuntingMode>
  725.      */
  726.     public function getHuntingMode(): Collection
  727.     {
  728.         return $this->huntingMode;
  729.     }
  730.     public function addHuntingMode(HuntingMode $huntingMode): self
  731.     {
  732.         if (!$this->huntingMode->contains($huntingMode)) {
  733.             $this->huntingMode[] = $huntingMode;
  734.         }
  735.         return $this;
  736.     }
  737.     public function removeHuntingMode(HuntingMode $huntingMode): self
  738.     {
  739.         $this->huntingMode->removeElement($huntingMode);
  740.         return $this;
  741.     }
  742.     /**
  743.      * @return string|null
  744.      */
  745.     public function getSlug(): ?string
  746.     {
  747.         return $this->slug;
  748.     }
  749.     /**
  750.      * @param string $slug
  751.      * @return slef
  752.      */
  753.     public function setSlug(string $slug): self
  754.     {
  755.         $this->slug $slug;
  756.         return $this;
  757.     }
  758.     public function getHigthKeyDispo(): int
  759.     {
  760.         if (empty($this->disponibilities)) return 0;
  761.         return max(array_keys($this->disponibilities))+1;
  762.     }
  763.     /**
  764.      * @return Collection<int, OfferCancellationRequest>
  765.      */
  766.     public function getOfferCancellationRequests(): Collection
  767.     {
  768.         return $this->offerCancellationRequests;
  769.     }
  770.     public function addOfferCancellationRequest(OfferCancellationRequest $offerCancellationRequest): self
  771.     {
  772.         if (!$this->offerCancellationRequests->contains($offerCancellationRequest)) {
  773.             $this->offerCancellationRequests[] = $offerCancellationRequest;
  774.             $offerCancellationRequest->setOffer($this);
  775.         }
  776.         return $this;
  777.     }
  778.     public function removeOfferCancellationRequest(OfferCancellationRequest $offerCancellationRequest): self
  779.     {
  780.         if ($this->offerCancellationRequests->removeElement($offerCancellationRequest)) {
  781.             // set the owning side to null (unless already changed)
  782.             if ($offerCancellationRequest->getOffer() === $this) {
  783.                 $offerCancellationRequest->setOffer(null);
  784.             }
  785.         }
  786.         return $this;
  787.     }
  788.     /**
  789.      * @return Collection<int, OfferImage>
  790.      */
  791.     public function getOfferImages(): Collection
  792.     {
  793.         return $this->offerImages;
  794.     }
  795.     public function addOfferImage(OfferImage $offerImage): self
  796.     {
  797.         if (!$this->offerImages->contains($offerImage)) {
  798.             $this->offerImages[] = $offerImage;
  799.             $offerImage->setOffer($this);
  800.         }
  801.         return $this;
  802.     }
  803.     public function removeOfferImage(OfferImage $offerImage): self
  804.     {
  805.         if ($this->offerImages->removeElement($offerImage)) {
  806.             // set the owning side to null (unless already changed)
  807.             if ($offerImage->getOffer() === $this) {
  808.                 $offerImage->setOffer(null);
  809.             }
  810.         }
  811.         return $this;
  812.     }
  813.     /**
  814.      * @return Collection<int, Gibier>
  815.      */
  816.     public function getGibiers(): Collection
  817.     {
  818.         return $this->gibiers;
  819.     }
  820.     public function addGibier(Gibier $gibier): self
  821.     {
  822.         if (!$this->gibiers->contains($gibier)) {
  823.             $this->gibiers[] = $gibier;
  824.         }
  825.         return $this;
  826.     }
  827.     public function removeGibier(Gibier $gibier): self
  828.     {
  829.         $this->gibiers->removeElement($gibier);
  830.         return $this;
  831.     }
  832.     public function getRecurrenceException(): ?string
  833.     {
  834.         return $this->recurrenceException;
  835.     }
  836.     public function setRecurrenceException(?string $recurrenceException): self
  837.     {
  838.         $this->recurrenceException $recurrenceException;
  839.         return $this;
  840.     }
  841.     public function getIsManagedByTuchassou(): ?bool
  842.     {
  843.         return $this->isManagedByTuchassou;
  844.     }
  845.     public function setIsManagedByTuchassou(?bool $isManagedByTuchassou): self
  846.     {
  847.         $this->isManagedByTuchassou $isManagedByTuchassou;
  848.         return $this;
  849.     }
  850. }