diff options
author | brettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2010-01-14 15:40:22 +0000 |
---|---|---|
committer | brettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2010-01-14 15:40:22 +0000 |
commit | de0963eafb5143fdf44dbac17fa115deacc46453 (patch) | |
tree | 78eb372f48570c9925aec8dcf145fa9a892d3f2f /mod/search/start.php | |
parent | 9c0a913909e0b560ce5e2723098e233601e86903 (diff) | |
download | elgg-de0963eafb5143fdf44dbac17fa115deacc46453.tar.gz elgg-de0963eafb5143fdf44dbac17fa115deacc46453.tar.bz2 |
Fixed an incorrect var name that caused a bug when hooking against a type but not a subtype.
Added first pass at results sorting.
git-svn-id: http://code.elgg.org/elgg/trunk@3808 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'mod/search/start.php')
-rw-r--r-- | mod/search/start.php | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/mod/search/start.php b/mod/search/start.php index 8e84a4144..4b3268f6e 100644 --- a/mod/search/start.php +++ b/mod/search/start.php @@ -424,6 +424,57 @@ function search_get_where_sql($table, $fields, $params, $use_fulltext = TRUE) { return $where; } + +/** + * Returns ORDER BY sql for insertion into elgg_get_entities(). + * + * @param str $entities_table Prefix for entities table. + * @param str $type_table Prefix for the type table. + * @param str $sort ORDER BY part + * @param str $order ASC or DESC + * @return str + */ +function search_get_order_by_sql($entities_table, $type_table, $sort, $order) { + + $on = NULL; + + switch ($sort) { + default: + case 'relevance': + // default is relevance descending. + // acending relevancy is silly and complicated. + $on = ''; + break; + case 'created': + $on = "$entities_table.time_created"; + break; + case 'updated': + $on = "$entities_table.time_updated"; + break; + case 'action_on': + // @todo not supported yet in core + $on = ''; + break; + case 'alpha': + // @todo not support yet because both title + // and name columns are used for this depending + // on the entity, which we don't always know. >:O + break; + } + + $order = strtolower($order); + if ($order != 'asc' && $order != 'desc') { + $order = 'DESC'; + } + + if ($on) { + $order_by = "ORDER BY $table.$column $dir"; + } else { + $order_by = ''; + } + + return $ob; +} /** Register init system event **/ register_elgg_event_handler('init','system','search_init');
\ No newline at end of file |