Update repo machine/search to match any keywords (space-separated) with a OR condition + minfix user
This commit is contained in:
parent
b745c9ef08
commit
f99d1a8435
|
@ -66,18 +66,74 @@
|
|||
*/
|
||||
public static function search($id_warehouse, $keyword){
|
||||
|
||||
// make keyword lowercase
|
||||
/* (1) Format keyword
|
||||
---------------------------------------------------------*/ {
|
||||
|
||||
/* (1) Make all lowercase */
|
||||
$keyword = strtolower($keyword);
|
||||
|
||||
// On recupere les donnees
|
||||
$search = Table::get('machine')
|
||||
/* (2) Create a keyword set (separator: space) */
|
||||
$keywords = [];
|
||||
$keywords_tmp = explode(' ', $keyword);
|
||||
|
||||
/* (4) Trim each keyword + ignore empty ones (2 consecutive spaces) */
|
||||
foreach($keywords_tmp as $kw){
|
||||
|
||||
// ignore empty keywords
|
||||
if( strlen(trim($kw)) == 0 )
|
||||
continue;
|
||||
|
||||
// store others
|
||||
$keywords[] = trim($kw);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* (2) Search for each keyword
|
||||
---------------------------------------------------------*/ {
|
||||
|
||||
/* (1) Initialise id list that will contain each matching user ids */
|
||||
$mac_id_list = [];
|
||||
|
||||
/* (2) Request for each keyword */
|
||||
foreach($keywords as $kw){
|
||||
|
||||
// {2.1} Request //
|
||||
$searchmac = Table::get('machine')
|
||||
->select('id_machine')
|
||||
->whereIdWarehouse($id_warehouse)
|
||||
->whereName(["%$keyword%", Rows::COND_LIKE])
|
||||
->whereName(["%$kw%", Rows::COND_LIKE] );
|
||||
|
||||
// {2.2} Fetch result //
|
||||
$matches = $searchmac->fetch();
|
||||
|
||||
// {2.3} Only add non-already added ids //
|
||||
foreach($matches as $match){
|
||||
|
||||
// {2.4.1} If not already -> add it //
|
||||
if( !isset($mac_id_list[ $match['id_machine'] ]) )
|
||||
$mac_id_list[ $match['id_machine'] ] = null;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* (3) Join results
|
||||
---------------------------------------------------------*/
|
||||
/* (1) Join request */
|
||||
$join_rq = Table::get('machine')
|
||||
->select('id_machine')
|
||||
->select('name')
|
||||
->orderby('name', Rows::ORDER_ASC);
|
||||
->whereId([array_keys($mac_id_list), Rows::COND_IN]);
|
||||
|
||||
/* (2) Return result */
|
||||
return $join_rq->fetch();
|
||||
|
||||
return $search->fetch();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -91,8 +91,10 @@
|
|||
|
||||
}
|
||||
|
||||
|
||||
/* (2) Search for each keyword
|
||||
---------------------------------------------------------*/
|
||||
---------------------------------------------------------*/ {
|
||||
|
||||
/* (1) Initialise id list that will contain each matching user ids */
|
||||
$user_id_list = [];
|
||||
|
||||
|
@ -128,6 +130,8 @@
|
|||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* (3) Join results
|
||||
---------------------------------------------------------*/
|
||||
|
|
|
@ -66,6 +66,20 @@ if( section.view.element != null ){
|
|||
/* (3) Gestion de la recherche instantannee */
|
||||
section.view.search.func = function(){
|
||||
|
||||
// if no keyword -> show all
|
||||
if( section.view.search.bar.value.length == 0 ){
|
||||
|
||||
// On recupere la liste des elements correspondants aux utilisateurs
|
||||
var mac_list = document.querySelectorAll(section.view.text + '> article.inline-box[id]');
|
||||
|
||||
// Affiche chaque carte
|
||||
for( var i = 0 ; i < mac_list.length ; i++ )
|
||||
mac_list[i].remClass('hidden');
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
var search = {
|
||||
path: 'machineDefault/search',
|
||||
keywords: section.view.search.bar.value
|
||||
|
@ -84,6 +98,7 @@ if( section.view.element != null ){
|
|||
var machine_list = document.querySelectorAll(section.view.text + '> article.inline-box[id]');
|
||||
|
||||
// Pour chaque machine
|
||||
console.log(uid_list);
|
||||
for( var i = 0 ; i < machine_list.length ; i++ ){
|
||||
// Si doit etre visible
|
||||
if( uid_list.indexOf(parseInt(machine_list[i].id)) > -1 )
|
||||
|
|
Loading…
Reference in New Issue