<?php
namespace App\Entity;
use App\Repository\SejourRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use function PHPSTORM_META\map;
/**
* @ORM\Entity(repositoryClass=SejourRepository::class)
*/
class Sejour
{
const MOIS =[
"1" => "Janvier",
"01" => "Janvier",
"02" => "Février",
"03" => "Mars",
"04" => "Avril",
"05" => "Mai",
"06" => "Juin",
"07" => "Juillet",
"08" => "Aout",
"09" => "Septembre",
"10" => "Octobre",
"11" => "Novembre",
"12" => "Décembre",
];
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $title;
/**
* @ORM\Column(type="text")
*/
private $description;
/**
* @ORM\Column(type="text")
*/
private $activites;
/**
* @ORM\Column(type="date",nullable= true)
*/
private $updatedDate;
/**
* @ORM\Column(type="text")
*/
private $hebergement;
/**
* @ORM\OneToMany(targetEntity=SejourSession::class, mappedBy="sejour", cascade={"persist", "remove"})
* @ORM\OrderBy({"dateDebut" = "ASC"})
*/
private $sejourSessions;
/**
* @ORM\Column(type="boolean")
*/
private $isActive;
/**
* @ORM\Column(type="boolean", options={"default" = true})
*/
private $isBientot;
/**
* @ORM\Column(type="boolean")
*/
private $isObjectifZeroCo2;
/**
* @ORM\ManyToMany(targetEntity=Theme::class, inversedBy="sejours")
*/
private $themes;
/**
* @ORM\ManyToMany(targetEntity=Country::class, inversedBy="sejours")
*/
private $countries;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $position;
/**
* @ORM\OneToOne(targetEntity=Location::class, inversedBy="sejour", cascade={"persist", "remove"})
*/
private $location;
/**
* @ORM\OneToMany(targetEntity=MajorationTransport::class, mappedBy="sejour", cascade={"persist", "remove"})
* @ORM\OrderBy({"ville" = "ASC"})
*/
private $majorationTransports;
/**
* @ORM\OneToMany(targetEntity=SejourEquipier::class, mappedBy="sejour", cascade={"persist", "remove"})
*/
private $sejourEquipiers;
/**
* @ORM\Column(type="integer")
*/
private $ageMin;
/**
* @ORM\Column(type="integer")
*/
private $ageMax;
/**
* @ORM\ManyToMany(targetEntity=Saison::class, inversedBy="sejours")
*/
private $saisons;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $isSejourLocation;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $isSejourCourt;
/**
* @ORM\Column(type="string", length=511, nullable=true)
*/
private $notreAvis;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $tarifs;
/**
* @ORM\Column(type="integer")
*/
private $placesCount;
/**
* @ORM\OneToMany(targetEntity=Media::class, mappedBy="sejour",cascade={"persist", "remove"})
*/
private $medias;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $legacyId;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $intro;
/**
* @ORM\Column(type="float", nullable=true)
*/
private $price;
/**
* @ORM\Column(type="string", length=511, nullable=true)
*/
private $duree;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $encadrement;
/**
* @ORM\Column(type="string", length=255)
*/
private $nombre;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $dureeInteger;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $tranport;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $transport;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $compris;
/**
* @ORM\Column(type="text")
*/
private $noncompris;
/**
* @ORM\Column(type="text")
*/
private $informationComplementaire;
/**
* @ORM\ManyToMany(targetEntity=Property::class, inversedBy="sejours")
*/
private $property;
/**
* @ORM\OneToMany(targetEntity=Temoignage::class, mappedBy="sejour",cascade={"persist", "remove"})
*/
private $temoignages;
/**
* @ORM\Column(type="string", length=511, nullable=true)
*/
private $url;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $sejourType;
/**
* @ORM\ManyToMany(targetEntity=TrancheAge::class, inversedBy="sejours")
*/
private $trancheAges;
/**
* @ORM\ManyToOne(targetEntity=TrancheAge::class, inversedBy="sejoursMin")
*/
private $trancheAge1;
/**
* @ORM\ManyToOne(targetEntity=TrancheAge::class, inversedBy="sejoursMax")
*/
private $trancheAge2;
/**
* @ORM\Column(type="string", length=511, nullable=true)
*/
private $videoLink;
/**
* @ORM\Column(type="string", length=511, nullable=true)
*/
private $activitesFicheSejour;
/**
* @ORM\Column(type="string", length=511, nullable=true)
*/
private $lienYoutube;
/**
* @ORM\OneToMany(targetEntity="App\Entity\SejourWhitelist", mappedBy="sejour")
*/
private $whitelists;
public function __construct()
{
$this->sejourSessions = new ArrayCollection();
$this->themes = new ArrayCollection();
$this->majorationTransports = new ArrayCollection();
$this->sejourEquipiers = new ArrayCollection();
$this->saisons = new ArrayCollection();
$this->medias = new ArrayCollection();
$this->countries = new ArrayCollection();
$this->noncompris ="argent de poche";
$this->property = new ArrayCollection();
$this->temoignages = new ArrayCollection();
$this->isBientot = false;
}
public function getId(): ?int
{
return $this->id;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title): self
{
$this->title = $title;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(string $description): self
{
$this->description = $description;
return $this;
}
public function getActivites(): ?string
{
return $this->activites;
}
public function setActivites(string $activites): self
{
$this->activites = $activites;
return $this;
}
public function getHebergement(): ?string
{
return $this->hebergement;
}
public function setHebergement(string $hebergement): self
{
$this->hebergement = $hebergement;
return $this;
}
/**
* @return Collection|SejourSession[]
*/
public function getSejourSessions(): Collection
{
return $this->sejourSessions;
}
public function addSejourSession(SejourSession $sejourSession): self
{
if (!$this->sejourSessions->contains($sejourSession)) {
$this->sejourSessions[] = $sejourSession;
$sejourSession->setSejour($this);
}
return $this;
}
public function removeSejourSession(SejourSession $sejourSession): self
{
if ($this->sejourSessions->removeElement($sejourSession)) {
// set the owning side to null (unless already changed)
if ($sejourSession->getSejour() === $this) {
$sejourSession->setSejour(null);
}
}
return $this;
}
public function getIsActive(): ?bool
{
return $this->isActive;
}
public function setIsActive(bool $isActive): self
{
$this->isActive = $isActive;
return $this;
}
public function getBientot(): ?bool
{
return $this->isBientot;
}
public function setBientot(bool $isBientot): self
{
$this->isBientot = $isBientot;
return $this;
}
public function getIsObjectifZeroCo2(): ?bool
{
return $this->isObjectifZeroCo2;
}
public function setIsObjectifZeroCo2(bool $isObjectifZeroCo2): self
{
$this->isObjectifZeroCo2 = $isObjectifZeroCo2;
return $this;
}
/**
* @return Collection|Theme[]
*/
public function getThemes(): Collection
{
return $this->themes;
}
public function addTheme(Theme $theme): self
{
if (!$this->themes->contains($theme)) {
$this->themes[] = $theme;
}
return $this;
}
public function addThemes(iterable $themes): self
{
foreach($themes as $theme)
$this->addTheme($theme);
return $this;
}
public function removeTheme(Theme $theme): self
{
$this->themes->removeElement($theme);
return $this;
}
/**
* @return Collection|Theme[]
*/
public function getCountries(): Collection
{
return $this->countries;
}
public function addCountry(Country $country): self
{
if (!$this->countries->contains($country)) {
$this->countries[] = $country;
}
return $this;
}
public function addCountries(iterable $countries): self
{
foreach($countries as $country)
$this->addTheme($country);
return $this;
}
public function removeCountry(Country $country): self
{
$this->countries->removeElement($country);
return $this;
}
public function getPosition(): ?int
{
return $this->position;
}
public function setPosition(?int $position): self
{
$this->position = $position;
return $this;
}
public function getLocation(): ?Location
{
return $this->location;
}
public function setLocation(?Location $location): self
{
$this->location = $location;
return $this;
}
/**
* @return Collection|MajorationTransport[]
*/
public function getMajorationTransports(): Collection
{
return $this->majorationTransports;
}
public function addMajorationTransport(MajorationTransport $majorationTransport): self
{
if (!$this->majorationTransports->contains($majorationTransport)) {
$this->majorationTransports[] = $majorationTransport;
$majorationTransport->setSejour($this);
}
return $this;
}
public function removeMajorationTransport(MajorationTransport $majorationTransport): self
{
if ($this->majorationTransports->removeElement($majorationTransport)) {
// set the owning side to null (unless already changed)
if ($majorationTransport->getSejour() === $this) {
$majorationTransport->setSejour(null);
}
}
return $this;
}
/**
* @return Collection|SejourEquipier[]
*/
public function getSejourEquipiers(): Collection
{
return $this->sejourEquipiers;
}
public function addSejourEquipier(SejourEquipier $sejourEquipier): self
{
if (!$this->sejourEquipiers->contains($sejourEquipier)) {
$this->sejourEquipiers[] = $sejourEquipier;
$sejourEquipier->setSejour($this);
}
return $this;
}
public function removeSejourEquipier(SejourEquipier $sejourEquipier): self
{
if ($this->sejourEquipiers->removeElement($sejourEquipier)) {
// set the owning side to null (unless already changed)
if ($sejourEquipier->getSejour() === $this) {
$sejourEquipier->setSejour(null);
}
}
return $this;
}
public function getAgeMin(): ?int
{
return $this->ageMin;
}
public function setAgeMin(int $ageMin): self
{
$this->ageMin = $ageMin;
return $this;
}
public function getAgeMax(): ?int
{
return $this->ageMax;
}
public function setAgeMax(int $ageMax): self
{
$this->ageMax = $ageMax;
return $this;
}
/**
* @return Collection|Saison[]
*/
public function getSaisons(): Collection
{
return $this->saisons;
}
public function addSaison(Saison $saison): self
{
if (!$this->saisons->contains($saison)) {
$this->saisons[] = $saison;
}
return $this;
}
public function removeSaison(Saison $saison): self
{
$this->saisons->removeElement($saison);
return $this;
}
public function getIsSejourLocation(): ?bool
{
return $this->isSejourLocation;
}
public function setIsSejourLocation(?bool $isSejourLocation): self
{
$this->isSejourLocation = $isSejourLocation;
return $this;
}
public function getIsSejourCourt(): ?bool
{
return $this->isSejourCourt;
}
public function setIsSejourCourt(?bool $isSejourLocation): self
{
$this->isSejourCourt = $isSejourLocation;
return $this;
}
public function getNotreAvis(): ?string
{
return $this->notreAvis;
}
public function setNotreAvis(?string $notreAvis): self
{
$this->notreAvis = $notreAvis;
return $this;
}
public function getTarifs(): ?string
{
return $this->tarifs;
}
public function setTarifs(?string $tarifs): self
{
$this->tarifs = $tarifs;
return $this;
}
public function getPlacesCount(): ?int
{
return $this->placesCount;
}
public function setPlacesCount(int $placesCount): self
{
$this->placesCount = $placesCount;
$this->nombre = $placesCount;
return $this;
}
/**
* @return Collection|SejourSession[]
*/
public function getFutureSejourSessions(): array
{
$output = [];
$date = new \Datetime();
foreach($this->sejourSessions as $session){
if ($session->getDateDebut() > $date){
$output [] = $session;
}
}
return $output;
}
public function getMinFuturePrice():float
{
$output = 20000;
$futures = $this->getFutureSejourSessions();
foreach($futures as $futur){
if($futur->getPrix() < $output){
$output = $futur->getPrix();
}
}
return $output;
}
public function getPeriode(): string
{
$output = "";
$futures = $this->getFutureSejourSessions();
$monthMin = 12;
$monthMax = 1 ;
foreach($futures as $futur)
{
if($futur->getDateDebut()->format('m')<$monthMin)
$monthMin = $futur->getDateDebut()->format('m');
if($futur->getDateDebut()->format('m')>$monthMax)
$monthMax = $futur->getDateDebut()->format('m');
}
if($monthMin == $monthMax)
return self::MOIS[$monthMin];
return self::MOIS[$monthMin]." - ".self::MOIS[$monthMax];
}
public function hasFutureSejourSessions(): bool
{
if(count($this->getFutureSejourSessions()) > 0 ) return true;
return false;
}
/**
* @return Collection|Media[]
*/
public function getMedias(): Collection
{
return $this->medias;
}
public function addMedia(Media $media): self
{
if (!$this->medias->contains($media)) {
$this->medias[] = $media;
$media->setSejour($this);
}
return $this;
}
public function removeMedia(Media $media): self
{
if ($this->medias->removeElement($media)) {
// set the owning side to null (unless already changed)
if ($media->getSejour() === $this) {
$media->setSejour(null);
}
}
return $this;
}
public function getLegacyId(): ?int
{
return $this->legacyId;
}
public function setLegacyId(?int $legacyId): self
{
$this->legacyId = $legacyId;
return $this;
}
public function getIntro(): ?string
{
return $this->intro;
}
public function setIntro(?string $intro): self
{
$this->intro = $intro;
return $this;
}
public function getPrice(): ?float
{
return $this->price;
}
public function setPrice(?float $price): self
{
$this->price = $price;
return $this;
}
public function getDuree(): ?string
{
return $this->duree;
}
public function setDuree(?string $duree): self
{
$this->duree = $duree;
return $this;
}
public function getEncadrement(): ?string
{
return $this->encadrement;
}
public function setEncadrement(?string $encadrement): self
{
$this->encadrement = $encadrement;
return $this;
}
public function getNombre(): ?string
{
return $this->nombre;
}
public function setNombre(string $nombre): self
{
$this->nombre = $nombre;
return $this;
}
public function getDureeInteger(): ?int
{
return $this->dureeInteger;
}
public function setDureeInteger(?int $dureeString): self
{
$this->dureeInteger = $dureeString;
return $this;
}
public function getTranport(): ?string
{
return $this->tranport;
}
public function setTranport(?string $tranport): self
{
$this->tranport = $tranport;
return $this;
}
public function getTransport(): ?string
{
return $this->transport;
}
public function setTransport(?string $transport): self
{
$this->transport = $transport;
return $this;
}
public function getCompris(): ?string
{
return $this->compris;
}
public function setCompris(?string $compris): self
{
$this->compris = $compris;
return $this;
}
public function getNoncompris(): ?string
{
return $this->noncompris;
}
public function setNoncompris(string $noncompris): self
{
$this->noncompris = $noncompris;
return $this;
}
public function getInformationComplementaire(): ?string
{
return $this->informationComplementaire;
}
public function setInformationComplementaire(string $noncompris): self
{
$this->informationComplementaire = $noncompris;
return $this;
}
/**
* @return Collection|Property[]
*/
public function getProperty(): Collection
{
return $this->property;
}
public function addProperty(Property $property): self
{
if (!$this->property->contains($property)) {
$this->property[] = $property;
}
return $this;
}
public function removeProperty(Property $property): self
{
$this->property->removeElement($property);
return $this;
}
/**
* @return Collection|Temoignage[]
*/
public function getTemoignages(): Collection
{
return $this->temoignages;
}
public function addTemoignage(Temoignage $temoignage): self
{
if (!$this->temoignages->contains($temoignage)) {
$this->temoignages[] = $temoignage;
$temoignage->setSejour($this);
}
return $this;
}
public function removeTemoignage(Temoignage $temoignage): self
{
if ($this->temoignages->removeElement($temoignage)) {
// set the owning side to null (unless already changed)
if ($temoignage->getSejour() === $this) {
$temoignage->setSejour(null);
}
}
return $this;
}
public function getSejourType(): ?string
{
return $this->sejourType;
}
public function setSejourType(?string $url): self
{
$this->sejourType = $url;
return $this;
}
public function getUrl(): ?string
{
return $this->url;
}
public function setUrl(?string $url): self
{
$this->url = $url;
return $this;
}
public function getAvailableplaces(): int
{
$output = 0 ;
$sessionsfutures = $this->getFutureSejourSessions();
foreach($sessionsfutures as $sf){
$output += $sf->getFreePlacesNumber();
}
return $output;
}
public function getMinPrice(): int
{
$output = 10000 ;
$sessionsfutures = $this->getFutureSejourSessions();
foreach($sessionsfutures as $sf){
if($sf->getPrix() < $output)
$output = $sf->getPrix();
}
return $output;
}
public function getTrancheAge1(): ?TrancheAge
{
return $this->trancheAge1;
}
public function setTrancheAge1(?TrancheAge $trancheAge1): self
{
$this->trancheAge1 = $trancheAge1;
return $this;
}
public function getTrancheAge2(): ?TrancheAge
{
return $this->trancheAge2;
}
public function setTrancheAge2(?TrancheAge $trancheAge2): self
{
$this->trancheAge2 = $trancheAge2;
return $this;
}
public function getVideoLink(): ?string
{
return $this->videoLink;
}
public function setVideoLink(?string $videoLink): self
{
$this->videoLink = $videoLink;
return $this;
}
public function getActivitesFicheSejour(): ?string
{
return $this->activitesFicheSejour;
}
public function setActivitesFicheSejour(?string $videoLink): self
{
$this->activitesFicheSejour = $videoLink;
return $this;
}
public function getLienYoutube(): ?string
{
return $this->lienYoutube;
}
public function setLienYoutube(?string $lienYoutube): self
{
$this->lienYoutube = $lienYoutube;
return $this;
}
public function isFutureComplete():bool{
$availables = 0;
foreach($this->getSejourSessions() as $session){
$availables += $session->getPlaceDispo();
}
return $availables == 0;
}
public function isInWhitelist(?User $user = null): ?SejourWhitelist
{
if ($user){
foreach ($this->whitelists as $whitelist) {
if ($whitelist->getUser() === $user) {
return $whitelist;
}
}
}
return null;
}
public function getUpdatedDate(): ?\DateTimeInterface
{
return $this->updatedDate;
}
public function setUpdatedDate(\DateTimeInterface $updatedDate): self
{
$this->updatedDate = $updatedDate;
return $this;
}
}