add support for select2 in 'searchfolder', search only in folder name

This commit is contained in:
Uwe Steinmann 2024-10-31 18:02:24 +01:00
parent a19d0c1b2a
commit 6849ccd34d

View File

@ -126,29 +126,46 @@ switch($command) {
}
break; /* }}} */
/* This is used for searching folders in the folder selectors
* 1. the selector also having a tree
* 2. the selector based on select2 for <select class="chzn-select-folder" ...>
* $format is set to 'select2' in the second case.
*/
case 'searchfolder': /* {{{ */
if($user) {
$query = $_GET['query'];
$format = $_GET['format'] ?? '';
$query = $_GET['query'] ?? '';
if(!$query) {
header('Content-Type: application/json');
if($format == 'select2')
echo json_encode(['results'=>[]]);
else
echo json_encode([]);
return;
}
if(false !== ($pos = strpos($query, '/'))) {
$subquery = substr($query, 0, $pos);
$hits = $dms->search($subquery, $limit=0, $offset=0, $logicalmode='AND', $searchin=array(), $startFolder=$dms->getRootFolder(), $owner=null, $status = array(), $creationstartdate=array(), $creationenddate=array(), $modificationstartdate=array(), $modificationenddate=array(), $categories=array(), $attributes=array(), $mode=0x2, $expirationstartdate=array(), $expirationenddate=array());
$hits = $dms->search($subquery, $limit=0, $offset=0, $logicalmode='AND', $searchin=array(2), $startFolder=$dms->getRootFolder(), $owner=null, $status = array(), $creationstartdate=array(), $creationenddate=array(), $modificationstartdate=array(), $modificationenddate=array(), $categories=array(), $attributes=array(), $mode=0x2, $expirationstartdate=array(), $expirationenddate=array());
if($hits) {
if(count($hits['folders']) == 1) {
$hit = $hits['folders'][0];
$basefolder = $dms->getFolder($hit->getID());
if($basefolder->getAccessMode($user, 'search') >= M_READ) {
if($subquery = substr($query, $pos+1)) {
$hits = $dms->search($subquery, $limit=0, $offset=0, $logicalmode='AND', $searchin=array(), $startFolder=$basefolder, $owner=null, $status = array(), $creationstartdate=array(), $creationenddate=array(), $modificationstartdate=array(), $modificationenddate=array(), $categories=array(), $attributes=array(), $mode=0x2, $expirationstartdate=array(), $expirationenddate=array());
$hits = $dms->search($subquery, $limit=0, $offset=0, $logicalmode='AND', $searchin=array(2), $startFolder=$basefolder, $owner=null, $status = array(), $creationstartdate=array(), $creationenddate=array(), $modificationstartdate=array(), $modificationenddate=array(), $categories=array(), $attributes=array(), $mode=0x2, $expirationstartdate=array(), $expirationenddate=array());
if($hits) {
$result = array();
foreach($hits['folders'] as $hit) {
if($hit->getAccessMode($user, 'search') >= M_READ)
// $result[] = $hit->getID().'#'.$hit->getFolderPathPlain(true, '/');
$result[] = array('type'=>'F', 'id'=>$hit->getId(), 'name'=>htmlspecialchars($hit->getFolderPathPlain(true, '/')), 'path'=>htmlspecialchars($hit->getParent()->getFolderPathPlain(true, '/')));
$result[] = array('type'=>'F', 'id'=>$hit->getId(), 'name'=>htmlspecialchars($hit->getName()), 'path'=>htmlspecialchars($hit->getParent()->getFolderPathPlain(true, '/')));
}
header('Content-Type: application/json');
echo json_encode($result);
if($format == 'select2')
echo json_encode(['results'=>$result]);
else
echo json_encode($result);
return;
}
} else {
@ -158,10 +175,13 @@ switch($command) {
foreach($subfolders as $subfolder) {
//$result[] = $subfolder->getID().'#'.$basefolder->getName().'/'.$subfolder->getName();
// $result[] = $subfolder->getID().'#'.$subfolder->getFolderPathPlain(true, '/');
$result[] = array('type'=>'F', 'id'=>$subfolder->getId(), 'name'=>htmlspecialchars($subfolder->getFolderPathPlain(true, '/')), 'path'=>htmlspecialchars($subfolder->getParent()->getFolderPathPlain(true, '/')));
$result[] = array('type'=>'F', 'id'=>$subfolder->getId(), 'name'=>htmlspecialchars($subfolder->getName()), 'path'=>htmlspecialchars($subfolder->getParent()->getFolderPathPlain(true, '/')));
}
header('Content-Type: application/json');
echo json_encode($result);
if($format == 'select2')
echo json_encode(['results'=>$result]);
else
echo json_encode($result);
return;
}
}
@ -174,10 +194,13 @@ switch($command) {
foreach($hits['folders'] as $hit) {
if($hit->getAccessMode($user, 'search') >= M_READ)
// $result[] = $hit->getID().'#'.$hit->getFolderPathPlain(true, '/');
$result[] = array('type'=>'F', 'id'=>$hit->getId(), 'name'=>htmlspecialchars($hit->getFolderPathPlain(true, '/')), 'path'=>htmlspecialchars($hit->getParent()->getFolderPathPlain(true, '/')));
$result[] = array('type'=>'F', 'id'=>$hit->getId(), 'name'=>htmlspecialchars($hit->getName()), 'path'=>htmlspecialchars($hit->getParent()->getFolderPathPlain(true, '/')));
}
header('Content-Type: application/json');
echo json_encode($result);
if($format == 'select2')
echo json_encode(['results'=>$result]);
else
echo json_encode($result);
}
}
break; /* }}} */