Commit c1d4a7af authored by root's avatar root
Browse files

Merge branch 'master' of https://git.unicaen.fr/dsi/preecog

parents 038f73c5 bf29239c
Loading
Loading
Loading
Loading
+1 −2
Changes for module/Application/src/Application/Controller/IndexController.php: 1 added line, 2 removed lines.
Original line number Diff line number Diff line
@@ -33,8 +33,7 @@ class IndexController extends AbstractActionController
        $connectedUser = $this->getUserService()->getConnectedUser();

        if ($this->getServiceUserContext()->getLdapUser()) {
            $supannId = ((int) $this->getServiceUserContext()->getLdapUser()->getSupannEmpId());
            $agent = $this->getAgentService()->getAgentBySupannId($supannId);
            $agent = $this->getAgentService()->getAgentByUsername($connectedUser->getUsername());

            if ($connectedUser !== null && $agent !== null && $agent->getUtilisateur() === null) {
                $agent->setUtilisateur($connectedUser);
+20
Changes for module/Application/src/Application/Service/Agent/AgentService.php: 20 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -204,6 +204,26 @@ EOS;
        return $result;
    }

    /**
     * @param string|null $unsername
     * @return Agent|null
     */
    public function getAgentByUsername(?string $username) : ?Agent
    {
        if ($username === null) return null;

        $qb = $this->getEntityManager()->getRepository(Agent::class)->createQueryBuilder('agent')
            ->andWhere('agent.login = :username')
            ->setParameter('username', $username)
        ;
        try {
            $result = $qb->getQuery()->getOneOrNullResult();
        } catch (NonUniqueResultException $e) {
            throw new RuntimeException("Plusieurs Agent liés au même Username [".$username."]", $e);
        }
        return $result;
    }

    /**
     * @param int $supannId
     * @return Agent|null