diff --git a/classes/NotificationStream.php b/classes/NotificationStream.php index 0a815fd..3f3c961 100644 --- a/classes/NotificationStream.php +++ b/classes/NotificationStream.php @@ -41,8 +41,13 @@ class NotificationStream $notification->limit($offset, $limit); $notification->orderBy('qvitternotification.created DESC'); - QvitterNotification::addWhereSinceId($notification, $since_id); - QvitterNotification::addWhereMaxId($notification, $max_id); + if($since_id) { + $notification->whereAdd(sprintf('qvitternotification.id > %d', $notification->escape($since_id))); + } + + if($max_id) { + $notification->whereAdd(sprintf('qvitternotification.id <= %d', $notification->escape($max_id))); + } if (!$notification->find()) { return array(); diff --git a/classes/QvitterNotification.php b/classes/QvitterNotification.php index 0757bb6..869827c 100644 --- a/classes/QvitterNotification.php +++ b/classes/QvitterNotification.php @@ -54,103 +54,5 @@ class QvitterNotification extends Managed_DataObject return $result; } - /** - * Look up the creation timestamp for a given notice ID, even - * if it's been deleted. - * - * @param int $id - * @return mixed string recorded creation timestamp, or false if can't be found - */ - public static function getAsTimestamp($id) - { - if (!$id) { - return false; - } - - $notice = QvitterNotification::getKV('id', $id); - if ($notice) { - return $notice->created; - } - - 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 = QvitterNotification::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 since_id - * parameter, matching notices posted after the given one (exclusive), and - * if necessary add it to the data object's query. - * - * @param DB_DataObject $obj - * @param int $id - * @param string $idField - * @param string $createdField - * @return mixed string or false if no match - */ - public static function addWhereSinceId(DB_DataObject $obj, $id, $idField='id', $createdField='created') - { - $since = self::whereSinceId($id, $idField, $createdField); - if ($since) { - $obj->whereAdd($since); - } - } - - /** - * 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 = QvitterNotification::getAsTimestamp($id); - if ($max) { - return sprintf("($createdField < '%s') or ($createdField = '%s' and $idField <= %d)", $max, $max, $id); - } - return false; - } - - /** - * Build an SQL 'where' fragment for timestamp-based sorting from a max_id - * parameter, matching notices posted before the given one (inclusive), and - * if necessary add it to the data object's query. - * - * @param DB_DataObject $obj - * @param int $id - * @param string $idField - * @param string $createdField - * @return mixed string or false if no match - */ - public static function addWhereMaxId(DB_DataObject $obj, $id, $idField='id', $createdField='created') - { - $max = self::whereMaxId($id, $idField, $createdField); - if ($max) { - $obj->whereAdd($max); - } - } }