diff --git a/code/AssetAdmin.php b/code/AssetAdmin.php index 4e6ea585..73f3c89f 100755 --- a/code/AssetAdmin.php +++ b/code/AssetAdmin.php @@ -253,6 +253,18 @@ JS 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. diff --git a/code/AssetTableField.php b/code/AssetTableField.php index e46e24e6..f06cf0a9 100755 --- a/code/AssetTableField.php +++ b/code/AssetTableField.php @@ -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) );