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

Ajout des roles pour l'ED, l'Etab dans INDIVIDU_ROLE + changement controleur

parent 46fd2ec6
Loading
Loading
Loading
Loading
+56 −20
Changes for module/Application/src/Application/Controller/EcoleDoctoraleController.php: 56 added lines, 20 removed lines.
Original line number Diff line number Diff line
@@ -3,23 +3,28 @@
namespace Application\Controller;

use Application\Entity\Db\EcoleDoctorale;
use Application\Entity\Db\IndividuRole;
use Application\Entity\Db\Role;
use Application\Form\EcoleDoctoraleForm;
use Application\RouteMatch;
use Application\Service\EcoleDoctorale\EcoleDoctoraleServiceAwareInterface;
use Application\Service\EcoleDoctorale\EcoleDoctoraleServiceAwareTrait;
use Application\Service\Individu\IndividuServiceAwareInterface;
use Application\Service\Individu\IndividuServiceAwareTrait;
use Application\Service\Role\RoleServiceAwareInterface;
use Application\Service\Role\RoleServiceAwareTrait;
use UnicaenLdap\Entity\People;
use UnicaenLdap\Service\LdapPeopleServiceAwareInterface;
use UnicaenLdap\Service\LdapPeopleServiceAwareTrait;
use Zend\View\Model\ViewModel;

class EcoleDoctoraleController extends AbstractController
    implements EcoleDoctoraleServiceAwareInterface, LdapPeopleServiceAwareInterface, IndividuServiceAwareInterface
    implements EcoleDoctoraleServiceAwareInterface, LdapPeopleServiceAwareInterface, IndividuServiceAwareInterface, RoleServiceAwareInterface
{
    use EcoleDoctoraleServiceAwareTrait;
    use LdapPeopleServiceAwareTrait;
    use IndividuServiceAwareTrait;
    use RoleServiceAwareTrait;

    /**
     * L'index récupére la liste des écoles doctorales et la liste des individus associés à une école
@@ -32,19 +37,28 @@ class EcoleDoctoraleController extends AbstractController
        $ecoles = $this->ecoleDoctoraleService->getRepository()->findAll();
        usort($ecoles, function($a,$b) {return $a->getLibelle() > $b->getLibelle();});

        // récupération de la liste des individus de l'école doctorale séléctionnée
        $ecoleDoctoraleIndividus = null;
        $ecoleDoctoraleRoles = null;
        $roles = null;
        $effectifs = null;
        if ($selected) {
            /** @var EcoleDoctorale $ed */
            $ed = $this->ecoleDoctoraleService->getRepository()->find($selected);
            $ecoleDoctoraleIndividus = $ed->getEcoleDoctoraleIndividus();
            /**
             * @var EcoleDoctorale $etablissement
             * @var Role[] $roles
             */
            $etablissement  = $this->ecoleDoctoraleService->getRepository()->find($selected);
            $roles = $etablissement->getStructure()->getStructureDependantRoles();

            $effectifs = [];
            foreach ($roles as $role) {
                $individus = $this->individuService->getIndividuByRole($role);
                $effectifs[] = $individus;
            }
        }

        return new ViewModel([
            'ecoles'                  => $ecoles,
            'selected'                => $selected,
            'ecoleDoctoraleIndividus' => $ecoleDoctoraleIndividus,
            'roles'                   => $roles,
            'effectifs'               => $effectifs,
        ]);
    }

@@ -163,8 +177,9 @@ class EcoleDoctoraleController extends AbstractController

    public function ajouterIndividuAction()
    {
        $ecoleId = $this->params()->fromRoute('ecoleDoctorale');
        $edId     = $this->params()->fromRoute('ecoleDoctorale');
        $data       = $this->params()->fromPost('people');
        $roleId     = $this->params()->fromPost('role');

        if (!empty($data['id'])) {
            /** @var People $people */
@@ -174,28 +189,49 @@ class EcoleDoctoraleController extends AbstractController
                if (! $individu) {
                    $individu = $this->individuService->createFromPeople($people);
                }
                /** @var EcoleDoctorale $ecole */
                $ecole = $this->ecoleDoctoraleService->getRepository()->find($ecoleId);

                $edi = $this->ecoleDoctoraleService->addIndividu($individu, $ecole);

                $this->flashMessenger()->addSuccessMessage("$individu est désormais membre de '$ecole' avec le rôle '{$edi->getRole()}'");
                /**
                 * @var EcoleDoctorale $ecole
                 * @var Role $role
                 * @var IndividuRole $individuRole
                 */
                $ecole = $this->ecoleDoctoraleService->getRepository()->find($edId);
                $role = $this->roleService->getRoleById($roleId);
                $individuRole = $this->roleService->addIndividuRole($individu,$role);

                $this->flashMessenger()->addSuccessMessage(
                    "<strong>{$individuRole->getIndividu()}</strong>". " est désormais " .
                    "<strong>{$individuRole->getRole()}</strong>". " de l'école doctorale ".
                    "<strong>{$ecole->getLibelle()}</strong>.");
            }
        }

        return $this->redirect()->toRoute('ecole-doctorale', [], ['query' => ['selected' => $ecoleId]], true);
        return $this->redirect()->toRoute('ecole-doctorale', [], ['query' => ['selected' => $edId]], true);
    }

    /**
     * @return \Zend\Http\Response
     * @throws \Doctrine\ORM\OptimisticLockException
     */
    public function retirerIndividuAction()
    {
        $ediId = $this->params()->fromRoute('edi');
        $edId = $this->params()->fromRoute('ecoleDoctorale');
        $irId = $this->params()->fromRoute('edi');

        $ecole = null;
        if ($edId !== null) {
            $ecole = $this->ecoleDoctoraleService->getEcoleDoctoraleById($edId);
        }

        if ($ediId) {
            $edi = $this->ecoleDoctoraleService->removeIndividu($ediId);
        if ($irId) {
            $individuRole = $this->roleService->removeIndividuRoleById($irId);

            $this->flashMessenger()->addSuccessMessage("{$edi->getIndividu()} n'est plus membre de '{$edi->getEcole()}'");
            $this->flashMessenger()->addSuccessMessage(
                "<strong>{$individuRole->getIndividu()}</strong>" . " n'est plus n'est plus "
                ."<strong>{$individuRole->getRole()}</strong>" . " de l'école doctorale "
                ."<strong>{$ecole->getLibelle()}</strong>"."</strong>");

            return $this->redirect()->toRoute('ecole-doctorale', [], ['query' => ['selected' => $edi->getEcole()->getId()]], true);
            return $this->redirect()->toRoute('ecole-doctorale', [], ['query' => ['selected' => $edId]], true);
        }

        return $this->redirect()->toRoute('ecole-doctorale', [], [], true);
+88 −25
Changes for module/Application/src/Application/Controller/EtablissementController.php: 88 added lines, 25 removed lines.
Original line number Diff line number Diff line
@@ -3,21 +3,31 @@
namespace Application\Controller;

use Application\Entity\Db\Etablissement;
use Application\Entity\Db\IndividuRole;
use Application\Entity\Db\Role;
use Application\Form\EtablissementForm;
use Application\Service\Etablissement\EtablissementServiceAwareInterface;
use Application\Service\Etablissement\EtablissementServiceAwareTrait;
use Application\Service\Individu\IndividuServiceAwareInterface;
use Application\Service\Individu\IndividuServiceAwareTrait;
use Application\Service\Role\RoleServiceAwareInterface;
use Application\Service\Role\RoleServiceAwareTrait;
use UnicaenLdap\Entity\People;
use UnicaenLdap\Service\LdapPeopleServiceAwareInterface;
use UnicaenLdap\Service\LdapPeopleServiceAwareTrait;
use Zend\View\Model\ViewModel;

/**
 * Class EtablissementController
 * @package Application\Controller
 */
class EtablissementController extends AbstractController
    implements EtablissementServiceAwareInterface, LdapPeopleServiceAwareInterface, IndividuServiceAwareInterface
    implements EtablissementServiceAwareInterface, LdapPeopleServiceAwareInterface, IndividuServiceAwareInterface, RoleServiceAwareInterface
{
    use EtablissementServiceAwareTrait;
    use LdapPeopleServiceAwareTrait;
    use IndividuServiceAwareTrait;
    use RoleServiceAwareTrait;

    /**
     * @var EtablissementForm $etablissementForm
@@ -53,19 +63,28 @@ class EtablissementController extends AbstractController
        $etablissements = $this->etablissementService->getRepository()->findAll();
        usort($etablissements, function($a,$b) {return $a->getLibelle() > $b->getLibelle();});

        /** les individus sont desactivés pour le moment */
        $etablissementIndividus = null;
        $roles = null;
        $effectifs = null;
        if ($selected) {
            /** @var Etablissement $etab */
            $etab = $this->etablissementService->getRepository()->find($selected);
            $etablissementIndividus = []; //$etab->getEtablissementIndividus();
            /**
             * @var Etablissement $etablissement
             * @var Role[] $roles
             */
            $etablissement  = $this->etablissementService->getRepository()->find($selected);
            $roles = $etablissement->getStructure()->getStructureDependantRoles();

            $effectifs = [];
            foreach ($roles as $role) {
                $individus = $this->individuService->getIndividuByRole($role);
                $effectifs[] = $individus;
            }
        }

        return new ViewModel([
            'etablissements'          => $etablissements,
            'selected'                => $selected,
            'etablissementIndividus' => $etablissementIndividus,

            'roles'                   => $roles,
            'effectifs'               => $effectifs,
        ]);
    }

@@ -236,23 +255,67 @@ class EtablissementController extends AbstractController
        return $chemin;
    }

    public function ajouterIndividuAction()
    {
        $etabId     = $this->params()->fromRoute('etablissement');
        $data       = $this->params()->fromPost('people');
        $roleId     = $this->params()->fromPost('role');

        if (!empty($data['id'])) {
            /** @var People $people */
            if ($people = $this->ldapPeopleService->get($data['id'])) {
                $supannEmpId = $people->get('supannEmpId');
                $individu = $this->individuService->getRepository()->findOneBy(['sourceCode' => $supannEmpId]);
                if (! $individu) {
                    $individu = $this->individuService->createFromPeople($people);
                }

                /**
                 * @var Etablissement $etablissement
                 * @var Role $role
                 * @var IndividuRole $individuRole
                 */
                $etablissement = $this->etablissementService->getRepository()->find($etabId);
                $role = $this->roleService->getRoleById($roleId);
                $individuRole = $this->roleService->addIndividuRole($individu,$role);

                $this->flashMessenger()->addSuccessMessage(
                    "<strong>{$individuRole->getIndividu()}</strong>". " est désormais " .
                    "<strong>{$individuRole->getRole()}</strong>". " de l'etablissement ".
                    "<strong>{$etablissement->getLibelle()}</strong>.");
            }
        }

        return $this->redirect()->toRoute('etablissement', [], ['query' => ['selected' => $etabId]], true);
    }

    /**
     * @return \Zend\Http\Response
     * @throws \Doctrine\ORM\OptimisticLockException
     */
    public function retirerIndividuAction()
    {
        $etabId = $this->params()->fromRoute('etablissement');
        $irId = $this->params()->fromRoute('etabi');

        $etablissement = null;
        if ($etabId !== null) {
            $etablissement = $this->etablissementService->getEtablissementById($etabId);
        }

        if ($irId) {
            $individuRole = $this->roleService->removeIndividuRoleById($irId);

            $this->flashMessenger()->addSuccessMessage(
                "<strong>{$individuRole->getIndividu()}</strong>" . " n'est plus n'est plus "
                ."<strong>{$individuRole->getRole()}</strong>" . " de l'établissement "
                ."<strong>{$etablissement->getLibelle()}</strong>"."</strong>");

            return $this->redirect()->toRoute('etablissement', [], ['query' => ['selected' => $etabId]], true);
        }

        return $this->redirect()->toRoute('etablissement', [], [], true);
    }

//    public function ajouterIndividuAction() {
//        $viewModel = new ViewModel([
//            'form' => $this->etablissementFormForm,
//        ]);
//        $viewModel->setTemplate('application/etablissement/index');
//
//        return $viewModel;
//    }

//    public function retirerIndividuAction() {
//        $viewModel = new ViewModel([
//            'form' => $this->etablissementForm,
//        ]);
//        $viewModel->setTemplate('application/etablissement/index');
//
//        return $viewModel;
//    }

}
 No newline at end of file
+9 −14
Changes for module/Application/src/Application/Controller/UniteRechercheController.php: 9 added lines, 14 removed lines.
Original line number Diff line number Diff line
@@ -13,8 +13,6 @@ use Application\Service\Role\RoleServiceAwareInterface;
use Application\Service\Role\RoleServiceAwareTrait;
use Application\Service\UniteRecherche\UniteRechercheServiceAwareInterface;
use Application\Service\UniteRecherche\UniteRechercheServiceAwareTrait;
use Doctrine\ORM\Tools\Pagination\Paginator;
use DoctrineORMModule\Paginator\Adapter\DoctrinePaginator;
use UnicaenLdap\Entity\People;
use UnicaenLdap\Service\LdapPeopleServiceAwareInterface;
use UnicaenLdap\Service\LdapPeopleServiceAwareTrait;
@@ -44,29 +42,26 @@ class UniteRechercheController extends AbstractController implements
        $unites = $this->uniteRechercheService->getRepository()->findAll();
        usort($unites, function($a,$b) {return $a->getLibelle() > $b->getLibelle();});

        // récupération de la liste des individus de l'unité de recherche séléctionnée
        $uniteRechercheIndividus = null;
        $roles = null;
        $effectifs = null;
        if ($selected) {

            /** @var UniteRecherche ur */
            /**
             * @var UniteRecherche $ur
             * @var Role[] $roles
             */
            $ur  = $this->uniteRechercheService->getRepository()->find($selected);
            $roles = $this->roleService->getRolesByStructure($ur->getStructure());
            $roles = $ur->getStructure()->getStructureDependantRoles();

            $effectifs = [];
            foreach ($roles as $role) {
                $individus = $this->individuService->getIndividuByRole($role);
                $effectifs[] = $individus;
            }

            $uniteRechercheIndividus = $ur->getUniteRechercheIndividus();
        }

        return new ViewModel([
            'unites'                  => $unites,
            'selected'                => $selected,
            'uniteRechercheIndividus' => $uniteRechercheIndividus,
            'roles'                   => $roles,
            'effectifs'               => $effectifs,
        ]);
@@ -191,8 +186,6 @@ class UniteRechercheController extends AbstractController implements
        $data       = $this->params()->fromPost('people');
        $roleId     = $this->params()->fromPost('role');



        if (!empty($data['id'])) {
            /** @var People $people */
            if ($people = $this->ldapPeopleService->get($data['id'])) {
@@ -207,7 +200,6 @@ class UniteRechercheController extends AbstractController implements
                 * @var Role $role
                 * @var IndividuRole $individuRole
                 */
                //$edi = $this->uniteRechercheService->addIndividu($individu, $unite);
                $unite = $this->uniteRechercheService->getRepository()->find($uniteId);
                $role = $this->roleService->getRoleById($roleId);
                $individuRole = $this->roleService->addIndividuRole($individu,$role);
@@ -222,6 +214,10 @@ class UniteRechercheController extends AbstractController implements
        return $this->redirect()->toRoute('unite-recherche', [], ['query' => ['selected' => $uniteId]], true);
    }

    /**
     * @return \Zend\Http\Response
     * @throws \Doctrine\ORM\OptimisticLockException
     */
    public function retirerIndividuAction()
    {
        $urId = $this->params()->fromRoute('uniteRecherche');
@@ -233,7 +229,6 @@ class UniteRechercheController extends AbstractController implements
        }

        if ($irId) {
            //$individuRole = $this->roleService->getIndividuRoleById($irId);
            $individuRole = $this->roleService->removeIndividuRoleById($irId);

            $this->flashMessenger()->addSuccessMessage(
+5
Changes for module/Application/src/Application/Service/EcoleDoctorale/EcoleDoctoraleService.php: 5 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -148,4 +148,9 @@ class EcoleDoctoraleService extends BaseService
            throw new RuntimeException("Erreur lors de l'enregistrement de l'ED", null, $e);
        }
    }

    public function getEcoleDoctoraleById($id) {
        $unite = $this->getRepository()->findOneBy(["id" => $id]);
        return $unite;
    }
}
 No newline at end of file
+5
Changes for module/Application/src/Application/Service/Etablissement/EtablissementService.php: 5 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -99,4 +99,9 @@ class EtablissementService extends BaseService
            throw new RuntimeException("Erreur lors de l'enregistrement de l'Etablissement", null, $e);
        }
    }

    public function getEtablissementById($id) {
        $etablissement = $this->getRepository()->findOneBy(["id" => $id]);
        return $etablissement;
    }
}
 No newline at end of file
Loading