<?php
namespace App\Entity;
use App\Repository\CompagneRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Persistence\ObjectManagerAware;
use Doctrine\Persistence\Mapping\ClassMetadata;
/**
* @ORM\Entity(repositoryClass=CompagneRepository::class)
*/
class Compagne implements ObjectManagerAware
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\OneToMany(targetEntity=CampagneCouche::class, mappedBy="compagne")
*/
private $campagneCouches;
/**
* @ORM\Column(type="integer")
*/
private $Type;
/**
* @ORM\Column(type="string", length=255)
*/
private $Nom;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $Description;
/**
* @ORM\Column(name="DateDebut",type="datetime")
*/
private $DateDebut;
/**
* @ORM\Column(name="DateFin",type="datetime")
*/
private $DateFin;
/**
* @ORM\Column(type="integer",nullable=true,options={"default" : 0})
*/
private $Progression;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $Objectif;
/**
* @ORM\ManyToOne(targetEntity=Projet::class, inversedBy="compagnes")
* @ORM\JoinColumn(name="id_projet", referencedColumnName="id")
*/
private $projet;
/**
* @ORM\Column(type="integer",nullable=true,options={"default" : 0 , "comment":"Nbr des apprenants appelés au moins une seule fois"})
*/
private $Tentative = 0;
/**
* @ORM\Column(type="integer",nullable=true,options={"default" : 0})
*/
private $archive = 0;
/**
* @ORM\Column(name="DateFinReelle",type="datetime", nullable=true)
*/
private $DateFinReelle;
/**
* @ORM\ManyToOne(targetEntity=Utilisateur::class, inversedBy="compagnes")
* @ORM\JoinColumn(name="createur", referencedColumnName="id")
*/
private $createur;
/**
* @ORM\Column(name="DateCreation",type="string", length=255, nullable=true)
*/
private $DateCreation;
/**
* @ORM\Column(type="integer", nullable=true , options={"default":0, "comment":"(1=CampagnePause) (2=CampagnePlay) (3=CampagneEnd)"})
*/
private $state = 0;
/**
* @ORM\Column(type="integer",nullable=true,options={"default" : 0})
*/
private $couche = 0;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $statut;
/**
* @ORM\OneToMany(targetEntity=Priorite::class, mappedBy="campagne")
*/
private $priorites;
/**
* @ORM\OneToMany(targetEntity=Tache::class, mappedBy="compagne")
*/
private $taches;
/**
* @ORM\ManyToMany(targetEntity=Utilisateur::class, inversedBy="campagnes")
*/
private $collaborateurs;
/**
* @ORM\ManyToOne(targetEntity=Cours::class, inversedBy="campagnes")
* @ORM\JoinColumn(name="id_cours", referencedColumnName="id")
*/
private $cours;
/**
* Init Object Manager
*/
private $em;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $forceVip;
/**
* Initialiser ObjectManager pour qu'on puisse utiliser Reporistory dans l'entity
*
* @param ObjectManager $objectManager
* @param ClassMetadata $classMetadata
* @return void
*/
public function injectObjectManager(\Doctrine\Persistence\ObjectManager $objectManager, ClassMetadata $classMetadata = null)
{
$this->em = $objectManager;
}
public function __construct()
{
$this->campagneCouches = new ArrayCollection();
$this->priorites = new ArrayCollection();
$this->taches = new ArrayCollection();
$this->collaborateurs = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
/**
* @return Collection|CampagneCouche[]
*/
public function getCampagneCouches(): Collection
{
return $this->campagneCouches;
}
public function addCampagneCouch(CampagneCouche $campagneCouch): self
{
if (!$this->campagneCouches->contains($campagneCouch)) {
$this->campagneCouches[] = $campagneCouch;
$campagneCouch->setCompagne($this);
}
return $this;
}
public function removeCampagneCouch(CampagneCouche $campagneCouch): self
{
if ($this->campagneCouches->contains($campagneCouch)) {
$this->campagneCouches->removeElement($campagneCouch);
// set the owning side to null (unless already changed)
if ($campagneCouch->getCompagne() === $this) {
$campagneCouch->setCompagne(null);
}
}
return $this;
}
public function getType(): ?int
{
return $this->Type;
}
public function setType(int $Type): self
{
$this->Type = $Type;
return $this;
}
public function getNom(): ?string
{
return $this->Nom;
}
public function setNom(string $Nom): self
{
$this->Nom = $Nom;
return $this;
}
public function getDescription(): ?string
{
return $this->Description;
}
public function setDescription(?string $Description): self
{
$this->Description = $Description;
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 getProgression(): ?int
{
return $this->Progression;
}
public function setProgression(int $Progression): self
{
$this->Progression = $Progression;
return $this;
}
public function getObjectif(): ?int
{
return $this->Objectif;
}
public function setObjectif(?int $Objectif): self
{
$this->Objectif = $Objectif;
return $this;
}
public function getProjet(): ?Projet
{
return $this->projet;
}
public function setProjet(?Projet $projet): self
{
$this->projet = $projet;
return $this;
}
public function getTentative(): ?int
{
return $this->Tentative;
}
public function setTentative(int $Tentative): self
{
$this->Tentative = $Tentative;
return $this;
}
public function getArchive(): ?int
{
return $this->archive;
}
public function setArchive(int $archive): self
{
$this->archive = $archive;
return $this;
}
public function getDateFinReelle(): ?\DateTimeInterface
{
return $this->DateFinReelle;
}
public function setDateFinReelle(?\DateTimeInterface $DateFinReelle): self
{
$this->DateFinReelle = $DateFinReelle;
return $this;
}
public function getCreateur(): ?Utilisateur
{
return $this->createur;
}
public function setCreateur(?Utilisateur $createur): self
{
$this->createur = $createur;
return $this;
}
public function getDateCreation(): ?string
{
return $this->DateCreation;
}
public function setDateCreation(?string $DateCreation): self
{
$this->DateCreation = $DateCreation;
return $this;
}
public function getState(): ?int
{
return $this->state;
}
public function setState(?int $state): self
{
$this->state = $state;
return $this;
}
public function getCouche(): ?int
{
return $this->couche;
}
public function setCouche(int $couche): self
{
$this->couche = $couche;
return $this;
}
public function getStatut(): ?string
{
return $this->statut;
}
public function setStatut(?string $statut): self
{
$this->statut = $statut;
return $this;
}
/**
* @return Collection|Priorite[]
*/
public function getPriorites(): Collection
{
return $this->priorites;
}
public function addPriorite(Priorite $priorite): self
{
if (!$this->priorites->contains($priorite)) {
$this->priorites[] = $priorite;
$priorite->setCampagne($this);
}
return $this;
}
public function removePriorite(Priorite $priorite): self
{
if ($this->priorites->contains($priorite)) {
$this->priorites->removeElement($priorite);
// set the owning side to null (unless already changed)
if ($priorite->getCampagne() === $this) {
$priorite->setCampagne(null);
}
}
return $this;
}
/**
* @return Collection|Tache[]
*/
public function getTaches(): Collection
{
return $this->taches;
}
public function addTach(Tache $tach): self
{
if (!$this->taches->contains($tach)) {
$this->taches[] = $tach;
$tach->setCompagne($this);
}
return $this;
}
public function removeTach(Tache $tach): self
{
if ($this->taches->contains($tach)) {
$this->taches->removeElement($tach);
// set the owning side to null (unless already changed)
if ($tach->getCompagne() === $this) {
$tach->setCompagne(null);
}
}
return $this;
}
/**
* @return Collection|Utilisateur[]
*/
public function getCollaborateurs(): Collection
{
return $this->collaborateurs;
}
public function addCollaborateur(Utilisateur $collaborateur): self
{
if (!$this->collaborateurs->contains($collaborateur)) {
$this->collaborateurs[] = $collaborateur;
}
return $this;
}
public function removeCollaborateur(Utilisateur $collaborateur): self
{
if ($this->collaborateurs->contains($collaborateur)) {
$this->collaborateurs->removeElement($collaborateur);
}
return $this;
}
public function getCours(): ?Cours
{
return $this->cours;
}
public function setCours(?Cours $cours): self
{
$this->cours = $cours;
return $this;
}
//Recuperer la derniere couche de la campagne
public function getLastCouche()
{
if (count($this->campagneCouches) > 0) {
$campagneCoucheObj = $this->em->getRepository(CampagneCouche::class)->findOneByCompagne($this, ['id' => 'DESC']);
return $campagneCoucheObj;
} else {
return null;
}
}
/**
* (La somme de la progression des couches par campagne) == (progression de la campagne)
*
* @return void
*/
public function sumProgressionCouches()
{
$sumProgression = 0;
$campagneCouches = $this->campagneCouches;
if (count($campagneCouches) > 0) {
foreach ($campagneCouches as $compagneCouche) {
$sumProgression += (int)$compagneCouche->getProgression();
}
return $sumProgression;
} else {
return $sumProgression;
}
}
/**
* Recuper un seul apprenant valide et non abouti par compagne
*/
public function getTotalAppels()
{
$appels = $this->em->getRepository(Appel::class)->findAppelByCompagne($this);
return $appels;
}
/**
* Recuper un seul apprenant valide et non abouti par compagne
*/
public function getApprenantByAgent($agent)
{
$apprenant = ($this->getForceVip()) ? $this->em->getRepository(Apprenant::class)->findApprenantIncludeVipDisponibleByCampagneByAgent($this, $agent) : $this->em->getRepository(Apprenant::class)->findApprenantDisponibleByCampagneByAgent($this, $agent);
return $apprenant;
}
public function getCurrentCouche()
{
$currentCouche = new CampagneCouche();
$campagneLastCoucheObj = $this->getLastCouche();
if (is_object($campagneLastCoucheObj)) {
$currentCouche->setProgression((int)$this->getProgression() - (int)$campagneLastCoucheObj->getProgression());
$currentCouche->setTentative((int)$this->getTentative() - (int)$campagneLastCoucheObj->getTentative());
$currentCouche->setObjectif((int)$campagneLastCoucheObj->getObjectif() - (int)$campagneLastCoucheObj->getProgression());
} else {
$currentCouche->setProgression((int)$this->getProgression());
$currentCouche->setTentative((int)$this->getTentative());
$currentCouche->setObjectif((int)$this->getObjectif());
}
$currentCouche->setCompagne($this);
$currentCouche->setCouche($this->getNom() . "__C" . $this->getCouche());
$currentCouche->setDateDebut($this->getDateDebut());
$currentCouche->setDateFin($this->getDateFin());
return $currentCouche;
}
/**
* Ajouter une nou_velle couche de la campagne
*
* @return void
*/
public function newCouche()
{
$campagneCouche = $this->getCurrentCouche();
$this->em->persist($campagneCouche);
$this->em->flush();
return $campagneCouche;
}
/**
* Recuper les apprenants valides par campagne => pour calculer l'objectif de la campagne
*
* @return array
*/
public function getValideNumbers()
{
$apprenants = $this->em->getRepository(Apprenant::class)->findApprenantsValidesByCampagneTwo($this);
return $apprenants;
}
public function getForceVip(): ?bool
{
return $this->forceVip;
}
public function setForceVip(?bool $forceVip): self
{
$this->forceVip = $forceVip;
return $this;
}
}