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

Ajout des roles pour l'UR dans INDIVIDU_ROLE + changement controleur

parent cfd9bb02
Loading
Loading
Loading
Loading
+5 −1
Changes for module/Application/src/Application/Controller/Factory/UniteRechercheControllerFactory.php: 5 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -4,10 +4,14 @@ namespace Application\Controller\Factory;

use Application\Controller\UniteRechercheController;
use Application\Form\UniteRechercheForm;
use Application\Service\Individu\IndividuServiceAwareInterface;
use Application\Service\Individu\IndividuServiceAwareTrait;
use Zend\Mvc\Controller\ControllerManager;

class UniteRechercheControllerFactory
class UniteRechercheControllerFactory implements IndividuServiceAwareInterface
{
    use IndividuServiceAwareTrait;

    /**
     * Create service
     *
+57 −12
Changes for module/Application/src/Application/Controller/UniteRechercheController.php: 57 added lines, 12 removed lines.
Original line number Diff line number Diff line
@@ -2,11 +2,15 @@

namespace Application\Controller;

use Application\Entity\Db\IndividuRole;
use Application\Entity\Db\Role;
use Application\Entity\Db\UniteRecherche;
use Application\Form\UniteRechercheForm;
use Application\RouteMatch;
use Application\Service\Individu\IndividuServiceAwareInterface;
use Application\Service\Individu\IndividuServiceAwareTrait;
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;
@@ -16,12 +20,18 @@ use UnicaenLdap\Service\LdapPeopleServiceAwareInterface;
use UnicaenLdap\Service\LdapPeopleServiceAwareTrait;
use Zend\View\Model\ViewModel;

class UniteRechercheController extends AbstractController
    implements UniteRechercheServiceAwareInterface, LdapPeopleServiceAwareInterface, IndividuServiceAwareInterface
class UniteRechercheController extends AbstractController implements
        UniteRechercheServiceAwareInterface,
        IndividuServiceAwareInterface,
        RoleServiceAwareInterface,
        LdapPeopleServiceAwareInterface

{
    use UniteRechercheServiceAwareTrait;
    use LdapPeopleServiceAwareTrait;
    use IndividuServiceAwareTrait;
    use RoleServiceAwareTrait;
    use LdapPeopleServiceAwareTrait;


    /**
     * L'index récupére la liste des unités de recherche et la liste des individus associés à une unité
@@ -36,9 +46,20 @@ class UniteRechercheController extends AbstractController

        // 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 */
            $ur  = $this->uniteRechercheService->getRepository()->find($selected);
            $roles = $this->roleService->getRolesByStructure($ur->getStructure());

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

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

@@ -46,6 +67,8 @@ class UniteRechercheController extends AbstractController
            'unites'                  => $unites,
            'selected'                => $selected,
            'uniteRechercheIndividus' => $uniteRechercheIndividus,
            'roles'                   => $roles,
            'effectifs'               => $effectifs,
        ]);
    }

@@ -166,6 +189,9 @@ class UniteRechercheController extends AbstractController
    {
        $uniteId    = $this->params()->fromRoute('uniteRecherche');
        $data       = $this->params()->fromPost('people');
        $roleId     = $this->params()->fromPost('role');



        if (!empty($data['id'])) {
            /** @var People $people */
@@ -175,12 +201,21 @@ class UniteRechercheController extends AbstractController
                if (! $individu) {
                    $individu = $this->individuService->createFromPeople($people);
                }
                /** @var UniteRecherche $unite */
                $unite = $this->uniteRechercheService->getRepository()->find($uniteId);

                $edi = $this->uniteRechercheService->addIndividu($individu, $unite);
                /**
                 * @var UniteRecherche $unite
                 * @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);

                $this->flashMessenger()->addSuccessMessage("$individu est désormais membre de '$unite' avec le rôle '{$edi->getRole()}'");
                $this->flashMessenger()->addSuccessMessage(
                    "<strong>{$individuRole->getIndividu()}</strong>". " est désormais " .
                    "<strong>{$individuRole->getRole()}</strong>". " de l'unité de recherche ".
                    "<strong>{$unite->getLibelle()}</strong>.");
            }
        }

@@ -189,14 +224,24 @@ class UniteRechercheController extends AbstractController

    public function retirerIndividuAction()
    {
        $ediId = $this->params()->fromRoute('edi');
        $urId = $this->params()->fromRoute('uniteRecherche');
        $irId = $this->params()->fromRoute('edi');

        $unite = null;
        if ($urId !== null) {
            $unite = $this->uniteRechercheService->getUniteRechercheById($urId);
        }

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

            $this->flashMessenger()->addSuccessMessage("{$edi->getIndividu()} n'est plus membre de '{$edi->getUniteRecherche()}'");
            $this->flashMessenger()->addSuccessMessage(
                 "<strong>{$individuRole->getIndividu()}</strong>" . " n'est plus n'est plus "
                ."<strong>{$individuRole->getRole()}</strong>" . " de l'unite de recherche "
                ."<strong>{$unite->getLibelle()}</strong>"."</strong>");

            return $this->redirect()->toRoute('unite-recherche', [], ['query' => ['selected' => $edi->getUniteRecherche()->getId()]], true);
            return $this->redirect()->toRoute('unite-recherche', [], ['query' => ['selected' => $urId]], true);
        }

        return $this->redirect()->toRoute('unite-recherche', [], [], true);
+59
Changes for module/Application/src/Application/Entity/Db/IndividuRole.php: 59 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace Application\Entity\Db;

use Doctrine\ORM\Mapping as ORM;

/**
 * UniteRechercheIndividu
 */
class IndividuRole
{
    /**
     * @var int $id
     * @var Individu $individu
     * @var Role $role
     */
    private $id;
    protected $individu;
    protected $role;

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

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

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

    /** @return Role */
    public function getRole()
    {
        return $this->role;
    }

    /**
     * @param Role $role
     * @return IndividuRole
     */
    public function setRole($role)
    {
        $this->role = $role;
        return $this;
    }

}
 No newline at end of file
+22
Changes for module/Application/src/Application/Entity/Db/Mapping/Application.Entity.Db.IndividuRole.dcm.xml: 22 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
    <entity name="Application\Entity\Db\IndividuRole" table="INDIVIDU_ROLE">
        <id name="id" type="integer" column="ID">
            <generator strategy="SEQUENCE"/>
        </id>

        <many-to-one field="individu" target-entity="Application\Entity\Db\Individu" fetch="LAZY">
            <join-columns>
                <join-column name="INDIVIDU_ID" referenced-column-name="ID"/>
            </join-columns>
        </many-to-one>
        <many-to-one field="role" target-entity="Application\Entity\Db\Role" fetch="LAZY">
            <join-columns>
                <join-column name="ROLE_ID" referenced-column-name="ID"/>
            </join-columns>
        </many-to-one>

    </entity>
</doctrine-mapping>
+31
Changes for module/Application/src/Application/Entity/Db/Repository/IndividuRoleRepository.php: 31 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace Application\Entity\Db\Repository;

use Application\Entity\Db\IndividuRole;
use Application\Entity\Db\Role;
use Doctrine\ORM\Query\Expr\Join;

class IndividuRoleRepository extends DefaultEntityRepository
{
    /**
     * @param Role role;
     * @return IndividuRole[]
     */
    public function findMembresByRole($role)
    {
        $qb = $this->getEntityManager()->getRepository(IndividuRole::class)->createQueryBuilder('ir');
        $qb
            ->addSelect('i, r')
            ->join('Role', 'r', Join::WITH, 'ir.role = :role')
            ->setParameter('role', $role);
        ;

        return $qb->getQuery()->getResult();
    }

//    public function findMembresByStructure($structure) {
//
//    }

}
 No newline at end of file
Loading