diff --git a/CHANGELOG.md b/CHANGELOG.md index 878cf98f52186d4b3a196eb29f6a2ce619d89a16..b4b3eafad66b67d75e21f5890c214f92b1fac628 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,25 @@ -#Version 6.2.1 21/01/2025 +# Version 6.3.0 01/04/2025 + +* Possibilité de restreindre l'affichage des indicateurs en fonction de rôles + + +/!\ la colonne `roles_autorises` dans la table `unicaen_indicateur_indicateur` a évolué /!\ +```sql +alter table unicaen_indicateur_indicateur add roles_autorises varchar(2048) default 'Tous les rôles' not null; +``` + +/!\ Nouveau privilèges pour l'affichage "forcé" des indicateurs +```sql +INSERT INTO unicaen_privilege_privilege(CATEGORIE_ID, CODE, LIBELLE, ORDRE) +WITH d(code, lib, ordre) AS ( + SELECT 'afficher_indicateur_tous', 'Afficher tous les indicateurs', 15 UNION +) +SELECT cp.id, d.code, d.lib, d.ordre +FROM d +JOIN unicaen_privilege_categorie cp ON cp.CODE = 'indicateur'; +``` + +# Version 6.2.1 21/01/2025 * Déclaration des périmètres en configuration * Périmètres multiples @@ -9,7 +30,7 @@ alter table unicaen_indicateur_indicateur alter column perimetre drop not null; alter table unicaen_indicateur_indicateur alter column perimetre drop default; ``` -#Version 6.2.0 17/01/2025 +# Version 6.2.0 17/01/2025 * Intégration d'une première version des périmétres diff --git a/documentation/01_table.sql b/documentation/01_table.sql index e23ce14209219f8417e6e9ae1fc4a619eadc1beb..9b42b4f62bf619ea79d19a278a1ba2000b7d8692 100644 --- a/documentation/01_table.sql +++ b/documentation/01_table.sql @@ -30,7 +30,8 @@ create table unicaen_indicateur_indicateur categorie_id integer constraint uii_unicaen_indicateur_categorie_id_fk references unicaen_indicateur_categorie, - perimetre varchar(256) + perimetre varchar(256), + roles_autorises varchar(2048) ); create unique index indicateur_id_uindex on unicaen_indicateur_indicateur (id); diff --git a/documentation/02_privileges.sql b/documentation/02_privileges.sql index c2d8770d0481474c0155868eb7ccb8b074797609..d7b1f691d38bc4cd0c0a05d12771fff7230fed32 100644 --- a/documentation/02_privileges.sql +++ b/documentation/02_privileges.sql @@ -2,10 +2,11 @@ INSERT INTO unicaen_privilege_categorie (code, libelle, ordre, namespace) VALUES ('indicateur', 'Gestions des indicateurs', 800, 'UnicaenIndicateur\Provider\Privilege'); INSERT INTO unicaen_privilege_privilege(CATEGORIE_ID, CODE, LIBELLE, ORDRE) WITH d(code, lib, ordre) AS ( - SELECT 'afficher_indicateur', 'Afficher un indicateur', 1 UNION - SELECT 'editer_indicateur', 'Éditer un indicateur', 2 UNION - SELECT 'detruire_indicateur', 'Effacer un indicateur', 3 UNION - SELECT 'indicateur_index', 'Accéder à l''index', 10 UNION + SELECT 'afficher_indicateur', 'Afficher un indicateur', 10 UNION + SELECT 'afficher_indicateur_tous', 'Afficher tous les indicateurs', 15 UNION + SELECT 'editer_indicateur', 'Éditer un indicateur', 20 UNION + SELECT 'detruire_indicateur', 'Effacer un indicateur', 30 UNION + SELECT 'indicateur_index', 'Accéder à l''index', 1 UNION SELECT 'indicateur_mes_indicateurs', 'Affichage du menu - Mes Indicateurs -', 100 ) SELECT cp.id, d.code, d.lib, d.ordre diff --git a/src/UnicaenIndicateur/Controller/IndicateurController.php b/src/UnicaenIndicateur/Controller/IndicateurController.php index 000b53851990ffe25d96698b1da9dd7bc0cae2cd..01ba75900160283aa1fff6a3b70cdab668adebc8 100644 --- a/src/UnicaenIndicateur/Controller/IndicateurController.php +++ b/src/UnicaenIndicateur/Controller/IndicateurController.php @@ -57,6 +57,7 @@ class IndicateurController extends AbstractActionController { 'indicateursByCategorie' => $indicateursByCategorie, 'indicateurs' => $indicateurs, 'abonnements' => $array, + 'role' => $this->getUserService()->getConnectedRole(), ]); } diff --git a/src/UnicaenIndicateur/Entity/Db/Indicateur.php b/src/UnicaenIndicateur/Entity/Db/Indicateur.php index 0cd6c0b99f64983111d451a003e69f1762948144..ec70912e37623ba8d505f49324745e620c8ac8f3 100644 --- a/src/UnicaenIndicateur/Entity/Db/Indicateur.php +++ b/src/UnicaenIndicateur/Entity/Db/Indicateur.php @@ -5,6 +5,9 @@ namespace UnicaenIndicateur\Entity\Db; use DateTime; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; +use UnicaenIndicateur\Service\Perimetre\PerimetreServiceInterface; +use UnicaenParametre\Service\Parametre\ParametreService; +use UnicaenUtilisateur\Entity\Db\RoleInterface; class Indicateur { @@ -29,6 +32,9 @@ class Indicateur { private ?int $nbElements = null; private ?string $perimetre = null; + private ?string $rolesAutorises = null; + + const TOUS_LES_ROLES = "Tous les rôles"; public function __construct() { @@ -153,6 +159,24 @@ class Indicateur { $this->perimetre = $perimetre; } + /** @return string[] */ + public function getRolesAutorises(): array + { + if ($this->rolesAutorises === null) return [Indicateur::TOUS_LES_ROLES]; + return explode(PerimetreServiceInterface::PERIMETRE_SEPARATOR, $this->rolesAutorises); + } + + public function setRolesAutorises(?string $rolesAutorises): void + { + $this->rolesAutorises = $rolesAutorises; + } + + public function isAutorise(?RoleInterface $role): bool + { + $listing = $this->getRolesAutorises(); + if (in_array(self::TOUS_LES_ROLES, $listing)) return true; + return in_array($role->getRoleId(), $listing); + } /** Abonnements **************************************************************** */ diff --git a/src/UnicaenIndicateur/Entity/Db/Mapping/UnicaenIndicateur.Entity.Db.Indicateur.dcm.xml b/src/UnicaenIndicateur/Entity/Db/Mapping/UnicaenIndicateur.Entity.Db.Indicateur.dcm.xml index 67760f8779b6a191035b44b35fed02be3e247652..6195fe9d9d43f244df142f5e00fcf9f58c6fdaae 100644 --- a/src/UnicaenIndicateur/Entity/Db/Mapping/UnicaenIndicateur.Entity.Db.Indicateur.dcm.xml +++ b/src/UnicaenIndicateur/Entity/Db/Mapping/UnicaenIndicateur.Entity.Db.Indicateur.dcm.xml @@ -1,33 +1,37 @@ <?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"> +<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 https://doctrine-project.org/schemas/orm/doctrine-mapping.xsd" +> <entity name="UnicaenIndicateur\Entity\Db\Indicateur" table="unicaen_indicateur_indicateur"> <id name="id" type="integer" column="id"> <generator strategy="IDENTITY"/> </id> - <field name="code" type="string" length="255" column="code" nullable="false"/> - <field name="titre" type="string" length="255" column="titre" nullable="false"/> - <field name="description" type="string" length="2047" column="description" nullable="false"/> - <field name="requete" type="string" length="4095" column="requete" nullable="false"/> - <field name="dernierRafraichissement" type="datetime" column="dernier_rafraichissement" nullable="true"/> - <field name="viewId" type="string" length="255" column="view_id" nullable="true"/> - <field name="entity" type="string" length="255" column="entity" nullable="true"/> - <field name="namespace" type="string" length="1024" column="namespace" nullable="true"/> - <field name="perimetre" type="string" length="256" column="perimetre" nullable="false"/> - <field name="nbElements" type="integer" column="nb_elements" nullable="true"/> + <field name="code" length="255" column="code" /> + <field name="titre" length="255" column="titre" /> + <field name="description" length="2047" column="description" /> + <field name="requete" length="4095" column="requete" /> + <field name="dernierRafraichissement" type="datetime" column="dernier_rafraichissement" nullable="true"/> + <field name="viewId" length="255" column="view_id" nullable="true"/> + <field name="entity" length="255" column="entity" nullable="true"/> + <field name="namespace" length="1024" column="namespace" nullable="true"/> + <field name="perimetre" length="256" column="perimetre" /> + <field name="rolesAutorises" length="2048" column="roles_autorises" /> + <field name="nbElements" type="integer" column="nb_elements" nullable="true"/> <many-to-one target-entity="UnicaenIndicateur\Entity\Db\Categorie" field="categorie"> - <join-column name="categorie_id" referenced-column-name="id"/> + <join-column name="categorie_id" /> </many-to-one> <one-to-many target-entity="UnicaenIndicateur\Entity\Db\Abonnement" field="abonnements" mapped-by="indicateur" /> - <many-to-many field="tableaux" target-entity="UnicaenIndicateur\Entity\Db\TableauDeBord" inversed-by="tableau" fetch="LAZY"> + <many-to-many field="tableaux" target-entity="UnicaenIndicateur\Entity\Db\TableauDeBord" inversed-by="tableau"> <join-table name="unicaen_indicateur_tableau_indicateur"> <join-columns> - <join-column name="indicateur_id" referenced-column-name="id"/> + <join-column name="indicateur_id" /> </join-columns> <inverse-join-columns> <join-column name="tableau_id" referenced-column-name="ID"/> diff --git a/src/UnicaenIndicateur/Form/Indicateur/IndicateurForm.php b/src/UnicaenIndicateur/Form/Indicateur/IndicateurForm.php index 65e4c1753ae5e679fdbfbea12658716f60c01d67..37398ca49c441c02eda3701e8c03444312649682 100644 --- a/src/UnicaenIndicateur/Form/Indicateur/IndicateurForm.php +++ b/src/UnicaenIndicateur/Form/Indicateur/IndicateurForm.php @@ -3,7 +3,6 @@ namespace UnicaenIndicateur\Form\Indicateur; use Laminas\Validator\Callback; -use UnicaenIndicateur\Entity\Db\Indicateur; use Laminas\Form\Element\Button; use Laminas\Form\Element\Select; use Laminas\Form\Element\Text; @@ -11,10 +10,13 @@ use Laminas\Form\Form; use Laminas\InputFilter\Factory; use UnicaenIndicateur\Service\Categorie\CategorieServiceAwareTrait; use UnicaenIndicateur\Service\Indicateur\IndicateurServiceAwareTrait; +use UnicaenUtilisateur\Entity\Db\RoleInterface; +use UnicaenUtilisateur\Service\Role\RoleServiceAwareTrait; class IndicateurForm extends Form { use IndicateurServiceAwareTrait; use CategorieServiceAwareTrait; + use RoleServiceAwareTrait; private ?string $oldCode = null; private array $perimetres = []; @@ -31,6 +33,14 @@ class IndicateurForm extends Form { public function init(): void { + $roles = $this->getRoleService()->getRepo()->findAll(); + usort($roles, function (RoleInterface $a, RoleInterface $b) { return $a->getLibelle() <=> $b->getLibelle(); }); + $listing = []; + $listing["Tous les rôles"] = "Tous les rôles"; + foreach ($roles as $role) { + $listing[$role->getRoleId()] = $role->getLibelle(); + } + // code $this->add([ 'type' => Text::class, @@ -82,17 +92,17 @@ class IndicateurForm extends Form { 'id' => 'categorie', ], ]); - // namespace - $this->add([ - 'type' => Text::class, - 'name' => 'namespace', - 'options' => [ - 'label' => "Namespace :", - ], - 'attributes' => [ - 'id' => 'namespace', - ], - ]); +// // namespace +// $this->add([ +// 'type' => Text::class, +// 'name' => 'namespace', +// 'options' => [ +// 'label' => "Namespace :", +// ], +// 'attributes' => [ +// 'id' => 'namespace', +// ], +// ]); // view_id $this->add([ 'type' => Text::class, @@ -105,35 +115,50 @@ class IndicateurForm extends Form { 'id' => 'libelle', ], ]); - // entity +// // entity +// $this->add([ +// 'type' => Select::class, +// 'name' => 'entity', +// 'options' => [ +// 'label' => "Entity associé <span class='icon icon-obligatoire' title='champ obligatoire'></span> :", +// 'label_options' => [ 'disable_html_escape' => true, ], +// 'empty_option' => "Sélectionner une entité ...", +// 'value_options' => [ +// Indicateur::ENTITY_LIBRE => 'Libre', +// Indicateur::ENTITY_ADAPTATIF => 'Adaptatif', +// Indicateur::ENTITY_AGENT => 'Agent', +// Indicateur::ENTITY_STRUCTURE => 'Structure', +// ] +// ], +// 'attributes' => [ +// 'id' => 'formations', +// 'class' => 'bootstrap-selectpicker show-tick', +// ], +// ]); + // perimetre $this->add([ 'type' => Select::class, - 'name' => 'entity', + 'name' => 'perimetre', 'options' => [ - 'label' => "Entity associé <span class='icon icon-obligatoire' title='champ obligatoire'></span> :", + 'label' => "Périmètres associés <span class='icon icon-information text-info' title='Sélection multiple possible'></span> :", 'label_options' => [ 'disable_html_escape' => true, ], - 'empty_option' => "Sélectionner une entité ...", - 'value_options' => [ - Indicateur::ENTITY_LIBRE => 'Libre', - Indicateur::ENTITY_ADAPTATIF => 'Adaptatif', - Indicateur::ENTITY_AGENT => 'Agent', - Indicateur::ENTITY_STRUCTURE => 'Structure', - ] + 'empty_option' => "Sélection des périmètres", + 'value_options' => $this->perimetres, ], 'attributes' => [ - 'id' => 'formations', - 'class' => 'bootstrap-selectpicker show-tick', + 'id' => 'perimetre', + 'class' => 'selectpicker show-tick', + 'multiple' => 'multiple', ], ]); - // perimetre + // roles autorises $this->add([ 'type' => Select::class, - 'name' => 'perimetre', + 'name' => 'roles_autorises', 'options' => [ - 'label' => "Périmètres associés <span class='icon icon-information text-info' title='Sélection multiple possible'></span> :", + 'label' => "Rôles autorisés <span class='icon icon-obligatoire' title='champ obligatoire'></span> <span class='icon icon-information text-info' title='Sélection multiple possible'></span> :", 'label_options' => [ 'disable_html_escape' => true, ], - 'empty_option' => "Sélection des périmètres", - 'value_options' => $this->perimetres, + 'value_options' => $listing, ], 'attributes' => [ 'id' => 'perimetre', @@ -197,10 +222,11 @@ class IndicateurForm extends Form { 'libelle' => [ 'required' => true, ], 'description' => [ 'required' => false, ], 'categorie' => [ 'required' => false, ], - 'namespace' => [ 'required' => false, ], +// 'namespace' => [ 'required' => false, ], 'view_id' => [ 'required' => true, ], - 'entity' => [ 'required' => true, ], +// 'entity' => [ 'required' => true, ], 'perimetre' => [ 'required' => false, ], + 'roles_autorises' => [ 'required' => true, ], 'requete' => [ 'required' => true, ], ])); } diff --git a/src/UnicaenIndicateur/Form/Indicateur/IndicateurFormFactory.php b/src/UnicaenIndicateur/Form/Indicateur/IndicateurFormFactory.php index 2460f496a4ed82b7b2dd5b4971e8bc47c1544623..db4ad50447db0a6ac997a75769ced8f2bfd98703 100644 --- a/src/UnicaenIndicateur/Form/Indicateur/IndicateurFormFactory.php +++ b/src/UnicaenIndicateur/Form/Indicateur/IndicateurFormFactory.php @@ -8,6 +8,7 @@ use Psr\Container\NotFoundExceptionInterface; use UnicaenIndicateur\Service\Categorie\CategorieService; use UnicaenIndicateur\Service\Indicateur\IndicateurService; use UnicaenIndicateur\Service\Perimetre\PerimetreServiceInterface; +use UnicaenUtilisateur\Service\Role\RoleService; class IndicateurFormFactory { @@ -22,9 +23,11 @@ class IndicateurFormFactory { /** * @var CategorieService $categorieService * @var IndicateurService $indicateurService - * @var IndicateurHydrator $hydrator */ + * @var IndicateurHydrator $hydrator + * @var RoleService $roleService */ $categorieService = $container->get(CategorieService::class); $indicateurService = $container->get(IndicateurService::class); + $roleService = $container->get(RoleService::class); $hydrator = $container->get('HydratorManager')->get(IndicateurHydrator::class); $config = $container->get('config'); @@ -37,6 +40,7 @@ class IndicateurFormFactory { $form = new IndicateurForm(); $form->setCategorieService($categorieService); $form->setIndicateurService($indicateurService); + $form->setRoleService($roleService); $form->setHydrator($hydrator); $form->setPerimetres($perimetres); return $form; diff --git a/src/UnicaenIndicateur/Form/Indicateur/IndicateurHydrator.php b/src/UnicaenIndicateur/Form/Indicateur/IndicateurHydrator.php index 0916cf0c250d514e2a2873f7ae87d8516711a8d1..7a5a085af914b5ae2919024b165b485f024b1a6f 100644 --- a/src/UnicaenIndicateur/Form/Indicateur/IndicateurHydrator.php +++ b/src/UnicaenIndicateur/Form/Indicateur/IndicateurHydrator.php @@ -18,10 +18,11 @@ class IndicateurHydrator implements HydratorInterface { 'libelle' => $object->getTitre(), 'description' => $object->getDescription(), 'categorie' => $object->getCategorie()?->getId(), - 'namespace' => $object->getNamespace(), +// 'namespace' => $object->getNamespace(), 'view_id' => $object->getViewId(), - 'entity' => $object->getEntity(), +// 'entity' => $object->getEntity(), 'perimetre' => ($object->getPerimetre())?explode(PerimetreServiceInterface::PERIMETRE_SEPARATOR, $object->getPerimetre()):null, + 'roles_autorises' => $object->getRolesAutorises()??null, 'requete' => $object->getRequete(), ]; return $data; @@ -31,20 +32,22 @@ class IndicateurHydrator implements HydratorInterface { { $code = (isset($data['code']) AND trim($data['code']) !== '')?trim($data['code']):null; $categorie = (isset($data['categorie']) && $data['categorie'] !== '')?$this->getCategorieService()->getCategorie($data['categorie']):null; - $namespace = (isset($data['namespace']) AND trim($data['namespace']) !== '')?trim($data['namespace']):null; +// $namespace = (isset($data['namespace']) AND trim($data['namespace']) !== '')?trim($data['namespace']):null; $perimetres = isset($data['perimetre'])?implode(PerimetreServiceInterface::PERIMETRE_SEPARATOR, $data['perimetre']):null; //HERE I AM// $perimetreIds = (isset($data['perimetre']) AND ($data['perimetre']) !== '')?explode(PerimetreServiceInterface::PERIMETRE_SEPARATOR, $data['perimetre']):null; + $rolesAutorises = isset($data['roles_autorises'])?implode(PerimetreServiceInterface::PERIMETRE_SEPARATOR, $data['roles_autorises']):null; /** @var Indicateur $object */ $object->setCode($code); $object->setTitre($data['libelle']); $object->setDescription($data['description']); $object->setCategorie($categorie); - $object->setNamespace($namespace); +// $object->setNamespace($namespace); $object->setPerimetre($perimetres); + $object->setRolesAutorises($rolesAutorises); $object->setViewId($data['view_id']); - $object->setEntity($data['entity']); +// $object->setEntity($data['entity']); $object->setRequete($data['requete']); return $object; } diff --git a/src/UnicaenIndicateur/Provider/Privilege/IndicateurPrivileges.php b/src/UnicaenIndicateur/Provider/Privilege/IndicateurPrivileges.php index af2982590733737dd4fd67d2f9e2fdeaaccd8c5c..167cc5033c904f383c0b66469466f6c68cc3aacb 100644 --- a/src/UnicaenIndicateur/Provider/Privilege/IndicateurPrivileges.php +++ b/src/UnicaenIndicateur/Provider/Privilege/IndicateurPrivileges.php @@ -9,6 +9,7 @@ class IndicateurPrivileges extends Privileges const INDICATEUR_MES_INDICATEURS = 'indicateur-indicateur_mes_indicateurs'; const INDICATEUR_INDEX = 'indicateur-indicateur_index'; const AFFICHER_INDICATEUR = 'indicateur-afficher_indicateur'; + const AFFICHER_INDICATEUR_TOUS = 'indicateur-afficher_indicateur_tous'; const EDITER_INDICATEUR = 'indicateur-editer_indicateur'; const DETRUIRE_INDICATEUR = 'indicateur-detruire_indicateur'; } \ No newline at end of file diff --git a/src/UnicaenIndicateur/Service/Indicateur/IndicateurService.php b/src/UnicaenIndicateur/Service/Indicateur/IndicateurService.php index 9693865e13cb356b0933673ccc99c593130b0f33..b4412347d0f0b0b54b2816c5f55d071aea5f18da 100644 --- a/src/UnicaenIndicateur/Service/Indicateur/IndicateurService.php +++ b/src/UnicaenIndicateur/Service/Indicateur/IndicateurService.php @@ -65,7 +65,7 @@ class IndicateurService $sql = "SELECT EXISTS (SELECT FROM pg_matviews WHERE matviewname='" . $viewname . "')"; $res = $this->getObjectManager()->getConnection()->executeQuery($sql, [], []); $tmp = $res->fetchAllAssociative(); - } catch (Exception $e) { + } catch (Exception) { return false; } return $tmp[0]['exists']; @@ -100,7 +100,7 @@ class IndicateurService } try { - $query = $this->getObjectManager()->getConnection()->prepare($sql); + $this->getObjectManager()->getConnection()->prepare($sql); } catch (DBA_Exception $e) { throw new RuntimeException("Un problème est survenu lors de la récupération de la session.", 0, $e); } @@ -269,7 +269,7 @@ class IndicateurService if ($rawdata === null) return null; $rubriques = []; - if ($indicateur->getEntity() === Indicateur::ENTITY_LIBRE) { + if ($indicateur->getEntity() === null OR $indicateur->getEntity() === Indicateur::ENTITY_LIBRE) { if (!empty($rawdata)) { foreach ($rawdata[0] as $key => $value) { $rubriques[] = $key; diff --git a/view/unicaen-indicateur/index/index.phtml b/view/unicaen-indicateur/index/index.phtml index 9d0e8100fde4544bf7bb10e5901f6635b6a5430d..92ae79c24da4919e6eb6faff1b8a16a472a4e838 100644 --- a/view/unicaen-indicateur/index/index.phtml +++ b/view/unicaen-indicateur/index/index.phtml @@ -1,16 +1,17 @@ <?php use UnicaenIndicateur\Entity\Db\Abonnement; +use UnicaenIndicateur\Provider\Privilege\AbonnementPrivileges; /** - * @see \Indicateur\Controller\IndexController::indexAction() + * @see \UnicaenIndicateur\Controller\IndexController::indexAction() * @var Abonnement[] $abonnements * @var int[] $result */ -$canLister = true; -$canAfficher = true; -$canDesabonnement = true; +$canLister = $this->isAllowed(AbonnementPrivileges::getResourceId(AbonnementPrivileges::AFFICHER_ABONNEMENT)); +$canAfficher = $this->isAllowed(AbonnementPrivileges::getResourceId(AbonnementPrivileges::AFFICHER_ABONNEMENT)); +$canDesabonnement = $this->isAllowed(AbonnementPrivileges::getResourceId(AbonnementPrivileges::DETRUIRE_ABONNEMENT)); ?> @@ -28,12 +29,12 @@ $canDesabonnement = true; <table class="table table-condensed table-hover"> <thead> - <tr> - <th> Indicateurs </th> - <th> Effectifs </th> - <th> Dernière maj </th> - <th> Action </th> - </tr> + <tr> + <th> Indicateurs</th> + <th> Effectifs</th> + <th> Dernière maj</th> + <th> Action</th> + </tr> </thead> <tbody> <?php foreach ($abonnements as $abonnement) : ?> @@ -43,12 +44,12 @@ $canDesabonnement = true; <td> <?php echo $abonnement->getIndicateur()->getDernierRafraichissement()->format('d/m/Y à H:i'); ?> </td> <td> <?php if ($canAfficher) : ?> - <?php /** @see \Indicateur\Controller\IndicateurController::afficherAction() */ ?> + <?php /** @see IndicateurController::afficherAction() */ ?> <a href="<?php echo $this->url('indicateur/afficher', ['indicateur' => $abonnement->getIndicateur()->getId()], [], true); ?>"> <span class="icon icon-voir"></span></a> <?php endif; ?> <?php if ($canDesabonnement) : ?> - <?php /** @see \Indicateur\Controller\AbonnementController::resilierAction() */ ?> + <?php /** @see AbonnementController::resilierAction() */ ?> <a href="<?php echo $this->url('abonnement/resilier', ['indicateur' => $abonnement->getIndicateur()->getId()], ['query' => ['retour' => $this->url('mes-indicateurs', [], [], true)]], true); ?>"> <span class="icon icon-unchecked"></span></a> <?php endif; ?> @@ -60,7 +61,7 @@ $canDesabonnement = true; <script> - $(function() { + $(function () { $("body").on("modification", function (event) { event.div.modal('hide'); window.location.reload(); diff --git a/view/unicaen-indicateur/indicateur/index.phtml b/view/unicaen-indicateur/indicateur/index.phtml index f042aa56754aa4d8615710592e783dd4240c19ed..e186dcf5e48c5a12143f3a86600da46a8084c740 100644 --- a/view/unicaen-indicateur/indicateur/index.phtml +++ b/view/unicaen-indicateur/indicateur/index.phtml @@ -6,6 +6,7 @@ * @var Categorie[] $categories * @var Indicateur[][] $indicateursByCategorie * @var Abonnement[] $abonnements + * @var RoleInterface $role */ use UnicaenIndicateur\Entity\Db\Abonnement; @@ -13,6 +14,7 @@ use UnicaenIndicateur\Entity\Db\Categorie; use UnicaenIndicateur\Entity\Db\Indicateur; use UnicaenIndicateur\Provider\Privilege\IndicateurPrivileges; use UnicaenIndicateur\Provider\Privilege\TableaudebordPrivileges; +use UnicaenUtilisateur\Entity\Db\RoleInterface; $canVoir = $this->isAllowed(IndicateurPrivileges::getResourceId(IndicateurPrivileges::AFFICHER_INDICATEUR)); $canEditer = $this->isAllowed(IndicateurPrivileges::getResourceId(IndicateurPrivileges::EDITER_INDICATEUR)); @@ -20,6 +22,8 @@ $canDetruire = $this->isAllowed(IndicateurPrivileges::getResourceId(IndicateurPr $canTableaux = $this->isAllowed(TableaudebordPrivileges::getResourceId(TableaudebordPrivileges::EDITER_TABLEAUDEBORD)); $canCategories = $this->isAllowed(IndicateurPrivileges::getResourceId(IndicateurPrivileges::EDITER_INDICATEUR)); + +$canAfficherTous = $this->isAllowed(IndicateurPrivileges::getResourceId(IndicateurPrivileges::AFFICHER_INDICATEUR_TOUS)); ?> <div class="row"> @@ -66,7 +70,13 @@ $canCategories = $this->isAllowed(IndicateurPrivileges::getResourceId(Indicateur <?php endif; ?> <?php foreach ($categories as $categorie) : ?> - <div class="card"> + <?php + $valides = $indicateursByCategorie[$categorie->getId()]; + if (!$canAfficherTous) $valides = array_filter($indicateursByCategorie[$categorie->getId()], function(Indicateur $indicateur) use ($role) { return $indicateur->isAutorise($role); }); + ?> + + <?php if (!empty ($valides)) : ?> + <div class="card"> <div class="card-header bg-default"> <strong><?php echo $categorie->getCode(); ?> </strong> <?php echo $categorie->getLibelle(); ?> </div> @@ -83,7 +93,7 @@ $canCategories = $this->isAllowed(IndicateurPrivileges::getResourceId(Indicateur </tr> </thead> <tbody> - <?php foreach ($indicateursByCategorie[$categorie->getId()] as $indicateur) : ?> + <?php foreach ($valides as $indicateur) : ?> <tr> <td> <?php echo $indicateur->getCode(); ?> </td> <td> <?php echo $indicateur->getNbElements(); ?> </td> @@ -148,6 +158,7 @@ $canCategories = $this->isAllowed(IndicateurPrivileges::getResourceId(Indicateur </table> </div> </div> + <?php endif; ?> <?php endforeach; ?> <script>