Skip to content

Commit

Permalink
MINOR Searching both Title and Filename in AssetAdmin (fixes #7013, s…
Browse files Browse the repository at this point in the history
…ee pull request #71)
  • Loading branch information
chillu committed Apr 11, 2012
1 parent 57d7655 commit 363dc9a
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions code/controllers/AssetAdmin.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -86,9 +86,21 @@ public function init() {
public function getList() { public function getList() {
$folder = $this->currentPage(); $folder = $this->currentPage();
$context = $this->getSearchContext(); $context = $this->getSearchContext();
// Overwrite name filter to search both Name and Title attributes
$context->removeFilterByName('Name');
$params = $this->request->requestVar('q'); $params = $this->request->requestVar('q');
$list = $context->getResults($params); $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 // Always show folders at the top
$list->sort('(CASE WHEN "File"."ClassName" = \'Folder\' THEN 0 ELSE 1 END), "Name"'); $list->sort('(CASE WHEN "File"."ClassName" = \'Folder\' THEN 0 ELSE 1 END), "Name"');


Expand Down

0 comments on commit 363dc9a

Please sign in to comment.