diff --git a/config/module.config.php b/config/module.config.php index 6cd5bd7684b0d3a226ca78f404b7316e28a9ac51..8d564f3d0faf0d2b77d156c95acd3813c1804dd6 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 ea1882d254ceea96817f6e18bd1c68683c06124e..d191807956aa38447d67a241501f10f9d164a95a 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 3de3fb2763821f9b8c3290f1c1075dad40dd525b..fa212d88d603e4710623f9bff8ad7432c9e850f6 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 3ff409031e9cded7255b7e175cc1aefcfda8486e..4b41922562455f44c5af86b2f8c3e4a2e387c49c 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 38a7cdb33c323169f6fc124bbd95dc2b64f74984..771452cbf85754dd014463191df795f038e46d9b 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 071f739d4d88df9e38d4f5ad08132f2bf60cfed3..6e80e0c132f226a2d98aea94e975b8cfa51d2848 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 27213dca3e2f8f4ed0b1b28e755b28dbc7960472..60a2169d152b8d90da15e1c532784089a6373125 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 8c48ac4eb8c637ad0f8d267b81cff1b819d6e594..bca14007ebf27c0647ea8fec86b407ab91530a9a 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 0000000000000000000000000000000000000000..c1a0f05cb5717b322871632179cdf4e6cf488c35 --- /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 0000000000000000000000000000000000000000..5a3c0d53dd2f7035e6478c5043498c9c60f834be --- /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 348823878c6bd7140bf90a9ad982b0085a2d1eb8..e30b83ed879ee15e1dd9b7566b20643bcb790040 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() : ''; ?>