Commit 67ac207b authored by Jean-Philippe Metivier's avatar Jean-Philippe Metivier
Browse files

Resultats

parent 8ef22bdc
Loading
Loading
Loading
Loading
+96 −5
Changes for module/Formation/config/others/enquete.config.php: 96 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -5,11 +5,17 @@ namespace Formation;

use Formation\Controller\EnqueteController;
use Formation\Controller\EnqueteControllerFactory;
use Formation\Form\EnqueteQuestion\EnqueteQuestionForm;
use Formation\Form\EnqueteQuestion\EnqueteQuestionFormFactory;
use Formation\Form\EnqueteQuestion\EnqueteQuestionHydrator;
use Formation\Form\EnqueteQuestion\EnqueteQuestionHydratorFactory;
use Formation\Form\EnqueteReponse\EnqueteReponseForm;
use Formation\Form\EnqueteReponse\EnqueteReponseFormFactory;
use Formation\Form\EnqueteReponse\EnqueteReponseHydrator;
use Formation\Form\EnqueteReponse\EnqueteReponseHydratorFactory;
use Formation\Provider\Privilege\IndexPrivileges;
use Formation\Service\EnqueteQuestion\EnqueteQuestionService;
use Formation\Service\EnqueteQuestion\EnqueteQuestionServiceFactory;
use Formation\Service\EnqueteReponse\EnqueteReponseService;
use Formation\Service\EnqueteReponse\EnqueteReponseServiceFactory;
use UnicaenAuth\Guard\PrivilegeController;
@@ -24,6 +30,14 @@ return [
                    'controller' => EnqueteController::class,
                    'action' => [
                        'afficher-questions',
                        'ajouter-question',
                        'modifier-question',
                        'historiser-question',
                        'restaurer-question',
                        'supprimer-question',

                        'afficher-resultats',

                        'repondre-questions',
                    ],
                    'privileges' => [
@@ -40,12 +54,18 @@ return [
                'pages' => [
                    'formation' => [
                        'pages' => [
                            'enquete' => [
                                'label'    => 'Enquête',
                                'route'    => 'formation/enquete/questions',
                            'enquete-question' => [
                                'label'    => 'Enquête - Question',
                                'route'    => 'formation/enquete/question',
                                'resource' => PrivilegeController::getResourceId(EnqueteController::class, 'afficher-questions') ,
                                'order'    => 700,
                            ],
                            'enquete-resultat' => [
                                'label'    => 'Enquête - Resultat',
                                'route'    => 'formation/enquete/resultat',
                                'resource' => PrivilegeController::getResourceId(EnqueteController::class, 'afficher-questions') ,
                                'order'    => 800,
                            ],
                        ],
                    ],
                ],
@@ -64,16 +84,84 @@ return [
                            'route'    => '/enquete',
                        ],
                        'child_routes' => [
                            'questions' => [
                            'resultat' => [
                                'type'  => Literal::class,
                                'may_terminate' => true,
                                'options' => [
                                    'route'    => '/resultat',
                                    'defaults' => [
                                        'controller' => EnqueteController::class,
                                        'action'     => 'afficher-resultats',
                                    ],
                                ],
                            ],
                            'question' => [
                                'type'  => Literal::class,
                                'may_terminate' => true,
                                'options' => [
                                    'route'    => '/questions',
                                    'route'    => '/question',
                                    'defaults' => [
                                        'controller' => EnqueteController::class,
                                        'action'     => 'afficher-questions',
                                    ],
                                ],
                                'child_routes' => [
                                    'ajouter' => [
                                        'type'  => Literal::class,
                                        'may_terminate' => true,
                                        'options' => [
                                            'route'    => '/ajouter',
                                            'defaults' => [
                                                'controller' => EnqueteController::class,
                                                'action'     => 'ajouter-question',
                                            ],
                                        ],
                                    ],
                                    'modifier' => [
                                        'type'  => Segment::class,
                                        'may_terminate' => true,
                                        'options' => [
                                            'route'    => '/modifier/:question',
                                            'defaults' => [
                                                'controller' => EnqueteController::class,
                                                'action'     => 'modifier-question',
                                            ],
                                        ],
                                    ],
                                    'historiser' => [
                                        'type'  => Segment::class,
                                        'may_terminate' => true,
                                        'options' => [
                                            'route'    => '/historiser/:question',
                                            'defaults' => [
                                                'controller' => EnqueteController::class,
                                                'action'     => 'historiser-question',
                                            ],
                                        ],
                                    ],
                                    'restaurer' => [
                                        'type'  => Segment::class,
                                        'may_terminate' => true,
                                        'options' => [
                                            'route'    => '/restaurer/:question',
                                            'defaults' => [
                                                'controller' => EnqueteController::class,
                                                'action'     => 'restaurer-question',
                                            ],
                                        ],
                                    ],
                                    'supprimer' => [
                                        'type'  => Segment::class,
                                        'may_terminate' => true,
                                        'options' => [
                                            'route'    => '/supprimer/:question',
                                            'defaults' => [
                                                'controller' => EnqueteController::class,
                                                'action'     => 'supprimer-question',
                                            ],
                                        ],
                                    ],
                                ],
                            ],
                            'repondre-questions' => [
                                'type'  => Segment::class,
@@ -95,6 +183,7 @@ return [

    'service_manager' => [
        'factories' => [
            EnqueteQuestionService::class => EnqueteQuestionServiceFactory::class,
            EnqueteReponseService::class => EnqueteReponseServiceFactory::class,
        ],
    ],
@@ -105,11 +194,13 @@ return [
    ],
    'form_elements' => [
        'factories' => [
            EnqueteQuestionForm::class => EnqueteQuestionFormFactory::class,
            EnqueteReponseForm::class => EnqueteReponseFormFactory::class,
        ],
    ],
    'hydrators' => [
        'factories' => [
            EnqueteQuestionHydrator::class => EnqueteQuestionHydratorFactory::class,
            EnqueteReponseHydrator::class => EnqueteReponseHydratorFactory::class,
        ],
    ]
+151 −1
Changes for module/Formation/src/Formation/Controller/EnqueteController.php: 151 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -7,27 +7,177 @@ use Doctrine\Common\Collections\ArrayCollection;
use Formation\Entity\Db\EnqueteQuestion;
use Formation\Entity\Db\EnqueteReponse;
use Formation\Entity\Db\Inscription;
use Formation\Form\EnqueteQuestion\EnqueteQuestionFormAwareTrait;
use Formation\Form\EnqueteReponse\EnqueteReponseFormAwareTrait;
use Formation\Service\EnqueteQuestion\EnqueteQuestionServiceAwareTrait;
use Formation\Service\EnqueteReponse\EnqueteReponseServiceAwareTrait;
use UnicaenApp\Service\EntityManagerAwareTrait;
use Zend\View\Model\ViewModel;

class EnqueteController extends AbstractController {
    use EntityManagerAwareTrait;
    use EnqueteQuestionServiceAwareTrait;
    use EnqueteReponseServiceAwareTrait;
    use EnqueteQuestionFormAwareTrait;
    use EnqueteReponseFormAwareTrait;

    public function afficherQuestionsAction() {
    /** ENQUETE *******************************************************************************************************/

    public function afficherResultatsAction()
    {
        $questions = $this->getEntityManager()->getRepository(EnqueteQuestion::class)->findAll();
        $questions = array_filter($questions, function (EnqueteQuestion $a) { return $a->estNonHistorise();});
        usort($questions, function (EnqueteQuestion $a, EnqueteQuestion $b) { return $a->getOrdre() > $b->getOrdre();});

        //todo exploiter le filtre pour réduire
        $reponses = $this->getEntityManager()->getRepository(EnqueteReponse::class)->findAll();
        $reponses = array_filter($reponses, function (EnqueteReponse $a) { return $a->estNonHistorise();});
        usort($reponses, function (EnqueteReponse $a, EnqueteReponse $b) { return $a->getQuestion()->getId() > $b->getQuestion()->getId();});

        /** PREP HISTOGRAMME $histogramme */
        $histogramme = [];
        foreach ($questions as $question) {
            $histogramme[$question->getId()] = [];
            foreach (EnqueteReponse::NIVEAUX as $clef => $value) $histogramme[$question->getId()][$clef] = 0;
        }

        $array = [];

        /** @var EnqueteReponse $reponse */
        foreach ($reponses as $reponse) {
            if ($reponse->getQuestion()->estNonHistorise()) {
                $question = $reponse->getQuestion()->getId();
                $inscription = $reponse->getInscription()->getId();

                $niveau = $reponse->getNiveau();
                $description = $reponse->getDescription();

                $array[$inscription]["Niveau_" . $question] = EnqueteReponse::NIVEAUX[$niveau];
                $array[$inscription]["Commentaire_" . $question] = $description;
                $histogramme[$question][$niveau]++;
            }
        }

        return new ViewModel([
            "array" => $array,
            "histogramme" => $histogramme,
            "nbReponses" => count($array),
            "questions" => $questions,
        ]);
    }

    /** QUESTIONS *****************************************************************************************************/
    public function afficherQuestionsAction() {

        $questions = $this->getEntityManager()->getRepository(EnqueteQuestion::class)->findAll();
//        $questions = array_filter($questions, function (EnqueteQuestion $a) { return $a->estNonHistorise();});
        usort($questions, function (EnqueteQuestion $a, EnqueteQuestion $b) { return $a->getOrdre() > $b->getOrdre();});

        return new ViewModel([
            'questions' => $questions,
        ]);
    }

    public function ajouterQuestionAction() {

        $question = new EnqueteQuestion();

        $form = $this->getEnqueteQuestionForm();
        $form->setAttribute('action', $this->url()->fromRoute('formation/enquete/question/ajouter', [], [], true));
        $form->bind($question);

        $request = $this->getRequest();
        if ($request->isPost()) {
            $data = $request->getPost();
            $form->setData($data);
            if ($form->isValid()) {
                $this->getEnqueteQuestionService()->create($question);
            }
        }

        $vm =  new ViewModel([
            'title' => "Ajout d'une question",
            'form' => $form,
        ]);
        $vm->setTemplate('formation/default/default-form');
        return $vm;
    }

    public function modifierQuestionAction() {

        /** @var EnqueteQuestion $question */
        $question = $this->getEntityManager()->getRepository(EnqueteQuestion::class)->getRequestedEnqueteQuestion($this);

        $form = $this->getEnqueteQuestionForm();
        $form->setAttribute('action', $this->url()->fromRoute('formation/enquete/question/modifier', ['question' => $question->getId()], [], true));
        $form->bind($question);

        $request = $this->getRequest();
        if ($request->isPost()) {
            $data = $request->getPost();
            $form->setData($data);
            if ($form->isValid()) {
                $this->getEnqueteQuestionService()->update($question);
            }
        }

        $vm =  new ViewModel([
            'title' => "Modification de la question",
            'form' => $form,
        ]);
        $vm->setTemplate('formation/default/default-form');
        return $vm;
    }

    public function historiserQuestionAction()
    {
        /** @var EnqueteQuestion $question */
        $question = $this->getEntityManager()->getRepository(EnqueteQuestion::class)->getRequestedEnqueteQuestion($this);
        $retour = $this->params()->fromQuery('retour');

        $this->getEnqueteQuestionService()->historise($question);

        if ($retour) return $this->redirect()->toUrl($retour);
        return $this->redirect()->toRoute('formation/enquete/question', [], [], true);
    }

    public function restaurerQuestionAction()
    {
        /** @var EnqueteQuestion $question */
        $question = $this->getEntityManager()->getRepository(EnqueteQuestion::class)->getRequestedEnqueteQuestion($this);
        $retour = $this->params()->fromQuery('retour');

        $this->getEnqueteQuestionService()->restore($question);

        if ($retour) return $this->redirect()->toUrl($retour);
        return $this->redirect()->toRoute('formation/enquete/question', [], [], true);
    }

    public function supprimerQuestionAction()
    {
        /** @var EnqueteQuestion|null $question */
        $question = $this->getEntityManager()->getRepository(EnqueteQuestion::class)->getRequestedEnqueteQuestion($this);

        $request = $this->getRequest();
        if ($request->isPost()) {
            $data = $request->getPost();
            if ($data["reponse"] === "oui") $this->getEnqueteQuestionService()->delete($question);
            exit();
        }

        $vm = new ViewModel();
        if ($question !== null) {
            $vm->setTemplate('formation/default/confirmation');
            $vm->setVariables([
                'title' => "Suppression de la question",
                'text' => "La suppression est définitive êtes-vous sûr·e de vouloir continuer ?",
                'action' => $this->url()->fromRoute('formation/enquete/question/supprimer', ["module" => $question->getId()], [], true),
            ]);
        }
        return $vm;
    }

    /** REPONSES ******************************************************************************************************/
    public function repondreQuestionsAction()
    {
        /** @var Inscription $inscription */
+8
Changes for module/Formation/src/Formation/Controller/EnqueteControllerFactory.php: 8 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -3,7 +3,9 @@
namespace Formation\Controller;

use Doctrine\ORM\EntityManager;
use Formation\Form\EnqueteQuestion\EnqueteQuestionForm;
use Formation\Form\EnqueteReponse\EnqueteReponseForm;
use Formation\Service\EnqueteQuestion\EnqueteQuestionService;
use Formation\Service\EnqueteReponse\EnqueteReponseService;
use Interop\Container\ContainerInterface;

@@ -13,20 +15,26 @@ class EnqueteControllerFactory {
    {
        /**
         * @var EntityManager $entityManager
         * @var EnqueteQuestionService $enqueteQuestionService
         * @var EnqueteReponseService $enqueteReponseService
         */
        $entityManager = $container->get('doctrine.entitymanager.orm_default');
        $enqueteQuestionService = $container->get(EnqueteQuestionService::class);
        $enqueteReponseService = $container->get(EnqueteReponseService::class);

        /**
         * @var EnqueteQuestionForm $enqueteQuestionForm
         * @var EnqueteReponseForm $enqueteReponseForm
         */
        $enqueteQuestionForm = $container->get('FormElementManager')->get(EnqueteQuestionForm::class);
        $enqueteReponseForm = $container->get('FormElementManager')->get(EnqueteReponseForm::class);

        $controller = new EnqueteController();
        $controller->setEntityManager($entityManager);
        $controller->setEnqueteQuestionService($enqueteQuestionService);
        $controller->setEnqueteReponseService($enqueteReponseService);
        $controller->setEnqueteReponseForm($enqueteReponseForm);
        $controller->setEnqueteQuestionForm($enqueteQuestionForm);
        return $controller;
    }
}
 No newline at end of file
+74
Changes for module/Formation/src/Formation/Form/EnqueteQuestion/EnqueteQuestionForm.php: 74 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace Formation\Form\EnqueteQuestion;

use Zend\Form\Element\Button;
use Zend\Form\Element\Text;
use Zend\Form\Element\Textarea;
use Zend\Form\Form;
use Zend\InputFilter\Factory;

class EnqueteQuestionForm extends Form {

    public function init()
    {
        //libelle
        $this->add([
            'type' => Text::class,
            'name' => 'libelle',
            'options' => [
                'label' => "Libellé de la question :",
            ],
            'attributes' => [
                'id' => 'libelle',
                'class' => 'required',
            ],
        ]);
        //description
        $this->add([
            'type' => Textarea::class,
            'name' => 'description',
            'options' => [
                'label' => "Complément d'information à propos de la question :",
            ],
            'attributes' => [
                'id' => 'description',
                'class' => 'tinymce',
            ],
        ]);
        //ordre
        $this->add([
            'type' => Text::class,
            'name' => 'ordre',
            'options' => [
                'label' => "Ordre de la question *:",
            ],
            'attributes' => [
                'id' => 'ordre',
                'class' => 'required',
            ],
        ]);
        //submit
        $this->add([
            'type' => Button::class,
            'name' => 'bouton',
            'options' => [
                'label' => '<i class="fas fa-save"></i> Enregistrer',
                'label_options' => [
                    'disable_html_escape' => true,
                ],
            ],
            'attributes' => [
                'type' => 'submit',
                'class' => 'btn btn-primary',

            ],
        ]);

        $this->setInputFilter((new Factory())->createInputFilter([
            'libelle'       => [ 'required' => true, ],
            'description'   => [ 'required' => false, ],
            'ordre'         => [ 'required' => true, ],
        ]));
    }
}
 No newline at end of file
+29
Changes for module/Formation/src/Formation/Form/EnqueteQuestion/EnqueteQuestionFormAwareTrait.php: 29 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace Formation\Form\EnqueteQuestion;

trait EnqueteQuestionFormAwareTrait {

    /** @var EnqueteQuestionForm */
    private $enqueteQuestionForm;

    /**
     * @return EnqueteQuestionForm
     */
    public function getEnqueteQuestionForm(): EnqueteQuestionForm
    {
        return $this->enqueteQuestionForm;
    }

    /**
     * @param EnqueteQuestionForm $enqueteQuestionForm
     * @return EnqueteQuestionForm
     */
    public function setEnqueteQuestionForm(EnqueteQuestionForm $enqueteQuestionForm): EnqueteQuestionForm
    {
        $this->enqueteQuestionForm = $enqueteQuestionForm;
        return $this->enqueteQuestionForm;
    }


}
 No newline at end of file
Loading