Skip to content
This repository
Browse code

MINOR Searching both Title and Filename in AssetAdmin (fixes #7013, s…

…ee pull request #71)
  • Loading branch information...
commit 363dc9a4a9bd3c4b1eceee9941585b9eac49ca67 1 parent 57d7655
Ingo Schommer authored

Showing 1 changed file with 12 additions and 0 deletions. Show diff stats Hide diff stats

  1. 12  code/controllers/AssetAdmin.php
12  code/controllers/AssetAdmin.php
@@ -86,9 +86,21 @@ public function init() {
86 86
 	public function getList() {
87 87
 		$folder = $this->currentPage();
88 88
 		$context = $this->getSearchContext();
  89
+		// Overwrite name filter to search both Name and Title attributes
  90
+		$context->removeFilterByName('Name');
89 91
 		$params = $this->request->requestVar('q');
90 92
 		$list = $context->getResults($params);
91 93
 
  94
+		// Re-add previously removed "Name" filter as combined filter
  95
+		// TODO Replace with composite SearchFilter once that API exists
  96
+		if(isset($params['Name'])) {
  97
+			$list->where(sprintf(
  98
+				'"Name" LIKE \'%%%s%%\' OR "Title" LIKE \'%%%s%%\'',
  99
+				Convert::raw2sql($params['Name']),
  100
+				Convert::raw2sql($params['Name'])
  101
+			));
  102
+		}
  103
+
92 104
 		// Always show folders at the top		
93 105
 		$list->sort('(CASE WHEN "File"."ClassName" = \'Folder\' THEN 0 ELSE 1 END), "Name"');
94 106
 

0 notes on commit 363dc9a

Please sign in to comment.
Something went wrong with that request. Please try again.