<?php
namespace App\Entity\Gestiform\Formations\Catalogue\Theme;
use App\Entity\AbstractEntity;
use App\Entity\Common\Upload;
use App\Entity\Gestiform\Admin\Tarifs\TarifVenteTheme;
use App\Entity\Gestiform\Admin\Tarifs\TarifVenteThemeIntra;
use App\Entity\Gestiform\Formations\Catalogue\Certification;
use App\Entity\Gestiform\Formations\Catalogue\Parcours\Parcours;
use App\Repository\Gestiform\Formations\Catalogue\Theme\ThemeRepository;
use App\Trait\SortableEntity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=ThemeRepository::class)
*/
class Theme extends AbstractEntity
{
use SortableEntity;
/**
* @ORM\Column(type="string", length=255, nullable=false)
*/
private string $intitule;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $code = null;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $altBanniere = null;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $altVignette = null;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $couleur = null;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $commentaire = null;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $seotitre = null;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $seodescription = null;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $path = null;
/**
* @ORM\Column(type="boolean")
*/
private ?bool $publication = true;
/**
* @ORM\OneToOne(targetEntity=Upload::class, cascade={"persist", "remove"})
* @ORM\JoinColumn(nullable=true)
*/
private ?Upload $vignette = null;
/**
* @ORM\OneToOne(targetEntity=Upload::class, cascade={"persist", "remove"})
* @ORM\JoinColumn(nullable=true)
*/
private ?Upload $banniere = null;
/**
* @ORM\OneToMany(targetEntity=SousThemeTheme::class, mappedBy="theme")
*/
private Collection $sousThemeThemes;
/**
* @ORM\OneToMany(targetEntity=Certification::class, mappedBy="theme")
*/
private Collection $certifications;
/**
* @ORM\ManyToMany(targetEntity=Parcours::class, mappedBy="themes")
*/
private Collection $parcours;
/**
* @ORM\OneToMany(targetEntity=TarifVenteTheme::class, mappedBy="theme", cascade={"persist", "remove"})
*/
private Collection $tarifsVentes;
/**
* @ORM\OneToMany(targetEntity=TarifVenteThemeIntra::class, mappedBy="theme", cascade={"persist", "remove"})
*/
private Collection $tarifsVenteIntras;
/**
* @ORM\ManyToOne(targetEntity=TarifVenteTheme::class)
*/
private ?TarifVenteTheme $tarifVenteDefaut = null;
/**
* @ORM\ManyToOne(targetEntity=TarifVenteThemeIntra::class)
*/
private ?TarifVenteThemeIntra $tarifventeintradefaut = null;
/**
* @ORM\OneToMany(targetEntity=Parcours::class, mappedBy="theme")
*/
private Collection $defaultParcours;
public function __construct()
{
$this->sousThemeThemes = new ArrayCollection();
$this->certifications = new ArrayCollection();
$this->parcours = new ArrayCollection();
$this->tarifsVentes = new ArrayCollection();
$this->tarifsVenteIntras = new ArrayCollection();
$this->defaultParcours = new ArrayCollection();
}
public function getIntitule(): ?string
{
return $this->intitule;
}
public function getTarifVenteActuel()
{
if (count($this->getTarifsVentes()) == 0) {
return $this->getTarifVenteDefaut();
}
$datedujour = new \DateTime();
$datedujour->setTime(0, 0);
// retourne le tarif dans les dates actuelles
foreach ($this->getTarifsVentes() as $tarif) {
if ($tarif->getStart() <= $datedujour &&
($tarif->getEnd() >= $datedujour || is_null($tarif->getEnd()))) {
return $tarif;
}
}
return $this->getTarifVenteDefaut();
}
public function getTarifVenteIntraActuel()
{
$datedujour = new \DateTime();
$datedujour->setTime(0, 0);
// retourne le tarif dans les dates actuelles
foreach ($this->getTarifsVenteIntras() as $tarif) {
if ($tarif->getStart() <= $datedujour && ($tarif->getEnd() >= $datedujour || is_null($tarif->getEnd()))) {
return $tarif;
}
}
return $this->getTarifVenteDefaut();
}
public function setIntitule(string $intitule): self
{
$this->intitule = $intitule;
return $this;
}
public function getCode(): ?string
{
return $this->code;
}
public function setCode(?string $code): self
{
$this->code = $code;
return $this;
}
public function getAltBanniere(): ?string
{
return $this->altBanniere;
}
public function setAltBanniere(?string $altBanniere): self
{
$this->altBanniere = $altBanniere;
return $this;
}
public function getAltVignette(): ?string
{
return $this->altVignette;
}
public function setAltVignette(?string $altVignette): self
{
$this->altVignette = $altVignette;
return $this;
}
public function getCouleur(): ?string
{
return $this->couleur;
}
public function setCouleur(?string $couleur): self
{
$this->couleur = $couleur;
return $this;
}
public function getCommentaire(): ?string
{
return $this->commentaire;
}
public function setCommentaire(?string $commentaire): self
{
$this->commentaire = $commentaire;
return $this;
}
public function getSeotitre(): ?string
{
return $this->seotitre;
}
public function setSeotitre(?string $seotitre): self
{
$this->seotitre = $seotitre;
return $this;
}
public function getSeodescription(): ?string
{
return $this->seodescription;
}
public function setSeodescription(?string $seodescription): self
{
$this->seodescription = $seodescription;
return $this;
}
public function getPublication(): ?bool
{
return $this->publication;
}
public function setPublication(?bool $publication): self
{
$this->publication = $publication;
return $this;
}
public function getVignette(): ?Upload
{
return $this->vignette;
}
public function setVignette(?Upload $vignette): self
{
$this->vignette = $vignette;
return $this;
}
public function getBanniere(): ?Upload
{
return $this->banniere;
}
public function setBanniere(?Upload $banniere): self
{
$this->banniere = $banniere;
return $this;
}
public function getPath(): ?string
{
return $this->path;
}
public function setPath(?string $path): self
{
$this->path = $path;
return $this;
}
/**
* @return Collection<int, SousThemeTheme>
*/
public function getSousThemeThemes(): Collection
{
return $this->sousThemeThemes;
}
public function addSousThemeTheme(SousThemeTheme $sousThemeTheme): self
{
if (!$this->sousThemeThemes->contains($sousThemeTheme)) {
$this->sousThemeThemes->add($sousThemeTheme);
$sousThemeTheme->setTheme($this);
}
return $this;
}
public function removeSousThemeTheme(SousThemeTheme $sousThemeTheme): self
{
if ($this->sousThemeThemes->removeElement($sousThemeTheme)) {
// set the owning side to null (unless already changed)
if ($sousThemeTheme->getTheme() === $this) {
$sousThemeTheme->setTheme(null);
}
}
return $this;
}
/**
* @return Collection<int, Parcours>
*/
public function getParcours(): Collection
{
return $this->parcours;
}
public function addParcour(Parcours $parcours): self
{
if (!$this->parcours->contains($parcours)) {
$this->parcours->add($parcours);
}
return $this;
}
public function removeParcour(Parcours $parcours): self
{
$this->parcours->removeElement($parcours);
return $this;
}
/**
* @return Collection<int, Certification>
*/
public function getCertifications(): Collection
{
return $this->certifications;
}
public function addCertification(Certification $certification): self
{
if (!$this->certifications->contains($certification)) {
$this->certifications->add($certification);
$certification->setTheme($this);
}
return $this;
}
public function removeCertification(Certification $certification): self
{
if ($this->certifications->removeElement($certification)) {
// set the owning side to null (unless already changed)
if ($certification->getTheme() === $this) {
$certification->setTheme(null);
}
}
return $this;
}
public function isPublication(): ?bool
{
return $this->publication;
}
/**
* @return Collection<int, TarifVenteTheme>
*/
public function getTarifsVentes(): Collection
{
return $this->tarifsVentes;
}
public function addTarifsVente(TarifVenteTheme $tarifsVente): self
{
if (!$this->tarifsVentes->contains($tarifsVente)) {
$this->tarifsVentes->add($tarifsVente);
$tarifsVente->setTheme($this);
}
return $this;
}
public function removeTarifsVente(TarifVenteTheme $tarifsVente): self
{
if ($this->tarifsVentes->removeElement($tarifsVente)) {
// set the owning side to null (unless already changed)
if ($tarifsVente->getTheme() === $this) {
$tarifsVente->setTheme(null);
}
}
return $this;
}
/**
* @return Collection<int, TarifVenteThemeIntra>
*/
public function getTarifsVenteIntras(): Collection
{
return $this->tarifsVenteIntras;
}
public function addTarifsVenteIntra(TarifVenteThemeIntra $tarifsVenteIntra): self
{
if (!$this->tarifsVenteIntras->contains($tarifsVenteIntra)) {
$this->tarifsVenteIntras->add($tarifsVenteIntra);
$tarifsVenteIntra->setTheme($this);
}
return $this;
}
public function removeTarifsVenteIntra(TarifVenteThemeIntra $tarifsVenteIntra): self
{
if ($this->tarifsVenteIntras->removeElement($tarifsVenteIntra)) {
// set the owning side to null (unless already changed)
if ($tarifsVenteIntra->getTheme() === $this) {
$tarifsVenteIntra->setTheme(null);
}
}
return $this;
}
public function getTarifVenteDefaut(): ?TarifVenteTheme
{
return $this->tarifVenteDefaut;
}
public function setTarifVenteDefaut(?TarifVenteTheme $tarifVenteDefaut): self
{
$this->tarifVenteDefaut = $tarifVenteDefaut;
return $this;
}
public function getTarifventeintradefaut(): ?TarifVenteThemeIntra
{
return $this->tarifventeintradefaut;
}
public function setTarifventeintradefaut(?TarifVenteThemeIntra $tarifventeintradefaut): self
{
$this->tarifventeintradefaut = $tarifventeintradefaut;
return $this;
}
/**
* @return Collection<int, Parcours>
*/
public function getDefaultParcours(): Collection
{
return $this->defaultParcours;
}
public function addDefaultParcour(Parcours $defaultParcour): self
{
if (!$this->defaultParcours->contains($defaultParcour)) {
$this->defaultParcours->add($defaultParcour);
$defaultParcour->setTheme($this);
}
return $this;
}
public function removeDefaultParcour(Parcours $defaultParcour): self
{
if ($this->defaultParcours->removeElement($defaultParcour)) {
// set the owning side to null (unless already changed)
if ($defaultParcour->getTheme() === $this) {
$defaultParcour->setTheme(null);
}
}
return $this;
}
}