Commit c8b8c900 authored by Johnny Leveneur's avatar Johnny Leveneur
Browse files

évolution du format de date d’un événement vers un modèle date-heure de début / date-heure de fin

parent 9aac5dc3
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -131,6 +131,14 @@ alter table public.evenementiel_evenement add nb_insc_anonyme_ext integer defaul
alter table public.evenementiel_evenement add nb_insc_anonyme_etu integer default 0;
alter table public.evenementiel_evenement add nb_insc_anonyme_per integer default 0;

-- modification des dates
alter table public.evenementiel_evenement add jour_fin timestamp;
-- modifier le nom du champ jour pour qu'il soit plus explicite
alter table public.evenementiel_evenement rename column jour to jour_debut;
-- recopier le contenu de la colonne jour_debut dans la colonne jour_fin pour chaque évènement
update evenementiel_evenement set jour_fin = jour_debut where jour_fin is null;


-- insert into evenementiel_evenement (libelle, description, jour, debut, fin, lieu_id, partenaire_id)
-- values ('Conférence sur les chapeaux', 'Conférence sur les chapeaux dans le monde', '2025-04-29 00:00:00', '20:00',
--         '22:00', 1, 1);
+27 −11
Original line number Diff line number Diff line
@@ -20,7 +20,8 @@ class Evenement implements HistoriqueAwareInterface, HasEtatsInterface, Resource
    private ?int $id = -1;
    private ?string $libelle = null;
    private ?string $description = null;
    private ?DateTime $jour = null;
    private ?DateTime $jourDebut = null;
    private ?DateTime $jourFin = null;
    private ?string $debut = null;
    private ?string $fin = null;
    private ?Categorie $categorie = null;
@@ -79,16 +80,27 @@ class Evenement implements HistoriqueAwareInterface, HasEtatsInterface, Resource
        $this->description = $description;
    }

    public function getJour(): ?DateTime
    public function getJourDebut(): ?DateTime
    {
        return $this->jour;
        return $this->jourDebut;
    }

    public function setJour(?DateTime $jour): void
    public function setJourDebut(?DateTime $jourDebut): void
    {
        $this->jour = $jour;
        $this->jourDebut = $jourDebut;
    }

    public function getJourFin(): ?DateTime
    {
        return $this->jourFin;
    }

    public function setJourFin(?DateTime $jourFin): void
    {
        $this->jourFin = $jourFin;
    }


    public function getDebut(): ?string
    {
        return $this->debut;
@@ -171,18 +183,22 @@ class Evenement implements HistoriqueAwareInterface, HasEtatsInterface, Resource

    public function getDateToString(): string
    {
        if ($this->jour === null) {
        if ($this->jourDebut === null) {
            return 'Date non définie';
        }
        return $this->jour->format('d/m/Y');
        if($this->jourDebut == $this->jourFin) {
            return $this->jourDebut->format('d/m/Y');
        }else{
            return $this->jourDebut->format('d/m/Y') . ' au ' . $this->jourFin->format('d/m/Y');
        }
    }

    public function getDateEtHoraire(): string
    {
        if ($this->jour === null) {
        if ($this->jourDebut === null) {
            return 'Date non définie';
        }
        $date = $this->jour->format('d/m/Y');
        $date = $this->getDateToString();
        if ($this->debut && $this->fin) {
            return sprintf('%s de %s à %s', $date, $this->debut, $this->fin);
        }
@@ -194,13 +210,13 @@ class Evenement implements HistoriqueAwareInterface, HasEtatsInterface, Resource

    public function getDateTimeDebut(): ?DateTime
    {
        $date = DateTime::createFromFormat('d/m/Y H:i', $this->getJour()->format('d/m/Y') . ' ' . $this->getDebut());
        $date = DateTime::createFromFormat('d/m/Y H:i', $this->getJourDebut()->format('d/m/Y') . ' ' . $this->getDebut());
        return $date;
    }

    public function getDateTimeFin(): ?DateTime
    {
        $date = DateTime::createFromFormat('d/m/Y H:i', $this->getJour()->format('d/m/Y') . ' ' . $this->getFin());
        $date = DateTime::createFromFormat('d/m/Y H:i', $this->getJourFin()->format('d/m/Y') . ' ' . $this->getFin());
        return $date;
    }

+2 −1
Original line number Diff line number Diff line
@@ -7,7 +7,8 @@

        <field name="libelle" column="libelle" type="string" length="256" nullable="false"/>
        <field name="description" column="description" type="text"/>
        <field name="jour"  column="jour" type="datetime" nullable="false"/>
        <field name="jourDebut"  column="jour_debut" type="datetime" nullable="false"/>
        <field name="jourFin"  column="jour_fin" type="datetime" nullable="false"/>
        <field name="debut" column="debut" type="string" length="64" nullable="false"/>
        <field name="fin" column="fin" type="string" length="64" nullable="false"/>
        <field name="organisateur" column="organisateur" type="string" length="256" nullable="false"/>
+20 −6
Original line number Diff line number Diff line
@@ -82,16 +82,29 @@ class EvenementForm extends Form
            ],
        ]);

        //jour
        //jour de début
        $this->add([
            'type' => Date::class,
            'name' => 'jour',
            'name' => 'jour-debut',
            'options' => [
                'label' => "Jour <span class='icon icon-obligatoire' title='Champ obligatoire'></span> :",
                'label' => "Jour de début <span class='icon icon-obligatoire' title='Champ obligatoire'></span> :",
                'label_options' => ['disable_html_escape' => true],
            ],
            'attributes' => [
                'id' => 'jour',
                'id' => 'jour-debut',
            ],
        ]);

        //jour de fin
        $this->add([
            'type' => Date::class,
            'name' => 'jour-fin',
            'options' => [
                'label' => "Jour de fin <span class='icon icon-obligatoire' title='Champ obligatoire'></span> :",
                'label_options' => ['disable_html_escape' => true],
            ],
            'attributes' => [
                'id' => 'jour-fin',
            ],
        ]);

@@ -193,7 +206,8 @@ class EvenementForm extends Form
            'organisateur' => ['required' => true,],
            'description' => ['required' => false,],
            'categorie' => ['required' => true,],
            'jour' => ['required' => true,],
            'jour-debut' => ['required' => true,],
            'jour-fin' => ['required' => true,],
            'debut' => ['required' => true,],
            'fin' => ['required' => true,],
            'lieu' => ['required' => false,],
+11 −6
Original line number Diff line number Diff line
@@ -21,13 +21,15 @@ class EvenementHydrator implements HydratorInterface
     */
    public function extract($object): array
    {
        $jour = ($object->getJour()) ? $object->getJour()->format('Y-m-d') : null;
        $jourDebut = ($object->getJourDebut()) ? $object->getJourDebut()->format('Y-m-d') : null;
        $jourFin = ($object->getJourFin()) ? $object->getJourFin()->format('Y-m-d') : null;
        $data = [
            'libelle' => $object->getLibelle(),
            'organisateur' => $object->getOrganisateur(),
            'description' => $object->getDescription(),
            'categorie' => ($object->getCategorie()) ? $object->getCategorie()->getId() : null,
            'jour' => $jour,
            'jour-debut' => $jourDebut,
            'jour-fin' => $jourFin,
            'debut' => $object->getDebut(),
            'fin' => $object->getFin(),
            'lieu' => ($object->getLieu()) ? $object->getLieu()->getId() : null,
@@ -49,8 +51,10 @@ class EvenementHydrator implements HydratorInterface
        $organisateur = (isset($data['organisateur']) && trim($data['organisateur']) !== "") ? trim($data['organisateur']) : null;
        $description = (isset($data['description']) && trim($data['description']) != '') ? trim($data['description']) : null;
        $categorie = (isset($data['categorie']) && is_numeric($data['categorie'])) ? $this->getCategorieService()->getEntity($data['categorie']) : null;
        $jour = (isset($data['jour'])) ? DateTime::createFromFormat('Y-m-d', $data['jour']) : null;
        $jour = ($jour === false) ? null : $jour;
        $jourDebut = (isset($data['jour-debut'])) ? DateTime::createFromFormat('Y-m-d', $data['jour-debut']) : null;
        $jourDebut = ($jourDebut === false) ? null : $jourDebut;
        $jourFin = (isset($data['jour-fin'])) ? DateTime::createFromFormat('Y-m-d', $data['jour-fin']) : null;
        $jourFin = ($jourFin === false) ? null : $jourFin;
        $debut = (isset($data['debut'])) ? $data['debut'] : null;
        $fin = (isset($data['fin'])) ? $data['fin'] : null;
        $lieu = (isset($data['lieu'])) ? $this->getLieuService()->getEntity($data['lieu']) : null;
@@ -61,7 +65,8 @@ class EvenementHydrator implements HydratorInterface
        $object->setOrganisateur($organisateur);
        $object->setDescription($description);
        $object->setCategorie($categorie);
        $object->setJour($jour);
        $object->setJourDebut($jourDebut);
        $object->setJourFin($jourFin);
        $object->setDebut($debut);
        $object->setFin($fin);
        $object->setLieu($lieu);
Loading