diff --git "a/data/Sql/R\303\264les.sql" "b/data/Sql/R\303\264les.sql" index b91d0a80da1b5a524e8681b2996c50c0f1ef150a..15f17099d7e29cb4f5b384cc5fca4d484b9abaef 100755 --- "a/data/Sql/R\303\264les.sql" +++ "b/data/Sql/R\303\264les.sql" @@ -1,6 +1,6 @@ -- liste des comptes utilisateurs select - tr.code type_role, + tr.code role, s.libelle_court structure, p.nom_usuel nom, p.prenom prenom, @@ -8,16 +8,16 @@ select r.id, r.source_code from - role r + affectation r JOIN personnel p ON p.id = r.personnel_id AND p.histo_destruction IS NULL - JOIN type_role tr ON tr.id = r.type_id AND tr.histo_destruction IS NULL + JOIN role tr ON tr.id = r.role_id AND tr.histo_destruction IS NULL JOIN source src ON src.id = r.source_id LEFT JOIN structure s ON s.id = r.structure_id AND s.histo_destruction IS NULL WHERE r.histo_destruction IS NULL --AND r.source_id = OSE_IMPORT.GET_SOURCE_ID('OSE') ORDER BY - structure, nom, source, type_role; + structure, nom, source, role; -- pour créer un nouveau rôle @@ -33,7 +33,7 @@ select id, libelle_court, libelle_long, source_code from structure where libelle select * from type_role where histo_destruction is null; -INSERT INTO ROLE ( +INSERT INTO affectation ( STRUCTURE_ID, PERSONNEL_ID, TYPE_ID, @@ -43,9 +43,9 @@ INSERT INTO ROLE ( )VALUES( null,--(SELECT ID FROM structure WHERE source_code = 'U01'), (SELECT ID FROM personnel WHERE source_code ='102416'), - (SELECT ID FROM TYPE_ROLE WHERE code = 'administrateur'), + (SELECT ID FROM ROLE WHERE code = 'administrateur'), 'administrateur-102416', - ROLE_ID_SEQ.NEXTVAL, OSE_IMPORT.GET_SOURCE_ID('OSE'), + affectation_ID_SEQ.NEXTVAL, OSE_IMPORT.GET_SOURCE_ID('OSE'), (select id from utilisateur where username='lecluse'), (select id from utilisateur where username='lecluse') -- laurent ); @@ -103,37 +103,14 @@ select * from individu_fonct_struct@harpprod ifs where no_dossier_pers = 16956; select * from individu@harpprod where nom_usuel = 'DENOYES'; -/* -INSERT -INTO PERSONNEL - ( - ID, - CIVILITE_ID, - NOM_USUEL, - PRENOM, - NOM_PATRONYMIQUE, - EMAIL, - STRUCTURE_ID, - SOURCE_ID, - SOURCE_CODE, - VALIDITE_DEBUT, - HISTO_CREATION, - HISTO_CREATEUR_ID, - HISTO_MODIFICATION, - HISTO_MODIFICATEUR_ID - ) - VALUES - ( - PERSONNEL_id_seq.nextval, - (select id from civilite where libelle_court = 'Mme'), - 'DOLLEY', - 'Coralie', - 'DOLLEY', - 'coralie.dolley@unicaen.fr', - (select id from structure where libelle_court like '%DRH%' AND niveau = 2), - (select id from source where code = 'Harpege'), - '102416', - sysdate, - sysdate,4,sysdate,4 - ); -*/ \ No newline at end of file + + +select +r.code ressource, +p.code privilege, +p.id p_id +from + privilege p + join ressource r on r.id = p.ressource_id +order by + ressource, privilege \ No newline at end of file diff --git a/module/Application/config/gestion.config.php b/module/Application/config/gestion.config.php index 293631f6e2cd8753846199021bbfd52c12189043..a845df9e7b7db890a885033e1572e419e42f5713 100755 --- a/module/Application/config/gestion.config.php +++ b/module/Application/config/gestion.config.php @@ -60,11 +60,13 @@ return [ 'action' => ['gestion'], 'roles' => [R_COMPOSANTE, R_ADMINISTRATEUR], ], + ], + 'Application\Guard\PrivilegeController' => [ [ 'controller' => 'Application\Controller\Gestion', 'action' => ['droits'], - 'roles' => [R_COMPOSANTE, R_ADMINISTRATEUR], - ], + 'privileges' => ['privilege-visualisation', 'privilege-edition'] + ] ], ], ], diff --git a/module/Application/config/module.config.php b/module/Application/config/module.config.php index b3661170d195c2b2d5e2963aa0a96b9484c1f430..e46d21b84c0d951f61a09fbd6e2dafc2f7048194 100755 --- a/module/Application/config/module.config.php +++ b/module/Application/config/module.config.php @@ -179,9 +179,6 @@ $main = [ 'Application\\Acl\\IntervenantPermanentRole', ], ], - 'guards' => [ - 'Application\Guard\ControllerGuard' => [], - ], ], 'service_manager' => [ 'invokables' => [ @@ -194,8 +191,9 @@ $main = [ 'ApplicationUtilisateur' => 'Application\\Service\\Utilisateur', 'ApplicationTypeIntervention' => 'Application\\Service\\TypeIntervention', 'ApplicationSource' => 'Application\\Service\\Source', + 'ApplicationAffectation' => 'Application\\Service\\Affectation', 'ApplicationRole' => 'Application\\Service\\Role', - 'ApplicationTypeRole' => 'Application\\Service\\TypeRole', + 'ApplicationPrivilege' => 'Application\\Service\\Privilege', 'IntervenantNavigationPageVisibility' => 'Application\\Service\\IntervenantNavigationPageVisibility', 'ApplicationRuleProvider' => 'Application\Provider\Rule\RuleProvider', ], diff --git a/module/Application/src/Application/Acl/Role.php b/module/Application/src/Application/Acl/Role.php index 651d6d7c36c2a31394906e37e7f9afbdd4f8edbf..9e0de1536895a8f776cf02f230ad7f179930acdb 100644 --- a/module/Application/src/Application/Acl/Role.php +++ b/module/Application/src/Application/Acl/Role.php @@ -3,7 +3,7 @@ namespace Application\Acl; use UnicaenAuth\Acl\NamedRole; -use Application\Entity\Db\TypeRole; +use Application\Entity\Db\Role as DbRole; use Zend\Permissions\Acl\Resource; use Application\Entity\Db\Privilege; @@ -18,11 +18,11 @@ class Role extends NamedRole const ROLE_ID = 'role'; /** - * Type de rôle + * Rôle en BDD * - * @var TypeRole + * @var DbRole */ - protected $typeRole; + protected $dbRole; @@ -33,16 +33,16 @@ class Role extends NamedRole /** * - * @return TypeRole + * @return RoleEntity */ - function getTypeRole() + function getDbRole() { - return $this->typeRole; + return $this->role; } - function setTypeRole(TypeRole $typeRole) + function setDbRole(DbRole $dbRole) { - $this->typeRole = $typeRole; + $this->dbRole = $dbRole; return $this; } diff --git a/module/Application/src/Application/Entity/Db/Affectation.php b/module/Application/src/Application/Entity/Db/Affectation.php new file mode 100644 index 0000000000000000000000000000000000000000..b5c819d1b66096b078e246a2c215723a40d4982c --- /dev/null +++ b/module/Application/src/Application/Entity/Db/Affectation.php @@ -0,0 +1,333 @@ +<?php + +namespace Application\Entity\Db; + +/** + * Affectation + */ +class Affectation implements HistoriqueAwareInterface +{ + /** + * @var \DateTime + */ + protected $histoCreation; + + /** + * @var \DateTime + */ + protected $histoDestruction; + + /** + * @var \DateTime + */ + protected $histoModification; + + /** + * @var string + */ + protected $sourceCode; + + /** + * @var integer + */ + protected $id; + + /** + * @var \Application\Entity\Db\Structure + */ + protected $structure; + + /** + * @var \Application\Entity\Db\Role + */ + protected $role; + + /** + * @var \Application\Entity\Db\Source + */ + protected $source; + + /** + * @var \Application\Entity\Db\Personnel + */ + protected $personnel; + + /** + * @var \Application\Entity\Db\Utilisateur + */ + protected $histoDestructeur; + + /** + * @var \Application\Entity\Db\Utilisateur + */ + protected $histoModificateur; + + /** + * @var \Application\Entity\Db\Utilisateur + */ + protected $histoCreateur; + + + /** + * Set histoCreation + * + * @param \DateTime $histoCreation + * @return Affectation + */ + public function setHistoCreation($histoCreation) + { + $this->histoCreation = $histoCreation; + + return $this; + } + + /** + * Get histoCreation + * + * @return \DateTime + */ + public function getHistoCreation() + { + return $this->histoCreation; + } + + /** + * Set histoDestruction + * + * @param \DateTime $histoDestruction + * @return Affectation + */ + public function setHistoDestruction($histoDestruction) + { + $this->histoDestruction = $histoDestruction; + + return $this; + } + + /** + * Get histoDestruction + * + * @return \DateTime + */ + public function getHistoDestruction() + { + return $this->histoDestruction; + } + + /** + * Set histoModification + * + * @param \DateTime $histoModification + * @return Affectation + */ + public function setHistoModification($histoModification) + { + $this->histoModification = $histoModification; + + return $this; + } + + /** + * Get histoModification + * + * @return \DateTime + */ + public function getHistoModification() + { + return $this->histoModification; + } + + /** + * Set sourceCode + * + * @param string $sourceCode + * @return Affectation + */ + public function setSourceCode($sourceCode) + { + $this->sourceCode = $sourceCode; + + return $this; + } + + /** + * Get sourceCode + * + * @return string + */ + public function getSourceCode() + { + return $this->sourceCode; + } + + /** + * Get id + * + * @return integer + */ + public function getId() + { + return $this->id; + } + + /** + * Set structure + * + * @param \Application\Entity\Db\Structure $structure + * @return Affectation + */ + public function setStructure(\Application\Entity\Db\Structure $structure = null) + { + $this->structure = $structure; + + return $this; + } + + /** + * Get structure + * + * @return \Application\Entity\Db\Structure + */ + public function getStructure() + { + return $this->structure; + } + + /** + * Set role + * + * @param \Application\Entity\Db\Role $role + * @return Affectation + */ + public function setRole(\Application\Entity\Db\Role $role = null) + { + $this->role = $role; + + return $this; + } + + /** + * Get role + * + * @return \Application\Entity\Db\Role + */ + public function getRole() + { + return $this->role; + } + + /** + * Set source + * + * @param \Application\Entity\Db\Source $source + * @return Affectation + */ + public function setSource(\Application\Entity\Db\Source $source = null) + { + $this->source = $source; + + return $this; + } + + /** + * Get source + * + * @return \Application\Entity\Db\Source + */ + public function getSource() + { + return $this->source; + } + + /** + * Set personnel + * + * @param \Application\Entity\Db\Personnel $personnel + * @return Affectation + */ + public function setPersonnel(\Application\Entity\Db\Personnel $personnel = null) + { + $this->personnel = $personnel; + + return $this; + } + + /** + * Get personnel + * + * @return \Application\Entity\Db\Personnel + */ + public function getPersonnel() + { + return $this->personnel; + } + + /** + * Set histoDestructeur + * + * @param \Application\Entity\Db\Utilisateur $histoDestructeur + * @return Affectation + */ + public function setHistoDestructeur(\Application\Entity\Db\Utilisateur $histoDestructeur = null) + { + $this->histoDestructeur = $histoDestructeur; + + return $this; + } + + /** + * Get histoDestructeur + * + * @return \Application\Entity\Db\Utilisateur + */ + public function getHistoDestructeur() + { + return $this->histoDestructeur; + } + + /** + * Set histoModificateur + * + * @param \Application\Entity\Db\Utilisateur $histoModificateur + * @return Affectation + */ + public function setHistoModificateur(\Application\Entity\Db\Utilisateur $histoModificateur = null) + { + $this->histoModificateur = $histoModificateur; + + return $this; + } + + /** + * Get histoModificateur + * + * @return \Application\Entity\Db\Utilisateur + */ + public function getHistoModificateur() + { + return $this->histoModificateur; + } + + /** + * Set histoCreateur + * + * @param \Application\Entity\Db\Utilisateur $histoCreateur + * @return Affectation + */ + public function setHistoCreateur(\Application\Entity\Db\Utilisateur $histoCreateur = null) + { + $this->histoCreateur = $histoCreateur; + + return $this; + } + + /** + * Get histoCreateur + * + * @return \Application\Entity\Db\Utilisateur + */ + public function getHistoCreateur() + { + return $this->histoCreateur; + } +} diff --git a/module/Application/src/Application/Entity/Db/Ressource.php b/module/Application/src/Application/Entity/Db/CategoriePrivilege.php similarity index 91% rename from module/Application/src/Application/Entity/Db/Ressource.php rename to module/Application/src/Application/Entity/Db/CategoriePrivilege.php index 4b1067b49bb3e49e0454850ac33510e8cecfcadd..fa762ee61f491dfc6f9392a3a92b46d083d772c2 100644 --- a/module/Application/src/Application/Entity/Db/Ressource.php +++ b/module/Application/src/Application/Entity/Db/CategoriePrivilege.php @@ -7,7 +7,7 @@ use Doctrine\ORM\Mapping as ORM; /** * Ressource */ -class Ressource +class CategoriePrivilege { /** * @var string @@ -29,7 +29,7 @@ class Ressource * Set code * * @param string $code - * @return Ressource + * @return CategoriePrivilege */ public function setCode($code) { @@ -52,7 +52,7 @@ class Ressource * Set libelle * * @param string $libelle - * @return Ressource + * @return CategoriePrivilege */ public function setLibelle($libelle) { diff --git a/module/Application/src/Application/Entity/Db/HistoriqueAwareTrait.php b/module/Application/src/Application/Entity/Db/HistoriqueAwareTrait.php index 8ccbd1d72ade7959da952ffc5415a073f3ed93a4..815b12998780ba2d6daa0e1e8a2a07d5c0183ffe 100644 --- a/module/Application/src/Application/Entity/Db/HistoriqueAwareTrait.php +++ b/module/Application/src/Application/Entity/Db/HistoriqueAwareTrait.php @@ -43,7 +43,7 @@ trait HistoriqueAwareTrait * Set histoCreation * * @param \DateTime $histoCreation - * @return TypeRole + * @return self */ public function setHistoCreation($histoCreation) { @@ -66,7 +66,7 @@ trait HistoriqueAwareTrait * Set histoDestruction * * @param \DateTime $histoDestruction - * @return TypeRole + * @return self */ public function setHistoDestruction($histoDestruction) { @@ -89,7 +89,7 @@ trait HistoriqueAwareTrait * Set histoModification * * @param \DateTime $histoModification - * @return TypeRole + * @return self */ public function setHistoModification($histoModification) { @@ -112,7 +112,7 @@ trait HistoriqueAwareTrait * Set histoModificateur * * @param \Application\Entity\Db\Utilisateur $histoModificateur - * @return TypeRole + * @return self */ public function setHistoModificateur(\Application\Entity\Db\Utilisateur $histoModificateur = null) { @@ -135,7 +135,7 @@ trait HistoriqueAwareTrait * Set histoDestructeur * * @param \Application\Entity\Db\Utilisateur $histoDestructeur - * @return TypeRole + * @return self */ public function setHistoDestructeur(\Application\Entity\Db\Utilisateur $histoDestructeur = null) { @@ -158,7 +158,7 @@ trait HistoriqueAwareTrait * Set histoCreateur * * @param \Application\Entity\Db\Utilisateur $histoCreateur - * @return TypeRole + * @return self */ public function setHistoCreateur(\Application\Entity\Db\Utilisateur $histoCreateur = null) { diff --git a/module/Application/src/Application/Entity/Db/Mapping/Application.Entity.Db.Affectation.dcm.xml b/module/Application/src/Application/Entity/Db/Mapping/Application.Entity.Db.Affectation.dcm.xml new file mode 100644 index 0000000000000000000000000000000000000000..5138bf30df1ee35fc382577c5bb8778ab7a9137e --- /dev/null +++ b/module/Application/src/Application/Entity/Db/Mapping/Application.Entity.Db.Affectation.dcm.xml @@ -0,0 +1,60 @@ +<?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"> + <entity name="Application\Entity\Db\Affectation" table="AFFECTATION"> + <indexes> + <index name="IDX_61FC67DE59860CDC" columns="HISTO_CREATEUR_ID"/> + <index name="IDX_61FC67DE7E9E2204" columns="HISTO_DESTRUCTEUR_ID"/> + <index name="IDX_61FC67DE63F06898" columns="HISTO_MODIFICATEUR_ID"/> + <index name="IDX_61FC67DEB16F9F85" columns="PERSONNEL_ID"/> + <index name="IDX_61FC67DEE9B3446E" columns="SOURCE_ID"/> + <index name="IDX_61FC67DE884B0F7B" columns="STRUCTURE_ID"/> + <index name="IDX_61FC67DEC2443469" columns="ROLE_ID"/> + </indexes> + <unique-constraints> + <unique-constraint name="affectation_source_un" columns="SOURCE_CODE"/> + <unique-constraint name="affectation_un" columns="STRUCTURE_ID,PERSONNEL_ID,ROLE_ID"/> + </unique-constraints> + <id name="id" type="integer" column="ID"> + <generator strategy="SEQUENCE"/> + </id> + <field name="histoCreation" type="datetime" column="HISTO_CREATION" nullable="false"/> + <field name="histoDestruction" type="datetime" column="HISTO_DESTRUCTION" nullable="true"/> + <field name="histoModification" type="datetime" column="HISTO_MODIFICATION" nullable="false"/> + <field name="sourceCode" type="string" column="SOURCE_CODE" length="100" nullable="true"/> + <many-to-one field="structure" target-entity="Application\Entity\Db\Structure"> + <join-columns> + <join-column name="STRUCTURE_ID" referenced-column-name="ID"/> + </join-columns> + </many-to-one> + <many-to-one field="role" target-entity="Application\Entity\Db\Role"> + <join-columns> + <join-column name="ROLE_ID" referenced-column-name="ID"/> + </join-columns> + </many-to-one> + <many-to-one field="source" target-entity="Application\Entity\Db\Source"> + <join-columns> + <join-column name="SOURCE_ID" referenced-column-name="ID"/> + </join-columns> + </many-to-one> + <many-to-one field="personnel" target-entity="Application\Entity\Db\Personnel"> + <join-columns> + <join-column name="PERSONNEL_ID" referenced-column-name="ID"/> + </join-columns> + </many-to-one> + <many-to-one field="histoDestructeur" target-entity="Application\Entity\Db\Utilisateur"> + <join-columns> + <join-column name="HISTO_DESTRUCTEUR_ID" referenced-column-name="ID"/> + </join-columns> + </many-to-one> + <many-to-one field="histoModificateur" target-entity="Application\Entity\Db\Utilisateur"> + <join-columns> + <join-column name="HISTO_MODIFICATEUR_ID" referenced-column-name="ID"/> + </join-columns> + </many-to-one> + <many-to-one field="histoCreateur" target-entity="Application\Entity\Db\Utilisateur"> + <join-columns> + <join-column name="HISTO_CREATEUR_ID" referenced-column-name="ID"/> + </join-columns> + </many-to-one> + </entity> +</doctrine-mapping> diff --git a/module/Application/src/Application/Entity/Db/Mapping/Application.Entity.Db.Ressource.dcm.xml b/module/Application/src/Application/Entity/Db/Mapping/Application.Entity.Db.CategoriePrivilege.dcm.xml similarity index 80% rename from module/Application/src/Application/Entity/Db/Mapping/Application.Entity.Db.Ressource.dcm.xml rename to module/Application/src/Application/Entity/Db/Mapping/Application.Entity.Db.CategoriePrivilege.dcm.xml index c2b3cadcd3c907ded3b1d7785eedd38f7cc0cc28..989b5db9ab0fa99e1a462607a965520997fa279e 100644 --- a/module/Application/src/Application/Entity/Db/Mapping/Application.Entity.Db.Ressource.dcm.xml +++ b/module/Application/src/Application/Entity/Db/Mapping/Application.Entity.Db.CategoriePrivilege.dcm.xml @@ -1,8 +1,8 @@ <?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"> - <entity name="Application\Entity\Db\Ressource" table="RESSOURCE"> + <entity name="Application\Entity\Db\CategoriePrivilege" table="CATEGORIE_PRIVILEGE"> <unique-constraints> - <unique-constraint name="ressource__un" columns="CODE"/> + <unique-constraint name="categorie_privilege__un" columns="CODE"/> </unique-constraints> <id name="id" type="integer" column="ID"> <generator strategy="SEQUENCE"/> diff --git a/module/Application/src/Application/Entity/Db/Mapping/Application.Entity.Db.Personnel.dcm.xml b/module/Application/src/Application/Entity/Db/Mapping/Application.Entity.Db.Personnel.dcm.xml index 3dea5bdadea61be5819d8565db51d7dd06b262a0..8e08fea70c33d21665b589f2f79cf6e0b05d7cd2 100644 --- a/module/Application/src/Application/Entity/Db/Mapping/Application.Entity.Db.Personnel.dcm.xml +++ b/module/Application/src/Application/Entity/Db/Mapping/Application.Entity.Db.Personnel.dcm.xml @@ -53,6 +53,6 @@ <join-column name="CIVILITE_ID" referenced-column-name="ID"/> </join-columns> </many-to-one> - <one-to-many field="role" target-entity="Application\Entity\Db\Role" mapped-by="personnel" /> + <one-to-many field="affectation" target-entity="Application\Entity\Db\Affectation" mapped-by="personnel" /> </entity> </doctrine-mapping> diff --git a/module/Application/src/Application/Entity/Db/Mapping/Application.Entity.Db.Privilege.dcm.xml b/module/Application/src/Application/Entity/Db/Mapping/Application.Entity.Db.Privilege.dcm.xml index d3c9b4d2db2d79884e5c4abebf0dc3e2e897140c..bae20ea556ad905ab4ee6b8e66684c1392060a56 100644 --- a/module/Application/src/Application/Entity/Db/Mapping/Application.Entity.Db.Privilege.dcm.xml +++ b/module/Application/src/Application/Entity/Db/Mapping/Application.Entity.Db.Privilege.dcm.xml @@ -12,18 +12,18 @@ </id> <field name="code" type="string" column="CODE" length="150" nullable="false"/> <field name="libelle" type="string" column="LIBELLE" length="200" nullable="false"/> - <many-to-one field="ressource" target-entity="Application\Entity\Db\Ressource"> + <many-to-one field="categorie" target-entity="Application\Entity\Db\CategoriePrivilege"> <join-columns> - <join-column name="RESSOURCE_ID" referenced-column-name="ID"/> + <join-column name="CATEGORIE_ID" referenced-column-name="ID"/> </join-columns> </many-to-one> - <many-to-many field="typeRole" target-entity="Application\Entity\Db\TypeRole" inversed-by="privilege"> - <join-table name="TYPE_ROLE_PRIVILEGE"> + <many-to-many field="role" target-entity="Application\Entity\Db\Role" inversed-by="privilege"> + <join-table name="ROLE_PRIVILEGE"> <join-columns> <join-column name="PRIVILEGE_ID" referenced-column-name="ID"/> </join-columns> <inverse-join-columns> - <join-column name="TYPE_ROLE_ID" referenced-column-name="ID"/> + <join-column name="ROLE_ID" referenced-column-name="ID"/> </inverse-join-columns> </join-table> </many-to-many> diff --git a/module/Application/src/Application/Entity/Db/Mapping/Application.Entity.Db.Role.dcm.xml b/module/Application/src/Application/Entity/Db/Mapping/Application.Entity.Db.Role.dcm.xml index 0b01453d8a99593c8ab7fd7852f68d9f14432449..9fa25ec22b3974c2e97100afbe042c717dc9bbf2 100644 --- a/module/Application/src/Application/Entity/Db/Mapping/Application.Entity.Db.Role.dcm.xml +++ b/module/Application/src/Application/Entity/Db/Mapping/Application.Entity.Db.Role.dcm.xml @@ -2,43 +2,24 @@ <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"> <entity name="Application\Entity\Db\Role" table="ROLE"> <indexes> - <index name="IDX_61FC67DE59860CDC" columns="HISTO_CREATEUR_ID"/> - <index name="IDX_61FC67DE7E9E2204" columns="HISTO_DESTRUCTEUR_ID"/> - <index name="IDX_61FC67DE63F06898" columns="HISTO_MODIFICATEUR_ID"/> - <index name="IDX_61FC67DEB16F9F85" columns="PERSONNEL_ID"/> - <index name="IDX_61FC67DEE9B3446E" columns="SOURCE_ID"/> - <index name="IDX_61FC67DE884B0F7B" columns="STRUCTURE_ID"/> - <index name="IDX_61FC67DEC2443469" columns="TYPE_ID"/> + <index name="IDX_5657E8959860CDC" columns="HISTO_CREATEUR_ID"/> + <index name="IDX_5657E897E9E2204" columns="HISTO_DESTRUCTEUR_ID"/> + <index name="IDX_5657E8963F06898" columns="HISTO_MODIFICATEUR_ID"/> </indexes> <unique-constraints> - <unique-constraint name="role_source_un" columns="SOURCE_CODE"/> - <unique-constraint name="role_un" columns="STRUCTURE_ID,PERSONNEL_ID,TYPE_ID"/> + <unique-constraint name="role_code_un" columns="CODE"/> </unique-constraints> <id name="id" type="integer" column="ID"> <generator strategy="SEQUENCE"/> </id> + <field name="code" type="string" column="CODE" length="3" nullable="false"/> <field name="histoCreation" type="datetime" column="HISTO_CREATION" nullable="false"/> <field name="histoDestruction" type="datetime" column="HISTO_DESTRUCTION" nullable="true"/> <field name="histoModification" type="datetime" column="HISTO_MODIFICATION" nullable="false"/> - <field name="sourceCode" type="string" column="SOURCE_CODE" length="100" nullable="true"/> - <many-to-one field="structure" target-entity="Application\Entity\Db\Structure"> - <join-columns> - <join-column name="STRUCTURE_ID" referenced-column-name="ID"/> - </join-columns> - </many-to-one> - <many-to-one field="type" target-entity="Application\Entity\Db\TypeRole"> - <join-columns> - <join-column name="TYPE_ID" referenced-column-name="ID"/> - </join-columns> - </many-to-one> - <many-to-one field="source" target-entity="Application\Entity\Db\Source"> - <join-columns> - <join-column name="SOURCE_ID" referenced-column-name="ID"/> - </join-columns> - </many-to-one> - <many-to-one field="personnel" target-entity="Application\Entity\Db\Personnel"> + <field name="libelle" type="string" column="LIBELLE" length="50" nullable="false"/> + <many-to-one field="histoModificateur" target-entity="Application\Entity\Db\Utilisateur"> <join-columns> - <join-column name="PERSONNEL_ID" referenced-column-name="ID"/> + <join-column name="HISTO_MODIFICATEUR_ID" referenced-column-name="ID"/> </join-columns> </many-to-one> <many-to-one field="histoDestructeur" target-entity="Application\Entity\Db\Utilisateur"> @@ -46,15 +27,12 @@ <join-column name="HISTO_DESTRUCTEUR_ID" referenced-column-name="ID"/> </join-columns> </many-to-one> - <many-to-one field="histoModificateur" target-entity="Application\Entity\Db\Utilisateur"> - <join-columns> - <join-column name="HISTO_MODIFICATEUR_ID" referenced-column-name="ID"/> - </join-columns> - </many-to-one> <many-to-one field="histoCreateur" target-entity="Application\Entity\Db\Utilisateur"> <join-columns> <join-column name="HISTO_CREATEUR_ID" referenced-column-name="ID"/> </join-columns> </many-to-one> + <one-to-many field="affectation" target-entity="Application\Entity\Db\Affectation" mapped-by="role" /> + <many-to-many field="privilege" target-entity="Application\Entity\Db\Privilege" mapped-by="role"/> </entity> </doctrine-mapping> diff --git a/module/Application/src/Application/Entity/Db/Mapping/Application.Entity.Db.RoleUtilisateur.dcm.xml b/module/Application/src/Application/Entity/Db/Mapping/Application.Entity.Db.RoleUtilisateur.dcm.xml deleted file mode 100644 index 4025667e027232e7ed16e3235a366911c744317a..0000000000000000000000000000000000000000 --- a/module/Application/src/Application/Entity/Db/Mapping/Application.Entity.Db.RoleUtilisateur.dcm.xml +++ /dev/null @@ -1,31 +0,0 @@ -<?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"> - <entity name="Application\Entity\Db\RoleUtilisateur" table="ROLE_UTILISATEUR"> - <indexes> - <index name="IDX_43A8DF1CEF5927F" columns="PARENT_ID"/> - </indexes> - <unique-constraints> - <unique-constraint name="role_utilisateur_id_un" columns="ROLE_ID"/> - </unique-constraints> - <id name="id" type="integer" column="ID"> - <generator strategy="SEQUENCE"/> - </id> - <field name="isDefault" type="integer" column="IS_DEFAULT" nullable="false"/> - <field name="roleId" type="string" column="ROLE_ID" length="64" nullable="false"/> - <many-to-one field="parent" target-entity="Application\Entity\Db\RoleUtilisateur"> - <join-columns> - <join-column name="PARENT_ID" referenced-column-name="ID"/> - </join-columns> - </many-to-one> - <many-to-many field="utilisateur" target-entity="Application\Entity\Db\Utilisateur" inversed-by="roleUtilisateur"> - <join-table name="role_utilisateur_linker"> - <join-columns> - <join-column name="ROLE_UTILISATEUR_ID" referenced-column-name="ID"/> - </join-columns> - <inverse-join-columns> - <join-column name="UTILISATEUR_ID" referenced-column-name="ID"/> - </inverse-join-columns> - </join-table> - </many-to-many> - </entity> -</doctrine-mapping> diff --git a/module/Application/src/Application/Entity/Db/Mapping/Application.Entity.Db.TypeRole.dcm.xml b/module/Application/src/Application/Entity/Db/Mapping/Application.Entity.Db.TypeRole.dcm.xml deleted file mode 100644 index 24e53f1a91aa009e488df41158c952823b69ba6e..0000000000000000000000000000000000000000 --- a/module/Application/src/Application/Entity/Db/Mapping/Application.Entity.Db.TypeRole.dcm.xml +++ /dev/null @@ -1,38 +0,0 @@ -<?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"> - <entity name="Application\Entity\Db\TypeRole" table="TYPE_ROLE"> - <indexes> - <index name="IDX_5657E8959860CDC" columns="HISTO_CREATEUR_ID"/> - <index name="IDX_5657E897E9E2204" columns="HISTO_DESTRUCTEUR_ID"/> - <index name="IDX_5657E8963F06898" columns="HISTO_MODIFICATEUR_ID"/> - </indexes> - <unique-constraints> - <unique-constraint name="type_role_code_un" columns="CODE"/> - </unique-constraints> - <id name="id" type="integer" column="ID"> - <generator strategy="SEQUENCE"/> - </id> - <field name="code" type="string" column="CODE" length="3" nullable="false"/> - <field name="histoCreation" type="datetime" column="HISTO_CREATION" nullable="false"/> - <field name="histoDestruction" type="datetime" column="HISTO_DESTRUCTION" nullable="true"/> - <field name="histoModification" type="datetime" column="HISTO_MODIFICATION" nullable="false"/> - <field name="libelle" type="string" column="LIBELLE" length="50" nullable="false"/> - <many-to-one field="histoModificateur" target-entity="Application\Entity\Db\Utilisateur"> - <join-columns> - <join-column name="HISTO_MODIFICATEUR_ID" referenced-column-name="ID"/> - </join-columns> - </many-to-one> - <many-to-one field="histoDestructeur" target-entity="Application\Entity\Db\Utilisateur"> - <join-columns> - <join-column name="HISTO_DESTRUCTEUR_ID" referenced-column-name="ID"/> - </join-columns> - </many-to-one> - <many-to-one field="histoCreateur" target-entity="Application\Entity\Db\Utilisateur"> - <join-columns> - <join-column name="HISTO_CREATEUR_ID" referenced-column-name="ID"/> - </join-columns> - </many-to-one> - <one-to-many field="role" target-entity="Application\Entity\Db\Role" mapped-by="type" /> - <many-to-many field="privilege" target-entity="Application\Entity\Db\Privilege" mapped-by="typeRole"/> - </entity> -</doctrine-mapping> diff --git a/module/Application/src/Application/Entity/Db/Mapping/Application.Entity.Db.Utilisateur.dcm.xml b/module/Application/src/Application/Entity/Db/Mapping/Application.Entity.Db.Utilisateur.dcm.xml index df353b048ec3ebc020ce97bbdc6515a6954cb269..5dd9d12d519b7287f5126502d52a31ef07546f98 100644 --- a/module/Application/src/Application/Entity/Db/Mapping/Application.Entity.Db.Utilisateur.dcm.xml +++ b/module/Application/src/Application/Entity/Db/Mapping/Application.Entity.Db.Utilisateur.dcm.xml @@ -24,6 +24,5 @@ <join-column name="PERSONNEL_ID" referenced-column-name="ID"/> </join-columns> </many-to-one> - <many-to-many field="roleUtilisateur" target-entity="Application\Entity\Db\RoleUtilisateur" mapped-by="utilisateur"/> </entity> </doctrine-mapping> diff --git a/module/Application/src/Application/Entity/Db/Personnel.php b/module/Application/src/Application/Entity/Db/Personnel.php index 59cf7ec0f8cdb1c01d08a60eacbbef95b03d4ff6..cd624d9e1d28978870349827165254ff98aad4a2 100644 --- a/module/Application/src/Application/Entity/Db/Personnel.php +++ b/module/Application/src/Application/Entity/Db/Personnel.php @@ -57,14 +57,14 @@ class Personnel implements HistoriqueAwareInterface /** * @var \Doctrine\Common\Collections\Collection */ - protected $role; + protected $affectation; /** * */ public function __construct() { - $this->role = new \Doctrine\Common\Collections\ArrayCollection(); + $this->affectation = new \Doctrine\Common\Collections\ArrayCollection(); } /** @@ -262,36 +262,36 @@ class Personnel implements HistoriqueAwareInterface } /** - * Add role + * Add affectation * - * @param \Application\Entity\Db\Role $role - * @return TypeRole + * @param \Application\Entity\Db\Affectation $affectation + * @return Personnel */ - public function addRole(\Application\Entity\Db\Role $role) + public function addAffectation(\Application\Entity\Db\Affectation $affectation) { - $this->role[] = $role; + $this->affectation[] = $affectation; return $this; } /** - * Remove role + * Remove affectation * - * @param \Application\Entity\Db\Role $role + * @param \Application\Entity\Db\Affectation $affectation */ - public function removeRole(\Application\Entity\Db\Role $role) + public function removeAffectation(\Application\Entity\Db\Affectation $affectation) { - $this->role->removeElement($role); + $this->affectation->removeElement($affectation); } /** - * Get role + * Get affectation * * @return \Doctrine\Common\Collections\Collection */ - public function getRole() + public function getAffectation() { - return $this->role; + return $this->affectation; } /** diff --git a/module/Application/src/Application/Entity/Db/Privilege.php b/module/Application/src/Application/Entity/Db/Privilege.php index 36449a152911b20c2c6ff8134c66c20d33de9a70..880d43f58f1d19f06a3d76c84d551b8b078aaaf0 100644 --- a/module/Application/src/Application/Entity/Db/Privilege.php +++ b/module/Application/src/Application/Entity/Db/Privilege.php @@ -2,8 +2,6 @@ namespace Application\Entity\Db; -use Doctrine\ORM\Mapping as ORM; - /** * Privilege */ @@ -25,14 +23,14 @@ class Privilege private $id; /** - * @var \Application\Entity\Db\Ressource + * @var \Application\Entity\Db\CategoriePrivilege */ - private $ressource; + private $categorie; /** * @var \Doctrine\Common\Collections\Collection */ - private $typeRole; + private $role; /** * @var \Doctrine\Common\Collections\Collection @@ -44,7 +42,7 @@ class Privilege */ public function __construct() { - $this->typeRole = new \Doctrine\Common\Collections\ArrayCollection(); + $this->role = new \Doctrine\Common\Collections\ArrayCollection(); $this->statut = new \Doctrine\Common\Collections\ArrayCollection(); } @@ -105,59 +103,69 @@ class Privilege } /** - * Set ressource + * Set categoriePrivilege * - * @param \Application\Entity\Db\Ressource $ressource + * @param \Application\Entity\Db\CategoriePrivilege $categoriePrivilege * @return Privilege */ - public function setRessource(\Application\Entity\Db\Ressource $ressource = null) + public function setCategoriePrivilege(\Application\Entity\Db\CategoriePrivilege $categoriePrivilege = null) { - $this->ressource = $ressource; + $this->categoriePrivilege = $categoriePrivilege; return $this; } /** - * Get ressource + * Get categoriePrivilege * - * @return \Application\Entity\Db\Ressource + * @return \Application\Entity\Db\CategoriePrivilege */ - public function getRessource() + public function getCategoriePrivilege() { - return $this->ressource; + return $this->categoriePrivilege; } /** - * Add typeRole + * Add role * - * @param \Application\Entity\Db\TypeRole $typeRole + * @param \Application\Entity\Db\Role $role * @return Privilege */ - public function addTypeRole(\Application\Entity\Db\TypeRole $typeRole) + public function addRole(\Application\Entity\Db\Role $role) { - $this->typeRole[] = $typeRole; + $this->Role[] = $role; return $this; } /** - * Remove typeRole + * Remove role * - * @param \Application\Entity\Db\TypeRole $typeRole + * @param \Application\Entity\Db\Role $role */ - public function removeTypeRole(\Application\Entity\Db\TypeRole $typeRole) + public function removeRole(\Application\Entity\Db\Role $role) { - $this->typeRole->removeElement($typeRole); + $this->role->removeElement($role); } /** - * Get typeRole + * Get role * * @return \Doctrine\Common\Collections\Collection */ - public function getTypeRole() + public function getRole() + { + return $this->role; + } + + public function getRoleCodes() { - return $this->typeRole; + $result = []; + foreach( $this->role as $role ){ + /* @var $role Role */ + $result[] = $role->getCode(); + } + return $result; } /** diff --git a/module/Application/src/Application/Entity/Db/Role.php b/module/Application/src/Application/Entity/Db/Role.php index cf66cc5f68e95690e41914654087f98068e6ec05..9d8714dc2e8eb770c271d2f121ee3d3ec61564ca 100644 --- a/module/Application/src/Application/Entity/Db/Role.php +++ b/module/Application/src/Application/Entity/Db/Role.php @@ -2,30 +2,28 @@ namespace Application\Entity\Db; +use Zend\Permissions\Acl\Role\RoleInterface; +use Zend\Permissions\Acl\Resource\ResourceInterface; + /** * Role */ -class Role implements HistoriqueAwareInterface +class Role implements HistoriqueAwareInterface, RoleInterface { - /** - * @var \DateTime - */ - protected $histoCreation; - - /** - * @var \DateTime - */ - protected $histoDestruction; + use HistoriqueAwareTrait; + + const CODE_RESPONSABLE_COMPOSANTE = 'responsable-composante'; + const CODE_GESTIONNAIRE_COMPOSANTE = 'gestionnaire-composante'; /** - * @var \DateTime + * @var string */ - protected $histoModification; + protected $code; /** * @var string */ - protected $sourceCode; + protected $libelle; /** * @var integer @@ -33,131 +31,88 @@ class Role implements HistoriqueAwareInterface protected $id; /** - * @var \Application\Entity\Db\Structure - */ - protected $structure; - - /** - * @var \Application\Entity\Db\TypeRole + * @var \Doctrine\Common\Collections\Collection */ - protected $type; + protected $affectation; /** - * @var \Application\Entity\Db\Source + * @var \Doctrine\Common\Collections\Collection */ - protected $source; - - /** - * @var \Application\Entity\Db\Personnel - */ - protected $personnel; - - /** - * @var \Application\Entity\Db\Utilisateur - */ - protected $histoDestructeur; - - /** - * @var \Application\Entity\Db\Utilisateur - */ - protected $histoModificateur; - - /** - * @var \Application\Entity\Db\Utilisateur - */ - protected $histoCreateur; - + private $privilege; /** - * Set histoCreation * - * @param \DateTime $histoCreation - * @return Role */ - public function setHistoCreation($histoCreation) + public function __construct() { - $this->histoCreation = $histoCreation; - - return $this; + $this->affectation = new \Doctrine\Common\Collections\ArrayCollection(); + $this->privilege = new \Doctrine\Common\Collections\ArrayCollection(); } - + /** - * Get histoCreation + * Returns the string identifier of the Role * - * @return \DateTime + * @return string */ - public function getHistoCreation() + public function getRoleId() { - return $this->histoCreation; - } - - /** - * Set histoDestruction - * - * @param \DateTime $histoDestruction - * @return Role - */ - public function setHistoDestruction($histoDestruction) - { - $this->histoDestruction = $histoDestruction; - - return $this; + return $this->getCode(); } - + /** - * Get histoDestruction - * - * @return \DateTime + * Retourne la représentation littérale de cet objet. + * + * @return string */ - public function getHistoDestruction() + public function __toString() { - return $this->histoDestruction; + return $this->getLibelle(); } /** - * Set histoModification + * Set code * - * @param \DateTime $histoModification - * @return Role + * @param string $code + * @return self */ - public function setHistoModification($histoModification) + public function setCode($code) { - $this->histoModification = $histoModification; + $this->code = $code; return $this; } /** - * Get histoModification + * Get code * - * @return \DateTime + * @return string */ - public function getHistoModification() + public function getCode() { - return $this->histoModification; + return $this->code; } /** - * Set sourceCode + * Set libelle * - * @param string $sourceCode - * @return Role + * @param string $libelle + * @return self */ - public function setSourceCode($sourceCode) + public function setLibelle($libelle) { - $this->sourceCode = $sourceCode; + $this->libelle = $libelle; return $this; } /** - * Get sourceCode + * Get libelle * * @return string */ - public function getSourceCode() + public function getLibelle() { - return $this->sourceCode; + return $this->libelle; } /** @@ -171,163 +126,102 @@ class Role implements HistoriqueAwareInterface } /** - * Set structure + * Add affectation * - * @param \Application\Entity\Db\Structure $structure - * @return Role + * @param \Application\Entity\Db\Affectation $affectation + * @return self */ - public function setStructure(\Application\Entity\Db\Structure $structure = null) + public function addAffectation(\Application\Entity\Db\Affectation $affectation) { - $this->structure = $structure; + $this->affectation[] = $affectation; return $this; } /** - * Get structure + * Remove affectation * - * @return \Application\Entity\Db\Structure + * @param \Application\Entity\Db\Affectation $affectation */ - public function getStructure() + public function removeAffectation(\Application\Entity\Db\Affectation $affectation) { - return $this->structure; - } - - /** - * Set type - * - * @param \Application\Entity\Db\TypeRole $type - * @return Role - */ - public function setType(\Application\Entity\Db\TypeRole $type = null) - { - $this->type = $type; - - return $this; + $this->affectation->removeElement($affectation); } /** - * Get type + * Get affectation * - * @return \Application\Entity\Db\TypeRole + * @return \Doctrine\Common\Collections\Collection */ - public function getType() + public function getAffectation() { - return $this->type; + return $this->affectation; } /** - * Set source + * Add privilege * - * @param \Application\Entity\Db\Source $source - * @return Role + * @param \Application\Entity\Db\Privilege $privilege + * @return StatutIntervenant */ - public function setSource(\Application\Entity\Db\Source $source = null) + public function addPrivilege(\Application\Entity\Db\Privilege $privilege) { - $this->source = $source; + $this->privilege[] = $privilege; return $this; } /** - * Get source + * Remove privilege * - * @return \Application\Entity\Db\Source + * @param \Application\Entity\Db\Privilege $privilege */ - public function getSource() + public function removePrivilege(\Application\Entity\Db\Privilege $privilege) { - return $this->source; + $this->privilege->removeElement($privilege); } /** - * Set personnel + * Get privilege * - * @param \Application\Entity\Db\Personnel $personnel - * @return Role + * @param ResourceInterface|string|null $resource + * @return \Doctrine\Common\Collections\Collection */ - public function setPersonnel(\Application\Entity\Db\Personnel $personnel = null) + public function getPrivilege( $resource=null ) { - $this->personnel = $personnel; - - return $this; - } - - /** - * Get personnel - * - * @return \Application\Entity\Db\Personnel - */ - public function getPersonnel() - { - return $this->personnel; - } - - /** - * Set histoDestructeur - * - * @param \Application\Entity\Db\Utilisateur $histoDestructeur - * @return Role - */ - public function setHistoDestructeur(\Application\Entity\Db\Utilisateur $histoDestructeur = null) - { - $this->histoDestructeur = $histoDestructeur; - - return $this; - } - - /** - * Get histoDestructeur - * - * @return \Application\Entity\Db\Utilisateur - */ - public function getHistoDestructeur() - { - return $this->histoDestructeur; - } - - /** - * Set histoModificateur - * - * @param \Application\Entity\Db\Utilisateur $histoModificateur - * @return Role - */ - public function setHistoModificateur(\Application\Entity\Db\Utilisateur $histoModificateur = null) - { - $this->histoModificateur = $histoModificateur; - - return $this; - } - - /** - * Get histoModificateur - * - * @return \Application\Entity\Db\Utilisateur - */ - public function getHistoModificateur() - { - return $this->histoModificateur; - } - - /** - * Set histoCreateur - * - * @param \Application\Entity\Db\Utilisateur $histoCreateur - * @return Role - */ - public function setHistoCreateur(\Application\Entity\Db\Utilisateur $histoCreateur = null) - { - $this->histoCreateur = $histoCreateur; - - return $this; + return $this->privilege->filter( function(Privilege $privilege) use ($resource){ + if (empty($resource)){ + return true; // pas de filtre + } + if ($resource instanceof ResourceInterface){ + $resource = $resource->getResourceId(); + } + return $privilege->getRessource()->getCode() === $resource; + }); } /** - * Get histoCreateur + * Détermine si le rôle possède un provilège ou non. + * Si le privilège transmis est un objet de classe Privilege, alors il est inutile de fournir la ressource, sinon il est obligatoire de la préciser * - * @return \Application\Entity\Db\Utilisateur + * @param Privilege|string $privilege + * @param ResourceInterface|string|null $resource + * @return boolean + * @throws \Common\Exception\LogicException */ - public function getHistoCreateur() + public function hasPrivilege( $privilege, $resource=null ) { - return $this->histoCreateur; + if ($privilege instanceof Privilege){ + $resource = $privilege->getRessource(); + $privilege = $privilege->getCode(); + } + if (empty($resource)){ + throw new \Common\Exception\LogicException('La ressource du privilège n\'est pas précisée'); + } + $privileges = $this->getPrivilege($resource); + foreach( $privileges as $priv ){ + if ($priv->getCode() === $privilege) return true; + } + return false; } -} +} \ No newline at end of file diff --git a/module/Application/src/Application/Entity/Db/RoleUtilisateur.php b/module/Application/src/Application/Entity/Db/RoleUtilisateur.php deleted file mode 100644 index da3442c918130dbd89927c3f947ba5e4fc699a73..0000000000000000000000000000000000000000 --- a/module/Application/src/Application/Entity/Db/RoleUtilisateur.php +++ /dev/null @@ -1,160 +0,0 @@ -<?php - -namespace Application\Entity\Db; - -/** - * RoleUtilisateur - */ -class RoleUtilisateur -{ - - /** - * @var integer - */ - protected $isDefault; - - /** - * @var string - */ - protected $roleId; - - /** - * @var integer - */ - protected $id; - - /** - * @var \Application\Entity\Db\RoleUtilisateur - */ - protected $parent; - - /** - * @var \Doctrine\Common\Collections\Collection - */ - protected $utilisateur; - - /** - * Constructor - */ - public function __construct() - { - $this->utilisateur = new \Doctrine\Common\Collections\ArrayCollection(); - } - - /** - * Set isDefault - * - * @param integer $isDefault - * @return RoleUtilisateur - */ - public function setIsDefault($isDefault) - { - $this->isDefault = $isDefault; - - return $this; - } - - /** - * Get isDefault - * - * @return integer - */ - public function getIsDefault() - { - return $this->isDefault; - } - - /** - * Set roleId - * - * @param string $roleId - * @return RoleUtilisateur - */ - public function setRoleId($roleId) - { - $this->roleId = $roleId; - - return $this; - } - - /** - * Get roleId - * - * @return string - */ - public function getRoleId() - { - return $this->roleId; - } - - /** - * Get id - * - * @return integer - */ - public function getId() - { - return $this->id; - } - - /** - * Set parent - * - * @param \Application\Entity\Db\RoleUtilisateur $parent - * @return RoleUtilisateur - */ - public function setParent(\Application\Entity\Db\RoleUtilisateur $parent = null) - { - $this->parent = $parent; - - return $this; - } - - /** - * Get parent - * - * @return \Application\Entity\Db\RoleUtilisateur - */ - public function getParent() - { - return $this->parent; - } - - /** - * Add utilisateur - * - * @param \Application\Entity\Db\Utilisateur $utilisateur - * @return RoleUtilisateur - */ - public function addUtilisateur(\Application\Entity\Db\Utilisateur $utilisateur) - { - $this->utilisateur[] = $utilisateur; - - return $this; - } - - /** - * Remove utilisateur - * - * @param \Application\Entity\Db\Utilisateur $utilisateur - */ - public function removeUtilisateur(\Application\Entity\Db\Utilisateur $utilisateur) - { - $this->utilisateur->removeElement($utilisateur); - } - - /** - * Get utilisateur - * - * @return \Doctrine\Common\Collections\Collection - */ - public function getUtilisateur() - { - return $this->utilisateur; - } - - public function __toString() - { - return $this->getRoleId(); - } -} \ No newline at end of file diff --git a/module/Application/src/Application/Entity/Db/TypeRole.php b/module/Application/src/Application/Entity/Db/TypeRole.php deleted file mode 100644 index 4a20313352c38b57503031f932064042b9966fc1..0000000000000000000000000000000000000000 --- a/module/Application/src/Application/Entity/Db/TypeRole.php +++ /dev/null @@ -1,227 +0,0 @@ -<?php - -namespace Application\Entity\Db; - -use Zend\Permissions\Acl\Role\RoleInterface; -use Zend\Permissions\Acl\Resource\ResourceInterface; - -/** - * TypeRole - */ -class TypeRole implements HistoriqueAwareInterface, RoleInterface -{ - use HistoriqueAwareTrait; - - const CODE_RESPONSABLE_COMPOSANTE = 'responsable-composante'; - const CODE_GESTIONNAIRE_COMPOSANTE = 'gestionnaire-composante'; - - /** - * @var string - */ - protected $code; - - /** - * @var string - */ - protected $libelle; - - /** - * @var integer - */ - protected $id; - - /** - * @var \Doctrine\Common\Collections\Collection - */ - protected $role; - - /** - * @var \Doctrine\Common\Collections\Collection - */ - private $privilege; - - /** - * - */ - public function __construct() - { - $this->role = new \Doctrine\Common\Collections\ArrayCollection(); - $this->privilege = new \Doctrine\Common\Collections\ArrayCollection(); - } - - /** - * Returns the string identifier of the Role - * - * @return string - */ - public function getRoleId() - { - return $this->getCode(); - } - - /** - * Retourne la représentation littérale de cet objet. - * - * @return string - */ - public function __toString() - { - return $this->getLibelle(); - } - - /** - * Set code - * - * @param string $code - * @return TypeRole - */ - public function setCode($code) - { - $this->code = $code; - - return $this; - } - - /** - * Get code - * - * @return string - */ - public function getCode() - { - return $this->code; - } - - /** - * Set libelle - * - * @param string $libelle - * @return TypeRole - */ - public function setLibelle($libelle) - { - $this->libelle = $libelle; - - return $this; - } - - /** - * Get libelle - * - * @return string - */ - public function getLibelle() - { - return $this->libelle; - } - - /** - * Get id - * - * @return integer - */ - public function getId() - { - return $this->id; - } - - /** - * Add role - * - * @param \Application\Entity\Db\Role $role - * @return TypeRole - */ - public function addRole(\Application\Entity\Db\Role $role) - { - $this->role[] = $role; - - return $this; - } - - /** - * Remove role - * - * @param \Application\Entity\Db\Role $role - */ - public function removeRole(\Application\Entity\Db\Role $role) - { - $this->role->removeElement($role); - } - - /** - * Get role - * - * @return \Doctrine\Common\Collections\Collection - */ - public function getRole() - { - return $this->role; - } - - /** - * Add privilege - * - * @param \Application\Entity\Db\Privilege $privilege - * @return StatutIntervenant - */ - public function addPrivilege(\Application\Entity\Db\Privilege $privilege) - { - $this->privilege[] = $privilege; - - return $this; - } - - /** - * Remove privilege - * - * @param \Application\Entity\Db\Privilege $privilege - */ - public function removePrivilege(\Application\Entity\Db\Privilege $privilege) - { - $this->privilege->removeElement($privilege); - } - - /** - * Get privilege - * - * @param ResourceInterface|string|null $resource - * @return \Doctrine\Common\Collections\Collection - */ - public function getPrivilege( $resource=null ) - { - return $this->privilege->filter( function(Privilege $privilege) use ($resource){ - if (empty($resource)){ - return true; // pas de filtre - } - if ($resource instanceof ResourceInterface){ - $resource = $resource->getResourceId(); - } - return $privilege->getRessource()->getCode() === $resource; - }); - } - - /** - * Détermine si le type de rôle possède un provilège ou non. - * Si le privilège transmis est un objet de classe Privilege, alors il est inutile de fournir la ressource, sinon il est obligatoire de la préciser - * - * @param Privilege|string $privilege - * @param ResourceInterface|string|null $resource - * @return boolean - * @throws \Common\Exception\LogicException - */ - public function hasPrivilege( $privilege, $resource=null ) - { - if ($privilege instanceof Privilege){ - $resource = $privilege->getRessource(); - $privilege = $privilege->getCode(); - } - if (empty($resource)){ - throw new \Common\Exception\LogicException('La ressource du privilège n\'est pas précisée'); - } - $privileges = $this->getPrivilege($resource); - foreach( $privileges as $priv ){ - if ($priv->getCode() === $privilege) return true; - } - return false; - } -} \ No newline at end of file diff --git a/module/Application/src/Application/Entity/Db/Utilisateur.php b/module/Application/src/Application/Entity/Db/Utilisateur.php index b83fd9db8b9f9fb8a97c7f0a8116db3cfa76fa05..39d2c02e2b28f5489169d0220942a709fe1a08b0 100644 --- a/module/Application/src/Application/Entity/Db/Utilisateur.php +++ b/module/Application/src/Application/Entity/Db/Utilisateur.php @@ -52,19 +52,6 @@ class Utilisateur implements UserInterface, ProviderInterface */ protected $personnel; - /** - * @var \Doctrine\Common\Collections\Collection - */ - protected $roleUtilisateur; - - /** - * Constructor - */ - public function __construct() - { - $this->roleUtilisateur = new \Doctrine\Common\Collections\ArrayCollection(); - } - /** * Set displayName * @@ -236,39 +223,6 @@ class Utilisateur implements UserInterface, ProviderInterface return $this->personnel; } - /** - * Add roleUtilisateur - * - * @param \Application\Entity\Db\RoleUtilisateur $roleUtilisateur - * @return Utilisateur - */ - public function addRoleUtilisateur(\Application\Entity\Db\RoleUtilisateur $roleUtilisateur) - { - $this->roleUtilisateur[] = $roleUtilisateur; - - return $this; - } - - /** - * Remove roleUtilisateur - * - * @param \Application\Entity\Db\RoleUtilisateur $roleUtilisateur - */ - public function removeRoleUtilisateur(\Application\Entity\Db\RoleUtilisateur $roleUtilisateur) - { - $this->roleUtilisateur->removeElement($roleUtilisateur); - } - - /** - * Get roleUtilisateur - * - * @return \Doctrine\Common\Collections\Collection - */ - public function getRoleUtilisateur() - { - return $this->roleUtilisateur; - } - /************************************************************************************************** * Début ajout @@ -303,6 +257,6 @@ class Utilisateur implements UserInterface, ProviderInterface */ public function getRoles() { - return $this->getRoleUtilisateur(); + return []; } } diff --git a/module/Application/src/Application/Guard/ControllerGuard.php b/module/Application/src/Application/Guard/ControllerGuard.php deleted file mode 100644 index df6977715f14691f8c393f093664e01b5782b4d5..0000000000000000000000000000000000000000 --- a/module/Application/src/Application/Guard/ControllerGuard.php +++ /dev/null @@ -1,29 +0,0 @@ -<?php - -namespace Application\Guard; - -use BjyAuthorize\Guard\Controller; -use Zend\ServiceManager\ServiceLocatorInterface; - -/** - * Description of ControllerGuard - * - * @author Laurent LECLUSE <laurent.lecluse at unicaen.fr> - */ -class ControllerGuard extends Controller -{ - - public function __construct(array $rules, ServiceLocatorInterface $serviceLocator) - { - $rules = [ - [ - 'controller' => 'Application\Controller\Gestion', - 'action' => ['droits'], - 'roles' => [\Application\Acl\AdministrateurRole::ROLE_ID], - ], - ]; - - parent::__construct($rules, $serviceLocator); - } - -} diff --git a/module/Application/src/Application/Guard/PrivilegeController.php b/module/Application/src/Application/Guard/PrivilegeController.php new file mode 100644 index 0000000000000000000000000000000000000000..38be6e6b4c1f60b133a19b1309c7f0528c2c3706 --- /dev/null +++ b/module/Application/src/Application/Guard/PrivilegeController.php @@ -0,0 +1,68 @@ +<?php + +namespace Application\Guard; + +use BjyAuthorize\Guard\Controller; +use Zend\ServiceManager\ServiceLocatorInterface; + +/** + * Description of ControllerGuard + * + * @author Laurent LECLUSE <laurent.lecluse at unicaen.fr> + */ +class PrivilegeController extends Controller +{ + use \Application\Service\Traits\PrivilegeAwareTrait + ; + + public function __construct(array $rules, ServiceLocatorInterface $serviceLocator) + { + $this->serviceLocator = $serviceLocator; + parent::__construct( $this->privilegesToRoles($rules), $serviceLocator ); + } + + protected function privilegesToRoles( array $rules ) + { + $pr = $this->getPrivilegesRoles(); + + foreach( $rules as $index => $rule ){ + if (isset($rule['privileges'])){ + $privileges = (array)$rule['privileges']; + $rule['roles'] = isset($rule['roles']) ? (array)$rule['roles'] : []; + foreach( $pr as $privilege => $roles ){ + if (in_array($privilege, $privileges)){ + $rule['roles'] = array_unique( array_merge($rule['roles'], $roles) ); + } + } + unset($rule['privileges']); + $rules[$index] = $rule; + } + } + return $rules; + } + + protected function getPrivilegesRoles() + { + $privileges = $this->getServicePrivilege()->getList(); + /* @var $privileges \Application\Entity\Db\Privilege[] */ + + $pr = []; + foreach( $privileges as $privilege ){ + $roles = $privilege->getRoleCodes(); + if (! empty($roles)){ + $pr[$privilege->getCode()] = $roles; + } + } + return $pr; + } + + /** + * Pour récupérer le serviceLocator depuis les traits de service + * + * @return ServiceLocatorInterface + */ + protected function getServiceLocator() + { + return $this->serviceLocator; + } +} \ No newline at end of file diff --git a/module/Application/src/Application/Interfaces/RoleAwareInterface.php b/module/Application/src/Application/Interfaces/RoleAwareInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..f9cc255d6aa21ebb63c0042df9d2e2cb8fd4f31e --- /dev/null +++ b/module/Application/src/Application/Interfaces/RoleAwareInterface.php @@ -0,0 +1,27 @@ +<?php + +namespace Application\Interfaces; + +use Application\Entity\Db\Role; + +/** + * + * @author Laurent LÉCLUSE <laurent.lecluse at unicaen.fr> + */ +interface RoleAwareInterface +{ + + /** + * Spécifie le rôle concerné. + * + * @param Role $role Rôle concernée + */ + public function setRole(Role $Role = null); + + /** + * Retourne le rôle concerné. + * + * @return Role + */ + public function getRole(); +} \ No newline at end of file diff --git a/module/Application/src/Application/Interfaces/TypeRoleAwareInterface.php b/module/Application/src/Application/Interfaces/TypeRoleAwareInterface.php deleted file mode 100644 index 8315ad3604312d9b32b71e0767cd76aeeecbb516..0000000000000000000000000000000000000000 --- a/module/Application/src/Application/Interfaces/TypeRoleAwareInterface.php +++ /dev/null @@ -1,27 +0,0 @@ -<?php - -namespace Application\Interfaces; - -use Application\Entity\Db\TypeRole; - -/** - * - * @author Laurent LÉCLUSE <laurent.lecluse at unicaen.fr> - */ -interface TypeRoleAwareInterface -{ - - /** - * Spécifie le type de rôle concerné. - * - * @param TypeRole $typeRole Type de rôle concernée - */ - public function setTypeRole(TypeRole $typeRole = null); - - /** - * Retourne le type de rôle concerné. - * - * @return TypeRole - */ - public function getTypeRole(); -} \ No newline at end of file diff --git a/module/Application/src/Application/Provider/Identity/IdentityProvider.php b/module/Application/src/Application/Provider/Identity/IdentityProvider.php index 480fb64bee5588b37c0c69b76a8c13441f6b3d13..6b615f96ec331903adcde41310e6b5202d58af40 100644 --- a/module/Application/src/Application/Provider/Identity/IdentityProvider.php +++ b/module/Application/src/Application/Provider/Identity/IdentityProvider.php @@ -4,7 +4,7 @@ namespace Application\Provider\Identity; use Application\Acl; use Application\Entity\Db\IntervenantExterieur; use Application\Entity\Db\IntervenantPermanent; -use Application\Entity\Db\Role; +use Application\Entity\Db\Affectation; use Application\Entity\Db\Utilisateur; use Common\Exception\RuntimeException; use UnicaenApp\Service\EntityManagerAwareInterface; @@ -90,12 +90,12 @@ class IdentityProvider implements ServiceLocatorAwareInterface, ChainableProvide } /** - * Responsabilités métier importées (tables ROLE et TYPE_ROLE) + * Responsabilités métier importées (tables affectation et TYPE_ROLE) */ if ($utilisateur->getPersonnel()) { - foreach ($utilisateur->getPersonnel()->getRole() as $role) { /* @var $role Role */ - $roleId = $role->getType()->getCode(); - if ($structure = $role->getStructure()){ + foreach ($utilisateur->getPersonnel()->getAffectation() as $affectation) { /* @var $affectation Affectation */ + $roleId = $affectation->getRole()->getCode(); + if ($structure = $affectation->getStructure()){ $roleId .= '-'.$structure->getSourceCode(); } $roles[] = $roleId; diff --git a/module/Application/src/Application/Provider/Role/RoleProvider.php b/module/Application/src/Application/Provider/Role/RoleProvider.php index 38ed45e90ec6fdf14f8bfcaf5d090f397d2c6c80..0659eb7af00260e456e8afe9c26c8c20b653d5aa 100644 --- a/module/Application/src/Application/Provider/Role/RoleProvider.php +++ b/module/Application/src/Application/Provider/Role/RoleProvider.php @@ -3,7 +3,7 @@ namespace Application\Provider\Role; use Application\Acl\AdministrateurRole; -use Application\Entity\Db\Role; +use Application\Entity\Db\Affectation; use Application\Entity\Db\Structure as StructureEntity; use Application\Interfaces\StructureAwareInterface; use BjyAuthorize\Provider\Role\ProviderInterface; @@ -76,28 +76,28 @@ class RoleProvider implements ProviderInterface, EntityManagerAwareInterface if (($utilisateur = $this->getUtilisateur()) && ($personnel = $utilisateur->getPersonnel())){ // chargement des rôles métiers $qb = $this->getEntityManager()->createQueryBuilder() - ->from("Application\Entity\Db\Role", "r") - ->select("r, tr, s") + ->from("Application\Entity\Db\Affectation", "a") + ->select("a, r, s") ->distinct() - ->join("r.type", "tr") - ->leftJoin("r.structure", "s") + ->join("a.role", "r") + ->leftJoin("a.structure", "s") + ->andWhere('1=compriseEntre(a.histoCreation,a.histoDestruction)') ->andWhere('1=compriseEntre(r.histoCreation,r.histoDestruction)') - ->andWhere('1=compriseEntre(tr.histoCreation,tr.histoDestruction)') - ->andWhere("r.personnel = :personnel")->setParameter(':personnel', $personnel); - foreach ($qb->getQuery()->getResult() as $role) { /* @var $role Role */ - $roleId = $role->getType()->getCode(); + ->andWhere("a.personnel = :personnel")->setParameter(':personnel', $personnel); + foreach ($qb->getQuery()->getResult() as $affectation) { /* @var $affectation Affectation */ + $roleId = $affectation->getRole()->getCode(); if (! isset($roles[$roleId])){ throw new Exception('Le rôle "'.$roleId.'" est inconnu.'); } $classname = get_class($roles[$roleId]); - if ($roles[$roleId] instanceof StructureAwareInterface && $role->getStructure()){ - $roleId .= '-'.$role->getStructure()->getSourceCode(); + if ($roles[$roleId] instanceof StructureAwareInterface && $affectation->getStructure()){ + $roleId .= '-'.$affectation->getStructure()->getSourceCode(); $roles[$roleId] = new $classname($roleId); - $roles[$roleId]->setStructure( $role->getStructure() ); + $roles[$roleId]->setStructure( $affectation->getStructure() ); }else{ $roles[$roleId] = new $classname($roleId); } - $roles[$roleId]->setTypeRole( $role->getType() ); + $roles[$roleId]->setDbRole( $affectation->getRole() ); $this->injectSelectedStructureInRole($roles[$roleId]); } @@ -122,7 +122,7 @@ class RoleProvider implements ProviderInterface, EntityManagerAwareInterface /** * Inject la structure sélectionnée en session dans le rôle Administrateur. * - * @param Role $role + * @param \Application\Acl\Role $role * @return self */ public function injectSelectedStructureInRole($role) diff --git a/module/Application/src/Application/Rule/Intervenant/AgrementFourniRule.php b/module/Application/src/Application/Rule/Intervenant/AgrementFourniRule.php index d0654c0cc1bc39bb138b1a443d837ea2fc84cbe2..a412bb346729100d8aeb5699c2b10e48df567a09 100644 --- a/module/Application/src/Application/Rule/Intervenant/AgrementFourniRule.php +++ b/module/Application/src/Application/Rule/Intervenant/AgrementFourniRule.php @@ -180,58 +180,6 @@ EOS; throw new LogicException("Cette méthode ne devrait pas être appelée!"); } - /** - * - * @return array - */ -// private function executeForIntervenant() -// { -// if (!($role = $this->getRole())) { -// throw new LogicException("Un rôle doit être spécifié."); -// } -// -// /** -// * Conseil Academique (un seul pour toutes les structures d'enseignement) -// */ -// if ($this->getTypeAgrement()->getCode() === TypeAgrement::CODE_CONSEIL_ACADEMIQUE) { -// if (!count($this->getTypesAgrementFournis())) { -// $this->message(self::MESSAGE_AUCUN, $this->getTypeAgrement()); -// return []; -// } -// // aucun critère de structure pour ce type d'agrément -// $structures = [ null ]; -// } -// /** -// * Conseil Restreint (un par structure d'enseignement) -// */ -// elseif ($this->getTypeAgrement()->getCode() === TypeAgrement::CODE_CONSEIL_RESTREINT) { -// // si une structure d'enseignement précise a été fournie, on ne considèrera qu'elle -// if ($this->getStructure()) { -// $structures = [ $this->getStructure()->getId() => $this->getStructure() ]; -// } -// // sinon, pour certains rôles, peu importe la structure -// elseif ($role instanceof IntervenantRole || $role instanceof AdministrateurRole) { -// // du point de vue intervenant, aucun critère de structure -// $structures = [ null ]; -// } -// else { -// $structures = $this->getStructuresEnseignement(); -// } -// } -// -// // teste si un agrément existe pour chaque structure d'enseignement -// foreach ($structures as $structure) { -// if (!count($this->getAgrementsFournis($structure))) { -// $this->message(self::MESSAGE_AUCUN, sprintf("« %s »%s", -// $this->getTypeAgrement(), -// $structure ? sprintf(" de la structure « %s »", $structure) : null)); -// return []; -// } -// } -// -// return [0 => ['id' => $this->getIntervenant()->getId()]]; -// } - public function isRelevant() { return true; diff --git a/module/Application/src/Application/Service/Affectation.php b/module/Application/src/Application/Service/Affectation.php new file mode 100644 index 0000000000000000000000000000000000000000..a4bb600754c0d48176ed5b0ddce8247c3d959e5e --- /dev/null +++ b/module/Application/src/Application/Service/Affectation.php @@ -0,0 +1,57 @@ +<?php + +namespace Application\Service; + +use Doctrine\ORM\QueryBuilder; + +/** + * Description of Affectation + * + * @author Laurent LÉCLUSE <laurent.lecluse at unicaen.fr> + */ +class Affectation extends AbstractEntityService +{ + /** + * retourne la classe des entités + * + * @return string + * @throws RuntimeException + */ + public function getEntityClass() + { + return 'Application\Entity\Db\Affectation'; + } + + /** + * Retourne l'alias d'entité courante + * + * @return string + */ + public function getAlias() + { + return 'aff'; + } + + /** + * + * @param \Application\Entity\Db\Role|string $role + * @param QueryBuilder $qb + * @param string $alias + * @return QueryBuilder + * @todo A REVOIR! ! ! ! + */ + public function finderByRole($role, QueryBuilder $qb = null, $alias = null) + { + list($qb, $alias) = $this->initQuery($qb, $alias); + + if ($role instanceof \Application\Entity\Db\Role) { + $role = $role->getCode(); + } + + $qb + ->innerJoin($alias.'.role', $ralias = uniqid('r')) + ->andWhere("$ralias.code = :code")->setParameter('code', $role); + + return $qb; + } +} \ No newline at end of file diff --git a/module/Application/src/Application/Service/TypeRole.php b/module/Application/src/Application/Service/Privilege.php similarity index 61% rename from module/Application/src/Application/Service/TypeRole.php rename to module/Application/src/Application/Service/Privilege.php index c673bc0b604139a3b1dee72e35f2b551f4f0507b..f8e8ab35c696a3cff3d081661397b80f1a9e3c2b 100644 --- a/module/Application/src/Application/Service/TypeRole.php +++ b/module/Application/src/Application/Service/Privilege.php @@ -2,23 +2,23 @@ namespace Application\Service; -use Doctrine\ORM\QueryBuilder; - /** - * Description of TypeRole + * Description of Privilege * * @author Laurent LÉCLUSE <laurent.lecluse at unicaen.fr> */ -class TypeRole extends AbstractEntityService +class Privilege extends AbstractEntityService { + /** * retourne la classe des entités * * @return string + * @throws RuntimeException */ public function getEntityClass() { - return 'Application\Entity\Db\TypeRole'; + return 'Application\Entity\Db\Privilege'; } /** @@ -26,8 +26,8 @@ class TypeRole extends AbstractEntityService * * @return string */ - public function getAlias() - { - return 'tr'; + public function getAlias(){ + return 'priv'; } + } \ No newline at end of file diff --git a/module/Application/src/Application/Service/Process/PieceJointeProcess.php b/module/Application/src/Application/Service/Process/PieceJointeProcess.php index 22c0025107ed373f48192f39ce54228b08734dac..3af6ea0cc1681672931622e4846ee7bcdbb1b1e3 100644 --- a/module/Application/src/Application/Service/Process/PieceJointeProcess.php +++ b/module/Application/src/Application/Service/Process/PieceJointeProcess.php @@ -304,7 +304,7 @@ class PieceJointeProcess extends AbstractService $structure = $this->getIntervenant()->getStructure(); do { - $qb = $service->finderByTypeRole(\Application\Entity\Db\TypeRole::CODE_GESTIONNAIRE_COMPOSANTE); + $qb = $service->finderByTypeRole(\Application\Entity\Db\Role::CODE_GESTIONNAIRE_COMPOSANTE); $service->finderByStructure($structure, $qb); $roles = $service->getList($qb); $structure = $structure->getParente(); diff --git a/module/Application/src/Application/Service/Role.php b/module/Application/src/Application/Service/Role.php index af78dd62ef1af86be368b67f798af04d767c4c0e..b80d57ab6aaa0f6c0c8a13de241aab1875adb0ea 100644 --- a/module/Application/src/Application/Service/Role.php +++ b/module/Application/src/Application/Service/Role.php @@ -2,8 +2,6 @@ namespace Application\Service; -use Doctrine\ORM\QueryBuilder; - /** * Description of Role * @@ -15,7 +13,6 @@ class Role extends AbstractEntityService * retourne la classe des entités * * @return string - * @throws RuntimeException */ public function getEntityClass() { @@ -31,42 +28,4 @@ class Role extends AbstractEntityService { return 'r'; } - - /** - * - * @param \Application\Entity\Db\TypeRole|string $typeRole - * @param type $qb - * @param type $alias - * @return type - */ - public function finderByTypeRole($typeRole, $qb = null, $alias = null) - { - list($qb, $alias) = $this->initQuery($qb, $alias); - - if ($typeRole instanceof \Application\Entity\Db\TypeRole) { - $typeRole = $typeRole->getCode(); - } - - $qb - ->innerJoin('r.type', $alias = uniqid('tr')) - ->andWhere("$alias.code = :code")->setParameter('code', $typeRole); - - return $qb; - } - - /** - * - * @param \Application\Entity\Db\Structure $structure - * @param type $qb - * @param type $alias - * @return type - */ - public function finderByStructure(\Application\Entity\Db\Structure $structure, $qb = null, $alias = null) - { - list($qb, $alias) = $this->initQuery($qb, $alias); - - $qb->andWhere("$alias.structure = :structure")->setParameter('structure', $structure); - - return $qb; - } } \ No newline at end of file diff --git a/module/Application/src/Application/Service/Structure.php b/module/Application/src/Application/Service/Structure.php index ee6b9b29adbea49eb74c26a1db1596227c194999..be2164089889713056b6aea90c229c4c2ac512d3 100644 --- a/module/Application/src/Application/Service/Structure.php +++ b/module/Application/src/Application/Service/Structure.php @@ -14,6 +14,7 @@ use Application\Entity\Db\Structure as EntityStructure; */ class Structure extends AbstractEntityService { + use Traits\AffectationAwareTrait; /** * retourne la classe des entités @@ -62,21 +63,21 @@ class Structure extends AbstractEntityService return [ $structure->getContactPj() ]; } - $serviceRole = $this->getServiceLocator()->get('applicationRole'); + $serviceAffectation = $this->getServiceAffectation(); $str = $structure; // recherche des rôles dans la structure, en remontant la hiérarchie des structures si besoin et demandé do { // recherche de "gestionnaires" - $qb = $serviceRole->finderByTypeRole(\Application\Entity\Db\TypeRole::CODE_GESTIONNAIRE_COMPOSANTE); - $serviceRole->finderByStructure($str, $qb); - $roles = $serviceRole->getList($qb); + $qb = $serviceAffectation->finderByRole(\Application\Entity\Db\Role::CODE_GESTIONNAIRE_COMPOSANTE); + $serviceAffectation->finderByStructure($str, $qb); + $roles = $serviceAffectation->getList($qb); // recherche de "responsables" - $qb = $serviceRole->finderByTypeRole(\Application\Entity\Db\TypeRole::CODE_RESPONSABLE_COMPOSANTE); - $serviceRole->finderByStructure($str, $qb); - $roles += $serviceRole->getList($qb); + $qb = $serviceAffectation->finderByRole(\Application\Entity\Db\Role::CODE_RESPONSABLE_COMPOSANTE); + $serviceAffectation->finderByStructure($str, $qb); + $roles += $serviceAffectation->getList($qb); // on grimpe la hiérarchie des structures $str = $str->getParente(); diff --git a/module/Application/src/Application/Service/Traits/AffectationAwareTrait.php b/module/Application/src/Application/Service/Traits/AffectationAwareTrait.php new file mode 100644 index 0000000000000000000000000000000000000000..d2ed0b1f814dcbaac835199b014a78e13f570625 --- /dev/null +++ b/module/Application/src/Application/Service/Traits/AffectationAwareTrait.php @@ -0,0 +1,51 @@ +<?php + +namespace Application\Service\Traits; + +use Application\Service\Affectation; +use Common\Exception\RuntimeException; + +trait AffectationAwareTrait +{ + /** + * description + * + * @var Affectation + */ + private $serviceAffectation; + + /** + * + * @param Affectation $serviceAffectation + * @return self + */ + public function setServiceAffectation( Affectation $serviceAffectation ) + { + $this->serviceAffectation = $serviceAffectation; + return $this; + } + + /** + * + * @return RolAffectatione + * @throws \Common\Exception\RuntimeException + */ + public function getServiceAffectation() + { + if (empty($this->serviceAffectation)){ + if (! method_exists($this, 'getServiceLocator')) { + throw new RuntimeException( 'La classe '.get_class($this).' n\'a pas accès au ServiceLocator.'); + } + + $serviceLocator = $this->getServiceLocator(); + if (method_exists($serviceLocator, 'getServiceLocator')) { + $serviceLocator = $serviceLocator->getServiceLocator(); + } + + return $serviceLocator->get('applicationAffectation'); + }else{ + return $this->serviceAffectation; + } + } + +} \ No newline at end of file diff --git a/module/Application/src/Application/Service/Traits/TypeRoleAwareTrait.php b/module/Application/src/Application/Service/Traits/PrivilegeAwareTrait.php similarity index 59% rename from module/Application/src/Application/Service/Traits/TypeRoleAwareTrait.php rename to module/Application/src/Application/Service/Traits/PrivilegeAwareTrait.php index a67acbc162e7a22eefc428fdc37ce9387e8947a9..d2ea516b1489181155e9c16e49829b95c78551c6 100644 --- a/module/Application/src/Application/Service/Traits/TypeRoleAwareTrait.php +++ b/module/Application/src/Application/Service/Traits/PrivilegeAwareTrait.php @@ -2,37 +2,37 @@ namespace Application\Service\Traits; -use Application\Service\TypeRole; +use Application\Service\Privilege; use Common\Exception\RuntimeException; -trait TypeRoleAwareTrait +trait PrivilegeAwareTrait { /** * description * - * @var TypeRole + * @var Privilege */ - private $serviceTypeRole; + private $servicePrivilege; /** * - * @param TypeRole $serviceTypeRole + * @param Privilege $servicePrivilege * @return self */ - public function setServiceTypeRole( TypeRole $serviceTypeRole ) + public function setServicePrivilege( Privilege $servicePrivilege ) { - $this->serviceTypeRole = $serviceTypeRole; + $this->servicePrivilege = $servicePrivilege; return $this; } /** * - * @return TypeRole + * @return Privilege * @throws \Common\Exception\RuntimeException */ - public function getServiceTypeRole() + public function getServicePrivilege() { - if (empty($this->serviceTypeRole)){ + if (empty($this->servicePrivilege)){ if (! method_exists($this, 'getServiceLocator')) { throw new RuntimeException( 'La classe '.get_class($this).' n\'a pas accès au ServiceLocator.'); } @@ -42,9 +42,9 @@ trait TypeRoleAwareTrait $serviceLocator = $serviceLocator->getServiceLocator(); } - return $serviceLocator->get('applicationTypeRole'); + return $serviceLocator->get('applicationPrivilege'); }else{ - return $this->serviceTypeRole; + return $this->servicePrivilege; } } diff --git a/module/Application/src/Application/Traits/TypeRoleAwareTrait.php b/module/Application/src/Application/Traits/TypeRoleAwareTrait.php deleted file mode 100644 index 212b8bedf6f742687367b5c07173af28994be892..0000000000000000000000000000000000000000 --- a/module/Application/src/Application/Traits/TypeRoleAwareTrait.php +++ /dev/null @@ -1,40 +0,0 @@ -<?php - -namespace Application\Traits; - -use Application\Entity\Db\TypeRole; - -/** - * Description of TypeRoleAwareTrait - * - * @author Laurent LÉCLUSE <laurent.lecluse at unicaen.fr> - */ -trait TypeRoleAwareTrait -{ - /** - * @var TypeRole - */ - protected $typeRole; - - /** - * Spécifie le type de rôle concerné. - * - * @param TypeRole $typeRole Type de rôle concerné - */ - public function setTypeRole(TypeRole $typeRole = null) - { - $this->typeRole = $typeRole; - - return $this; - } - - /** - * Retourne le type de rôle concerné. - * - * @return TypeRole - */ - public function getTypeRole() - { - return $this->typeRole; - } -} \ No newline at end of file