summaryrefslogtreecommitdiff
path: root/classes/Notice.php
diff options
context:
space:
mode:
authorBrion Vibber <brion@pobox.com>2010-12-17 13:03:18 -0800
committerBrion Vibber <brion@pobox.com>2010-12-17 13:03:18 -0800
commit9e8bbff8ac3825dc789bcd19b1751fe24017a789 (patch)
tree4e3cc552ee0b4ef9a137a921b72cae0b35cffb2b /classes/Notice.php
parent53dd2583fcf5d026f682b0966e87dbdd35fc19a8 (diff)
Notice::whereSinceId() and Notice::whereMaxId() encapsulate logic for building where clauses for since_id/max_id parameters. Can override the field names from 'id' and 'created'.
Diffstat (limited to 'classes/Notice.php')
-rw-r--r--classes/Notice.php48
1 files changed, 44 insertions, 4 deletions
diff --git a/classes/Notice.php b/classes/Notice.php
index b5a1b4597..14a91977d 100644
--- a/classes/Notice.php
+++ b/classes/Notice.php
@@ -668,14 +668,14 @@ class Notice extends Memcached_DataObject
$notice->whereAdd('is_local !='. Notice::GATEWAY);
}
- $since = Notice::getAsTimestamp($since_id);
+ $since = Notice::whereSinceId($since_id);
if ($since) {
- $notice->whereAdd(sprintf("(created = '%s' and id > %d) or (created > '%s')", $since, $since_id, $since));
+ $notice->whereAdd($since);
}
- $max = Notice::getAsTimestamp($max_id);
+ $max = Notice::whereMaxId($max_id);
if ($max) {
- $notice->whereAdd(sprintf("(created < '%s') or (created = '%s' and id <= %d)", $max, $max, $max_id));
+ $notice->whereAdd($max);
}
$ids = array();
@@ -2006,4 +2006,44 @@ class Notice extends Memcached_DataObject
return false;
}
+
+ /**
+ * Build an SQL 'where' fragment for timestamp-based sorting from a since_id
+ * parameter, matching notices posted after the given one (exclusive).
+ *
+ * If the referenced notice can't be found, will return false.
+ *
+ * @param int $id
+ * @param string $idField
+ * @param string $createdField
+ * @return mixed string or false if no match
+ */
+ public static function whereSinceId($id, $idField='id', $createdField='created')
+ {
+ $since = Notice::getAsTimestamp($id);
+ if ($since) {
+ return sprintf("($createdField = '%s' and $idField > %d) or ($createdField > '%s')", $since, $id, $since);
+ }
+ return false;
+ }
+
+ /**
+ * Build an SQL 'where' fragment for timestamp-based sorting from a max_id
+ * parameter, matching notices posted before the given one (inclusive).
+ *
+ * If the referenced notice can't be found, will return false.
+ *
+ * @param int $id
+ * @param string $idField
+ * @param string $createdField
+ * @return mixed string or false if no match
+ */
+ public static function whereMaxId($id, $idField='id', $createdField='created')
+ {
+ $max = Notice::getAsTimestamp($id);
+ if ($max) {
+ return sprintf("($createdField < '%s') or ($createdField = '%s' and $idField <= %d)", $max, $max, $id);
+ }
+ return false;
+ }
}