diff --git a/src/UnicaenUtilisateur/Acl/NamedRole.php b/src/UnicaenUtilisateur/Acl/NamedRole.php index ed45c999fba2a6f8b242f020b5f9565a59436f83..db2b2293b65b03b536bd89954922a31cfbf0bab3 100644 --- a/src/UnicaenUtilisateur/Acl/NamedRole.php +++ b/src/UnicaenUtilisateur/Acl/NamedRole.php @@ -1,14 +1,13 @@ <?php namespace UnicaenUtilisateur\Acl; +use BjyAuthorize\Acl\Role; use Laminas\Permissions\Acl\Role\RoleInterface; /** * Rôle avec nom explicite (humainement intelligible). - * - * @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr> */ -class NamedRole extends \BjyAuthorize\Acl\Role +class NamedRole extends Role { /** * @var string @@ -31,11 +30,11 @@ class NamedRole extends \BjyAuthorize\Acl\Role * * @param string|null $id * @param RoleInterface|string|null $parent - * @param string $name - * @param string $description + * @param string|null $name + * @param string|null $description * @param bool $selectable */ - public function __construct($id = null, $parent = null, $name = null, $description = null, $selectable = true) + public function __construct($id = null, $parent = null, ?string $name = null, ?string $description = null, bool $selectable = true) { parent::__construct($id, $parent); @@ -60,7 +59,7 @@ class NamedRole extends \BjyAuthorize\Acl\Role * * @return string */ - public function getRoleName() + public function getRoleName() : string { return $this->roleName; } @@ -71,9 +70,9 @@ class NamedRole extends \BjyAuthorize\Acl\Role * @param string $roleName * @return self */ - public function setRoleName($roleName) + public function setRoleName(string $roleName) : NamedRole { - $this->roleName = (string) $roleName; + $this->roleName = $roleName; return $this; } @@ -82,7 +81,7 @@ class NamedRole extends \BjyAuthorize\Acl\Role * * @return string */ - public function getRoleDescription() + public function getRoleDescription() : string { return $this->roleDescription; } @@ -90,12 +89,12 @@ class NamedRole extends \BjyAuthorize\Acl\Role /** * Spécifie la description du rôle. * - * @param string $roleDescription + * @param string|null $roleDescription * @return self */ - public function setRoleDescription($roleDescription) + public function setRoleDescription(?string $roleDescription) : NamedRole { - $this->roleDescription = (string) $roleDescription; + $this->roleDescription = $roleDescription; return $this; } @@ -106,7 +105,7 @@ class NamedRole extends \BjyAuthorize\Acl\Role * * @return bool */ - public function getSelectable() + public function getSelectable() : bool { return $this->selectable; } @@ -119,7 +118,7 @@ class NamedRole extends \BjyAuthorize\Acl\Role * @param bool $selectable * @return NamedRole */ - public function setSelectable($selectable = true) + public function setSelectable(bool $selectable = true) : NamedRole { $this->selectable = $selectable; return $this; diff --git a/src/UnicaenUtilisateur/Controller/RoleController.php b/src/UnicaenUtilisateur/Controller/RoleController.php index 59956be83bbec4bcb00ea9525665f199e0855cf0..9b8109ec52ddc19078ee07820d53af1489eae4de 100644 --- a/src/UnicaenUtilisateur/Controller/RoleController.php +++ b/src/UnicaenUtilisateur/Controller/RoleController.php @@ -10,7 +10,6 @@ use UnicaenUtilisateur\Entity\Db\RoleInterface; use UnicaenUtilisateur\Entity\Db\UserInterface; use UnicaenUtilisateur\Form\Role\RoleFormAwareTrait; use UnicaenUtilisateur\Service\Role\RoleServiceAwareTrait; -use Laminas\Http\Request; use Laminas\Mvc\Controller\AbstractActionController; use Laminas\Mvc\Plugin\FlashMessenger\FlashMessenger; use Laminas\View\Model\ViewModel; @@ -29,19 +28,18 @@ class RoleController extends AbstractActionController { $this->identityProviders = $provider; } - public function indexAction() + public function indexAction() : ViewModel { /** @var RoleInterface[] $roles */ $roles = $this->roleService->findAll(); return new ViewModel([ - 'title' => "Gestion des rôles", 'roles' => $roles, 'identityproviders' => $this->identityProviders, ]); } - public function exporterAction() + public function exporterAction() : CsvModel { $role = $this->roleService->getRequestedRole($this); @@ -84,7 +82,7 @@ class RoleController extends AbstractActionController { return $CSV; } - public function ajouterAction() + public function ajouterAction() : ViewModel { $role = $this->roleService->getEntityInstance(); $form = $this->roleForm; @@ -113,7 +111,7 @@ class RoleController extends AbstractActionController { return $view; } - public function modifierAction() + public function modifierAction() : ViewModel { $role = $this->roleService->getRequestedRole($this); $form = $this->roleForm; @@ -142,8 +140,9 @@ class RoleController extends AbstractActionController { return $view; } - public function supprimerAction() + public function supprimerAction() : array { + $role = null; try { $role = $this->roleService->getRequestedRole($this); $this->roleService->delete($role); diff --git a/src/UnicaenUtilisateur/Controller/RoleControllerFactory.php b/src/UnicaenUtilisateur/Controller/RoleControllerFactory.php index cd0b401d70602c72383bf0ce189eb27d19c97ffa..7ee8ac952ff512c2d543fd7e4fad44730c9127cd 100644 --- a/src/UnicaenUtilisateur/Controller/RoleControllerFactory.php +++ b/src/UnicaenUtilisateur/Controller/RoleControllerFactory.php @@ -3,20 +3,22 @@ namespace UnicaenUtilisateur\Controller; use Interop\Container\ContainerInterface; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\NotFoundExceptionInterface; use UnicaenUtilisateur\Form\Role\RoleForm; use UnicaenUtilisateur\Service\Role\RoleService; class RoleControllerFactory { /** - * Create controller - * * @param ContainerInterface $container * @param string $requestedName * @param array|null $options * @return RoleController|object + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ - public function __invoke(ContainerInterface $container, $requestedName, array $options = null) + public function __invoke(ContainerInterface $container, string $requestedName, array $options = null) { /** * @var RoleService $roleService diff --git a/src/UnicaenUtilisateur/Controller/UtilisateurController.php b/src/UnicaenUtilisateur/Controller/UtilisateurController.php index 26dcd347d3d231b8565e12e468e95c48293863f2..dc0b393b8d8081d3686ac8566eec67efd3af624e 100644 --- a/src/UnicaenUtilisateur/Controller/UtilisateurController.php +++ b/src/UnicaenUtilisateur/Controller/UtilisateurController.php @@ -4,6 +4,7 @@ namespace UnicaenUtilisateur\Controller; use BjyAuthorize\Provider\Identity\ProviderInterface; use DateTime; +use Exception; use UnicaenApp\Service\EntityManagerAwareTrait; use UnicaenApp\View\Model\CsvModel; use UnicaenUtilisateur\Entity\Db\UserInterface; @@ -13,7 +14,6 @@ use UnicaenUtilisateur\Service\RechercheIndividu\RechercheIndividuResultatInterf use UnicaenUtilisateur\Service\RechercheIndividu\RechercheIndividuServiceInterface; use UnicaenUtilisateur\Service\Role\RoleServiceAwareTrait; use UnicaenUtilisateur\Service\User\UserServiceAwareTrait; -use Laminas\Http\Request; use Laminas\Mvc\Controller\AbstractActionController; use Laminas\Mvc\Plugin\FlashMessenger\FlashMessenger; use Laminas\View\Model\JsonModel; @@ -42,24 +42,18 @@ class UtilisateurController extends AbstractActionController /** * @param $searchServices - * @return self */ - public function setSearchServices($searchServices) + public function setSearchServices($searchServices) : void { $this->searchServices = $searchServices; - - return $this; } /** * @param $provider - * @return self */ - public function setIdentityProvider($provider) + public function setIdentityProvider($provider) : void { $this->identityProvider = $provider; - - return $this; } public function indexAction() @@ -196,6 +190,7 @@ class UtilisateurController extends AbstractActionController public function changerStatutAction() { + $utilisateur = null; try { $utilisateur = $this->userService->getRequestedUser($this); $utilisateur = $this->userService->changeStatus($utilisateur); @@ -214,6 +209,7 @@ class UtilisateurController extends AbstractActionController public function supprimerAction() { + $utilisateur = null; try { $utilisateur = $this->userService->getRequestedUser($this); $this->userService->delete($utilisateur); @@ -269,7 +265,7 @@ class UtilisateurController extends AbstractActionController return new JsonModel($result); } - public function listerAction() + public function listerAction() : ViewModel { $users = $this->userService->findAll(); @@ -279,7 +275,7 @@ class UtilisateurController extends AbstractActionController ]); } - public function exporterAction() + public function exporterAction() : CsvModel { $users = $this->userService->findAll(); $headers = [ 'Identifiant de connexion', 'Nom', 'Activé', 'Rôle']; diff --git a/src/UnicaenUtilisateur/Controller/UtilisateurControllerFactory.php b/src/UnicaenUtilisateur/Controller/UtilisateurControllerFactory.php index 66a7959cbfb2b9d5433f4feca13e64b96cd6daac..83f39a434b862ef95d84dd74c25a6f941969ac72 100644 --- a/src/UnicaenUtilisateur/Controller/UtilisateurControllerFactory.php +++ b/src/UnicaenUtilisateur/Controller/UtilisateurControllerFactory.php @@ -2,9 +2,9 @@ namespace UnicaenUtilisateur\Controller; -use Application\Provider\IdentityProvider; -use Doctrine\ORM\EntityManager; use Interop\Container\ContainerInterface; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\NotFoundExceptionInterface; use UnicaenUtilisateur\Form\User\UserForm; use UnicaenUtilisateur\Form\User\UserRechercheForm; use UnicaenUtilisateur\Service\RechercheIndividu\RechercheIndividuServiceInterface; @@ -15,14 +15,14 @@ class UtilisateurControllerFactory { /** - * Create controller - * * @param ContainerInterface $container * @param string $requestedName * @param array|null $options * @return UtilisateurController|object + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ - public function __invoke(ContainerInterface $container, $requestedName, array $options = null) + public function __invoke(ContainerInterface $container, string $requestedName, array $options = null) { /** * @var RoleService $roleService diff --git a/src/UnicaenUtilisateur/Entity/Db/AbstractRole.php b/src/UnicaenUtilisateur/Entity/Db/AbstractRole.php index 2079f017515a962c957dff7fa827d99c1ff96316..38a7cdb33c323169f6fc124bbd95dc2b64f74984 100644 --- a/src/UnicaenUtilisateur/Entity/Db/AbstractRole.php +++ b/src/UnicaenUtilisateur/Entity/Db/AbstractRole.php @@ -19,7 +19,7 @@ abstract class AbstractRole implements RoleInterface protected $roleId; /** - * @var libelle + * @var string */ protected $libelle; @@ -78,9 +78,9 @@ abstract class AbstractRole implements RoleInterface /** * Get id. * - * @return int + * @return int|null */ - public function getId() + public function getId() : ?int { return $this->id; } diff --git a/src/UnicaenUtilisateur/Service/Role/RoleService.php b/src/UnicaenUtilisateur/Service/Role/RoleService.php index 970409d822c9c5436b5da0720e686696ec7d5d01..4a23449666e096c4ca3a947c6f27158c270ab036 100644 --- a/src/UnicaenUtilisateur/Service/Role/RoleService.php +++ b/src/UnicaenUtilisateur/Service/Role/RoleService.php @@ -3,14 +3,12 @@ namespace UnicaenUtilisateur\Service\Role; use Doctrine\ORM\EntityRepository; -use Doctrine\ORM\NonUniqueResultException; use Doctrine\ORM\ORMException; -use Doctrine\ORM\QueryBuilder; +use InvalidArgumentException; +use Laminas\Mvc\Controller\AbstractActionController; use UnicaenApp\Service\EntityManagerAwareTrait; -use UnicaenUtilisateur\Entity\Db\AbstractRole; use UnicaenUtilisateur\Entity\Db\RoleInterface; use UnicaenUtilisateur\Exception\RuntimeException; -use Laminas\Mvc\Controller\AbstractActionController; class RoleService { @@ -26,7 +24,7 @@ class RoleService * @param string $roleEntityClass * @return void */ - public function setRoleEntityClass($roleEntityClass) + public function setRoleEntityClass(string $roleEntityClass) { if (! class_exists($roleEntityClass) || ! in_array(RoleInterface::class, class_implements($roleEntityClass))) { throw new InvalidArgumentException("L'entité associée aux rôles doit implémenter " . RoleInterface::class); @@ -38,7 +36,7 @@ class RoleService /** * @return string */ - public function getEntityClass() + public function getEntityClass() : string { return $this->roleEntityClass; } @@ -62,10 +60,10 @@ class RoleService } /** - * @param mixed $id + * @param ?int $id * @return RoleInterface|null */ - public function find($id) + public function find(?int $id) { return $this->getRepo()->find($id); } @@ -99,7 +97,7 @@ class RoleService /** * @return array */ - public function getRolesAsOptions() + public function getRolesAsOptions() : array { $roles = $this->findAll(); $result = []; @@ -116,7 +114,7 @@ class RoleService * @param string $paramName * @return RoleInterface */ - public function getRequestedRole(AbstractActionController $controller, string $paramName = 'role') + public function getRequestedRole(AbstractActionController $controller, string $paramName = 'role') : RoleInterface { $id = $controller->params()->fromRoute($paramName); $role = $this->find($id); @@ -128,7 +126,7 @@ class RoleService * @param RoleInterface $role * @return RoleInterface */ - public function create(RoleInterface $role) + public function create(RoleInterface $role) : RoleInterface { try { $this->getEntityManager()->persist($role); @@ -144,7 +142,7 @@ class RoleService * @param RoleInterface $role * @return RoleInterface */ - public function update(RoleInterface $role) + public function update(RoleInterface $role) : RoleInterface { try { $this->getEntityManager()->flush($role); @@ -159,7 +157,7 @@ class RoleService * @param RoleInterface $role * @return RoleInterface */ - public function delete(RoleInterface $role) + public function delete(RoleInterface $role) : RoleInterface { try { $this->getEntityManager()->remove($role); diff --git a/view/unicaen-utilisateur/role/index.phtml b/view/unicaen-utilisateur/role/index.phtml index ac89a59587b0bdc9970be85515fb6338856e569f..348823878c6bd7140bf90a9ad982b0085a2d1eb8 100644 --- a/view/unicaen-utilisateur/role/index.phtml +++ b/view/unicaen-utilisateur/role/index.phtml @@ -17,12 +17,12 @@ $canAjouter = $this->isAllowed(RolePrivileges::getResourceId(RolePrivileges: $canModifier = $this->isAllowed(RolePrivileges::getResourceId(RolePrivileges::ROLE_MODIFIER)); $canEffacer = $this->isAllowed(RolePrivileges::getResourceId(RolePrivileges::ROLE_EFFACER)); -?> +$this->headTitle("Rôles"); -<?php $this->headTitle($this->translate($title)) ?> +?> <h1 class="page-header"> - <?php echo $title; ?> + Rôles <span class="badge"><?php echo count($roles); ?></span> </h1> @@ -41,7 +41,7 @@ $canEffacer = $this->isAllowed(RolePrivileges::getResourceId(RolePrivileges: <?php endif; ?> -<div class="card border-default mb-3"> +<div class="card"> <div class="card-header bg-default"> <h2> Liste des rôles @@ -166,9 +166,7 @@ $canEffacer = $this->isAllowed(RolePrivileges::getResourceId(RolePrivileges: $("body").on("event-unicaen-role-editer", function (event) { event.div.modal('hide'); window.location.reload(); - }); - - $("body").on("event-unicaen-role-supprimer", function (event) { + }).on("event-unicaen-role-supprimer", function (event) { window.location.reload(); }); @@ -194,7 +192,7 @@ $canEffacer = $this->isAllowed(RolePrivileges::getResourceId(RolePrivileges: "next": "<i class=\"fas fa-chevron-right\"></i>" } }, - "createdRow": function (row, data, index) { + "createdRow": function (row) { $('.pop-ajax', row).popAjax(); }, }); diff --git a/view/unicaen-utilisateur/utilisateur/index.phtml b/view/unicaen-utilisateur/utilisateur/index.phtml index ae2be8ada82031ba7867f350d8e5354f585cae21..0b4adc7b4e857fa55bce86428b3318411f40b64f 100644 --- a/view/unicaen-utilisateur/utilisateur/index.phtml +++ b/view/unicaen-utilisateur/utilisateur/index.phtml @@ -4,7 +4,6 @@ use UnicaenUtilisateur\Controller\UtilisateurController; use UnicaenUtilisateur\Entity\Db\RoleInterface; use UnicaenUtilisateur\Entity\Db\UserInterface; use UnicaenUtilisateur\Form\User\UserRechercheForm; -use UnicaenUtilisateur\Provider\Privilege\Privileges; use UnicaenUtilisateur\Provider\Privilege\UtilisateurPrivileges; /** @@ -164,7 +163,8 @@ $canCreerLocal = $canAjouter; <button type='submit' class='btn btn-success'><i class='fas fa-check'></i> Oui</button> <button type='button' class='btn btn-danger pop-ajax-hide'><i class='fas fa-times'></i> Non</button> </div> - </div>"> + </div>" + > <i class="fas fa-user-times"></i> Suspendre </a> @@ -176,15 +176,14 @@ $canCreerLocal = $canAjouter; data-submit-close="true" data-submit-event="event-unicaen-utilisateur-changer-statut" title="Activer l'utilisateur" - data-title="Activation de l'utilisateur - data-confirm-button="" - data-cancel-button="" - data-content="<p>Voulez-vous activer - l'utilisateur ?</p> - <div class='text-center'> - <div class='btn-group'> - <button type='submit' class='btn btn-success'><i class='fas fa-check'></i> Oui</button> - <button type='button' class='btn btn-danger pop-ajax-hide'><i class='fas fa-times'></i> Non + data-title="Activation de l'utilisateur" + data-confirm-button=" + data-cancel-button='' + data-content='<p>Voulez-vous activer l\'utilisateur ?</p> + <div class=\'text-center\'> + <div class=\'btn-group\'> + <button type=\'submit\' class=\'btn btn-success\'><i class=\'fas fa-check\'></i> Oui</button> + <button type=\'button\' class=\'btn btn-danger pop-ajax-hide\'><i class=\'fas fa-times\'></i> Non </button> </div> </div>"> @@ -297,9 +296,7 @@ $canCreerLocal = $canAjouter; function (event) { event.div.modal('hide'); window.location.reload(); - }); - - $("body").on("event-unicaen-utilisateur-changer-statut " + + }).on("event-unicaen-utilisateur-changer-statut " + "event-unicaen-utilisateur-supprimer", function (event) { window.location.reload(); @@ -333,13 +330,13 @@ $canCreerLocal = $canAjouter; }, }) .autocomplete("instance")._renderItem = function (ul, item) { - var template = '<span id=\"{id}\">{label} <span class=\"extra\">{extra}</span></span>'; - var markup = template + let template = '<span id=\"{id}\">{label} <span class=\"extra\">{extra}</span></span>'; + let markup = template .replace('{id}', item.id ? item.id : '') .replace('{label}', item.label ? item.label : '') .replace('{extra}', item.extra ? item.extra : ''); markup = '<a id="autocomplete-item-' + item.id + '">' + markup + "</a>"; - var li = $("<li></li>"); + let li = $("<li></li>"); if (item.id) { const t = item.id.split("||"); if (t[0] == 'app') { @@ -360,7 +357,7 @@ $canCreerLocal = $canAjouter; }; $('form').on('submit', function () { - var btn = $(this).find('button[type="submit"]:first'); + let btn = $(this).find('button[type="submit"]:first'); btn.attr("disabled", "disabled") .find('i').attr('class', 'fas fa-pulse fa-spinner'); }); @@ -432,7 +429,5 @@ $canCreerLocal = $canAjouter; cursor: pointer; } - .text-highlight { - color: #919191; - } + </style> \ No newline at end of file diff --git a/view/unicaen-utilisateur/utilisateur/lister.phtml b/view/unicaen-utilisateur/utilisateur/lister.phtml index f537a74c7217afc5970df4c448b34a462363047c..b1bdb2273b044cc777cff9a5d1c1f581d4cb9d2e 100644 --- a/view/unicaen-utilisateur/utilisateur/lister.phtml +++ b/view/unicaen-utilisateur/utilisateur/lister.phtml @@ -4,6 +4,7 @@ use UnicaenUtilisateur\Entity\Db\UserInterface; /** * @var UserInterface[] $users + * @var string $title */ ?> @@ -94,14 +95,14 @@ use UnicaenUtilisateur\Entity\Db\UserInterface; "next": "<i class=\"fas fa-chevron-right\"></i>" } }, - "createdRow": function (row, data, index) { + "createdRow": function (row) { $('.pop-ajax', row).popAjax(); }, }); } $('#utilisateur-liste tbody').on('click', 'tr', function () { - var href = $(this).find("a").attr("href"); + let href = $(this).find("a").attr("href"); if (href) { window.location.href = href; }