From 5f1a795b735e6054c7e9e7f2b32850c74ec95552 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Sat, 5 Mar 2011 01:54:47 -0800 Subject: [PATCH] Add some other ways to order searches to the base search engine class --- lib/search_engines.php | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/lib/search_engines.php b/lib/search_engines.php index 19703e03fd..7f1684a3e7 100644 --- a/lib/search_engines.php +++ b/lib/search_engines.php @@ -41,8 +41,35 @@ class SearchEngine function set_sort_mode($mode) { - if ('chron' === $mode) - return $this->target->orderBy('created desc'); + switch ($mode) { + case 'chron': + return $this->target->orderBy('created DESC'); + break; + case 'reverse_chron': + return $this->target->orderBy('created ASC'); + break; + case 'nickname_desc': + if ($this->table != 'profile') { + throw new Exception( + 'nickname_desc sort mode can only be use when searching profile.' + ); + } else { + return $this->target->orderBy('nickname DESC'); + } + break; + case 'nickname_asc': + if ($this->table != 'profile') { + throw new Exception( + 'nickname_desc sort mode can only be use when searching profile.' + ); + } else { + return $this->target->orderBy('nickname ASC'); + } + break; + default: + return $this->target->orderBy('created DESC'); + break; + } } }