src/Entity/GDA/Accueil.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity\GDA;
  3. use \JsonSerializable;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Symfony\Component\Validator\Context\ExecutionContextInterface;
  6. use Symfony\Component\Validator\Constraints as Assert;
  7. /**
  8.  * @ORM\Entity(repositoryClass="App\Repository\GDA\AccueilRepository")
  9.  * @ORM\Table(name="efc.gda_accueil")
  10.  */
  11. class Accueil implements JsonSerializable
  12. {
  13.     const DATE_FORMAT 'd-m-Y';
  14.     const TYPE_NOUVEAUTE_ARRIVEE "Arrivée";
  15.     const TYPE_NOUVEAUTE_ARRIVEEE "Arrivee";
  16.     const TYPE_NOUVEAUTE_PREMIER_ACCUEIL "1er Accueil";
  17.     const TYPE_NOUVEAUTE_MODIFICATION "Modification";
  18.     const TYPE_NOUVEAUTE_DEPART "Départ";
  19.     const TYPE_NOUVEAUTE_DEEPART "Depart";
  20.     use \App\Entity\Commun\IdTrait;
  21.     // <editor-fold defaultstate="collapsed" desc="Attributs privés">
  22.     /**
  23.      * Id de l'assmat dans le SI du département (donnée dupliquée dans les accueils pour faciliter la restitution des données au département)
  24.      * @ORM\Column(type="string", length=70)
  25.      */
  26.     private $id_fonctionnel_assmat;
  27.     /**
  28.      * @Assert\Type("\DateTimeInterface")
  29.      * @Assert\LessThan("tomorrow midnight")
  30.      * @Assert\GreaterThan(propertyPath="enfant.date_naissance", message="Vous ne pouvez pas accueillir un enfant avant sa date de naissance.")
  31.      * @ORM\Column(type="date")
  32.      */
  33.     private $date_debut;
  34.     /**
  35.      * @ORM\Column(type="date", nullable=true)
  36.      * @Assert\GreaterThan(propertyPath="date_debut", message="La date de fin d'accueil doit être postérieure à la date de début de l'accueil.")
  37.      */
  38.     private $date_fin;
  39.     /**
  40.      * @ORM\Column(type="date", nullable=true)
  41.      * @Assert\GreaterThan(propertyPath="date_debut", message="La date prévisionnelle de fin d'accueil doit être postérieure à la date de début de l'accueil.")
  42.      */
  43.     private $date_fin_prevue;
  44.     /**
  45.      * @Assert\Length(
  46.      *      max = 250,
  47.      *      maxMessage = "Votre message est trop long."
  48.      * )
  49.      * @ORM\Column(type="string", length=250, nullable=true)
  50.      */
  51.     private $commentaire '';
  52.     /**
  53.      * Indique si l'enfant est gardé de nuit par l'assmat
  54.      * @ORM\Column(type="boolean", nullable=false)
  55.      */
  56.     private $est_nuit;
  57.     /**
  58.      * Indique si l'accueil de l'enfant suit des horaires atypiques
  59.      * @ORM\Column(type="boolean", nullable=false)
  60.      */
  61.     private $est_atypique;
  62.     /**
  63.      * @Assert\NotNull()
  64.      * @ORM\ManyToOne(targetEntity="App\Entity\AssistantMaternel\AssistantMaternel", inversedBy="accueils")
  65.      * @ORM\JoinColumn(name="id_assmat", referencedColumnName="id")
  66.      */
  67.     private $assmat;
  68.     //NB : cascade={"persist"} permet de créer les entités filles en cascade
  69.     /**
  70.      * @Assert\NotNull()
  71.      * @Assert\Valid
  72.      * @ORM\ManyToOne(targetEntity="App\Entity\GDA\Enfant", inversedBy="accueils", cascade={"persist", "remove"})
  73.      * @ORM\JoinColumn(name="id_enfant", referencedColumnName="id")
  74.      */
  75.     private $enfant;
  76.     /**
  77.      * @Assert\NotNull()
  78.      * @ORM\ManyToOne(targetEntity="App\Entity\Referentiel\TypeAccueil")
  79.      * @ORM\JoinColumn(name="id_type_accueil", referencedColumnName="id")
  80.      */
  81.     private $type_accueil;
  82.     /**
  83.      * @Assert\NotNull()
  84.      * @ORM\ManyToOne(targetEntity="App\Entity\Referentiel\LieuAccueil")
  85.      * @ORM\JoinColumn(name="id_lieu_accueil", referencedColumnName="id")
  86.      */
  87.     private $lieu_accueil;
  88.     /**
  89.      * @ORM\OneToMany(targetEntity="App\Entity\GDA\PlanningAccueil", mappedBy="accueil", cascade={"persist", "remove"})
  90.      * @ORM\OrderBy({"periode" = "ASC","tranche_horaire" = "ASC","jour_semaine" = "ASC"})
  91.      */
  92.     private $planning_accueil;
  93.     /**
  94.      * Indique si l'enfant est absent
  95.      * si oui, le planning rattaché à l'accueil n'est pas applicable actuellement = l'enfant n'occupe pas de place d'agrément
  96.      * @ORM\Column(type="boolean", nullable=false, options={"default":false})
  97.      */
  98.     private $est_absent;
  99.     /**
  100.      * @Assert\Type("\DateTimeInterface")
  101.      * @Assert\NotNull()
  102.      * @ORM\Column(type="datetime")
  103.      */
  104.     private $date_creation;
  105.     /**
  106.      * @Assert\Type("\DateTimeInterface")
  107.      * @Assert\NotNull()
  108.      * @ORM\Column(type="datetime")
  109.      */
  110.     private $date_derniere_modification;
  111.     /**
  112.      * Indique si la déclaration de cet accueil est le 1er pour l'assmat depuis le début de son agrément
  113.      * si oui, indiquerea aux pros du département que le 2nd volet de formation doit être planifié
  114.      * @ORM\Column(type="boolean", nullable=false, options={"default":false})
  115.      */
  116.     private $est_premier_accueil;
  117.     /**
  118.      * Indique si cet accueil est déclaré comme dérogatoire
  119.      * (sans distingo : avec accord préalable pour l'accueil ou nouveauté 2021 50h/mois)
  120.      * @ORM\Column(type="boolean", nullable=false, options={"default":false})
  121.      */
  122.     private $est_derogation;
  123.     /**
  124.      * @ORM\OneToOne(targetEntity="App\Entity\GDA\LogAccueil", mappedBy="accueil", cascade={"persist", "remove"})
  125.      */
  126.     private $log_accueil//TODO : traçabilité : à terme sera OneToMany : on aura autant de lignes que de modifs (date, nom du champ, ancienne valeur(tostring) - à plat pour enfant, respleg, planning)
  127.     // </editor-fold>
  128.     /**
  129.      * @Assert\Callback
  130.      */
  131.     public function verifierAge(ExecutionContextInterface $context$payload)
  132.     {
  133.         if ($this->getEnfant()->getAgeAnnees($this->date_debut) >= 18) {
  134.             $context->buildViolation("L'enfant accueilli doit avoir moins de 18 ans.")->atPath('date_naissance')->addViolation();
  135.         }
  136.     }
  137.     
  138.     // <editor-fold desc="Accesseurs">
  139.     /**
  140.      * Get assmat
  141.      *
  142.      * @return Assmat
  143.      */
  144.     public function getAssmat(): \App\Entity\AssistantMaternel\AssistantMaternel
  145.     {
  146.         return $this->assmat;
  147.     }
  148.     /**
  149.      * Set assmat
  150.      *
  151.      * @param Assmat $assmat
  152.      * 
  153.      * @return Accueil
  154.      */
  155.     public function setAssmat($assmat)
  156.     {
  157.         $this->assmat $assmat;
  158.         $this->id_fonctionnel_assmat $assmat->getIdFonctionnel();
  159.         return $this;
  160.     }
  161.     /**
  162.      * Get enfant
  163.      *
  164.      * @return Enfant
  165.      */
  166.     public function getEnfant()
  167.     {
  168.         return $this->enfant;
  169.     }
  170.     /**
  171.      * Set enfant
  172.      *
  173.      * @param Enfant $enfant
  174.      * 
  175.      * @return Accueil
  176.      */
  177.     public function setEnfant($enfant)
  178.     {
  179.         $this->enfant $enfant;
  180.         return $this;
  181.     }
  182.     /**
  183.      * Get lieu_accueil
  184.      *
  185.      * @return LieuAccueil
  186.      */
  187.     public function getLieuAccueil()
  188.     {
  189.         return $this->lieu_accueil;
  190.     }
  191.     /**
  192.      * Set lieu_accueil
  193.      *
  194.      * @param LieuAccueil $lieuAccueil
  195.      * 
  196.      * @return Accueil
  197.      */
  198.     public function setLieuAccueil($lieuAccueil)
  199.     {
  200.         $this->lieu_accueil $lieuAccueil;
  201.         return $this;
  202.     }
  203.     /**
  204.      * Get type_accueil
  205.      *
  206.      * @return TypeAccueil
  207.      */
  208.     public function getTypeAccueil()
  209.     {
  210.         return $this->type_accueil;
  211.     }
  212.     /**
  213.      * Set type_accueil
  214.      *
  215.      * @param TypeAccueil $typeAccueil
  216.      * 
  217.      * @return Accueil
  218.      */
  219.     public function setTypeAccueil($typeAccueil)
  220.     {
  221.         $this->type_accueil $typeAccueil;
  222.         return $this;
  223.     }
  224.     /**
  225.      * Get date_debut
  226.      *
  227.      * @return date
  228.      */
  229.     public function getDateDebut()
  230.     {
  231.         return $this->date_debut;
  232.     }
  233.     /**
  234.      * Set date_debut
  235.      *
  236.      * @param Date $dateDebut
  237.      *
  238.      * @return Accueil
  239.      */
  240.     public function setDateDebut($dateDebut)
  241.     {
  242.         $this->date_debut $dateDebut;
  243.         return $this;
  244.     }
  245.     /**
  246.      * Get date_fin
  247.      *
  248.      * @return date
  249.      */
  250.     public function getDateFin()
  251.     {
  252.         return $this->date_fin;
  253.     }
  254.     /**
  255.      * Set date_fin
  256.      *
  257.      * @param Date $dateFin
  258.      *
  259.      * @return Accueil
  260.      */
  261.     public function setDateFin($dateFin)
  262.     {
  263.         $this->date_fin $dateFin;
  264.         return $this;
  265.     }
  266.     /**
  267.      * Get date_fin_prevue
  268.      *
  269.      * @return date
  270.      */
  271.     public function getDateFinPrevue()
  272.     {
  273.         return $this->date_fin_prevue;
  274.     }
  275.     /**
  276.      * Set date_fin
  277.      *
  278.      * @param Date $dateFinPrevue
  279.      *
  280.      * @return Accueil
  281.      */
  282.     public function setDateFinPrevue($dateFinPrevue)
  283.     {
  284.         $this->date_fin_prevue $dateFinPrevue;
  285.         return $this;
  286.     }
  287.     /**
  288.      * Obtient le texte à afficher pour la date de fin prévionnelle
  289.      * Affiche un texte de remplacement si la valeur est nulle
  290.      *
  291.      * @return string
  292.      */
  293.     public function getTextForDateFinPrevue()
  294.     {
  295.         if ($this->date_fin_prevue) {
  296.             $text date_format($this->date_fin_prevue"d/m/Y");
  297.         } else {
  298.             $text 'non renseignée';
  299.         }
  300.         return $text;
  301.     }
  302.     /**
  303.      * Get commentaire
  304.      *
  305.      * @return string
  306.      */
  307.     public function getCommentaire()
  308.     {
  309.         return $this->commentaire;
  310.     }
  311.     /**
  312.      * Set commentaire
  313.      *
  314.      * @param string $commentaire
  315.      *
  316.      * @return Accueil
  317.      */
  318.     public function setCommentaire($commentaire)
  319.     {
  320.         $this->commentaire $commentaire;
  321.         return $this;
  322.     }
  323.     /**
  324.      * Get estNuit
  325.      *
  326.      * @return string
  327.      */
  328.     public function getEstNuit()
  329.     {
  330.         return $this->est_nuit;
  331.     }
  332.     /**
  333.      * Set estNuit
  334.      *
  335.      * @param string $estNuit
  336.      * 
  337.      * @return Accueil
  338.      */
  339.     public function setEstNuit($estNuit)
  340.     {
  341.         $this->est_nuit $estNuit;
  342.         return $this;
  343.     }
  344.     /**
  345.      * Get estAtypique
  346.      *
  347.      * @return string
  348.      */
  349.     public function getEstAtypique()
  350.     {
  351.         return $this->est_atypique;
  352.     }
  353.     /**
  354.      * Set estAtypique
  355.      *
  356.      * @param string $estAtypique
  357.      *
  358.      * @return Accueil
  359.      */
  360.     public function setEstAtypique($estAtypique)
  361.     {
  362.         $this->est_atypique $estAtypique;
  363.         return $this;
  364.     }
  365.     /**
  366.      * Get estAbsent
  367.      *
  368.      * @return string
  369.      */
  370.     public function getEstAbsent()
  371.     {
  372.         return $this->est_absent;
  373.     }
  374.     /**
  375.      * Set estAbsent
  376.      *
  377.      * @param string $estAbsent
  378.      *
  379.      * @return Accueil
  380.      */
  381.     public function setEstAbsent($estAbsent)
  382.     {
  383.         $this->est_absent $estAbsent;
  384.         return $this;
  385.     }
  386.     /**
  387.      * Get date_creation
  388.      *
  389.      * @return date
  390.      */
  391.     public function getDateCreation()
  392.     {
  393.         return $this->date_creation;
  394.     }
  395.     /**
  396.      * Set date_creation
  397.      *
  398.      * @param Date $dateCreation
  399.      *
  400.      * @return Accueil
  401.      */
  402.     public function setDateCreation($dateCreation)
  403.     {
  404.         $this->date_creation $dateCreation;
  405.         $this->log_accueil->setDateCreation($dateCreation);
  406.         return $this;
  407.     }
  408.     /**
  409.      * Get date_derniere_modification
  410.      *
  411.      * @return date
  412.      */
  413.     public function getDateDerniereModification()
  414.     {
  415.         return $this->date_derniere_modification;
  416.     }
  417.     /**
  418.      * Set date_modification
  419.      *
  420.      * @param Date $dateModification
  421.      *
  422.      * @return Accueil
  423.      */
  424.     public function setDateModification($dateModification)
  425.     {
  426.         $this->date_derniere_modification $dateModification;
  427.         $this->log_accueil->setDateModification($dateModification);
  428.         return $this;
  429.     }
  430.     /**
  431.      * Get UtilisateurCreation
  432.      *
  433.      * @return UtilisateurCreation
  434.      */
  435.     public function getUtilisateurCreation()
  436.     {
  437.         return $this->log_accueil->getUtilisateurCreation();
  438.     }
  439.     /**
  440.      * Set utilisateur_creation
  441.      *
  442.      * @param Utilisateur $utilisateurCreation
  443.      *
  444.      * @return Accueil
  445.      */
  446.     public function setUtilisateurCreation($utilisateurCreation)
  447.     {
  448.         $this->log_accueil->setUtilisateurCreation($utilisateurCreation);
  449.         return $this;
  450.     }
  451.     /**
  452.      * Get UtilisateurModification
  453.      *
  454.      * @return UtilisateurModification
  455.      */
  456.     public function getUtilisateurModification()
  457.     {
  458.         return $this->log_accueil->getUtilisateurModification();
  459.     }
  460.     /**
  461.      * Set utilisateur_modification
  462.      *
  463.      * @param Utilisateur $utilisateurModification
  464.      *
  465.      * @return Accueil
  466.      */
  467.     public function setUtilisateurModification($utilisateurModification)
  468.     {
  469.         $this->log_accueil->setUtilisateurModification($utilisateurModification);
  470.         return $this;
  471.     }
  472.     /**
  473.      * Set log_accueil
  474.      *
  475.      * @param LogAccueil $logAccueil
  476.      *
  477.      * @return Accueil
  478.      */
  479.     public function setLogAccueil($logAccueil)
  480.     {
  481.         $this->log_accueil $logAccueil;
  482.         return $this;
  483.     }
  484.     /**
  485.      * Get LogAccueil
  486.      *
  487.      * @return LogAccueil
  488.      */
  489.     public function getLogAccueil()
  490.     {
  491.         return $this->log_accueil;
  492.     }
  493.     /**
  494.      * Get estPremierAccueil
  495.      *
  496.      * @return bool
  497.      */
  498.     public function getEstPremierAccueil()
  499.     {
  500.         return $this->est_premier_accueil;
  501.     }
  502.     /**
  503.      * Set estPremierAccueil
  504.      *
  505.      * @param bool $estPremierAccueil
  506.      *
  507.      * @return Accueil
  508.      */
  509.     public function setEstPremierAccueil($estPremierAccueil)
  510.     {
  511.         $this->est_premier_accueil $estPremierAccueil;
  512.         return $this;
  513.     }
  514.     /**
  515.      * Get estDerogation
  516.      *
  517.      * @return bool
  518.      */
  519.     public function getEstDerogation()
  520.     {
  521.         return $this->est_derogation;
  522.     }
  523.     /**
  524.      * Set estDerogation
  525.      *
  526.      * @param bool $estDerogation
  527.      *
  528.      * @return Accueil
  529.      */
  530.     public function setEstDerogation($estDerogation)
  531.     {
  532.         $this->est_derogation $estDerogation;
  533.         return $this;
  534.     }
  535.     /* gestion du planning d'accueil */
  536.     public function getPlanningAccueil()
  537.     {
  538.         return $this->planning_accueil;
  539.     }
  540.     public function setPlanningAccueil($planning_accueil)
  541.     {
  542.         $this->planning_accueil $planning_accueil;
  543.         return $this;
  544.     }
  545.     public function addPlanningAccueil(PlanningAccueil $planning_accueil)
  546.     {
  547.         $this->planning_accueil[] = $planning_accueil;
  548.         return $this;
  549.     }
  550.     public function removePlanningAccueil(PlanningAccueil $planning_accueil)
  551.     {
  552.         $this->planning_accueil->removeElement($planning_accueil);
  553.     }
  554.     /*
  555.      * Indique si l'accueil est actif
  556.      * RG : l'accueil est actif si la date de fin est null
  557.      */
  558.     public function isActif()
  559.     {
  560.         return is_null($this->date_fin);
  561.     }
  562.     /*
  563.      * Indique si l'accueil est terminé
  564.      * RG : l'accueil est terminé si la date de fin n'est pas null et est dans le passé
  565.      */
  566.     public function isPast()
  567.     {
  568.         return !is_null($this->date_fin) && $this->date_fin < new \DateTime();
  569.     }
  570.     // </editor-fold>
  571.     // <editor-fold desc="Méthodes publiques">
  572.     /**
  573.      * Constructor
  574.      */
  575.     public function __construct()
  576.     {
  577.         
  578.     }
  579.     public function __toString()
  580.     {
  581.         return json_encode($this->jsonSerialize());
  582.     }
  583.     /**
  584.      * Obtient une nouvelle instance d'Accueil, initialisée à partir du tableau associatif fourni en paramètre
  585.      *
  586.      * @param array $data
  587.      * @return Accueil
  588.      */
  589.     public static function createFromArray(array $data)
  590.     {
  591.         $newInstance = new Accueil();
  592.         return $newInstance->initFromArray($data);
  593.     }
  594.     /**
  595.      * mappe les propriétés sur l'instance à partir d'un tableau associatif
  596.      *
  597.      * @param array $data
  598.      * @return void
  599.      */
  600.     public function initFromArray(array $data)
  601.     {
  602.         foreach ($data as $prop => $value) {
  603.             $this->{$prop} = $value;
  604.         }
  605.         return $this;
  606.     }
  607.     /*
  608.      * Implémentation de JsonSerializable
  609.      * Ne liste que les champs modifiables par les utilisateurs
  610.      */
  611.     public function jsonSerialize()
  612.     {
  613.         return [
  614.             'id' => $this->id,
  615.             'assmat' => $this->assmat === null null $this->assmat->getId(),
  616.             'enfant' => $this->enfant === null null $this->enfant->jsonSerialize(),
  617.             'type_accueil' => $this->type_accueil->jsonSerialize(),
  618.             'lieu_accueil' => $this->lieu_accueil->jsonSerialize(),
  619.             'id_fonctionnel_assmat' => $this->id_fonctionnel_assmat,
  620.             'date_debut' => $this->date_debut === null null $this->date_debut->format(self::DATE_FORMAT),
  621.             'date_fin' => $this->date_fin === null null $this->date_fin->format(self::DATE_FORMAT),
  622.             'date_fin_prevue' => $this->date_fin_prevue === null null $this->date_fin_prevue->format(self::DATE_FORMAT),
  623.             'commentaire' => $this->commentaire,
  624.             'est_nuit' => $this->est_nuit,
  625.             'est_atypique' => $this->est_atypique,
  626.             'est_derogation' => $this->est_derogation,
  627.             'est_absent' => $this->est_absent,
  628.             'est_premier_accueil' => $this->est_premier_accueil
  629.         ];
  630.     }
  631.     /**
  632.      * Enregistre la date création/modification et l'utilisateur création/modification
  633.      * selon que l'accueil est en train d'être créé ou non
  634.      * @param type $currentUser
  635.      */
  636.     public function enregistrerInfosCreationModification($currentUser)
  637.     {
  638.         // Date création et modification : maintenant
  639.         $maintenant = new \DateTime();
  640.         if (!$this->getId()) { //si c'est une création
  641.             $this->setDateCreation($maintenant);
  642.             $this->setUtilisateurCreation($currentUser);
  643.         }
  644.         $this->setDateModification($maintenant);
  645.         $this->setUtilisateurModification($currentUser);
  646.     }
  647.     /**
  648.      * Quel est le dernier évènement de modification de l'accueil
  649.      * Pour la fonctionnalité Nouveautés
  650.      * Arrivée = création de l'accueil
  651.      * Départ = fermeture de l'accueil
  652.      * Modification = toute autre modification
  653.      * @return string
  654.      */
  655.     public function getTypeNouveaute(): string
  656.     {
  657.         if ($this->date_creation == $this->date_derniere_modification) {
  658.             if ($this->est_premier_accueil) {
  659.                 return self::TYPE_NOUVEAUTE_PREMIER_ACCUEIL;
  660.             } else {
  661.                 return self::TYPE_NOUVEAUTE_ARRIVEE;
  662.             }
  663.         }
  664.         if ($this->date_fin) {
  665.             return self::TYPE_NOUVEAUTE_DEPART;
  666.         }
  667.         return self::TYPE_NOUVEAUTE_MODIFICATION;
  668.     }
  669.     // </editor-fold>
  670. }