Commit 5a123bd1 authored by Stephane Bouvry's avatar Stephane Bouvry
Browse files

Les rôles attribués en dur dans la BDD apparaissent paintenant dans la liste des personnes

parent c987cab1
Loading
Loading
Loading
Loading
+4 −0
Changes for module/Oscar/src/Oscar/Controller/PersonController.php: 4 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -252,7 +252,11 @@ class PersonController extends AbstractOscarController

        $roles = $this->getEntityManager()->getRepository(Person::class)->getRolesLdapUsed();


        $dbroles =$this->getPersonService()->getRolesByAuthentification();

        return array(
            'dbroles' => $dbroles,
            'roles' => $roles,
            'search' => $search,
            'persons' => $datas,
+0 −1
Changes for module/Oscar/src/Oscar/Controller/ProjectController.php: 0 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -649,7 +649,6 @@ class ProjectController extends AbstractOscarController
        $sort = 'activityDateCreated';
        $projects->orderBy($orderBy, 'DESC');


        return array(
            'projects' => new UnicaenDoctrinePaginator($projects, $page),
            'search' => $search,
+35 −0
Changes for module/Oscar/src/Oscar/Service/PersonService.php: 35 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -81,6 +81,41 @@ class PersonService implements ServiceLocatorAwareInterface, EntityManagerAwareI
            ->getSingleResult();
    }

    /**
     * @return array
     * @throws \Exception
     */
    public function getRolesByAuthentification(){
        try {
            $rsm = new Query\ResultSetMapping();
            $rsm->addScalarResult('login', 'login');
            $rsm->addScalarResult('roleid', 'roleid');

            $native = $this->getEntityManager()->createNativeQuery(
                'SELECT a.username as login, ur.role_id as roleid FROM authentification a
                    INNER JOIN authentification_role ar
                    ON ar.authentification_id = a.id
                    INNER JOIN user_role ur
                    ON ar.role_id = ur.id',
                $rsm
            );

            $out = [];

            foreach ($native->getResult() as $row) {
                if( !array_key_exists($row['login'], $out) ){
                    $out[$row['login']] = [];
                }
                $out[$row['login']][] = $row['roleid'];
            }

            return $out;

        } catch(\Exception $e ){
            throw $e;
        }
    }

    /**
     * @param int $currentPage
     * @param int $resultByPage
+7 −1
Changes for module/Oscar/view/oscar/person/index.phtml: 7 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -46,7 +46,13 @@ $markText = function( $text, $search ){
<section data-context="#ddm" class="container">
    <h3 class="text-center"><?= count($persons) ?> résultat(s) - page <?= $persons->getCurrentPage() ?> / <?= $persons->getCountPage() ?></h3>
    <?php foreach( $persons as $person ): ?>
        <?= $this->partial('/oscar/person/item-list.phtml', ['person' => $person, 'markText' => $markText, 'search' => $search, 'ldapFilters' => $roles]) ?>
        <?= $this->partial('/oscar/person/item-list.phtml', [
            'person' => $person,
            'markText' => $markText,
            'search' => $search,
            'ldapFilters' => $roles,
            'dbroles'=> array_key_exists($person->getLadapLogin(), $dbroles) ? $dbroles[$person->getLadapLogin()] : []
        ]) ?>
    <?php endforeach; ?>
        <script>
            Initer.ready(function(){
+11 −2
Changes for module/Oscar/view/oscar/person/item-list.phtml: 11 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -41,8 +41,8 @@
        <?php foreach( $person->getLdapMemberOf() as $ldapFilter ): ?>
            <?php if( array_key_exists($ldapFilter, $ldapFilters )) : ?>
                <?php foreach($ldapFilters[$ldapFilter] as $roles ): ?>
                    <span class="cartouche <?= $roles['principal'] ? 'primary' : 'cartouche-default' ?>" title="Droit obtenu via LDAP">
                        <i class="icon-database"></i>
                    <span class="cartouche <?= $roles['principal'] ? 'primary' : 'secondary1' ?>" title="Droit obtenu via LDAP">
                        <i class="icon-link-outline"></i>
                        <?= $roles['label'] ?>
                    </span>
                <?php endforeach; ?>
@@ -50,6 +50,15 @@
        <?php endforeach; ?>
    <?php endif; ?>

    <?php if ($dbroles): ?>
        <?php foreach( $dbroles as $role ): ?>
        <span class="cartouche complementary" title="Droit attribué en base de données">
            <i class="icon-database"></i>
            <?= $role ?>
        </span>
        <?php endforeach; ?>
    <?php endif; ?>


    <!--
            <div class="card-content text-highlight">