mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
ENHANCEMENT #3920: Alllow searching within subfolders in Files and Images section
BUGFIX: Let users open the root folder in Files and Images section git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/branches/2.3@75226 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
859cfe66bd
commit
e9f1a7e0c4
@ -253,6 +253,18 @@ JS
|
||||
</script>
|
||||
HTML;
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom currentPage() method to handle opening the 'root' folder
|
||||
*/
|
||||
public function currentPage() {
|
||||
$id = $this->currentPageID();
|
||||
if($id && is_numeric($id)) {
|
||||
return DataObject::get_by_id($this->stat('tree_class'), $id);
|
||||
} else if($id == 'root') {
|
||||
return singleton($this->stat('tree_class'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the form that displays the details of a folder, including a file list and fields for editing the folder name.
|
||||
|
@ -16,6 +16,12 @@ class AssetTableField extends ComplexTableField {
|
||||
"delete",
|
||||
//"export",
|
||||
);
|
||||
|
||||
/**
|
||||
* Indicates whether a search is being executed on this object
|
||||
*/
|
||||
protected $searchingFor = null;
|
||||
|
||||
function __construct($controller, $name, $sourceClass, $fieldList, $detailFormFields, $sourceFilter = "", $sourceSort = "", $sourceJoin = "") {
|
||||
parent::__construct($controller, $name, $sourceClass, $fieldList, $detailFormFields, $sourceFilter, $sourceSort, $sourceJoin);
|
||||
|
||||
@ -29,6 +35,7 @@ class AssetTableField extends ComplexTableField {
|
||||
if(strpos($fieldName, '.') === false) $searchFilters[] = "`$fieldName` LIKE '%{$SQL_search}%'";
|
||||
}
|
||||
$this->sourceFilter = '(' . implode(' OR ', $searchFilters) . ')';
|
||||
$this->searchingFor = $_REQUEST['FileSearch'];
|
||||
}
|
||||
|
||||
$this->sourceSort = 'Title';
|
||||
@ -47,7 +54,25 @@ class AssetTableField extends ComplexTableField {
|
||||
function setFolder($folder) {
|
||||
$this->folder = $folder;
|
||||
$this->sourceFilter .= ($this->sourceFilter) ? " AND " : "";
|
||||
$this->sourceFilter .= " ParentID = '" . $folder->ID . "' AND ClassName <> 'Folder'";
|
||||
|
||||
// If you are searching for files then show all those from subfolders
|
||||
if($this->searchingFor) {
|
||||
$folderIDs = $nextIDSet = array($folder->ID);
|
||||
$folderClasses = "'" . implode("','", ClassInfo::subclassesFor("Folder")) . "'";
|
||||
|
||||
while($nextIDSet) {
|
||||
// TO DO: In 2.4 this should be refactored to use the new data mapper.
|
||||
$nextIDSet = DB::query("SELECT ID FROM `File` WHERE ParentID IN ("
|
||||
. implode(", " , $nextIDSet) . ") AND ClassName IN ($folderClasses)")->column();
|
||||
if($nextIDSet) $folderIDs = array_merge($folderIDs, $nextIDSet);
|
||||
}
|
||||
|
||||
$this->sourceFilter .= " ParentID IN (" . implode(", ", $folderIDs) . ") AND ClassName <> 'Folder'";
|
||||
|
||||
// Otherwise just show the direct contents
|
||||
} else {
|
||||
$this->sourceFilter .= " ParentID = '" . $folder->ID . "' AND ClassName <> 'Folder'";
|
||||
}
|
||||
}
|
||||
|
||||
function Folder() {
|
||||
@ -141,7 +166,7 @@ class AssetTableField extends ComplexTableField {
|
||||
*/
|
||||
function SearchForm() {
|
||||
$searchFields = new FieldGroup(
|
||||
new TextField('FileSearch', _t('MemberTableField.SEARCH', 'Search')),
|
||||
new TextField('FileSearch', _t('MemberTableField.SEARCH', 'Search'), $this->searchingFor),
|
||||
new HiddenField("ctf[ID]", '', $this->ID),
|
||||
new HiddenField('FileFieldName', '', $this->name)
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user