<?php
namespace App\Entity\Gestiform\Formations\Emargement;
use App\Entity\AbstractEntity;
use App\Entity\Gestiform\Admin\MasterListe\Masterlistelg;
use App\Entity\Gestiform\Formations\Session\Planning\Event;
use App\Repository\Gestiform\Formations\Emargement\EmargementRepository;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=EmargementRepository::class)
*/
class Emargement extends AbstractEntity
{
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private ?\DateTime $start = null;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private ?\DateTime $end = null;
/**
* @ORM\ManyToOne(targetEntity=Event::class, inversedBy="emargements", cascade={"persist"})
*/
private ?Event $event;
/**
* @ORM\Column( type="text", nullable=true)
*/
private ?string $presence = null;
/**
* @ORM\Column( type="text", nullable=true)
*/
private ?string $absence = null;
/**
* @ORM\ManyToOne(targetEntity=Masterlistelg::class)
*/
private ?Masterlistelg $ampm = null;
/**
* @ORM\ManyToOne(targetEntity=Masterlistelg::class)
*/
private ?Masterlistelg $declaration= null;
public function getStart(): ?\DateTimeInterface
{
return $this->start;
}
public function setStart(?\DateTimeInterface $start): static
{
$this->start = $start;
return $this;
}
public function getEnd(): ?\DateTimeInterface
{
return $this->end;
}
public function setEnd(?\DateTimeInterface $end): static
{
$this->end = $end;
return $this;
}
public function getEvent(): ?Event
{
return $this->event;
}
public function setEvent(?Event $event): static
{
$this->event = $event;
return $this;
}
public function removeDataAbsence(string $idDossier): self
{
$absence = json_decode($this->absence ?? '{}', true);
if (isset($absence[$idDossier])) {
unset($absence[$idDossier]);
}
$this->absence = json_encode($absence);
return $this;
}
public function removeDataPresence(string $idDossier): self
{
$presence = json_decode($this->presence ?? '{}', true);
if (isset($presence[$idDossier])) {
unset($presence[$idDossier]);
}
$this->presence = json_encode($presence);
return $this;
}
public function addJustificatif(string $idDossier, bool $justifier, string $piece, string $startJustificatif, string $endJustificatif,string $commentaireJustificatif): self
{
$dataAbsence = json_decode($this->getAbsence() ?? '{}', true);
if (isset($dataAbsence[$idDossier])) {
$dataAbsence[$idDossier]['justifier'] = $justifier;
$dataAbsence[$idDossier]['piece'] = $piece;
$dataAbsence[$idDossier]['startJustificatif'] = $startJustificatif;
$dataAbsence[$idDossier]['endJustificatif'] = $endJustificatif;
$dataAbsence[$idDossier]['commentaireJustificatif'] = $commentaireJustificatif;
}
$this->absence = json_encode($dataAbsence);
return $this;
}
public function getAbsence(): ?string
{
return $this->absence;
}
public function setAbsence(?string $absence): Emargement
{
$this->absence = $absence;
return $this;
}
public function addAbsent(string $idDossier, $motifAbsence, string $nom, string $prenom, string $commentaire = '', bool $justifier = false, string $piece = '', string $startJustificatif = '', string $endJustificatif = '', string $commentaireJustificatif = ''): self
{
$dataAbsence = json_decode($this->getAbsence() ?? '{}', true);
$dataAbsence[$idDossier] = [
'idDossier' => $idDossier,
'motifAbsence' => $motifAbsence,
'nom' => $nom,
'prenom' => $prenom,
'commentaire' => $commentaire,
'justifier' => $justifier,
'piece' => $piece,
'startJustificatif' => $startJustificatif,
'endJustificatif' => $endJustificatif,
'commentaireJustificatif' => $commentaireJustificatif
];
$this->absence = json_encode($dataAbsence);
return $this;
}
public function getDataPresence()
{
if ($this->presence === null || $this->presence === "") {
return [];
}
return json_decode($this->presence, true);
}
public function getByIdDossier(string $idDossier): ?array
{
$dataAbsence = $this->getDataAbsence() ?? [];
if (isset($dataAbsence[$idDossier])) {
return $dataAbsence[$idDossier];
}
return null;
}
public function getDataAbsence()
{
if ($this->absence === null || $this->absence === "") {
return [];
}
return json_decode($this->absence, true);
}
public function addPresence(string $idDossier, $motifRetard, bool $retard, string $nom, string $prenom, string $commentaire): self
{
$dataPresence = json_decode($this->getPresence() ?? '{}', true);
$dataPresence[$idDossier] = [
'idDossier' => $idDossier,
'nom' => $nom,
'prenom' => $prenom,
'retard' => $retard,
'motifRetard' => $motifRetard,
'commentaire' => $commentaire
];
$this->presence = json_encode($dataPresence);
return $this;
}
public function getPresence(): ?string
{
return $this->presence;
}
public function setPresence(?string $presence): Emargement
{
$this->presence = $presence;
return $this;
}
public function getAmpm(): ?Masterlistelg
{
return $this->ampm;
}
public function setAmpm(?Masterlistelg $ampm): self
{
$this->ampm = $ampm;
return $this;
}
public function getDeclaration(): ?Masterlistelg
{
return $this->declaration;
}
public function setDeclaration(?Masterlistelg $declaration): Emargement
{
$this->declaration = $declaration;
return $this;
}
}