aboutsummaryrefslogtreecommitdiff
path: root/engine/lib/elgglib.php
diff options
context:
space:
mode:
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2011-02-12 23:08:00 +0000
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2011-02-12 23:08:00 +0000
commit26847773312887a4a982e4afd457b3da5fced384 (patch)
treeed9322af765681eccc195959bb62929dcae9604d /engine/lib/elgglib.php
parentda90ff55725a9118ce6111ab2b6371650bf78ade (diff)
downloadelgg-26847773312887a4a982e4afd457b3da5fced384.tar.gz
elgg-26847773312887a4a982e4afd457b3da5fced384.tar.bz2
Fixes #2906. Added elgg_sql_reverse_order_by() and wired it up to ege() and ega(). Pass 'reverse_order_by' => true in option arrays.
git-svn-id: http://code.elgg.org/elgg/trunk@8184 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/lib/elgglib.php')
-rw-r--r--engine/lib/elgglib.php24
1 files changed, 24 insertions, 0 deletions
diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php
index 12560308e..7ebf918b7 100644
--- a/engine/lib/elgglib.php
+++ b/engine/lib/elgglib.php
@@ -1659,6 +1659,30 @@ function css_page_handler($page) {
}
/**
+ * Reverses the ordering in an ORDER BY clause. This is achived by replacing
+ * asc with desc, or appending desc to the end of the clause.
+ *
+ * This is used mostly for elgg_get_entities() and other similar functions.
+ *
+ * @access private
+ * @param string $order_by An order by clause
+ */
+function elgg_sql_reverse_order_by_clause($order_by) {
+ $order_by = strtolower($order_by);
+
+ if (strpos($order_by, ' asc') !== false) {
+ $return = str_replace(' asc', ' desc', $order_by);
+ } elseif (strpos($order_by, ' desc') !== false) {
+ $return = str_replace(' desc', ' asc', $order_by);
+ } else {
+ // no order specified, so default to desc since mysql defaults to asc
+ $return = $order_by . ' desc';
+ }
+
+ return $return;
+}
+
+/**
* Intercepts the index page when Walled Garden mode is enabled.
*
* @link http://docs.elgg.org/Tutorials/WalledGarden