mirror of
https://git.code.sf.net/p/seeddms/code
synced 2025-05-10 13:42:41 +00:00
add support for select2 in 'searchfolder', search only in folder name
This commit is contained in:
parent
a19d0c1b2a
commit
6849ccd34d
|
@ -126,29 +126,46 @@ switch($command) {
|
||||||
}
|
}
|
||||||
break; /* }}} */
|
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': /* {{{ */
|
case 'searchfolder': /* {{{ */
|
||||||
if($user) {
|
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, '/'))) {
|
if(false !== ($pos = strpos($query, '/'))) {
|
||||||
$subquery = substr($query, 0, $pos);
|
$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($hits) {
|
||||||
if(count($hits['folders']) == 1) {
|
if(count($hits['folders']) == 1) {
|
||||||
$hit = $hits['folders'][0];
|
$hit = $hits['folders'][0];
|
||||||
$basefolder = $dms->getFolder($hit->getID());
|
$basefolder = $dms->getFolder($hit->getID());
|
||||||
if($basefolder->getAccessMode($user, 'search') >= M_READ) {
|
if($basefolder->getAccessMode($user, 'search') >= M_READ) {
|
||||||
if($subquery = substr($query, $pos+1)) {
|
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) {
|
if($hits) {
|
||||||
$result = array();
|
$result = array();
|
||||||
foreach($hits['folders'] as $hit) {
|
foreach($hits['folders'] as $hit) {
|
||||||
if($hit->getAccessMode($user, 'search') >= M_READ)
|
if($hit->getAccessMode($user, 'search') >= M_READ)
|
||||||
// $result[] = $hit->getID().'#'.$hit->getFolderPathPlain(true, '/');
|
// $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');
|
header('Content-Type: application/json');
|
||||||
echo json_encode($result);
|
if($format == 'select2')
|
||||||
|
echo json_encode(['results'=>$result]);
|
||||||
|
else
|
||||||
|
echo json_encode($result);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -158,10 +175,13 @@ switch($command) {
|
||||||
foreach($subfolders as $subfolder) {
|
foreach($subfolders as $subfolder) {
|
||||||
//$result[] = $subfolder->getID().'#'.$basefolder->getName().'/'.$subfolder->getName();
|
//$result[] = $subfolder->getID().'#'.$basefolder->getName().'/'.$subfolder->getName();
|
||||||
// $result[] = $subfolder->getID().'#'.$subfolder->getFolderPathPlain(true, '/');
|
// $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');
|
header('Content-Type: application/json');
|
||||||
echo json_encode($result);
|
if($format == 'select2')
|
||||||
|
echo json_encode(['results'=>$result]);
|
||||||
|
else
|
||||||
|
echo json_encode($result);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -174,10 +194,13 @@ switch($command) {
|
||||||
foreach($hits['folders'] as $hit) {
|
foreach($hits['folders'] as $hit) {
|
||||||
if($hit->getAccessMode($user, 'search') >= M_READ)
|
if($hit->getAccessMode($user, 'search') >= M_READ)
|
||||||
// $result[] = $hit->getID().'#'.$hit->getFolderPathPlain(true, '/');
|
// $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');
|
header('Content-Type: application/json');
|
||||||
echo json_encode($result);
|
if($format == 'select2')
|
||||||
|
echo json_encode(['results'=>$result]);
|
||||||
|
else
|
||||||
|
echo json_encode($result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break; /* }}} */
|
break; /* }}} */
|
||||||
|
|
Loading…
Reference in New Issue
Block a user