diff --git a/module/Structure/src/Structure/Controller/StructureController.php b/module/Structure/src/Structure/Controller/StructureController.php index 013449cd0c2b46e13b1746f6a7c1e293b1ca8acb..82df1a6f642fe8a7fab82b2d47436b866e69ad4a 100644 --- a/module/Structure/src/Structure/Controller/StructureController.php +++ b/module/Structure/src/Structure/Controller/StructureController.php @@ -93,7 +93,8 @@ class StructureController extends AbstractActionController { /** Récupération des agents et postes liés aux structures */ $agents = $this->getAgentService()->getAgentsByStructures($structures); - $agentsForces = array_map(function (StructureAgentForce $a) { return $a->getAgent(); }, $structure->getAgentsForces()); + $agentsForces = $this->getStructureService()->getAgentsForces($structure); + $agentsForces = array_map(function (StructureAgentForce $a) { return $a->getAgent(); }, $agentsForces); $allAgents = array_merge($agents, $agentsForces); $fichesRecrutements = $this->getStructureService()->getFichesPostesRecrutementsByStructures($structures); diff --git a/module/Structure/src/Structure/Service/Structure/StructureService.php b/module/Structure/src/Structure/Service/Structure/StructureService.php index 7646899b66ddab415e29523fc6db15b379811fe9..9b427ea9eae470916ce461312481fad5a013fba4 100644 --- a/module/Structure/src/Structure/Service/Structure/StructureService.php +++ b/module/Structure/src/Structure/Service/Structure/StructureService.php @@ -12,6 +12,7 @@ use Doctrine\ORM\NonUniqueResultException; use Doctrine\ORM\ORMException; use Doctrine\ORM\QueryBuilder; use Structure\Entity\Db\Structure; +use Structure\Entity\Db\StructureAgentForce; use Structure\Entity\Db\StructureGestionnaire; use Structure\Entity\Db\StructureResponsable; use Structure\Provider\RoleProvider; @@ -572,4 +573,40 @@ EOS; $result = $qb->getQuery()->getResult(); return $result; } + + /** GESTION DES AGENTS FORCES *************************************************************************************/ + + /** + * @param Structure $structure + * @param DateTime|null $date + * @return StructureAgentForce[] + */ + public function getAgentsForces(Structure $structure, ?DateTime $date = null) : array + { + if ($date === null) $date = new DateTime(); + + $qb = $this->getEntityManager()->getRepository(StructureAgentForce::class)->createQueryBuilder('af') + ->join('af.agent', 'af_agent')->addSelect('af_agent') + ->join('af.structure', 'af_structure')->addSelect('af_structure') + ->leftjoin('af_agent.affectations', 'af_affectation')->addSelect('af_affectation') + ->leftjoin('af_affectation.structure', 'affectation_structure')->addSelect('affectation_structure') +// ->leftJoin('affectation_structure.responsables', 'structure_responsable')->addSelect('structure_responsable') +// ->leftJoin('structure_responsable.agent', 'structure_responsable_agent')->addSelect('structure_responsable_agent') + ->leftjoin('affectation_structure.niv2', 'affectation_niv2')->addSelect('affectation_niv2') +// ->leftJoin('affectation_niv2.responsables', 'niv2_responsable')->addSelect('niv2_responsable') +// ->leftJoin('niv2_responsable.agent', 'niv2_responsable_agent')->addSelect('niv2_responsable_agent') + + ->andWhere('af.structure = :structure') + ->setParameter('structure', $structure) + ->andWhere('af_affectation.dateDebut IS NULL or af_affectation.dateDebut <= :date') + ->andWhere('af_affectation.dateFin IS NULL or af_affectation.dateFin >= :date') +// ->andWhere('structure_responsable.dateDebut IS NULL or structure_responsable.dateDebut <= :date') +// ->andWhere('structure_responsable.dateFin IS NULL or structure_responsable.dateFin >= :date') +// ->andWhere('niv2_responsable.dateDebut IS NULL or niv2_responsable.dateDebut <= :date') +// ->andWhere('niv2_responsable.dateFin IS NULL or niv2_responsable.dateFin >= :date') + ->setParameter('date', $date) + ; + $result = $qb->getQuery()->getResult(); + return $result; + } }