Skip to content

Commit

Permalink
Fix dol_dir_list_in_database to use filters for db (#31835)
Browse files Browse the repository at this point in the history
* Fix dol_dir_list_in_database to use filters as an Universal Search String

* fix CI

* fix Ci

---------

Co-authored-by: Hystepik <lmarcouiller@nltechno.com>
  • Loading branch information
Hystepik and Hystepik authored Nov 15, 2024
1 parent eb8fcc8 commit d9ee8a3
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion htdocs/core/lib/files.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,12 @@ function dol_dir_list($utf8_path, $types = "all", $recursive = 0, $filter = "",
* @param string $sortcriteria Sort criteria ("","fullname","name","date","size")
* @param int $sortorder Sort order (SORT_ASC, SORT_DESC)
* @param int $mode 0=Return array minimum keys loaded (faster), 1=Force all keys like description
* @param string $sqlfilters Filter as an Universal Search string.
* Example: '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')'
* @return array<array{rowid:string,label:string,name:string,path:string,level1name:string,fullname:string,fullpath_orig:string,date_c:string,date_m:string,type:string,keywords:string,cover:string,position:int,acl:string,share:string,description:string}> Array of array('name'=>'xxx','fullname'=>'/abc/xxx','date'=>'yyy','size'=>99,'type'=>'dir|file',...)
* @see dol_dir_list()
*/
function dol_dir_list_in_database($path, $filter = "", $excludefilter = null, $sortcriteria = "name", $sortorder = SORT_ASC, $mode = 0)
function dol_dir_list_in_database($path, $filter = "", $excludefilter = null, $sortcriteria = "name", $sortorder = SORT_ASC, $mode = 0, $sqlfilters = "")
{
global $conf, $db;

Expand All @@ -277,6 +279,14 @@ function dol_dir_list_in_database($path, $filter = "", $excludefilter = null, $s
$sql .= " AND filepath = '".$db->escape($path)."'";
}

// Manage filter
$errormessage = '';
$sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
if ($errormessage) {
dol_print_error(null, $errormessage);
return array();
}

$resql = $db->query($sql);
if ($resql) {
$file_list = array();
Expand Down

0 comments on commit d9ee8a3

Please sign in to comment.