From 363dc9a4a9bd3c4b1eceee9941585b9eac49ca67 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Wed, 11 Apr 2012 16:18:38 +0200 Subject: [PATCH] MINOR Searching both Title and Filename in AssetAdmin (fixes #7013, see pull request #71) --- code/controllers/AssetAdmin.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/code/controllers/AssetAdmin.php b/code/controllers/AssetAdmin.php index 571787c5..1e8d93eb 100644 --- a/code/controllers/AssetAdmin.php +++ b/code/controllers/AssetAdmin.php @@ -86,9 +86,21 @@ JS public function getList() { $folder = $this->currentPage(); $context = $this->getSearchContext(); + // Overwrite name filter to search both Name and Title attributes + $context->removeFilterByName('Name'); $params = $this->request->requestVar('q'); $list = $context->getResults($params); + // Re-add previously removed "Name" filter as combined filter + // TODO Replace with composite SearchFilter once that API exists + if(isset($params['Name'])) { + $list->where(sprintf( + '"Name" LIKE \'%%%s%%\' OR "Title" LIKE \'%%%s%%\'', + Convert::raw2sql($params['Name']), + Convert::raw2sql($params['Name']) + )); + } + // Always show folders at the top $list->sort('(CASE WHEN "File"."ClassName" = \'Folder\' THEN 0 ELSE 1 END), "Name"');