From 7fc79b1c78e707c1be36d73495ef491b5b80ced1 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Metivier <jean-philippe.metivier@unicaen.fr> Date: Thu, 16 Feb 2023 12:37:56 +0100 Subject: [PATCH] =?UTF-8?q?=20Ajout=20du=20champs=20description=20pour=20l?= =?UTF-8?q?es=20r=C3=B4les=20+=20Ajout=20d'un=20view=20helper=20pour=20l'a?= =?UTF-8?q?ffichage=20des=20r=C3=B4les?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/module.config.php | 4 + data/sql/schema_oracle.sql | 1 + data/sql/schema_postgresql.sql | 1 + readme.md | 8 + .../Entity/Db/AbstractRole.php | 283 ++++-------------- .../UnicaenUtilisateur.Entity.Db.Role.dcm.xml | 2 +- .../Entity/Db/RoleInterface.php | 196 ++---------- src/UnicaenUtilisateur/Form/Role/RoleForm.php | 17 +- .../View/Helper/RoleViewHelper.php | 29 ++ .../View/Helper/partial/role.phtml | 17 ++ view/unicaen-utilisateur/role/index.phtml | 4 +- 11 files changed, 161 insertions(+), 401 deletions(-) create mode 100644 src/UnicaenUtilisateur/View/Helper/RoleViewHelper.php create mode 100644 src/UnicaenUtilisateur/View/Helper/partial/role.phtml diff --git a/config/module.config.php b/config/module.config.php index 6cd5bd7..8d564f3 100644 --- a/config/module.config.php +++ b/config/module.config.php @@ -4,6 +4,7 @@ use Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain; use Doctrine\ORM\Mapping\Driver\XmlDriver; use UnicaenUtilisateur\ORM\Event\Listeners\HistoriqueListener; use UnicaenUtilisateur\ORM\Event\Listeners\HistoriqueListenerFactory; +use UnicaenUtilisateur\View\Helper\RoleViewHelper; use UnicaenUtilisateur\View\Helper\UserConnection; use UnicaenUtilisateur\View\Helper\UserConnectionFactory; use UnicaenUtilisateur\View\Helper\UserCurrent; @@ -78,6 +79,9 @@ return [ ], 'view_helpers' => [ + 'invokables' => [ + 'role' => RoleViewHelper::class, + ], 'aliases' => [ 'userCurrent' => UserCurrent::class, 'userStatus' => UserStatus::class, diff --git a/data/sql/schema_oracle.sql b/data/sql/schema_oracle.sql index ea1882d..d191807 100644 --- a/data/sql/schema_oracle.sql +++ b/data/sql/schema_oracle.sql @@ -7,6 +7,7 @@ CREATE TABLE UNICAEN_UTILISATEUR_ROLE ( ID NUMBER(*, 0) NOT NULL, ROLE_ID VARCHAR2(64) NOT NULL, LIBELLE VARCHAR2(255) NOT NULL, + DESCRIPTION CLOB NOT NULL, IS_DEFAULT NUMBER(1) DEFAULT 0 NOT NULL, IS_AUTO NUMBER(1) DEFAULT 0 NOT NULL, PARENT_ID NUMBER(*, 0), diff --git a/data/sql/schema_postgresql.sql b/data/sql/schema_postgresql.sql index 3de3fb2..fa212d8 100644 --- a/data/sql/schema_postgresql.sql +++ b/data/sql/schema_postgresql.sql @@ -5,6 +5,7 @@ CREATE TABLE UNICAEN_UTILISATEUR_ROLE ( ID SERIAL PRIMARY KEY, ROLE_ID VARCHAR(64) NOT NULL, LIBELLE VARCHAR(255) NOT NULL, + DESCRIPTION TEXT NOT NULL, IS_DEFAULT BOOLEAN DEFAULT false NOT NULL, IS_AUTO BOOLEAN DEFAULT false NOT NULL, PARENT_ID INTEGER, diff --git a/readme.md b/readme.md index 3ff4090..4b41922 100644 --- a/readme.md +++ b/readme.md @@ -2,6 +2,14 @@ Module Unicaen Utilisateur ======================= ------------------------ +Changelogs +========== + +**5.0.7** +* Ajout du champs description pour les rôles +* Ajout d'un view helper pour l'affichage des rôles ```echo $this->role($role)``` +* Début de nettoyage des classes vers la syntaxe PHP8 + Description ======================= diff --git a/src/UnicaenUtilisateur/Entity/Db/AbstractRole.php b/src/UnicaenUtilisateur/Entity/Db/AbstractRole.php index 38a7cdb..771452c 100644 --- a/src/UnicaenUtilisateur/Entity/Db/AbstractRole.php +++ b/src/UnicaenUtilisateur/Entity/Db/AbstractRole.php @@ -8,325 +8,152 @@ use UnicaenPrivilege\Entity\Db\PrivilegeInterface; abstract class AbstractRole implements RoleInterface { - /** - * @var int - */ - protected $id; - - /** - * @var string - */ - protected $roleId; - - /** - * @var string - */ - protected $libelle; - - /** - * @var boolean - */ - protected $default = false; - - /** - * @var boolean - */ - protected $auto = false; - - /** - * @var RoleInterface - */ - protected $parent; - - /** - * @var string - */ - protected $ldapFilter; - - /** - * @var boolean - */ - protected $accessibleExterieur = true; - - /** - * @var ArrayCollection - */ - protected $users; - - /** - * @var ArrayCollection - */ - protected $privileges; - - - /** - * AbstractRole constructor. - */ + protected ?int $id = null; + protected ?string $roleId = null; + protected ?string $libelle = null; + protected ?string $description = null; + protected bool $default = false; + protected bool $auto = false; + protected ?RoleInterface $parent = null; + protected ?string $ldapFilter = null; + protected bool $accessibleExterieur = true; + + protected Collection $users; + protected Collection $privileges; + + public function __construct() { $this->users = new ArrayCollection(); + $this->privileges = new ArrayCollection(); } - /** - * @return string - */ - public function __toString() - { - return $this->getLibelle(); - } - - /** - * Get id. - * - * @return int|null - */ public function getId() : ?int { return $this->id; } - /** - * Set id. - * - * @param int $id - * @return RoleInterface - */ - public function setId($id) + public function setId(?int $id) : void { $this->id = (int)$id; - - return $this; } - /** - * Get roleId. - * - * @return string - */ - public function getRoleId() + public function getRoleId() : ?string { return $this->roleId; } - /** - * Set roleId. - * - * @param string $roleId - * @return RoleInterface - */ - public function setRoleId($roleId) + public function setRoleId(?string $roleId) : void { $this->roleId = (string)$roleId; - - return $this; } - /** - * Get libelle. - * - * @return string - */ - public function getLibelle() + public function getLibelle() : ?string { return $this->libelle; } - /** - * Set libelle. - * - * @param string|null $libelle - * @return RoleInterface - */ - public function setLibelle($libelle) + public function setLibelle(?string $libelle) : void { $this->libelle = $libelle; - return $this; } - /** - * Is this role the default one ? - * - * @return boolean - */ - public function isDefault() + public function getDescription(): ?string { - return $this->default; + return $this->description; } - /** - * Set this role as the default one. - * - * @param boolean $default - * @return RoleInterface - */ - public function setDefault($default) + public function setDescription(?string $description): void { - $this->default = (boolean)$default; + $this->description = $description; + } + - return $this; + public function isDefault() : bool + { + return $this->default; } - /** - * Is auto ? - * - * @return boolean - */ - public function isAuto() + public function setDefault(bool $default) : void + { + $this->default = (boolean) $default; + } + + public function isAuto() : bool { return $this->auto; } - /** - * Set auto. - * - * @param boolean $auto - * @return RoleInterface - */ - public function setAuto($auto) + public function setAuto(bool $auto) : void { $this->auto = $auto; - - return $this; } - /** - * Is accessible from the outside ? - * - * @return boolean - */ - public function isAccessibleExterieur() + public function isAccessibleExterieur() : bool { return $this->accessibleExterieur; } - /** - * Set accessible from the outside. - * - * @param boolean $accessibleExterieur - * @return RoleInterface - */ - public function setAccessibleExterieur($accessibleExterieur) + public function setAccessibleExterieur(bool $accessibleExterieur) : void { $this->accessibleExterieur = $accessibleExterieur; - - return $this; } - /** - * Get the parent role - * - * @return RoleInterface - */ - public function getParent() + public function getParent() : ?RoleInterface { return $this->parent; } - /** - * Set the parent role. - * - * @param RoleInterface|null $parent - * @return RoleInterface - */ - public function setParent(?RoleInterface $parent = null) + public function setParent(?RoleInterface $parent = null) : void { $this->parent = $parent; - - return $this; } - /** - * Get ldapFilter. - * - * @return string - */ - public function getLdapFilter() + public function getLdapFilter() : ?string { return $this->ldapFilter; } - /** - * Set ldapFilter. - * - * @param string $ldapFilter - * @return RoleInterface - */ - public function setLdapFilter($ldapFilter) + public function setLdapFilter(?string $ldapFilter) : void { $this->ldapFilter = $ldapFilter; - - return $this; } - /** - * Get users. - * - * @return Collection - */ - public function getUsers() + public function getUsers() : Collection { return $this->users; } - /** - * Add user. - * - * @param UserInterface $user - * @return RoleInterface - */ - public function addUser(UserInterface $user) + public function addUser(UserInterface $user) : void { $this->users->add($user); - - return $this; } - /** - * Remove user. - * - * @param UserInterface $user - * @return RoleInterface - */ - public function removeUser(UserInterface $user) + public function removeUser(UserInterface $user) : void { $this->users->removeElement($user); - - return $this; } - /** - * Get privileges. - * - * @return Collection - */ - public function getPrivileges() + public function getPrivileges() : Collection { return $this->privileges; } - /** - * Add privilege. - * - * @param PrivilegeInterface $privilege - * @return RoleInterface - */ - public function addPrivilege(PrivilegeInterface $privilege) + public function addPrivilege(PrivilegeInterface $privilege) : void { $this->privileges->add($privilege); - - return $this; } - /** - * Remove privilege. - * - * @param PrivilegeInterface $privilege - * @return RoleInterface - */ - public function removePrivilege(PrivilegeInterface $privilege) + public function removePrivilege(PrivilegeInterface $privilege) : void { $this->privileges->removeElement($privilege); + } + + /** Fonctions magiques ********************************************************************************************/ - return $this; + public function __toString() : string + { + return $this->getLibelle(); } + } \ No newline at end of file diff --git a/src/UnicaenUtilisateur/Entity/Db/Mapping/UnicaenUtilisateur.Entity.Db.Role.dcm.xml b/src/UnicaenUtilisateur/Entity/Db/Mapping/UnicaenUtilisateur.Entity.Db.Role.dcm.xml index 071f739..6e80e0c 100644 --- a/src/UnicaenUtilisateur/Entity/Db/Mapping/UnicaenUtilisateur.Entity.Db.Role.dcm.xml +++ b/src/UnicaenUtilisateur/Entity/Db/Mapping/UnicaenUtilisateur.Entity.Db.Role.dcm.xml @@ -19,9 +19,9 @@ <generator strategy="IDENTITY"/> </id> -<!-- <field name="id" type="integer" column="ID" nullable="false"/>--> <field name="roleId" type="string" column="ROLE_ID" length="64" nullable="false"/> <field name="libelle" type="string" column="LIBELLE" length="64" nullable="false"/> + <field name="description" type="string" column="DESCRIPTION" length="9999" nullable="false"/> <field name="default" type="boolean" column="IS_DEFAULT" nullable="false"/> <field name="auto" type="boolean" column="IS_AUTO" nullable="false"/> <field name="ldapFilter" type="string" column="LDAP_FILTER" length="255" nullable="true"/> diff --git a/src/UnicaenUtilisateur/Entity/Db/RoleInterface.php b/src/UnicaenUtilisateur/Entity/Db/RoleInterface.php index 27213dc..60a2169 100644 --- a/src/UnicaenUtilisateur/Entity/Db/RoleInterface.php +++ b/src/UnicaenUtilisateur/Entity/Db/RoleInterface.php @@ -8,174 +8,34 @@ use UnicaenPrivilege\Entity\Db\PrivilegeInterface; interface RoleInterface extends HierarchicalRoleInterface { - /** - * @return string - */ - public function __toString(); + public function __toString() : string; + + public function getId() : ?int; + public function setId(?int $id) : void; + public function getRoleId() : ?string; + public function setRoleId(?string $roleId) : void; + public function getLibelle() : ?string; + public function setLibelle(?string $libelle) : void; + public function getDescription() : ?string; + public function setDescription(?string $description) : void; + + public function isDefault() : bool; + public function setDefault(bool $default) : void; + public function isAuto() : bool; + public function setAuto(bool $auto) : void; + public function isAccessibleExterieur() : bool; + public function setAccessibleExterieur(bool $accessibleExterieur) : void; + + public function getParent() : ?RoleInterface; + public function setParent(?RoleInterface $parent = null) : void; + public function getLdapFilter() : ?string; + public function setLdapFilter(?string $ldapFilter) : void; + + public function getUsers() : Collection; + public function addUser(UserInterface $user) : void; + public function removeUser(UserInterface $user) : void; - /** - * Get id. - * - * @return int - */ - public function getId(); - - /** - * Set id. - * - * @param int $id - * @return self - */ - public function setId($id); - - /** - * Get roleId. - * - * @return string - */ - public function getRoleId(); - - /** - * Set roleId. - * - * @param string $roleId - * @return RoleInterface - */ - public function setRoleId($roleId); - - /** - * Get libelle. - * - * @return string - */ - public function getLibelle(); - - /** - * Set libelle. - * - * @param string|null $libelle - * @return RoleInterface - */ - public function setLibelle($libelle); - - /** - * Is this role the default one ? - * - * @return boolean - */ - public function isDefault(); - - /** - * Set this role as the default one. - * - * @param boolean $default - * @return RoleInterface - */ - public function setDefault($default); - - /** - * Is auto ? - * - * @return boolean - */ - public function isAuto(); - - /** - * Set auto. - * - * @param boolean $auto - * @return RoleInterface - */ - public function setAuto($auto); - - /** - * Get parent. - * - * @return RoleInterface|null - */ - public function getParent(); - - /** - * Set parent. - * - * @param RoleInterface|null $parent - * @return RoleInterface - */ - public function setParent(RoleInterface $parent = null); - - /** - * Get ldapFilter. - * - * @return string - */ - public function getLdapFilter(); - - /** - * Set ldapFilter. - * - * @param string $ldapFilter - * @return RoleInterface - */ - public function setLdapFilter($ldapFilter); - - /** - * Check accessibleExterieur. - * - * @return boolean - */ - public function isAccessibleExterieur(); - - /** - * Set accessibleExterieur. - * - * @param boolean $accessibleExterieur - * @return RoleInterface - */ - public function setAccessibleExterieur($accessibleExterieur); - - /** - * Get users. - * - * @return Collection - */ - public function getUsers(); - - /** - * Add user. - * - * @param UserInterface $user - * @return RoleInterface - */ - public function addUser(UserInterface $user); - - /** - * Remove user. - * - * @param UserInterface $user - * @return RoleInterface - */ - public function removeUser(UserInterface $user); - - /** - * Get privileges. - * - * @return Collection - */ public function getPrivileges(); - - /** - * Add privilege. - * - * @param PrivilegeInterface $privilege - * @return RoleInterface - */ - public function addPrivilege(PrivilegeInterface $privilege); - - /** - * Remove privilege. - * - * @param PrivilegeInterface $privilege - * @return RoleInterface - */ - public function removePrivilege(PrivilegeInterface $privilege); + public function addPrivilege(PrivilegeInterface $privilege) : void; + public function removePrivilege(PrivilegeInterface $privilege) : void; } \ No newline at end of file diff --git a/src/UnicaenUtilisateur/Form/Role/RoleForm.php b/src/UnicaenUtilisateur/Form/Role/RoleForm.php index 8c48ac4..bca1400 100644 --- a/src/UnicaenUtilisateur/Form/Role/RoleForm.php +++ b/src/UnicaenUtilisateur/Form/Role/RoleForm.php @@ -6,6 +6,7 @@ use Application\Entity\Db\UtilisateurRole; use DoctrineModule\Form\Element\ObjectSelect; use DoctrineModule\Validator\NoObjectExists; use DoctrineModule\Validator\UniqueObject; +use Laminas\Form\Element\Textarea; use UnicaenApp\Service\EntityManagerAwareTrait; use UnicaenUtilisateur\Entity\Db\UserInterface; use UnicaenUtilisateur\Form\Strategy\RoleParentStrategy; @@ -43,6 +44,18 @@ class RoleForm extends Form 'id' => 'libelle', ], ]); + $this->add([ + 'type' => Textarea::class, + 'name' => 'description', + 'options' => [ + 'label' => "Description :", + 'label_attributes' => [ + ], + ], + 'attributes' => [ + 'id' => 'description', + ], + ]); $this->add([ 'type' => Text::class, @@ -177,7 +190,9 @@ class RoleForm extends Form ], ], ], - + 'description' => [ + 'required' => true, + ], 'roleId' => [ 'required' => true, 'validators' => [ diff --git a/src/UnicaenUtilisateur/View/Helper/RoleViewHelper.php b/src/UnicaenUtilisateur/View/Helper/RoleViewHelper.php new file mode 100644 index 0000000..c1a0f05 --- /dev/null +++ b/src/UnicaenUtilisateur/View/Helper/RoleViewHelper.php @@ -0,0 +1,29 @@ +<?php + +namespace UnicaenUtilisateur\View\Helper; + +use Laminas\View\Helper\AbstractHelper; +use Laminas\View\Helper\Partial; +use Laminas\View\Renderer\PhpRenderer; +use Laminas\View\Resolver\TemplatePathStack; +use Prestation\Entity\Db\Type; +use UnicaenUtilisateur\Entity\Db\RoleInterface; + +class RoleViewHelper extends AbstractHelper +{ + /** + * @param RoleInterface|null $role + * @param array $options + * @return string|Partial + * + * options :: tooltip + */ + public function __invoke(RoleInterface $role, array $options = []) + { + /** @var PhpRenderer $view */ + $view = $this->getView(); + $view->resolver()->attach(new TemplatePathStack(['script_paths' => [__DIR__ . "/partial"]])); + + return $view->partial('role', ['role' => $role, 'options' => $options]); + } +} \ No newline at end of file diff --git a/src/UnicaenUtilisateur/View/Helper/partial/role.phtml b/src/UnicaenUtilisateur/View/Helper/partial/role.phtml new file mode 100644 index 0000000..5a3c0d5 --- /dev/null +++ b/src/UnicaenUtilisateur/View/Helper/partial/role.phtml @@ -0,0 +1,17 @@ +<?php + +use UnicaenUtilisateur\Entity\Db\RoleInterface; + +/** + * @see \UnicaenUtilisateur\View\Helper\RoleViewHelper + * @var RoleInterface $role + * @var array $options + */ + +?> + +<span title="<?php echo $role->getDescription(); ?>"> + <?php echo $role->getLibelle(); ?> +</span> +<?php echo $role->isDefault() + ? '<i title="par défaut" class="fas fa-check-circle text-muted"></i>' : ''; ?> diff --git a/view/unicaen-utilisateur/role/index.phtml b/view/unicaen-utilisateur/role/index.phtml index 3488238..e30b83e 100644 --- a/view/unicaen-utilisateur/role/index.phtml +++ b/view/unicaen-utilisateur/role/index.phtml @@ -73,9 +73,7 @@ $this->headTitle("Rôles"); ?> <tr> <td> - <?php echo $role->getLibelle(); ?> - <?php echo $role->isDefault() - ? '<i title="par défaut" class="fas fa-check-circle text-muted"></i>' : ''; ?> + <?php echo $this->role($role); ?> </td> <td> <?php echo ($parent = $role->getParent()) ? $parent->getLibelle() : ''; ?> -- GitLab