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

retrait/don de privilège ok (ajax ?)

parent 82c36d83
Loading
Loading
Loading
Loading
Loading
+13 −0
Changes for module/Application/config/others/admin.config.php: 13 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ use Application\Controller\AdminController;
use Application\Provider\Privilege\UtilisateurPrivileges;
use UnicaenAuth\Guard\PrivilegeController;
use Zend\Mvc\Router\Http\Literal;
use Zend\Mvc\Router\Http\Segment;

return [
    'bjyauthorize'    => [
@@ -21,6 +22,7 @@ return [
                    'controller' => 'Application\Controller\Role',
                    'action'     => [
                        'index',
                        'modifier',
                    ],
                    'privileges' => UtilisateurPrivileges::UTILISATEUR_ATTRIBUTION_ROLE,
                ],
@@ -58,6 +60,17 @@ return [
                    ],
                ],
            ],
            'modifier-privilege' => [
                'type'          => Segment::class,
                'options'       => [
                    'route'    => '/modifier-privilege/:role/:privilege',
                    'defaults' => [
                        '__NAMESPACE__' => 'Application\Controller',
                        'controller'    => 'Role',
                        'action'        => 'modifier',
                    ],
                ],
            ],
            'test-envoi-mail' => [
                'type'          => 'Segment',
                'options'       => [
+5 −0
Changes for module/Application/src/Application/Controller/Factory/RoleControllerFactory.php: 5 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -3,15 +3,20 @@
namespace Application\Controller\Factory;

use Application\Controller\RoleController;
use UnicaenAuth\Service\PrivilegeService;
use Zend\Mvc\Controller\ControllerManager;
//use UnicaenAuth\Service\Traits\PrivilegeServiceAwareTrait;

class RoleControllerFactory
{
//    use PrivilegeServiceAwareTrait;

    public function __invoke(ControllerManager $controllerManager)
    {

//        $service = $controllerManager->getServiceLocator()->get(PrivilegeService::class);
        $controller = new RoleController();
//        $controller->setServicePrivilege($service);

        return $controller;
    }
+30 −2
Changes for module/Application/src/Application/Controller/RoleController.php: 30 added lines, 2 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\Role\RoleServiceAwareInterface;
use Application\Service\Role\RoleServiceAwareTrait;
use Doctrine\ORM\QueryBuilder;
use UnicaenApp\Service\EntityManagerAwareInterface;
use UnicaenApp\Service\EntityManagerAwareTrait;
@@ -11,13 +13,13 @@ use UnicaenAuth\Entity\Db\CategoriePrivilege;
use Zend\View\Model\ViewModel;

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

    public function indexAction()
    {

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

@@ -30,9 +32,35 @@ class RoleController extends AbstractController
        return new ViewModel([
            'roles' => $roles,
            'privileges' => $privileges,
            'params' => $this->params()->fromQuery(),
        ]);
    }

    public function modifierAction()
    {
        $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]);

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

//        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);
    }

    private function decorateWithDepend(QueryBuilder $qb, $depend) {
        switch($depend) {
            case "ED" :
+113 −45
Changes for module/Application/view/application/role/index.phtml: 113 added lines, 45 removed lines.
Original line number Diff line number Diff line
@@ -16,77 +16,145 @@

<?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'>";
//$paramQuery = $this->params()->fromQuery();
//echo $paramQuery;
echo "<input type='submit' value='refresh' id='refresh'/>";
echo "<table id='mytable' class='droits-tbl table table-hover table-bordered table-condensed table-extra-condensed table-header-rotated'>";
echo "<tr><th></th>";

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


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 "<a href='".$this->url("modifier-privilege", ['role' => $role->getId(), 'privilege'=> $privilege->getId()], ["query" => $params], true)."' />";
//        echo "[" . $role->getId() . "|" . $privilege->getId() . "|";
//        echo (array_search($role, $privilege->getRole()->toArray()) === false);
//        echo "]";
        if( array_search($role, $privilege->getRole()->toArray()) !== false) {
            echo "<span style='color: green'; class='glyphicon glyphicon-ok'></span>";
        } else {
            echo "<span style='color: red'; class='glyphicon glyphicon-remove'></span>";
        }
        echo "</a>";
        echo "</td>";

    }
    echo "</tr>";
}
echo "</table>";
?>

<script>
    $(document).ready(function() {

        function RefreshTable() {
            //alert("clicked !");
            $("#mytable").innerHTML = "oups";
        }

        $("#refresh").on("click", RefreshTable);

        // OR CAN THIS WAY
        //
        // $("#refresh-btn").on("click", function() {
        //    $( "#mytable" ).load( "your-current-page.html #mytable" );
        // });


    });
</script>


<style>

    .table-header-rotated th.row-header {
        width: auto;

    }

    .table-header-rotated td {
        width: 40px;
        vertical-align: middle;
        text-align: center;
    }

    .table-header-rotated th.rotate-45 {
        /*border: none;*/
        /*height: 200px;*/
        /*width: 40px;*/
        /*min-width: 40px;*/
        /*max-width: 40px;*/
        /*position: relative;*/
        /*vertical-align: bottom;*/
        /*padding: 0;*/
        /*line-height: 1;*/
        /*white-space: nowrap;*/

        /*position: relative;*/
        /*top: 0px;*/
        /*left: 83px;*/
        /*height: 100%;*/
        /*transform: skew(-40deg, 0deg);*/
        /*overflow: hidden;*/
        /*border-right: 1px solid #ddd;*/
    }

    .table-header-rotated th.rotate-45 > div {
        position: relative;
        top: 0px;
        left: 83px;
        height: 100%;
        transform: skew(-40deg, 0deg);
        overflow: hidden;
        border-right: 1px solid #ddd;
    }

    .table-header-rotated th.rotate-45 > div.first {
        border-left: 1px solid #ddd;
    }

    .table-header-rotated th.rotate-45 span {
        transform: skew(40deg, 0deg) rotate(310deg);
        position: absolute;
        bottom: 40px;
        left: -30px;
        display: inline-block;
        width: 100px;
        text-align: left;
    }

    .table-header-rotated .separator {
        border: none;
    }

    .droits-tbl th.privilege {
        min-width: 200px;
        max-width: 200px;
        width: 200px;
    }

    .droits-tbl td span.refuse {
        opacity: 0.5;
    }


</style>
 No newline at end of file