From de44a536216d15a764b9519af8bc18fea2396a78 Mon Sep 17 00:00:00 2001
From: Damien <damien.burel@maarch.org>
Date: Thu, 20 Dec 2018 18:13:36 +0100
Subject: [PATCH] FEAT #8956 Improve list : Filters and order again

---
 .../controllers/ResourceListController.php       | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/src/app/resource/controllers/ResourceListController.php b/src/app/resource/controllers/ResourceListController.php
index d8850c5edf7..5bee6d12485 100644
--- a/src/app/resource/controllers/ResourceListController.php
+++ b/src/app/resource/controllers/ResourceListController.php
@@ -88,6 +88,14 @@ class ResourceListController
         if (!empty($data['delayed']) && $data['delayed'] == 'true') {
             $where[] = 'process_limit_date < CURRENT_TIMESTAMP';
         }
+        if (!empty($data['reference'])) {
+            $where[] = 'alt_identifier ilike ?';
+            $queryData[] = "%{$data['reference']}%";
+        }
+        if (!empty($data['subject']) && mb_strlen($data['subject']) >= 3) {
+            $where[] = 'subject ilike ?';
+            $queryData[] = "%{$data['subject']}%";
+        }
         if (!empty($data['priorities'])) {
             $where[] = 'priority in (?)';
             $queryData[] = explode(',', $data['priorities']);
@@ -96,6 +104,10 @@ class ResourceListController
             $where[] = 'category_id in (?)';
             $queryData[] = explode(',', $data['categories']);
         }
+        if (!empty($data['statuses'])) {
+            $where[] = 'status in (?)';
+            $queryData[] = explode(',', $data['statuses']);
+        }
         if (!empty($data['entities'])) {
             $where[] = 'destination in (?)';
             $queryData[] = explode(',', $data['entities']);
@@ -113,6 +125,10 @@ class ResourceListController
             }
         }
 
+        if (!empty($data['order']) && strpos($data['order'], 'alt_identifier') !== false) {
+            $data['order'] = 'order_alphanum(alt_identifier) ' . explode(' ', $data['order'])[1];
+        }
+
         $rawResources = ResModel::getOnView([
             'select'    => ['count(1) OVER()', 'res_id'],
             'where'     => $where,
-- 
GitLab