Skip to content
Snippets Groups Projects
Commit 001bf29b authored by gauthierb's avatar gauthierb
Browse files

Nouvelle entité TypeRolePhpRole permettant de spécifier quels rôles Harpege...

Nouvelle entité TypeRolePhpRole permettant de spécifier quels rôles Harpege sont pris en compte et associés à quel rôle applicatif PHP.
Ex: le rôle Harpege "Responsable Administratif" est rattaché au rôle PHP 'composante'.
parent d4f224e5
No related branches found
No related tags found
No related merge requests found
......@@ -146,6 +146,7 @@ $main = array(
'ApplicationParametres' => 'Application\\Service\\Parametres',
'ApplicationTypeIntervention' => 'Application\\Service\\TypeIntervention',
'ApplicationSource' => 'Application\\Service\\Source',
'ApplicationTypeRolePhpRole' => 'Application\\Service\\TypeRolePhpRole',
'ApplicationRole' => 'Application\\Service\\Role',
'ApplicationRoleUtilisateur' => 'Application\\Service\\RoleUtilisateur',
'NavigationPageVisibility' => 'Application\\Service\\NavigationPageVisibility',
......
<?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\TypeRolePhpRole" table="TYPE_ROLE_PHP_ROLE">
<id name="id" type="integer" column="ID">
<!--<generator strategy="SEQUENCE"/>-->
</id>
<field name="phpRoleId" type="string" column="PHP_ROLE_ID" length="64" nullable="false"/>
<many-to-one field="typeRole" target-entity="Application\Entity\Db\TypeRole">
<join-columns>
<join-column name="TYPE_ROLE_ID" referenced-column-name="ID"/>
</join-columns>
</many-to-one>
</entity>
</doctrine-mapping>
<?php
namespace Application\Entity\Db;
/**
* TypeRolePhpRole
*/
class TypeRolePhpRole
{
/**
* @var integer
*/
protected $id;
/**
* @var \Application\Entity\Db\TypeRole
*/
protected $typeRole;
/**
* @var string
*/
protected $phpRoleId;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set type
*
* @param \Application\Entity\Db\TypeRole $typeRole
* @return self
*/
public function setTypeRole(\Application\Entity\Db\TypeRole $typeRole = null)
{
$this->typeRole = $typeRole;
return $this;
}
/**
* Get type
*
* @return \Application\Entity\Db\TypeRole
*/
public function getTypeRole()
{
return $this->typeRole;
}
/**
* Set phpRoleId
*
* @param string $phpRoleId
* @return TypeRole
*/
public function setPhpRoleId($phpRoleId)
{
$this->phpRoleId = $phpRoleId;
return $this;
}
/**
* Get phpRoleId
*
* @return string
*/
public function getPhpRoleId()
{
return $this->phpRoleId;
}
}
......@@ -11,6 +11,7 @@ use Application\Acl\ComposanteRole;
use Application\Acl\ComposanteDbRole;
use Application\Entity\Db\Role as RoleEntity;
use Application\Service\Role as RoleService;
use Application\Service\TypeRolePhpRole as TypeRolePhpRoleService;
use Application\Service\RoleUtilisateur as RoleUtilisateurService;
use Zend\Permissions\Acl\Role\GenericRole;
......@@ -36,13 +37,19 @@ class RoleProvider implements ProviderInterface
/**
* Constructeur.
*
* @param TypeRolePhpRoleService $typeRolePhpRole
* @param RoleService $serviceRole
* @param RoleUtilisateurService $serviceRoleUtilisateur
* @param array $config
*/
public function __construct(RoleService $serviceRole, RoleUtilisateurService $serviceRoleUtilisateur, $config = null)
public function __construct(
TypeRolePhpRoleService $typeRolePhpRole,
RoleService $serviceRole,
RoleUtilisateurService $serviceRoleUtilisateur,
$config = null)
{
$this
->setServiceTypeRolePhpRole($typeRolePhpRole)
->setServiceRole($serviceRole)
->setServiceRoleUtilisateur($serviceRoleUtilisateur);
......@@ -66,8 +73,15 @@ class RoleProvider implements ProviderInterface
/**
* Rôles "composante" : exercés sur une structure de niveau 2 PORTEUSE d'éléments pédagogiques
*/
// rôle père
$roleComposante = new ComposanteRole();
$rolesComposante = $this->serviceRole->getList();
// rôles métier (importés d'Harpege) correspondant au ROLE_ID PHP
$qb = $this->serviceTypeRolePhpRole->finderByPhpRole($roleComposante->getRoleId());
$rolesComposante = array();
foreach ($qb->getQuery()->getResult() as $trpr) { /* @var $trpr \Application\Entity\Db\TypeRolePhpRole */
$qb2 = $this->serviceRole->finderByTypeRole($trpr->getTypeRole());
$rolesComposante += $this->serviceRole->getList($qb2);
}
/**
* Rôles utilisateurs au sein de l'application (tables UTILISATEUR, ROLE_UTILISATEUR et ROLE_UTILISATEUR_LINKER)
......@@ -116,6 +130,11 @@ class RoleProvider implements ProviderInterface
return new GenericRole($roleId);
}
/**
* @var TypeRolePhpRoleService
*/
private $serviceTypeRolePhpRole;
/**
* @var RoleService
*/
......@@ -126,6 +145,12 @@ class RoleProvider implements ProviderInterface
*/
private $serviceRoleUtilisateur;
public function setServiceTypeRolePhpRole(TypeRolePhpRoleService $serviceTypeRolePhpRole)
{
$this->serviceTypeRolePhpRole = $serviceTypeRolePhpRole;
return $this;
}
public function setServiceRole(RoleService $serviceRole)
{
$this->serviceRole = $serviceRole;
......
......@@ -21,8 +21,9 @@ class RoleProviderFactory implements FactoryInterface
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
$serviceTypeRolePhpRole = $serviceLocator->get('applicationTypeRolePhpRole'); /* @var $serviceTypeRolePhpRole \Application\Service\TypeRolePhpRole */
$serviceRole = $serviceLocator->get('applicationRole'); /* @var $serviceRole \Application\Service\Role */
$serviceUtilisateurRole = $serviceLocator->get('applicationRoleUtilisateur'); /* @var $serviceRole \Application\Service\RoleUtilisateur */
$serviceUtilisateurRole = $serviceLocator->get('applicationRoleUtilisateur'); /* @var $serviceUtilisateurRole \Application\Service\RoleUtilisateur */
$config = $serviceLocator->get('BjyAuthorize\Config');
if (! isset($config['role_providers']['ApplicationRoleProvider'])) {
......@@ -33,6 +34,6 @@ class RoleProviderFactory implements FactoryInterface
$providerConfig = $config['role_providers']['ApplicationRoleProvider'];
return new RoleProvider($serviceRole, $serviceUtilisateurRole, $providerConfig);
return new RoleProvider($serviceTypeRolePhpRole, $serviceRole, $serviceUtilisateurRole, $providerConfig);
}
}
\ No newline at end of file
......@@ -34,7 +34,7 @@ class Role extends AbstractEntityService
/**
*
* @param string $typeRole
* @param \Application\Entity\Db\TypeRole|string $typeRole
* @param type $qb
* @param type $alias
* @return type
......@@ -43,6 +43,10 @@ class Role extends AbstractEntityService
{
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);
......@@ -66,6 +70,28 @@ class Role extends AbstractEntityService
return $qb;
}
/**
*
* @param QueryBuilder $qb
* @param string $alias
* @return QueryBuilder
*/
public function finderByOffreFormationExistante(QueryBuilder $qb = null, $alias = null)
{
list($qb, $alias) = $this->initQuery($qb, $alias);
$qb
->select("$alias, tr123, s")
->distinct()
->innerJoin('r.type', 'tr123')
->innerJoin('r.structure', 's')
->innerJoin('s.elementPedagogique', 'ep');
// ->where('tr.code <> :code')->setParameter('code', 'IND')
// ->andWhere('s.niveau = :niv')->setParameter('niv', 2);
return $qb;
}
/**
* Retourne une liste d'entités en fonction du QueryBuilder donné
*
......@@ -80,11 +106,11 @@ class Role extends AbstractEntityService
list($qb, $alias) = $this->initQuery($qb, $alias);
$qb
->addSelect("tr, s")
->addSelect("tr987, s12")
->distinct()
->innerJoin('r.type', 'tr')
->innerJoin('r.structure', 's')
->andWhere('tr.code <> :codeExclu')->setParameter('codeExclu', 'IND')/*
->innerJoin('r.type', 'tr987')
->innerJoin('r.structure', 's12')
->andWhere('tr987.code <> :codeExclu')->setParameter('codeExclu', 'IND')/*
->andWhere('s.niveau = :niv')->setParameter('niv', 2)*/;
return parent::getList($qb);
......
<?php
namespace Application\Service;
use Doctrine\ORM\QueryBuilder;
/**
* Description of TypeRolePhpRole
*
* @author Laurent LÉCLUSE <laurent.lecluse at unicaen.fr>
*/
class TypeRolePhpRole extends AbstractEntityService
{
/**
* retourne la classe des entités
*
* @return string
* @throws RuntimeException
*/
public function getEntityClass()
{
return 'Application\Entity\Db\TypeRolePhpRole';
}
/**
* Retourne l'alias d'entité courante
*
* @return string
*/
public function getAlias()
{
return 'trpr';
}
/**
*
* @param \Application\Entity\Db\TypeRole|string $typeRole
* @param QueryBuilder $qb
* @param string $alias
* @return QueryBuilder
*/
public function finderByTypeRole($typeRole, QueryBuilder $qb = null, $alias = null)
{
list($qb, $alias) = $this->initQuery($qb, $alias);
if ($typeRole instanceof \Application\Entity\Db\TypeRole) {
$typeRole = $typeRole->getCode();
}
$qb
->innerJoin("$alias.typeRole", $trAlias = uniqid('tr'))
->andWhere("$trAlias.code = :code")->setParameter('code', $typeRole);
return $qb;
}
/**
*
* @param \Zend\Permissions\Acl\Role\RoleInterface|string $phpRole
* @param QueryBuilder $qb
* @param string $alias
* @return QueryBuilder
*/
public function finderByPhpRole($phpRole, QueryBuilder $qb = null, $alias = null)
{
list($qb, $alias) = $this->initQuery($qb, $alias);
if ($phpRole instanceof \Zend\Permissions\Acl\Role\RoleInterface) {
$phpRole = $phpRole->getRoleId();
}
$qb
->distinct()
->andWhere("$alias.phpRoleId = :roleId")->setParameter('roleId', $phpRole);
return $qb;
}
/**
* Retourne une liste d'entités en fonction du QueryBuilder donné
*
* La liste de présente sous la forme d'un tableau associatif, dont les clés sont les ID des entités et les valeurs les entités elles-mêmes
*
* @param QueryBuilder|null $qb
* @param string|null $alias
* @return array
*/
// public function getList(QueryBuilder $qb=null, $alias=null )
// {
// list($qb, $alias) = $this->initQuery($qb, $alias);
//
// $qb
// ->addSelect("tr, s")
// ->distinct()
// ->innerJoin('r.typeRole', $trAlias = uniqid('tr'))
// ->andWhere("$trAlias.code <> :codeExclu")->setParameter('codeExclu', 'IND');
//
// return parent::getList($qb);
// }
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment