Commit 7e37293a authored by Jean-Philippe Metivier's avatar Jean-Philippe Metivier
Browse files

Changement calcul de la chaine hierarchique

parent b7faa6bd
Loading
Loading
Loading
Loading
+2 −5
Original line number Diff line number Diff line
@@ -128,11 +128,8 @@ class AgentAssertion extends AbstractAssertion
        $role = $this->getUserService()->getConnectedRole();

        /** @var Agent|null $entity */
        $entity = null;
//        if (true AND $agent) {
        $agentId = (($this->getMvcEvent()->getRouteMatch()->getParam('agent')));
        $entity = $this->getAgentService()->getAgent($agentId);
//        }

        $structures = [];
        $affectations = $this->getAgentAffectationService()->getAgentAffectationsByAgent($entity);
+5 −16
Original line number Diff line number Diff line
@@ -292,19 +292,6 @@ class AgentService {
        return $result;
    }

    public function getAgentByHarp(string $st_harp_id)
    {
        $qb = $this->createQueryBuilder()
            ->andWhere('agent.harpId = :harp_id')
            ->setParameter('harp_id', $st_harp_id);
        try {
            $result = $qb->getQuery()->getOneOrNullResult();
        } catch (NonUniqueResultException $e) {
            throw new RuntimeException("Plusieurs agents partagent le même harp_id [".$st_harp_id."]");
        }
        return $result;
    }

    /**
     * @param $st_prenom
     * @param $st_nom
@@ -355,10 +342,12 @@ class AgentService {
        if (!empty($liste)) return $liste;

       //checking structure
       $affectationsPrincipales = $this->getAgentAffectationService()->getAgentAffectationsByAgent($agent);
       $affectationsPrincipales = $this->getAgentAffectationService()->getAgentAffectationHierarchiquePrincipaleByAgent($agent);
       if (count($affectationsPrincipales) !== 1) return []; //throw new LogicException("Plusieurs affectations principales pour l'agent ".$agent->getId() . ":".$agent->getDenomination());

       $structure = $affectationsPrincipales[0]->getStructure();
       $affectationPrincipale = $affectationsPrincipales[0];

       $structure = $affectationPrincipale->getStructure();
       do {
           $responsablesAll = array_map(function (StructureResponsable $a) {
               return $a->getAgent();
@@ -394,7 +383,7 @@ class AgentService {
        if ($superieurs === null) $superieurs = $this->computeSuperieures($agent, $date);

        //checking structure
        $affectationsPrincipales = $this->getAgentAffectationService()->getAgentAffectationsByAgent($agent);
        $affectationsPrincipales = $this->getAgentAffectationService()->getAgentAffectationHierarchiquePrincipaleByAgent($agent);
        $structure = null;
        if (count($affectationsPrincipales) === 1) {
            $structure = $affectationsPrincipales[0]->getStructure()->getNiv2();
+13 −1
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ namespace Application\Service\AgentAffectation;
use Application\Entity\Db\Agent;
use Application\Entity\Db\AgentAffectation;
use Doctrine\ORM\QueryBuilder;
use RuntimeException;
use Structure\Entity\Db\Structure;
use UnicaenApp\Service\EntityManagerAwareTrait;

@@ -30,10 +31,11 @@ class AgentAffectationService {
     * @param Agent $agent
     * @param bool $actif
     * @param bool $principale
     * @param bool $hierarchique
     * @param bool $fonctionnelle
     * @return AgentAffectation[]
     */
    public function getAgentAffectationsByAgent(Agent $agent, bool $actif = true, bool $principale = false, bool $fonctionnelle = true) : array
    public function getAgentAffectationsByAgent(Agent $agent, bool $actif = true, bool $principale = false, bool $hierarchique = true, bool $fonctionnelle = false) : array
    {
        $qb = $this->createQueryBuilder()
            ->andWhere('agentaffectation.agent = :agent')
@@ -42,6 +44,7 @@ class AgentAffectationService {
        ;

        if ($principale) $qb = $qb->andWhere("agentaffectation.principale = 'O'");
        if ($hierarchique) $qb = $qb->andWhere("agentaffectation.hierarchique = 'O'");
        if ($fonctionnelle) $qb = $qb->andWhere("agentaffectation.fonctionnelle = 'O'");
        if ($actif === true) $qb = AgentAffectation::decorateWithActif($qb, 'agentaffectation');

@@ -49,6 +52,15 @@ class AgentAffectationService {
        return $result;
    }

    /** @return AgentAffectation[]|null */
    public function getAgentAffectationHierarchiquePrincipaleByAgent(Agent $agent) : ?array
    {
        $result = $this->getAgentAffectationsByAgent($agent, true, true,true, false);
        $nb = count($result);
//        if ( $nb > 1) throw new RuntimeException("Plusieurs affections hiérarchique principale pour l'agent [".$agent->getDenomination()."]");
        if ($nb === 0 ) return null;
        return $result;
    }

    /**
     * @param Structure $structure