Skip to content
Snippets Groups Projects
Verified Commit ce7ea753 authored by Damien's avatar Damien
Browse files

FEAT #12869 TIME 0:50 Search count + all ids

parent a0ae7ee5
No related branches found
No related tags found
No related merge requests found
...@@ -17,6 +17,7 @@ namespace Search\controllers; ...@@ -17,6 +17,7 @@ namespace Search\controllers;
use Attachment\models\AttachmentModel; use Attachment\models\AttachmentModel;
use Basket\models\BasketModel; use Basket\models\BasketModel;
use Basket\models\RedirectBasketModel; use Basket\models\RedirectBasketModel;
use Doctype\models\DoctypeModel;
use Priority\models\PriorityModel; use Priority\models\PriorityModel;
use Resource\models\ResModel; use Resource\models\ResModel;
use Resource\models\ResourceContactModel; use Resource\models\ResourceContactModel;
...@@ -143,20 +144,38 @@ class SearchController ...@@ -143,20 +144,38 @@ class SearchController
$offset = (int)$queryParams['offset']; $offset = (int)$queryParams['offset'];
} }
$resources = ResModel::getOnView([ $allResources = ResModel::getOnView([
'select' => [ 'select' => ['res_id as "resId"'],
'res_id as "resId"', 'alt_identifier as "chrono"', 'subject', 'barcode', 'filename', 'creation_date as "creationDate"',
'type_id as "type"', 'priority', 'status', 'dest_user as "destUser"'
],
'where' => $searchWhere, 'where' => $searchWhere,
'data' => $searchData, 'data' => $searchData,
'orderBy' => ['creation_date DESC'], 'orderBy' => ['creation_date DESC']
'limit' => $limit,
'offset' => $offset
]); ]);
if (empty($allResources[$offset])) {
return $response->withJson(['resources' => [], 'count' => 0]);
}
$resIds = [];
$order = 'CASE res_id ';
for ($i = $offset; $i < $limit; $i++) {
if (empty($allResources[$i]['resId'])) {
break;
}
$order .= "WHEN {$allResources[$i]['resId']} THEN {$i} ";
$resIds[] = $allResources[$i]['resId'];
}
$order .= 'END';
$resources = ResModel::get([
'select' => [
'res_id as "resId"', 'category_id as "category"', 'alt_identifier as "chrono"', 'subject', 'barcode', 'filename', 'creation_date as "creationDate"',
'type_id as "type"', 'priority', 'status', 'dest_user as "destUser"', 'count(1) OVER()'
],
'where' => ['res_id in (?)'],
'data' => [$resIds],
'orderBy' => [$order]
]);
if (empty($resources)) { if (empty($resources)) {
return $response->withJson([]); return $response->withJson(['resources' => [], 'count' => 0]);
} }
$resourcesIds = array_column($resources, 'resId'); $resourcesIds = array_column($resources, 'resId');
...@@ -168,6 +187,9 @@ class SearchController ...@@ -168,6 +187,9 @@ class SearchController
$statusesIds = array_column($resources, 'status'); $statusesIds = array_column($resources, 'status');
$statuses = StatusModel::get(['select' => ['id', 'label_status', 'img_filename'], 'where' => ['id in (?)'], 'data' => [$statusesIds]]); $statuses = StatusModel::get(['select' => ['id', 'label_status', 'img_filename'], 'where' => ['id in (?)'], 'data' => [$statusesIds]]);
$doctypesIds = array_column($resources, 'type');
$doctypes = DoctypeModel::get(['select' => ['type_id', 'description'], 'where' => ['type_id in (?)'], 'data' => [$doctypesIds]]);
$correspondents = ResourceContactModel::get([ $correspondents = ResourceContactModel::get([
'select' => ['item_id as id', 'type', 'mode', 'res_id'], 'select' => ['item_id as id', 'type', 'mode', 'res_id'],
'where' => ['res_id in (?)'], 'where' => ['res_id in (?)'],
...@@ -190,6 +212,11 @@ class SearchController ...@@ -190,6 +212,11 @@ class SearchController
} }
} }
} }
foreach ($doctypes as $doctype) {
if ($doctype['type_id'] == $resource['type']) {
$resources[$key]['typeLabel'] = $doctype['description'];
}
}
if (!empty($resource['destUser'])) { if (!empty($resource['destUser'])) {
$resources[$key]['destUserLabel'] = UserModel::getLabelledUserById(['login' => $resource['destUser']]); $resources[$key]['destUserLabel'] = UserModel::getLabelledUserById(['login' => $resource['destUser']]);
} }
...@@ -212,6 +239,6 @@ class SearchController ...@@ -212,6 +239,6 @@ class SearchController
} }
} }
return $response->withJson($resources); return $response->withJson(['resources' => $resources, 'count' => count($allResources)]);
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment