Now history.view.search searches through users+machines (as on its views) + TODO: manage space separated keywords
This commit is contained in:
parent
ad4143771c
commit
d30ec35636
|
@ -235,34 +235,60 @@
|
|||
/* [1] Recherche dans les relations 'machines'
|
||||
=========================================================*/
|
||||
/* (1) On exécute la requête */
|
||||
$machines_r = new Repo('machine/search', [$id_warehouse, $keyword]);
|
||||
$machines_rq = new Repo('machine/search', [$id_warehouse, $keyword]);
|
||||
|
||||
$machines_rs = $machines_rq->answer();
|
||||
|
||||
/* (2) Gestion succès */
|
||||
if( $machines_r->error->get() == Err::Success )
|
||||
foreach($machines_r->answer() as $row)
|
||||
if( is_array($machines_rs) )
|
||||
foreach($machines_rs as $row)
|
||||
$machine_ids[] = $row['id_machine'];
|
||||
|
||||
/* [2] Recherche dans les relations 'users'
|
||||
=========================================================*/
|
||||
/* (1) On cherche dans les utilisateurs */
|
||||
$users_r = new Repo('user/search', [$id_warehouse, $keyword]);
|
||||
$users_rq = new Repo('user/search', [$id_warehouse, $keyword]);
|
||||
|
||||
$users_rs = $users_rq->answer();
|
||||
|
||||
/* (2) Gestion succès */
|
||||
if( $users_r->error->get() == Err::Success )
|
||||
foreach($users_r->answer() as $row)
|
||||
if( is_array($users_rs) )
|
||||
foreach($users_rs as $row)
|
||||
$user_ids[] = $row['id_user'];
|
||||
|
||||
|
||||
/* [3] On rédige/execute la requête
|
||||
=========================================================*/
|
||||
$history_r = DatabaseDriver::getPDO()->prepare("SELECT id_history FROM history
|
||||
WHERE id_user IN (SELECT id_user FROM user WHERE username LIKE '%$keyword%')
|
||||
or id_machine IN (SELECT id_machine FROM machine WHERE name LIKE '%$keyword%')
|
||||
ORDER BY timestamp DESC;");
|
||||
/* (1) Recherche par utilisateur */
|
||||
$history_r_user = Table::get('history')
|
||||
->select('id_history')
|
||||
->whereIdUser([ $user_ids, Rows::COND_IN ]);
|
||||
|
||||
$history_r->execute();
|
||||
/* (2) Recherche par utilisateur */
|
||||
$history_r_machine = Table::get('history')
|
||||
->select('id_history')
|
||||
->whereIdMachine([ $machine_ids, Rows::COND_IN ]);
|
||||
|
||||
return DatabaseDriver::delNumeric( $history_r->fetchAll() );
|
||||
/* (3) On enregistre les entrées par utilisateur */
|
||||
$already_id = [];
|
||||
$ids = $history_r_user->fetch();
|
||||
|
||||
foreach($ids as $user_result)
|
||||
$already_id[ $user_result['id_history'] ] = null;
|
||||
|
||||
/* (4) On ajoute les entrées par machines (si pas déja) */
|
||||
foreach($history_r_machine->fetch() as $machine_result)
|
||||
|
||||
if( !isset($already_id[$machine_result['id_history']]) ){
|
||||
|
||||
$ids[] = $machine_result;
|
||||
$already_id[ $machine_result['id_history'] ] = null;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* (5) On retourne le total */
|
||||
return $ids;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -65,6 +65,10 @@
|
|||
*
|
||||
*/
|
||||
public static function search($id_warehouse, $keyword){
|
||||
|
||||
// make keyword lowercase
|
||||
$keyword = strtolower($keyword);
|
||||
|
||||
// On recupere les donnees
|
||||
$search = Table::get('machine')
|
||||
->whereIdWarehouse($id_warehouse)
|
||||
|
|
|
@ -66,14 +66,18 @@
|
|||
*
|
||||
*/
|
||||
public static function search($id_warehouse, $keyword){
|
||||
|
||||
// make keyword lowercase
|
||||
$keyword = strtolower($keyword);
|
||||
|
||||
// On recupere les donnees
|
||||
$searchusers = DatabaseDriver::getPDO()->prepare("SELECT * FROM user
|
||||
WHERE id_warehouse = :id_warehouse
|
||||
AND ( code LIKE '%".$keyword."%'
|
||||
OR username LIKE '%".$keyword."%'
|
||||
OR firstname LIKE '%".$keyword."%'
|
||||
OR lastname LIKE '%".$keyword."%'
|
||||
OR mail LIKE '%".$keyword."%'
|
||||
AND ( LOWER(code) LIKE '%".$keyword."%'
|
||||
OR LOWER(username) LIKE '%".$keyword."%'
|
||||
OR LOWER(firstname) LIKE '%".$keyword."%'
|
||||
OR LOWER(lastname) LIKE '%".$keyword."%'
|
||||
OR LOWER(mail) LIKE '%".$keyword."%'
|
||||
)
|
||||
");
|
||||
|
||||
|
|
Loading…
Reference in New Issue