Commit 4445d820 authored by Jean-Philippe Metivier's avatar Jean-Philippe Metivier
Browse files

Amélioration de la gestion de la saisie des formateurs

parent aef02809
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ class FormateurController extends AbstractActionController
        }

        $vm = new ViewModel();
        $vm->setTemplate('application/default/default-form');
        $vm->setTemplate('formation/formateur/modifier');
        $vm->setVariables([
            'title' => "Ajout d'un formateur de formation",
            'form' => $form,
@@ -65,7 +65,7 @@ class FormateurController extends AbstractActionController
        }

        $vm = new ViewModel();
        $vm->setTemplate('application/default/default-form');
        $vm->setTemplate('formation/formateur/modifier');
        $vm->setVariables([
            'title' => "Modification d'un formateur de formation",
            'form' => $form,
+59 −8
Original line number Diff line number Diff line
@@ -9,14 +9,24 @@ class Formateur implements HistoriqueAwareInterface
{
    use HistoriqueAwareTrait;

    private int $id = -1;
    const TYPE_FORMATEUR = 'Formateur';
    const TYPE_ORGANISME = 'Organisme';
    const TYPES = [
        Formateur::TYPE_FORMATEUR => 'Formateur·trice',
        Formateur::TYPE_ORGANISME => 'Organisme',
    ];

    private ?int $id = -1;
    private ?FormationInstance $instance = null;
    private string $type = Formateur::TYPE_FORMATEUR;
    private ?string $organisme = null;
    private ?string $prenom = null;
    private ?string $nom = null;
    private ?string $email = null;
    private ?string $telephone = null;
    private ?string $attachement = null;

    public function getId(): int
    public function getId(): ?int
    {
        return $this->id;
    }
@@ -31,12 +41,32 @@ class Formateur implements HistoriqueAwareInterface
        $this->instance = $instance;
    }

    public function getType(): string
    {
        return $this->type;
    }

    public function setType(string $type): void
    {
        $this->type = $type;
    }

    public function getOrganisme(): ?string
    {
        return $this->organisme;
    }

    public function setOrganisme(?string $organisme): void
    {
        $this->organisme = $organisme;
    }

    public function getPrenom(): ?string
    {
        return $this->prenom;
    }

    public function setPrenom(string $prenom): void
    public function setPrenom(?string $prenom): void
    {
        $this->prenom = $prenom;
    }
@@ -46,11 +76,20 @@ class Formateur implements HistoriqueAwareInterface
        return $this->nom;
    }

    public function setNom(string $nom): void
    public function setNom(?string $nom): void
    {
        $this->nom = $nom;
    }

    public function getAttachement(): ?string
    {
        return $this->attachement;
    }

    public function setAttachement(?string $attachement): void
    {
        $this->attachement = $attachement;
    }
    public function getEmail(): ?string
    {
        return $this->email;
@@ -61,14 +100,26 @@ class Formateur implements HistoriqueAwareInterface
        $this->email = $email;
    }

    public function getAttachement(): ?string
    public function getTelephone(): ?string
    {
        return $this->attachement;
        return $this->telephone;
    }

    public function setAttachement(?string $attachement): void
    public function setTelephone(?string $telephone): void
    {
        $this->attachement = $attachement;
        $this->telephone = $telephone;
    }


    public function getDenomination() : string
    {
        switch ($this->type) {
            case Formateur::TYPE_FORMATEUR :
                return $this->getPrenom() . " " . strtoupper($this->getNom());
            case Formateur::TYPE_ORGANISME :
                return $this->organisme;
            default:
                return "Type de formateur non prévu";
        }
    }
}
 No newline at end of file
+10 −3
Original line number Diff line number Diff line
@@ -10,11 +10,18 @@
            <join-column name="instance_id" referenced-column-name="id"/>
        </many-to-one>

        <field name="prenom"              column="prenom"           type="string"  length="256"    nullable="false"/>
        <field name="nom"                 column="nom"              type="string"  length="256"    nullable="false"/>
        <field name="email"               column="email"            type="string"  length="1024"   nullable="false"/>
        <field name="type"                column="type"             type="string"  length="64"    nullable="false"/>

        <field name="organisme"           column="organisme"        type="string"  length="1024"   nullable="true"/>

        <field name="prenom"              column="prenom"           type="string"  length="256"    nullable="true"/>
        <field name="nom"                 column="nom"              type="string"  length="256"    nullable="true"/>
        <field name="attachement"         column="attachement"      type="string"  length="1024"   nullable="true"/>

        <field name="email"               column="email"            type="string"  length="1024"   nullable="true"/>
        <field name="telephone"           column="telephone"        type="string"  length="64"     nullable="true"/>

        <!-- HISTO ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
        <field name="histoCreation"     type="datetime"                 column="histo_creation"     nullable="false"/>
        <field name="histoModification" type="datetime"                 column="histo_modification" nullable="false"/>
        <field name="histoDestruction"  type="datetime"                 column="histo_destruction"  nullable="true"/>
+73 −12
Original line number Diff line number Diff line
@@ -2,16 +2,46 @@

namespace Formation\Form\Formateur;

use Formation\Entity\Db\Formateur;
use Formation\Entity\Db\Seance;
use Laminas\Form\Element\Button;
use Laminas\Form\Element\Select;
use Laminas\Form\Element\Text;
use Laminas\Form\Form;
use Laminas\InputFilter\Factory;
use Laminas\Validator\Callback;

class FormateurForm extends Form
{

    public function init()
    {
        // type
        $this->add([
            'type' => Select::class,
            'name' => 'type',
            'options' => [
                'label' => "Type de formateur <span class='icon icon-obligatoire' title='Champ obligatoire'></span>:",
                'label_options' => [ 'disable_html_escape' => true, ],
                'value_options' => Formateur::TYPES
            ],
            'attributes' => [
                'id' => 'type',
                'class'             => 'bootstrap-selectpicker show-tick',
            ],
        ]);
        //organisme
        $this->add([
            'type' => Text::class,
            'name' => 'organisme',
            'options' => [
                'label' => "Organisme * :",
            ],
            'attributes' => [
                'id' => 'organisme',
            ],
        ]);

        //prenom
        $this->add([
            'type' => Text::class,
@@ -34,37 +64,47 @@ class FormateurForm extends Form
                'id' => 'nom',
            ],
        ]);
        //nom
        //attachement
        $this->add([
            'type' => Text::class,
            'name' => 'attachement',
            'options' => [
                'label' => "Structure de rattachement / Organisme  :",
            ],
            'attributes' => [
                'id' => 'attachement',
            ],
        ]);
        //email
        $this->add([
            'type' => Text::class,
            'name' => 'email',
            'options' => [
                'label' => "Adresse électronique * :",
                'label' => "Adresse électronique  :",
            ],
            'attributes' => [
                'id' => 'email',
            ],
        ]);
        //attachement
        //email
        $this->add([
            'type' => Text::class,
            'name' => 'attachement',
            'name' => 'telephone',
            'options' => [
                'label' => "Structure de rattachement / Organisme  :",
                'label' => "Téléphone :",
            ],
            'attributes' => [
                'id' => 'attachement',
                'id' => 'telephone',
            ],
        ]);

        //button
        $this->add([
            'type' => Button::class,
            'name' => 'creer',
            'options' => [
                'label' => '<i class="fas fa-save"></i> Enregistrer',
                'label_options' => [
                    'disable_html_escape' => true,
                ],
                'label_options' => [ 'disable_html_escape' => true, ],
            ],
            'attributes' => [
                'type' => 'submit',
@@ -74,10 +114,31 @@ class FormateurForm extends Form

        //inputfilter
        $this->setInputFilter((new Factory())->createInputFilter([
            'prenom' => ['required' => true],
            'nom' => ['required' => true],
            'email' => ['required' => true],
            'type' => ['required' => true,
                'validators' => [[
                    'name' => Callback::class,
                    'options' => [
                        'messages' => [
                            Callback::INVALID_VALUE => "Une information obligatoire est manquante",
                        ],
                        'callback' => function ($value, $context = []) {
                            if($context['type'] === Formateur::TYPE_FORMATEUR)
                                return ($context['nom'] !== '' AND $context['prenom']);
                            if($context['type'] === Formateur::TYPE_ORGANISME)
                                return ($context['organisme'] !== '');
                            return true;
                        },
                        //'break_chain_on_failure' => true,
                    ],
                ]],],

            'organisme' => ['required' => false],
            'prenom' => ['required' => false],
            'nom' => ['required' => false],
            'attachement' => ['required' => false],

            'email' => ['required' => false],
            'telephone' => ['required' => false],
        ]));
    }
}
 No newline at end of file
+24 −4
Original line number Diff line number Diff line
@@ -15,10 +15,17 @@ class FormateurHydrator implements HydratorInterface
    public function extract($object): array
    {
        $data = [
            'type' => ($object) ? $object->getType() : null,

            'organisme' => ($object) ? $object->getOrganisme() : null,

            'prenom' => ($object) ? $object->getPrenom() : null,
            'nom' => ($object) ? $object->getNom() : null,
            'email' => ($object) ? $object->getEmail() : null,
            'attachement' => ($object) ? $object->getAttachement() : null,

            'email' => ($object) ? $object->getEmail() : null,
            'telephone' => ($object) ? $object->getTelephone() : null,

        ];
        return $data;
    }
@@ -28,17 +35,30 @@ class FormateurHydrator implements HydratorInterface
     * @param Formateur $object
     * @return Formateur
     */
    public function hydrate(array $data, $object)
    public function hydrate(array $data, $object) : object
    {
        $type = $data['type'] ?? null;

        $organisme = (isset($data['organisme']) and trim($data['organisme']) !== "") ? trim($data['organisme']) : null;

        $prenom = (isset($data['prenom']) and trim($data['prenom']) !== "") ? trim($data['prenom']) : null;
        $nom = (isset($data['nom']) and trim($data['nom']) !== "") ? trim($data['nom']) : null;
        $email = (isset($data['email']) and trim($data['email']) !== "") ? trim($data['email']) : null;
        $attachement = (isset($data['attachement']) and trim($data['attachement']) !== "") ? trim($data['attachement']) : null;

        $email = (isset($data['email']) and trim($data['email']) !== "") ? trim($data['email']) : null;
        $telephone = (isset($data['telephone']) and trim($data['telephone']) !== "") ? trim($data['telephone']) : null;

        $object->setType($type);

        $object->setOrganisme($organisme);

        $object->setPrenom($prenom);
        $object->setNom($nom);
        $object->setEmail($email);
        $object->setAttachement($attachement);

        $object->setEmail($email);
        $object->setTelephone($telephone);

        return $object;
    }

Loading