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

Ajout d'une nouvelle visualisation pour les privilèges

parent ca2ef928
Loading
Loading
Loading
Loading
Loading
+21 −0
Changes for module/Application/config/others/admin.config.php: 21 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

use Application\Controller\Factory\RoleControllerFactory;
use Application\Controller\AdminController;
use Application\Provider\Privilege\UtilisateurPrivileges;
use UnicaenAuth\Guard\PrivilegeController;
use Zend\Mvc\Router\Http\Literal;

return [
    'bjyauthorize'    => [
@@ -15,6 +17,13 @@ return [
                    ],
                    'privileges' => UtilisateurPrivileges::UTILISATEUR_ATTRIBUTION_ROLE,
                ],
                [
                    'controller' => 'Application\Controller\Role',
                    'action'     => [
                        'index',
                    ],
                    'privileges' => UtilisateurPrivileges::UTILISATEUR_ATTRIBUTION_ROLE,
                ],
                [
                    'controller' => 'UnicaenApp\Controller\Application',
                    'action'     => [
@@ -38,6 +47,17 @@ return [
                    ],
                ],
            ],
            'roles' => [
                'type'          => Literal::class,
                'options'       => [
                    'route'    => '/roles',
                    'defaults' => [
                        '__NAMESPACE__' => 'Application\Controller',
                        'controller'    => 'Role',
                        'action'        => 'index',
                    ],
                ],
            ],
            'test-envoi-mail' => [
                'type'          => 'Segment',
                'options'       => [
@@ -89,6 +109,7 @@ return [
            'Application\Controller\Admin' => AdminController::class,
        ],
        'factories' => [
            'Application\Controller\Role' => RoleControllerFactory::class,
        ],
    ],
];
+18 −0
Changes for module/Application/src/Application/Controller/Factory/RoleControllerFactory.php: 18 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace Application\Controller\Factory;

use Application\Controller\RoleController;
use Zend\Mvc\Controller\ControllerManager;

class RoleControllerFactory
{

    public function __invoke(ControllerManager $controllerManager)
    {

        $controller = new RoleController();

        return $controller;
    }
}
 No newline at end of file
+73 −0
Changes for module/Application/src/Application/Controller/RoleController.php: 73 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace Application\Controller;

use Application\Entity\Db\Privilege;
use Application\Entity\Db\Role;
use Doctrine\ORM\QueryBuilder;
use UnicaenApp\Service\EntityManagerAwareInterface;
use UnicaenApp\Service\EntityManagerAwareTrait;
use UnicaenAuth\Entity\Db\CategoriePrivilege;
use Zend\View\Model\ViewModel;

class RoleController extends AbstractController
        implements EntityManagerAwareInterface
{
    use EntityManagerAwareTrait;

    public function indexAction()
    {

        $depend = $this->params()->fromQuery("depend");
        $categorie = $this->params()->fromQuery("categorie");

        $qb_depend = $this->entityManager->getRepository(Role::class)->createQueryBuilder("r");
        $qb_depend = $this->decorateWithDepend($qb_depend, $depend);
        $roles = $qb_depend->getQuery()->execute();
        $qb_categorie = $this->entityManager->getRepository(Privilege::class)->createQueryBuilder("p");
        $qb_categorie = $this->decorateWithCategorie($qb_categorie, $categorie);
        $privileges = $qb_categorie->getQuery()->execute();
        return new ViewModel([
            'roles' => $roles,
            'privileges' => $privileges,
        ]);
    }

    private function decorateWithDepend(QueryBuilder $qb, $depend) {
        switch($depend) {
            case "ED" :
                $qb = $qb->andWhere("r.typeStructureDependant = :type")
                    ->setParameter("type", "2");
                return $qb;
            case "UR" :
                $qb = $qb->andWhere("r.typeStructureDependant = :type")
                    ->setParameter("type", "3");
                return $qb;
            case "Etab" :
                $qb = $qb->andWhere("r.typeStructureDependant = :type")
                    ->setParameter("type", "1");
                return $qb;
            case "These" :
                $qb = $qb->andWhere("r.theseDependant = :value")
                    ->setParameter("value", true);
                return $qb;
            case "Aucune" :
                $qb = $qb->andWhere("r.theseDependant = :value")
                    ->andWhere("r.typeStructureDependant IS NULL")
                    ->setParameter("value", false);
                return $qb;
            default:
                return $qb;
        }
    }

    private function decorateWithCategorie(QueryBuilder $qb, $categorie)
    {
        if ($categorie !== null && $categorie !== "") {
            $qb = $qb->leftJoin(CategoriePrivilege::class, "cp", "WITH", "cp.id = p.categorie")
                ->andWhere("cp.code = :type")
                ->setParameter("type", $categorie);
        }
        return $qb;
    }
}
 No newline at end of file
+9 −2
Changes for module/Application/src/Application/View/Helper/FilterPanel/partial/filter-form.phtml: 9 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -23,17 +23,24 @@ use Application\View\Renderer\PhpRenderer;
 ]
 *
 */

$titre = current($config)['titre'];
if (!isset($titre) || $titre == null) $titre = "Filtres";

?>



<div class="panel panel-default filters">
    <div class="panel-heading">
        <span class="glyphicon glyphicon-filter"></span> <?php echo $this->translate("Filtres"); ?>
        <span class="glyphicon glyphicon-filter"></span> <?php echo $titre; ?>
    </div>
    <table class="table table-bordered">
        <?php foreach ($config as $label => $data): ?>
        <tr>
            <th>
                <?php echo $label ?>
                <?php if ($titre === "Filtres") echo $label; ?>

            </th>
            <td>
                <?php echo $this->partial('filter-form-item', $data) ?>
+92 −0
Changes for module/Application/view/application/role/index.phtml: 92 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php
    use Application\Entity\Db\Role;
    use Application\Entity\Db\Privilege;

/**
 * //Provenant du controleur
 * @var Role[] $roles
 * @var Privilege[] $privileges
 *
 * //Utilisée couramment
 * @var Role $role
 * @var Privilege $privilege
 */
?>


<?php $this->headTitle($this->translate("Rôles/Privilèges")) ?>
<h1 class="page-header first"><?php echo $this->translate("Rôles/Privilèges") ?>
<!--    <span class="badge">--</span>-->
</h1>

    <div class="pull-left">
        <?php echo $this->partial('partial/form-filtrage') ?>
    </div>

<!--<form action="--><?php //echo $this->url('roles', [], ['query' => $queryParams], true);?><!--" method="post">-->
<!--    Dépend de :-->
<!--    <select>-->
<!--        <option value="---"> --- </option>-->
<!--        <option value="aucun"> Aucun </option>-->
<!--        <option value="structure"> Structure </option>-->
<!--        <option value="ecole-doctorale"> &nbsp;-&nbsp;École doctorale</option>-->
<!--        <option value="etablissement"> &nbsp;-&nbsp;Établissement</option>-->
<!--        <option value="unite-de-recherche"> &nbsp;-&nbsp;Unité de recherche</option>-->
<!--        <option value="these"> These </option>-->
<!--    </select>-->
<!--    <input type="submit" value="Filtrer"/>-->
<!--</form>-->


<?php
//foreach($roles as $role) {
//    if ($role->isStructureDependant()) {
//        switch($role->getTypeStructureDependant()) {
//            case "Établissement" :
//                echo "<span style='background-color: limegreen; font-family: monospace;'>ST_ET</span>";
//                break;
//            case "École doctorale" :
//                echo "<span style='background-color: darkgreen; font-family: monospace;'>ST_ED</span>";
//                break;
//            case "Unité de recherche" :
//                echo "<span style='background-color: greenyellow; font-family: monospace;'>ST_UR</span>";
//                break;
//            default:
//                echo "<span style='background-color: #5cb85c; font-family: monospace;'>STRUC</span>";
//                break;
//        }
//
//    } elseif ($role->isTheseDependant()) {
//        echo "<span style='background-color: salmon; font-family: monospace;'>THESE</span>";
//    } else {
//        echo "<span style='background-color: #9D9D9D; font-family: monospace;'>AUCUN</span>";
//    }
//    echo $role->getLibelle() . "<br/>";
//}
?>

<?php
echo "<table class='table-bordered'>";
echo "<tr><th></th>";

foreach($roles as $role) {
    echo "<th > <span style='text-orientation: upright;'> {$role->getLibelle()} </span></th>";
}
echo "</tr>";
foreach($privileges as $privilege) {

    echo "<tr>";
    echo "<th> {$privilege->getLibelle()} </th>";
    foreach($roles as $role) {
        echo "<td>";
        if( array_search($role, $privilege->getRole()->toArray())) {
            echo "<span style='color: green'; class='glyphicon glyphicon-ok'></span>";
        } else {
            echo "<span style='color: red'; class='glyphicon glyphicon-remove'></span>";
        }
        echo "</td>";
    }
    echo "</tr>";
}
echo "</table>";
Loading