<?php
namespace App\Entity;
use App\Repository\SejourSessionRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use phpDocumentor\Reflection\Types\Boolean;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass=SejourSessionRepository::class)
* @UniqueEntity(fields={"code"}, message="Ce code est déjà utilisé")
*/
class SejourSession
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=20, unique= true)
*/
private $code;
/**
* @ORM\Column(type="string", length=20,nullable= true)
*/
private $codeGen;
/**
* @ORM\Column(type="date")
*/
private $dateDebut;
/**
* @ORM\Column(type="date")
*/
private $dateFin;
/**
* @ORM\Column(type="float",nullable= true)
*
*/
private $prix;
/**
* @ORM\Column(type="integer")
*/
private $placeDispo;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $mediaStatut;
/**
* @ORM\Column(type="date", nullable=true)
*/
private $lastUpdate;
/**
* @ORM\ManyToOne(targetEntity=Sejour::class, inversedBy="sejourSessions", fetch="EAGER",cascade={"persist"})
* @ORM\JoinColumn(nullable=false)
*/
private $sejour;
/**
* @ORM\OneToMany(targetEntity=MessageParent::class, mappedBy="sejourSession",cascade={"persist", "remove"})
*/
private $messageParents;
/**
* @ORM\OneToMany(targetEntity=Inscription::class, mappedBy="sejourSession",cascade={"persist", "remove"})
*/
private $inscriptions;
/**
* @ORM\OneToMany(targetEntity=Equipier::class, mappedBy="sejourSession",cascade={"persist"})
*/
private $equipiers;
/**
* @ORM\OneToMany(targetEntity=SejourSessionEquipier::class, mappedBy="sejourSession",cascade={"persist", "remove"})
*/
private $sejourSessionEquipiers;
/**
* @ORM\OneToMany(targetEntity=SejourSessionMajorationTransport::class, mappedBy="sejourSession",cascade={"persist", "remove"})
*/
private $sejourSessionMajorationTransports;
/**
* @ORM\OneToMany(targetEntity=Media::class, mappedBy="sejourSession", cascade={"persist", "remove"})
*/
private $medias;
/**
* @ORM\OneToMany(targetEntity=MessageDirecteurAuxParents::class, mappedBy="sejourSession",cascade={"persist", "remove"})
* @ORM\OrderBy({"createdDate" = "DESC"})
*/
private $messageDirecteurAuxParents;
/**
* @ORM\Column(type="string", length=50, nullable=true)
*/
private $legacyId;
/**
* @ORM\OneToMany(targetEntity=Temoignage::class, mappedBy="sejourSession",cascade={"persist", "remove"})
*/
private $temoignages;
/**
* @ORM\OneToMany(targetEntity=EnterpriseOptionSejourSession::class, mappedBy="sejourSession", cascade={"persist", "remove"})
*/
private $enterpriseOptionSejourSessions;
/**
* @ORM\OneToMany(targetEntity=SejourSessionPicture::class, mappedBy="sejourSession",cascade={"persist", "remove"})
* @ORM\OrderBy({"creationDate" = "DESC"})
*/
private $sejourSessionPictures;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $overridePlacesDispos;
public function __construct()
{
$this->messageParents = new ArrayCollection();
$this->inscriptions = new ArrayCollection();
$this->equipiers = new ArrayCollection();
$this->sejourSessionEquipiers = new ArrayCollection();
$this->sejourSessionMajorationTransports = new ArrayCollection();
$this->medias = new ArrayCollection();
$this->messageDirecteurAuxParents = new ArrayCollection();
$this->prix = 1000;
$this->placeDispo = 0;
$this->temoignages = new ArrayCollection();
$this->enterpriseOptionSejourSessions = new ArrayCollection();
$this->sejourSessionPictures = new ArrayCollection();
}
public function getMediaStatut():?int
{
return $this->mediaStatut;
}
public function setMediaStatut(?int $statut)
{
$this->mediaStatut = $statut;
return $this;
}
public function setLastUpdate(\Datetime $date)
{
$this->lastUpdate = $date;
return $this;
}
public function getLastUpdate()
{
return $this->lastUpdate;
}
public function getDirector(): ?Contact
{
foreach($this->getSejourSessionEquipiers() as $sse){
if($sse->getMetier()->getName() == Metier::TYPE_DIRECTOR){
return $sse->getContact();
}
}
return null;
}
public function hasEnfant(Contact $enfant): bool
{
foreach($this->getInscriptions() as $inscription){
if ($inscription->getEnfant() == $enfant && ($inscription->getStatut() == Inscription::PAID || $inscription->getStatut() == Inscription::PART|| $inscription->getStatut() == Inscription::OPTION) )
return true;
}
return false;
}
public function getId(): ?int
{
return $this->id;
}
public function getCode(): ?string
{
return $this->code;
}
public function setCode(string $code): self
{
$this->code = $code;
return $this;
}
public function getCodeGen(): ?string
{
return $this->code;
}
public function setCodeGen(string $codeGen): self
{
$this->codeGen = $codeGen;
return $this;
}
public function getDateDebut(): ?\DateTimeInterface
{
return $this->dateDebut;
}
public function setDateDebut(\DateTimeInterface $dateDebut): self
{
$this->dateDebut = $dateDebut;
return $this;
}
public function getDateFin(): ?\DateTimeInterface
{
return $this->dateFin;
}
public function setDateFin(\DateTimeInterface $dateFin): self
{
$this->dateFin = $dateFin;
return $this;
}
public function getPrix(): ?float
{
return $this->prix;
}
public function setPrix(?float $prix): self
{
$this->prix = $prix;
return $this;
}
public function getPlaceDispo(): ?int
{
return (int)$this->placeDispo;
}
public function setPlaceDispo(int $placeDispo): self
{
$this->placeDispo = $placeDispo;
return $this;
}
public function getSejour(): ?Sejour
{
return $this->sejour;
}
public function setSejour(?Sejour $sejour): self
{
$this->sejour = $sejour;
if ($sejour !== null)
$this->placeDispo = $sejour->getNombre();
return $this;
}
/**
* @return Collection|MessageParent[]
*/
public function getMessageParents(): Collection
{
return $this->messageParents;
}
public function addMessageParent(MessageParent $messageParent): self
{
if (!$this->messageParents->contains($messageParent)) {
$this->messageParents[] = $messageParent;
$messageParent->setSejourSession($this);
}
return $this;
}
public function removeMessageParent(MessageParent $messageParent): self
{
if ($this->messageParents->removeElement($messageParent)) {
// set the owning side to null (unless already changed)
if ($messageParent->getSejourSession() === $this) {
$messageParent->setSejourSession(null);
}
}
return $this;
}
/**
* @return Collection|Inscription[]
*/
public function getInscriptions(): Collection
{
return $this->inscriptions;
}
public function addInscription(Inscription $inscription): self
{
if (!$this->inscriptions->contains($inscription)) {
$this->inscriptions[] = $inscription;
$inscription->setSejourSession($this);
}
return $this;
}
public function removeInscription(Inscription $inscription): self
{
if ($this->inscriptions->removeElement($inscription)) {
// set the owning side to null (unless already changed)
if ($inscription->getSejourSession() === $this) {
$inscription->setSejourSession(null);
}
}
return $this;
}
/**
* @return Collection|Equipier[]
*/
public function getEquipiers(): Collection
{
return $this->equipiers;
}
public function addEquipier(Equipier $equipier): self
{
if (!$this->equipiers->contains($equipier)) {
$this->equipiers[] = $equipier;
$equipier->setSejourSession($this);
}
return $this;
}
public function removeEquipier(Equipier $equipier): self
{
if ($this->equipiers->removeElement($equipier)) {
// set the owning side to null (unless already changed)
if ($equipier->getSejourSession() === $this) {
$equipier->setSejourSession(null);
}
}
return $this;
}
/**
* @return Collection|SejourSessionEquipier[]
*/
public function getSejourSessionEquipiers(): Collection
{
return $this->sejourSessionEquipiers;
}
public function addSejourSessionEquipier(SejourSessionEquipier $sejourSessionEquipier): self
{
if (!$this->sejourSessionEquipiers->contains($sejourSessionEquipier)) {
$this->sejourSessionEquipiers[] = $sejourSessionEquipier;
$sejourSessionEquipier->setSejourSession($this);
}
return $this;
}
public function removeSejourSessionEquipier(SejourSessionEquipier $sejourSessionEquipier): self
{
if ($this->sejourSessionEquipiers->removeElement($sejourSessionEquipier)) {
// set the owning side to null (unless already changed)
if ($sejourSessionEquipier->getSejourSession() === $this) {
$sejourSessionEquipier->setSejourSession(null);
}
}
return $this;
}
/**
* @return Collection|SejourSessionMajorationTransports[]
*/
public function getSejourSessionMajorationTransports(): Collection
{
return $this->sejourSessionMajorationTransports;
}
public function addSejourSessionMajorationTransport(SejourSessionMajorationTransport $sejourSessionMajorationTransport): self
{
if (!$this->sejourSessionMajorationTransports->contains($sejourSessionMajorationTransport)) {
$this->sejourSessionMajorationTransports[] = $sejourSessionMajorationTransport;
$sejourSessionMajorationTransport->setSejourSession($this);
}
return $this;
}
public function removeSejourSessionMajorationTransport(SejourSessionEquipier $sejourSessionMajorationTransport): self
{
if ($this->sejourSessionMajorationTransports->removeElement($sejourSessionMajorationTransport)) {
// set the owning side to null (unless already changed)
if ($sejourSessionMajorationTransport->getSejourSession() === $this) {
$sejourSessionMajorationTransport->setSejourSession(null);
}
}
return $this;
}
/**
* @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->setSejourSession($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->getSejourSession() === $this) {
$media->setSejourSession(null);
}
}
return $this;
}
/**
* @return Collection|MessageDirecteurAuxParents[]
*/
public function getMessageDirecteurAuxParents(): Collection
{
return $this->messageDirecteurAuxParents;
}
/**
* @return Collection|MessageDirecteurAuxParents[]
*/
public function getMessageDirecteurAuxParentsValide(): array
{
$output = [];
foreach($this->messageDirecteurAuxParents as $message)
{
if ($message->getStatus() == MessageDirecteurAuxParents::STATE_VALIDATED)
$output[] = $message;
}
return $output;
}
public function addMessageDirecteurAuxParent(MessageDirecteurAuxParents $messageDirecteurAuxParent): self
{
if (!$this->messageDirecteurAuxParents->contains($messageDirecteurAuxParent)) {
$this->messageDirecteurAuxParents[] = $messageDirecteurAuxParent;
$messageDirecteurAuxParent->setSejourSession($this);
}
return $this;
}
public function removeMessageDirecteurAuxParent(MessageDirecteurAuxParents $messageDirecteurAuxParent): self
{
if ($this->messageDirecteurAuxParents->removeElement($messageDirecteurAuxParent)) {
// set the owning side to null (unless already changed)
if ($messageDirecteurAuxParent->getSejourSession() === $this) {
$messageDirecteurAuxParent->setSejourSession(null);
}
}
return $this;
}
public function getLegacyId(): ?string
{
return $this->legacyId;
}
public function setLegacyId(?string $legacyId): self
{
$this->legacyId = $legacyId;
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->setSejourSession($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->getSejourSession() === $this) {
$temoignage->setSejourSession(null);
}
}
return $this;
}
/**
* @return Collection|EnterpriseOptionSejourSession[]
*/
public function getEnterpriseOptionSejourSessions(): Collection
{
return $this->enterpriseOptionSejourSessions;
}
public function addEnterpriseOptionSejourSession(EnterpriseOptionSejourSession $enterpriseOptionSejourSession): self
{
if (!$this->enterpriseOptionSejourSessions->contains($enterpriseOptionSejourSession)) {
$this->enterpriseOptionSejourSessions[] = $enterpriseOptionSejourSession;
$enterpriseOptionSejourSession->setSejourSession($this);
}
return $this;
}
public function removeEnterpriseOptionSejourSession(EnterpriseOptionSejourSession $enterpriseOptionSejourSession): self
{
if ($this->enterpriseOptionSejourSessions->removeElement($enterpriseOptionSejourSession)) {
// set the owning side to null (unless already changed)
if ($enterpriseOptionSejourSession->getSejourSession() === $this) {
$enterpriseOptionSejourSession->setSejourSession(null);
}
}
return $this;
}
/**
* @return Collection|SejourSessionPicture[]
*/
public function getSejourSessionPictures(): Collection
{
return $this->sejourSessionPictures;
}
public function addSejourSessionPicture(SejourSessionPicture $sejourSessionPicture): self
{
if (!$this->sejourSessionPictures->contains($sejourSessionPicture)) {
$this->sejourSessionPictures[] = $sejourSessionPicture;
$sejourSessionPicture->setSejourSession($this);
}
return $this;
}
public function removeSejourSessionPicture(SejourSessionPicture $sejourSessionPicture): self
{
if ($this->sejourSessionPictures->removeElement($sejourSessionPicture)) {
// set the owning side to null (unless already changed)
if ($sejourSessionPicture->getSejourSession() === $this) {
$sejourSessionPicture->setSejourSession(null);
}
}
return $this;
}
public function getOverridePlacesDispos(): ?int
{
return $this->overridePlacesDispos;
}
public function setOverridePlacesDispos(?int $overridePlacesDispos): self
{
$this->overridePlacesDispos = $overridePlacesDispos;
return $this;
}
public function getReserved(): int
{
$now = new \Datetime();
$count = 0;
foreach($this->getEnterpriseOptionSejourSessions() as $option){
if($now < $option->getEndDate() and $option->getStatut() == "validated"){
$count += $option->getNbreSouhaite();
}
}
return $count;
}
public function getReservedAndBooked(): int
{
$now = new \Datetime();
$count = 0;
foreach($this->inscriptions as $inscription){
if(($inscription->getEnterpriseOptionSejourSession() !== null) && ($inscription->getStatut() == "option" || $inscription->getStatut() == "part"|| $inscription->getStatut() == "complete"))
$count ++;
}
return $count;
}
public function getReservedBookedAndOpen(): int
{
$now = new \Datetime();
$count = 0;
foreach($this->inscriptions as $inscription){
if( ($inscription->getEnterpriseOptionSejourSession() !== null) &&($inscription->getEnterpriseOptionSejourSession()->getEndDate() > $now) &&($inscription->getStatut() == "option" || $inscription->getStatut() == "part"|| $inscription->getStatut() == "complete") )
$count ++;
}
return $count;
}
public function getCodeComplet(): string
{
return $this->getCode() . " - " . $this->getSejour()->getTitle()." - ".$this->getDateDebut()->format('d/m/Y') ;
}
public function getOpen(): int
{
$now = new \Datetime();
$count = 0;
foreach($this->getInscriptions() as $inscription){
if (($inscription->getStatut() == Inscription::OPEN) && $inscription->getEnterpriseOptionSejourSession()==null )
$count ++;
}
return $count;
}
public function getPaid(): int
{
$now = new \Datetime();
$count = 0;
foreach($this->getInscriptions() as $inscription){
if (( $inscription->getStatut() == Inscription::PAID ) && $inscription->getEnterpriseOptionSejourSession()==null )
$count ++;
}
return $count;
}
public function getPart(): int
{
$now = new \Datetime();
$count = 0;
foreach($this->getInscriptions() as $inscription){
if (( $inscription->getStatut() == Inscription::PART ) && $inscription->getEnterpriseOptionSejourSession()==null )
$count ++;
}
return $count;
}
public function getInscritsCount3():int
{
$count = 0;
foreach($this->getInscriptions() as $inscription){
if (($inscription->getStatut() == Inscription::PAID || $inscription->getStatut() == Inscription::PART) )
$count ++;
}
if($this->getOverridePlacesDispos() === 1 && $count>0)
return 1;
return $count;
}
public function getInscritsCount2():int
{
$count = 0;
foreach($this->getInscriptions() as $inscription){
if (($inscription->getStatut() == Inscription::PAID || $inscription->getStatut() == Inscription::PART || $inscription->getStatut() == Inscription::OPEN) )
$count ++;
}
if($this->getOverridePlacesDispos() === 1 && $count>0)
return 1;
return $count;
}
public function getInscritsCount():int
{
$count = 0;
foreach($this->getInscriptions() as $inscription){
if (($inscription->getStatut() == Inscription::PAID || $inscription->getStatut() == Inscription::PART || $inscription->getStatut() == Inscription::OPEN) && $inscription->getEnterpriseOptionSejourSession()==null )
$count ++;
}
if($this->getOverridePlacesDispos() === 1 && $count>0)
return 1;
return $count;
}
public function getOptionOuvertes():int
{
$count = 0;
$now = new \Datetime();
foreach($this->getEnterpriseOptionSejourSessions() as $option){
if($now < $option->getEndDate() and $option->getStatut()=="validated"){
$count += $option->getNbreSouhaite();
$count += - count($option->getInscriptionsValides());
}
}
return $count;
}
public function getNonPayees():int
{
$count = 0;
foreach($this->getInscriptions() as $inscription){
if (($inscription->getStatut() == Inscription::OPEN) && $inscription->getEnterpriseOptionSejourSession()==null )
$count ++;
}
if($this->getOverridePlacesDispos() === 1 && $count>0)
return 1;
return $count;
}
public function getFreePlacesNumber(): int
{
if($this->getOverridePlacesDispos() === 0)
return 0;
$count = $this->getPlaceDispo();
foreach($this->getInscriptions() as $inscription){
if (($inscription->getStatut() == Inscription::PAID || $inscription->getStatut() == Inscription::PART || $inscription->getStatut() == 'option'|| $inscription->getStatut() == 'open') )
$count --;
}
//var_dump($this->getPlaceDispo());
//var_dump($count);
$now = new \Datetime();
foreach($this->getEnterpriseOptionSejourSessions() as $option){
if($now < $option->getEndDate() && $option->getStatut()=="validated"){
$count += - $option->getNbreSouhaite();
$count += count($option->getInscriptionsValides());
}
}
if($this->getOverridePlacesDispos() === 1 && $count>0)
return 1;
return $count;
}
public function getFreePlacesCountWithoutReserved(): int
{
if($this->getOverridePlacesDispos() === 0)
return 0;
$count = $this->getPlaceDispo();
foreach($this->getInscriptions() as $inscription){
if (($inscription->getStatut() == Inscription::PAID || $inscription->getStatut() == Inscription::PART || $inscription->getStatut() == Inscription::OPEN|| $inscription->getStatut() == Inscription::OPTION) && $inscription->getEnterpriseOptionSejourSession()==null )
$count --;
}
if($this->getOverridePlacesDispos() === 1 && $count>0)
return 1;
return $count;
}
public function isComplete(): bool
{
$count = $this->getFreePlacesNumber();
return $count <= 0;;
}
}