Commit 613f6190 authored by Stephane Bouvry's avatar Stephane Bouvry
Browse files

[Up] Critère de tri ajouté à la recherche des organisations.

parent 79f04673
Loading
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -2,6 +2,10 @@

## 2024

### Décembre
 - [Up] Critère de tri ajouté à la recherche des organisations.
 - [Up] La colonne indicence financière a été ajoutée pour les exports des projets.

### Novembre 2024
 - [Fix] Erreur sur les filtres 'Plusieurs personnes' et 'Plusieurs organisations'
 - [Fix] Erreur avec les commandes lièes aux dépenses (`spent:list`, `spent:infos`, `spent:accounts`)
+36 −1
Original line number Diff line number Diff line
@@ -111,6 +111,7 @@ class OrganizationController extends AbstractOscarController implements UseOrgan
        $allow = false;
        $justXHR = true;


        // On test les accès
        if ($this->getOscarUserContextService()->hasPrivileges(Privileges::ORGANIZATION_SHOW)) {
            $allow = true;
@@ -133,15 +134,44 @@ class OrganizationController extends AbstractOscarController implements UseOrgan
        $search = $this->params()->fromQuery('q', '');
        $type = $this->params()->fromQuery('t', []);
        $active = $this->params()->fromQuery('active', '');
        $sort = $this->params()->fromQuery('sort', 'hit');
        $direction = $this->params()->fromQuery('direction', 'ASC');
        $error = null;
        $organizations = null;

        $sorting = [
            'hit'         => 'Pertinence (recherche textuelle)',
            'shortName'   => 'Nom court',
            'fullName'    => 'Nom long',
            'code'        => 'Code',
            'dateUpdated' => 'Date de mise à jour',
            'dateEnd'     => 'Date de fermeture',
            'dateCreated' => 'Date de création',
        ];

        $directions = [
            'ASC'  => "Croissant",
            'DESC' => "Décroissant"
        ];

        // Controle du trie/direction
        if (!in_array($sort, array_keys($sorting))) {
            $sort = 'hit';
        }

        if (!in_array($direction, array_keys($directions))) {
            $direction = 'ASC';
        }

        $filter = [
            'roles'     => $this->params()->fromQuery('roles', []),
            'type'      => $type,
            'sort'      => $sort,
            'active'    => $active,
            'direction' => $direction,
        ];


        $organizations = [];

        if ($justXHR === false && $this->getRequest()->getQuery('action') == 'export-csv') {
@@ -181,6 +211,10 @@ class OrganizationController extends AbstractOscarController implements UseOrgan
        return array(
            'entities'   => $organizations,
            'error'      => $error,
            'sorting'    => $sorting,
            'sort'       => $sort,
            'direction'  => $direction,
            'directions' => $directions,
            'search'     => $search,
            'types'      => $this->getOrganizationService()->getOrganizationTypesSelect(),
            'type'       => $type,
@@ -371,7 +405,8 @@ class OrganizationController extends AbstractOscarController implements UseOrgan
                    $subStructures = $this->getOrganizationService()->getSubStructure($organizationId);
                    foreach ($subStructures as &$organization) {
                        $organization['show'] = $this->url()->fromRoute(
                            'organization/show', ['id' => $organization['id']]
                            'organization/show',
                            ['id' => $organization['id']]
                        );
                    }
                    $output['organizations'] = $subStructures;
+45 −5
Original line number Diff line number Diff line
@@ -704,6 +704,8 @@ class OrganizationService implements UseOscarConfigurationService, UseEntityMana
    public function getOrganizationsSearchPaged(string $search, int $page, array $filter = []): UnicaenDoctrinePaginator
    {
        $qb = $this->getSearchQuery($search, $filter);

        //die($qb->getDQL());
        return new UnicaenDoctrinePaginator($qb, $page);
    }

@@ -807,17 +809,19 @@ class OrganizationService implements UseOscarConfigurationService, UseEntityMana

    public function getSearchQuery($search, $filter)
    {
        $this->getLoggerService()->debug(__METHOD__);
        $qb = $this->getBaseQuery();

        if ($search != "") {
            $ids = $this->search($search, true);

            $sortSize = 25;

            // ORDER BY de LREM
            // Permet de forcer le trie dans l'ordre des IDs fournit par Elastic Search
            if (count($ids) > 1 ) {
                if( $filter['sort'] == 'hit' ){
                    $sortSize = 25; // On ne trie que les 25 premiers
                    $this->getLoggerService()->debug("SORT BY HIT (elastic IDS)");

                    $selectHidden = "(CASE ";
                    $i = 0;
                    foreach ($ids as $id) {
@@ -831,13 +835,48 @@ class OrganizationService implements UseOscarConfigurationService, UseEntityMana
                    $qb->addSelect($selectHidden);
                    $qb->orderBy('ORD', 'ASC');
                }

                $qb->where('o.id IN(:ids)')->setParameter('ids', $ids);
            }
        else {
            $qb->addOrderBy('o.dateEnd', 'DESC')->addOrderBy('o.dateUpdated', 'DESC');
        }

        if( $filter['sort'] != 'hit' ){
            $field = $filter['sort'];
            $direction = $filter['direction'];
            $this->getLoggerService()->debug("TRIE $field/$direction");
            $qb->addSelect("CASE WHEN o.$field IS NULL THEN 0 ELSE 1 END as HIDDEN null_value");
            $qb->addOrderBy('null_value', 'DESC');
            if( $field != 'dateUpdated' && $field != 'dateEnd' && $field != 'dateCreated'){
                $qb->addSelect("CASE WHEN o.$field =  '' THEN 0 ELSE 1 END as HIDDEN zero_value");
                $qb->addOrderBy('zero_value', 'DESC');
            }

            switch ($filter['sort']) {
                case 'shortName':
                    $qb->addOrderBy('o.shortName', $direction);
                    break;
                case 'fullName':
                    $qb->addOrderBy('o.fullName', $direction);
                    break;
                case 'code':
                    $qb->addOrderBy('o.code', $direction);
                    break;
                case 'dateUpdated':
                    $qb->addOrderBy('o.dateUpdated', $direction);
                    break;
                case 'dateEnd':
                    $qb->addOrderBy('o.dateEnd', $direction);
                    break;
                case 'dateCreated':
                    $qb->addOrderBy('o.dateCreated', $direction);
                    break;
            }


        }
//        else {
//            $qb->addOrderBy('o.dateEnd', 'DESC')->addOrderBy('o.dateUpdated', 'DESC');
//        }

        //

        // -------------------------------------------------------------------------------------------------------------
@@ -891,6 +930,7 @@ class OrganizationService implements UseOscarConfigurationService, UseEntityMana
            $qb->andWhere('o.id IN (:ids)')
                ->setParameter('ids', $ids);
        }
        //die($qb->getDQL());

        return $qb;
    }
+30 −1
Original line number Diff line number Diff line
@@ -45,7 +45,36 @@ $markText = function( $text, $search ){
                </select>
            </div>
            <div class="col-md-6">

                <label>Trie :</label>
                <div class="row">
                    <div class="col-md-6">
                        <select name="sort" class="form-control" onchange="handlerChangeSort" id="sort">
                            <?php foreach ($sorting as $key=>$label): ?>
                            <option value="<?= $key ?>" <?= $sort == $key ? 'SELECTED' : '' ?>><?= $label ?></option>
                            <?php endforeach; ?>
                        </select>
                    </div>
                    <div class="col-md-6" id="direction">
                        <select name="direction" class="form-control">
                            <?php foreach ($directions as $key=>$label): ?>
                                <option value="<?= $key ?>" <?= $direction == $key ? 'SELECTED' : '' ?>><?= $label ?></option>
                            <?php endforeach; ?>
                        </select>
                    </div>
                    <script>
                        document.querySelector('#sort').addEventListener('change', handlerChangeSort);
                        function handlerChangeSort(e){
                            console.log("handlerChangeSort");
                            let isHit = document.querySelector('#sort').value == 'hit';
                            if( isHit ){
                                document.querySelector('#direction').style.display = 'none';
                            } else {
                                document.querySelector('#direction').style.display = 'block';
                            }
                        }
                        handlerChangeSort();
                    </script>
                </div>
            </div>
        </div>
        <h3 class="text-center">