From 0720091ca73b9714aab2b38c3682c15a0cbd4533 Mon Sep 17 00:00:00 2001 From: Jesse Morgan Date: Thu, 2 Jun 2011 17:20:54 -0700 Subject: Added pages --- htdocs/src/PageIterator.inc.php | 79 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 htdocs/src/PageIterator.inc.php (limited to 'htdocs/src/PageIterator.inc.php') diff --git a/htdocs/src/PageIterator.inc.php b/htdocs/src/PageIterator.inc.php new file mode 100644 index 0000000..080c4db --- /dev/null +++ b/htdocs/src/PageIterator.inc.php @@ -0,0 +1,79 @@ + + * + */ + +require_once "base.inc.php"; + +class PageIterator 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 = "title asc"; + $this->limit = 0; + } + + public function orderBy($order) { + $this->order = $order; + } + + public function limit($limit) { + $this->limit = $limit; + } + + public function rewind() { + $this->position = 0; + } + + public function current() { + return new Page($this->rows[$this->position]); + } + + public function key() { + return $this->rows[$this->position]['id']; + } + + public function next() { + ++$this->position; + } + + public function valid() { + return isset($this->rows[$this->position]); + } + + public function query() { + $query = "SELECT * FROM page"; + + 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); + $this->position = 0; + } +} + +?> + + -- cgit v1.2.3