Commit 6668c9fe authored by Jean-Philippe Metivier's avatar Jean-Philippe Metivier
Browse files

Elargissement de la recherche pour les complements (les agents ont plus besoin...

Elargissement de la recherche pour les complements (les agents ont plus besoin d'une affectation valide)
parent 736d73c2
Loading
Loading
Loading
Loading
+11
Changes for module/Application/config/merged/agent.config.php: 11 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -103,6 +103,7 @@ return [
                    'controller' => AgentController::class,
                    'action' => [
                        'rechercher',
                        'rechercher-large',
                        'rechercher-with-structure-mere',
                        'rechercher-responsable',
                        'rechercher-gestionnaire',
@@ -229,6 +230,16 @@ return [
                            ],
                        ],
                    ],
                    'rechercher-large' => [
                        'type'  => Literal::class,
                        'options' => [
                            'route'    => '/rechercher-large',
                            'defaults' => [
                                'controller' => AgentController::class,
                                'action'     => 'rechercher-large',
                            ],
                        ],
                    ],
                    'rechercher-with-structure-mere' => [
                        'type'  => Segment::class,
                        'options' => [
+10
Changes for module/Application/src/Application/Controller/AgentController.php: 10 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -395,6 +395,16 @@ class AgentController extends AbstractActionController

    /** Recherche d'agent  ********************************************************************************************/

    public function rechercherLargeAction() : JsonModel
    {
        if (($term = $this->params()->fromQuery('term'))) {
            $agents = $this->getAgentService()->getAgentsLargeByTerm($term);
            $result = $this->getAgentService()->formatAgentJSON($agents);
            return new JsonModel($result);
        }
        exit;
    }

    public function rechercherAction() : JsonModel
    {
        if (($term = $this->params()->fromQuery('term'))) {
+2 −1
Changes for module/Application/src/Application/Controller/ComplementController.php: 2 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -49,7 +49,8 @@ class ComplementController extends AbstractActionController {
            case Complement::COMPLEMENT_TYPE_RESPONSABLE :
            case Complement::COMPLEMENT_TYPE_AUTORITE :
                $complement->setComplementType(Agent::class);
                $form->get('sas')->setAutocompleteSource($this->url()->fromRoute('agent/rechercher', [], [], true));
                /** @see AgentController::rechercherAction() */
                $form->get('sas')->setAutocompleteSource($this->url()->fromRoute('agent/rechercher-large', [], [], true));
                break;
            case Complement::COMPLEMENT_TYPE_STRUCTURE :
                $complement->setComplementType(Structure::class);
+16
Changes for module/Application/src/Application/Service/Agent/AgentService.php: 16 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -152,6 +152,22 @@ EOS;
        return $result;
    }

    /**
     * @param string|null $term
     * @return Agent[]
     */
    public function getAgentsLargeByTerm(?string $term) : array
    {
        $qb = $this->getEntityManager()->getRepository(Agent::class)->createQueryBuilder('agent')
            ->andWhere("LOWER(CONCAT(agent.prenom, ' ', agent.nomUsuel)) like :search OR LOWER(CONCAT(agent.nomUsuel, ' ', agent.prenom)) like :search")
            ->setParameter('search', '%'.strtolower($term).'%')
        ;

        $result =  $qb->getQuery()->getResult();
        return $result;
    }


    /**
     * @param string|null $id
     * @return Agent|null