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

Formateur et mise en place des bouton d'action doctorant

parent d4d8f84f
Loading
Loading
Loading
Loading
+2
Changes for module/Formation/config/module.config.php: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ use Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain;
use Doctrine\DBAL\Driver\OCI8\Driver as OCI8;
use Doctrine\ORM\Mapping\Driver\XmlDriver;
use Formation\View\Helper\EtatViewHelper;
use Formation\View\Helper\FormateursViewHelper;
use Formation\View\Helper\ModaliteViewHelper;
use Formation\View\Helper\SeancesViewHelper;
use Formation\View\Helper\SiteViewHelper;
@@ -83,6 +84,7 @@ return array(
            'type' => TypeViewHelper::class,
            'etat' => EtatViewHelper::class,
            'seances' => SeancesViewHelper::class,
            'formateurs' => FormateursViewHelper::class,
        ]
    ],

+89
Changes for module/Formation/config/others/formateur.config.php: 89 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace Formation;

use Formation\Controller\FormateurController;
use Formation\Controller\FormateurControllerFactory;
use Formation\Provider\Privilege\IndexPrivileges;
use Formation\Service\Formateur\FormateurService;
use Formation\Service\Formateur\FormateurServiceFactory;
use UnicaenAuth\Guard\PrivilegeController;
use Zend\Router\Http\Literal;
use Zend\Router\Http\Segment;

return [
    'bjyauthorize' => [
        'guards' => [
            PrivilegeController::class => [
                [
                    'controller' => FormateurController::class,
                    'action' => [
                        'ajouter',
                        'retirer',
                    ],
                    'privileges' => [
                        IndexPrivileges::INDEX_AFFICHER,
                    ],
                ],
            ],
        ],
    ],

    'router'          => [
        'routes' => [
            'formation' => [
                'child_routes' => [
                    'formateur' => [
                        'type'  => Literal::class,
                        'may_terminate' => false,
                        'options' => [
                            'route'    => '/formateur',
                        ],
                        'child_routes' => [
                            'ajouter' => [
                                'type'  => Segment::class,
                                'may_terminate' => true,
                                'options' => [
                                    'route'    => '/ajouter/:session',
                                    'defaults' => [
                                        'controller' => FormateurController::class,
                                        'action'     => 'ajouter',
                                    ],
                                ],
                            ],
                            'retirer' => [
                                'type'  => Segment::class,
                                'may_terminate' => true,
                                'options' => [
                                    'route'    => '/retirer/:formateur',
                                    'defaults' => [
                                        'controller' => FormateurController::class,
                                        'action'     => 'retirer',
                                    ],
                                ],
                            ],
                        ],
                    ],
                ],
            ],
        ],
    ],

    'service_manager' => [
        'factories' => [
            FormateurService::class => FormateurServiceFactory::class,
        ],
    ],
    'controllers'     => [
        'factories' => [
            FormateurController::class => FormateurControllerFactory::class,
        ],
    ],
    'form_elements' => [
        'factories' => [],
    ],
    'hydrators' => [
        'factories' => [],
    ]

];
 No newline at end of file
+67
Changes for module/Formation/src/Formation/Controller/FormateurController.php: 67 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace Formation\Controller;

use Application\Controller\AbstractController;
use Application\Entity\Db\Individu;
use Application\Service\Individu\IndividuServiceAwareTrait;
use Formation\Entity\Db\Formateur;
use Formation\Entity\Db\Module;
use Formation\Entity\Db\Session;
use Formation\Service\Formateur\FormateurServiceAwareTrait;
use UnicaenApp\Service\EntityManagerAwareTrait;
use Zend\View\Model\ViewModel;

class FormateurController extends AbstractController {
    use EntityManagerAwareTrait;
    use FormateurServiceAwareTrait;
    use IndividuServiceAwareTrait;

    public function ajouterAction()
    {
        /** @var Session $session */
        $session = $this->getEntityManager()->getRepository(Session::class)->getRequestedSession($this);

        $request = $this->getRequest();
        if ($request->isPost()) {
            $data = $request->getPost();
            /** @var Individu $individu */
            $individu = $this->getIndividuService()->getRepository()->find($data["individu"]["id"]);
            if ($individu !== null) {
                $formateur = new Formateur();
                $formateur->setSession($session);
                $formateur->setIndividu($individu);
                $this->getFormateurService()->create($formateur);
            }
        }

        return new ViewModel([
            'title' => "Ajout d'un formateur pour la session " . $session->getModule()->getLibelle() . " #" . $session->getIndex(),
            'session' => $session,
        ]);
    }

    public function retirerAction() {
        /** @var Formateur $formateur */
        $formateur = $this->getEntityManager()->getRepository(Formateur::class)->getRequestedFormateur($this);

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

        $vm = new ViewModel();
        if ($formateur !== null) {
            $vm->setTemplate('formation/default/confirmation');
            $vm->setVariables([
                'title' => "Retrait du formateur&middot;trice " . $formateur->getIndividu()->getNomComplet(),
                'text' => "La suppression est définitive êtes-vous sûr&middot;e de vouloir continuer ?",
                'action' => $this->url()->fromRoute('formation/formateur/retirer', ["formateur" => $formateur->getId()], [], true),
            ]);
        }
        return $vm;

    }
}
 No newline at end of file
+29
Changes for module/Formation/src/Formation/Controller/FormateurControllerFactory.php: 29 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace Formation\Controller;

use Application\Service\Individu\IndividuService;
use Doctrine\ORM\EntityManager;
use Formation\Service\Formateur\FormateurService;
use Interop\Container\ContainerInterface;

class FormateurControllerFactory {

    public function __invoke(ContainerInterface $container)
    {
        /**
         * @var EntityManager $entityManager
         * @var FormateurService $formateurService
         * @var IndividuService $individuService
         */
        $entityManager = $container->get('doctrine.entitymanager.orm_default');
        $formateurService = $container->get(FormateurService::class);
        $individuService = $container->get(IndividuService::class);

        $controller = new FormateurController();
        $controller->setEntityManager($entityManager);
        $controller->setFormateurService($formateurService);
        $controller->setIndividuService($individuService);
        return $controller;
    }
}
 No newline at end of file
+82
Changes for module/Formation/src/Formation/Entity/Db/Formateur.php: 82 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace Formation\Entity\Db;

use Application\Entity\Db\Individu;
use UnicaenApp\Entity\HistoriqueAwareInterface;
use UnicaenApp\Entity\HistoriqueAwareTrait;

class Formateur  implements HistoriqueAwareInterface{
    use HistoriqueAwareTrait;

    /** @var int */
    private $id;
    /** @var Individu */
    private $individu;
    /** @var Session */
    private $session;
    /** @var string|null */
    private $description;

    /**
     * @return int
     */
    public function getId(): int
    {
        return $this->id;
    }

    /**
     * @return Individu
     */
    public function getIndividu(): Individu
    {
        return $this->individu;
    }

    /**
     * @param Individu $individu
     * @return Formateur
     */
    public function setIndividu(Individu $individu): Formateur
    {
        $this->individu = $individu;
        return $this;
    }

    /**
     * @return Session
     */
    public function getSession(): Session
    {
        return $this->session;
    }

    /**
     * @param Session $session
     * @return Formateur
     */
    public function setSession(Session $session): Formateur
    {
        $this->session = $session;
        return $this;
    }

    /**
     * @return string|null
     */
    public function getDescription(): ?string
    {
        return $this->description;
    }

    /**
     * @param string|null $description
     * @return Formateur
     */
    public function setDescription(?string $description): Formateur
    {
        $this->description = $description;
        return $this;
    }
}
 No newline at end of file
Loading