Commit 662f0c41 authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Merge branch 'master' of git.unicaen.fr:dsi/sygal

parents cf7883bb af6e3a92
Loading
Loading
Loading
Loading
+1 −1
Changes for module/Application/config/others/droits.config.php: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -90,7 +90,7 @@ return [
                            'privileges' => [
                                'label'      => "Privilèges",
                                'title'      => "Gestion des privilèges",
                                'route'      => 'droits/privileges',
                                'route'      => 'roles',
                                'resource'   => PrivilegeController::getResourceId('UnicaenAuth\Controller\Droits', 'privileges'),
                                'withtarget' => true,
                            ],
+10 −6
Changes for module/Application/src/Application/Controller/Factory/StatistiqueControllerFactory.php: 10 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -7,15 +7,19 @@ use Zend\Mvc\Controller\ControllerManager;

class StatistiqueControllerFactory
{
    /**
     * Create service
     *
     * @param ControllerManager $controllerManager
     * @return StatistiqueController
     */
    public function __invoke(ControllerManager $controllerManager)
    {
        $sl = $controllerManager->getServiceLocator();
        $theseService = $sl->get('TheseService');
        $ecoleService = $sl->get('EcoleDoctoraleService');
        $etabService  = $sl->get('EtablissementService');
        $uniteService = $sl->get('UniteRechercheService');

        $controller = new StatistiqueController();
        $controller->setTheseService($theseService);
        $controller->setEcoleDoctoraleService($ecoleService);
        $controller->setEtablissementService($etabService);
        $controller->setUniteRechercheService($uniteService);
        return $controller;
    }
}
 No newline at end of file
+8 −8
Changes for module/Application/src/Application/Controller/FichierTheseController.php: 8 added lines, 8 removed lines.
Original line number Diff line number Diff line
@@ -48,14 +48,8 @@ class FichierTheseController extends AbstractController implements
         */
        $needsRedirect = false;
        $queryParams = $this->params()->fromQuery();
//        // filtres
//        $etatThese = $this->params()->fromQuery($name = 'etatThese');
//        if ($etatThese === null) { // null <=> paramètre absent
//            // filtrage par défaut : thèse en préparation
//            $queryParams = array_merge($queryParams, [$name => These::ETAT_EN_COURS]);
//            $needsRedirect = true;
//        }
        // tris

        $version = $this->params()->fromQuery('version');
        $sort = $this->params()->fromQuery('sort');
        if ($sort === null) { // null <=> paramètre absent
            // tri par défaut : datePremiereInscription
@@ -78,6 +72,12 @@ class FichierTheseController extends AbstractController implements
            ->join('t.doctorant', 'd')
            ->leftJoin('f.validites', 'val')
            ->join('f.version', 'ver');
        if (isset($version) && $version !== '')
        {
            $qb->andWhere('ver.code = :version')
                ->setParameter("version" , $version);
        }


        foreach (explode('+', $sort) as $sortProp) {
            if ($sortProp === 't.titre') {
+22 −9
Changes for module/Application/src/Application/Controller/RoleController.php: 22 added lines, 9 removed lines.
Original line number Diff line number Diff line
@@ -4,6 +4,8 @@ namespace Application\Controller;

use Application\Entity\Db\Privilege;
use Application\Entity\Db\Role;
use Application\Service\Etablissement\EtablissementServiceAwareInterface;
use Application\Service\Etablissement\EtablissementServiceAwareTrait;
use Application\Service\Role\RoleServiceAwareInterface;
use Application\Service\Role\RoleServiceAwareTrait;
use Doctrine\ORM\QueryBuilder;
@@ -13,10 +15,11 @@ use UnicaenAuth\Entity\Db\CategoriePrivilege;
use Zend\View\Model\ViewModel;

class RoleController extends AbstractController
        implements EntityManagerAwareInterface, RoleServiceAwareInterface
        implements EntityManagerAwareInterface, RoleServiceAwareInterface, EtablissementServiceAwareInterface
{
    use EntityManagerAwareTrait;
    use RoleServiceAwareTrait;
    use EtablissementServiceAwareTrait;

    public function indexAction()
    {
@@ -24,15 +27,23 @@ class RoleController extends AbstractController
        $categorie = $this->params()->fromQuery("categorie");

        $qb_depend = $this->entityManager->getRepository(Role::class)->createQueryBuilder("r");
//        $qb_depend = $qb_depend->select("r, s");
//        $qb_depend = $qb_depend->join("r.structure", "s");
        $qb_depend = $this->decorateWithDepend($qb_depend, $depend);
        $qb_depend = $qb_depend->orderBy("r.typeStructureDependant, r.libelle, r.structure", 'asc');
        $roles = $qb_depend->getQuery()->execute();
        $qb_categorie = $this->entityManager->getRepository(Privilege::class)->createQueryBuilder("p");
        $qb_categorie = $this->decorateWithCategorie($qb_categorie, $categorie);
        $qb_categorie->orderBy("p.categorie, p.ordre","ASC");
        $privileges = $qb_categorie->getQuery()->execute();

        $etablissements = $this->etablissementService->getEtablissements();

        return new ViewModel([
            'roles' => $roles,
            'privileges' => $privileges,
            'params' => $this->params()->fromQuery(),
            'etablissements' => $etablissements,
        ]);
    }

@@ -40,25 +51,26 @@ class RoleController extends AbstractController
    {
        $privilege_id = $this->params()->fromRoute("privilege");
        $role_id = $this->params()->fromRoute("role");
//        var_dump($privilege_id);
//        var_dump($role_id);
        $privilege = $this->entityManager->getRepository(Privilege::class)->findOneBy(["id" => $privilege_id]);
        $role = $this->entityManager->getRepository(Role::class)->findOneBy(["id" => $role_id]);


        $value = null;
        if( array_search($role, $privilege->getRole()->toArray()) !== false) {
            $privilege->removeRole($role);
            $this->entityManager->flush($privilege);
            $value = 0;
        } else {
            $privilege->addRole($role);
            $this->entityManager->flush($privilege);
            $value = 1;
        }

//        var_dump($privilege);
        //$has = array_search($role_id, $privilege->getRoles());
        //var_dump($has);
        //die("Die die");
        $queryParams = $this->params()->fromQuery();
        $this->redirect()->toRoute("roles", [], ["query" => $queryParams], true);
        return new ViewModel([
            'value' => $value,
        ]);
        //$this->redirect()->toRoute("roles", [], ["query" => $queryParams], true);
    }

    private function decorateWithDepend(QueryBuilder $qb, $depend) {
@@ -91,8 +103,9 @@ class RoleController extends AbstractController

    private function decorateWithCategorie(QueryBuilder $qb, $categorie)
    {
        $qb->leftJoin(CategoriePrivilege::class, "cp", "WITH", "cp.id = p.categorie");
        if ($categorie !== null && $categorie !== "") {
            $qb = $qb->leftJoin(CategoriePrivilege::class, "cp", "WITH", "cp.id = p.categorie")
            $qb
                ->andWhere("cp.code = :type")
                ->setParameter("type", $categorie);
        }
+106 −3
Changes for module/Application/src/Application/Controller/StatistiqueController.php: 106 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -2,20 +2,123 @@

namespace Application\Controller;

use Application\Service\These\TheseServiceAwareInterface;
use Application\Service\EcoleDoctorale\EcoleDoctoraleServiceAwareTrait;
use Application\Service\Etablissement\EtablissementServiceAwareTrait;
use Application\Service\These\TheseServiceAwareTrait;
use Application\Service\UniteRecherche\UniteRechercheServiceAwareTrait;
use DateTime;
use Doctrine\ORM\QueryBuilder;
use Zend\View\Model\ViewModel;

class StatistiqueController extends AbstractController
    implements TheseServiceAwareInterface
{
    use TheseServiceAwareTrait;
    use EcoleDoctoraleServiceAwareTrait;
    use UniteRechercheServiceAwareTrait;
    use EtablissementServiceAwareTrait;

    public function indexAction()
    {
        $theses = $this->theseService->getRepository()->findAll();

        /**
         * Certaines statistiques exploites le genre de la personne et nécessite de récupérer
         * les données présentent dans la table Individu. Afin d'évite moultes requêtes, il
         * faut faire les jointures qui vont biens (et aussi le select)
         */

        $qb = $this->theseService->getRepository()->createQueryBuilder("t");
        $qb = $qb
            ->select("t,d,i")
            ->join("t.doctorant", "d")
            ->join("d.individu", "i");


        $structureType = $this->params()->fromQuery("structure_type");
        $structureId = $this->params()->fromQuery("structure_id");
        $qb = $this->decorateWithStructure($qb, $structureType, $structureId);

        $dateType = $this->params()->fromQuery("date");
        $dateDebut = $this->params()->fromQuery("debut");
        $dateFin = $this->params()->fromQuery("fin");
        $qb = $this->decorateWithDate($qb, $dateType, $dateDebut, $dateFin);

        $theses = $qb->getQuery()->execute();
        $ecoles = $this->ecoleDoctoraleService->getEcolesDoctorales();
        $unites = $this->uniteRechercheService->getUnitesRecherches();
        $etablissements = $this->etablissementService->getEtablissements();
        return new ViewModel([
            'theses' => $theses,
            'ecoles' => $ecoles,
            'unites' => $unites,
            'etablissements' => $etablissements,
        ]);
    }

    /**
     * @param QueryBuilder $qb
     * @param string $type (parmi ED, UR, Etab)
     * @param string $id l'identifiant d'une structure
     * @return QueryBuilder
     */
    private function decorateWithStructure(QueryBuilder $qb, $type = null, $id = null)
    {
        if ($type !== null && $id !== null) {
            switch($type) {
                case "ED" :
                    $ecole = $this->ecoleDoctoraleService->getEcoleDoctoraleById($id);
                    return  $qb->andWhere("t.ecoleDoctorale = :ed")
                                ->setParameter(":ed", $ecole);
                case "UR" :
                    $unite = $this->uniteRechercheService->getUniteRechercheById($id);
                    return $qb->andWhere("t.uniteRecherche = :ur")
                                ->setParameter(":ur", $unite);
                case "Etab" :
                    $etablissement = $this->etablissementService->getEtablissementById($id);
                    return $qb->andWhere("t.etablissement = :etab")
                                ->setParameter("etab", $etablissement);
            }
        }
        return $qb;
    }

    /**
     * @param QueryBuilder $qb
     * @param string $type (parmi soutenance, inscription)
     * @param string $debut (YYYY)
     * @param string $fin (YYYY)
     * @return QueryBuilder
     */
    private function decorateWithDate(QueryBuilder $qb, $type = null, $debut = null, $fin = null)
    {
        if ($debut !== null) $debut .= "-01-01";
        if ($fin !== null) $fin .= "-12-31";

        if ($type !== null) {
            switch($type) {
                case "soutenance" :
                    if ($debut !== null) {
                        $qb->andWhere("t.dateSoutenance >= :debut")
                            ->setParameter("debut", new DateTime($debut));
                    }
                    if ($fin !== null) {
                        $qb->andWhere("t.dateSoutenance <= :fin")
                            ->setParameter("fin", new DateTime($fin));
                    }
                    return $qb;
                case "inscription" :
                    if ($debut !== null) {
                        $qb->andWhere("t.datePremiereInscription >= :debut")
                            ->setParameter("debut", new DateTime($debut));
                    }
                    if ($fin !== null) {
                        $qb->andWhere("t.datePremiereInscription <= :fin")
                            ->setParameter("fin", new DateTime($fin));
                    }
                    return $qb;
            }
        }
        return $qb;
    }


}
 No newline at end of file
Loading