diff options
Diffstat (limited to 'htdocs/src/PostIterator.inc.php')
-rw-r--r-- | htdocs/src/PostIterator.inc.php | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/htdocs/src/PostIterator.inc.php b/htdocs/src/PostIterator.inc.php index 6106f23..52eb750 100644 --- a/htdocs/src/PostIterator.inc.php +++ b/htdocs/src/PostIterator.inc.php @@ -14,11 +14,15 @@ class PostIterator implements Iterator { private $where; private $rows; private $position; + private $order; + private $limit; public function __construct() { $this->where = array(); $this->rows = array(); $this->position = 0; + $this->order = "created desc"; + $this->limit = 0; } public function filterStage($stage) { @@ -29,6 +33,14 @@ class PostIterator implements Iterator { $this->where[] = "source_id='$source'"; } + public function orderBy($order) { + $this->order = $order; + } + + public function limit($limit) { + $this->limit = limit; + } + public function rewind() { $this->position = 0; } @@ -50,13 +62,19 @@ class PostIterator implements Iterator { } public function query() { - $query = "SELECT * FROM post"; + $query = "SELECT *, UNIX_TIMESTAMP(created) AS createdts FROM post"; if (count($this->where) > 0) { $where = join(' AND ', $this->where); $query .= " WHERE $where"; } + $query .= " ORDER BY ". $this->order; + + if ($this->limit != 0) { + $query .= " LIMIT ". $this->limit; + } + $db = getDatabase(); $this->rows = $db->fetchAssocRows($query); |