Commit a344ba5f authored by Antony Le Courtes's avatar Antony Le Courtes
Browse files

Amélioration de la recherche intervenant pour appliquer la limitation du...

Amélioration de la recherche intervenant pour appliquer la limitation du nombre de résultat aprés la recherche Oracle. Ajout également du filtrage par type d'intervenant directement dans le sql. (#67401)
parent f587fd2d
Loading
Loading
Loading
Loading
+2 −1
Changes for front/Intervenant/Recherche.vue: 2 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -122,7 +122,8 @@ export default {

                unicaenVue.axios.post(
                    unicaenVue.url("intervenant/recherche-json"), {
                        term: this.searchTerm
                        term: this.searchTerm,
                        types: this.checkedTypes,
                    }
                )
                    .then(response => {
+15 −1
Changes for module/Intervenant/src/Controller/IntervenantController.php: 15 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -128,9 +128,23 @@ class IntervenantController extends AbstractController
        $recherche->setShowHisto($canShowHistorises);
        $intervenants = [];
        $term = $this->axios()->fromPost('term');
        $requestedTypes = (array)$this->axios()->fromPost('types', []);
        $typeCodesByFilter = [
            'vacataire' => 'E',
            'permanent' => 'P',
            'etudiant'  => 'S',
        ];
        $typeCodes = [];
        foreach ($requestedTypes as $requestedType) {
            if (isset($typeCodesByFilter[$requestedType])) {
                $typeCodes[] = $typeCodesByFilter[$requestedType];
            }
        }

        if (!empty($term)) {
            $intervenants = $recherche->rechercher($term, 40);
            $intervenants = array_values(
                $recherche->rechercher($term, 40, ':CODE', $typeCodes)
            );
        }

        return new AxiosModel($intervenants);
+33 −9
Changes for module/Intervenant/src/Processus/RechercheProcessus.php: 33 added lines, 9 removed lines.
Original line number Diff line number Diff line
@@ -25,18 +25,24 @@ class RechercheProcessus
     *
     * @return array
     */
    public function rechercher ($critere, $limit = 50, string $key = ':CODE')
    public function rechercher ($critere, $limit = 50, string $key = ':CODE', array $typeIntervenantCodes = [])
    {
        try {
            return $this->rechercheGenerique($critere, $limit, $key, false);
            return $this->rechercheGenerique($critere, $limit, $key, false, $typeIntervenantCodes);
        } catch (\Exception $e) {
            return $this->rechercheGenerique($critere, $limit, $key, true);
            return $this->rechercheGenerique($critere, $limit, $key, true, $typeIntervenantCodes);
        }
    }



    private function rechercheGenerique ($critere, $limit = 50, string $key = ':CODE', $onlyLocale = false)
    private function rechercheGenerique (
        $critere,
        $limit = 50,
        string $key = ':CODE',
        $onlyLocale = false,
        array $typeIntervenantCodes = []
    )
    {
        if (strlen($critere) < 2) return [];

@@ -49,8 +55,8 @@ class RechercheProcessus
        WITH vrec AS (
            ' . $this->sqlLocale() . '  
        )
        SELECT * FROM vrec WHERE 
          rownum <= ' . (int)$limit . ' AND annee_id = ' . $anneeId;
        SELECT * FROM (
          SELECT * FROM vrec WHERE annee_id = ' . $anneeId;
        $sqlCri  = '';
        $criCode = 0;

@@ -71,7 +77,20 @@ class RechercheProcessus
            $orc[] = 'code LIKE \'%' . $criCode . '%\'';
        }
        $orc = implode(' OR ', $orc);
        $sql .= ' AND (' . $orc . ') ORDER BY nom_usuel, prenom';

        $validTypeCodes = array_values(array_intersect(['E', 'P', 'S'], $typeIntervenantCodes));
        if ([] !== $validTypeCodes) {
            $quotedTypeCodes = array_map(
                static fn(string $code): string => "'" . $code . "'",
                $validTypeCodes
            );
            $sql .= ' AND type_intervenant_code IN (' . implode(', ', $quotedTypeCodes) . ')';
        }

        $sql .= ' AND (' . $orc . ')
          ORDER BY nom_usuel, prenom
        ) WHERE rownum <= ' . (int)$limit . '
        ORDER BY nom_usuel, prenom';

        $intervenants = [];

@@ -225,9 +244,14 @@ class RechercheProcessus
     *
     * @return array
     */
    public function rechercherLocalement ($critere, $limit = 50, string $key = ':CODE')
    public function rechercherLocalement (
        $critere,
        $limit = 50,
        string $key = ':CODE',
        array $typeIntervenantCodes = []
    )
    {
        return $this->rechercheGenerique($critere, $limit, $key, true);
        return $this->rechercheGenerique($critere, $limit, $key, true, $typeIntervenantCodes);
    }

    /**