year = $year; $this->month = $month; $this->execute(); } public function getYear() { return $this->year; } public function getMonth() { return $this->month; } /** * Get the year and month filter in a unix timestamp. * * @return The month and year filter as a unix timestamp. */ function getDate() { return mktime(0, 0, 0, $this->month + 1, 0, $this->year); } /** * Provided to allow subclasses to set the result used by the iterator. * * @param DBResult $result database result set */ protected function setResult(DBResult &$result) { $this->result = $result; } /** * Perform the database lookup. */ private function execute() { if (is_null($this->result)) { $db = new DB(); $sql = "SELECT p.id, p.url, p.title, UNIX_TIMESTAMP(p.created) as created, p.published, e.allow_comments FROM pages as p, entries e WHERE p.published = 1 AND p.id = e.id "; if (!is_null($this->year)) { $sql .= "AND DATE_FORMAT(p.created, '%Y') = ? "; } if (!is_null($this->month)) { $sql .= "AND DATE_FORMAT(p.created, '%m') = ? "; } $sql .= "ORDER BY DATE_FORMAT(p.created, '%Y-%m-%d') DESC, p.title ASC"; $this->result = $db->query($sql, $this->year, $this->month); Model::assertError($this->result); } } /** * Get the entries in the archive. * * @return array of Entry objects. */ public function getEntries() { if (count($this->entries) != count($this)) { foreach ($this as $entry) { // Do nothing. Iterator will fill up the object cache. } } return $this->entries; } /** {@inheritDoc} */ public function count() { return count($this->result); } /** {@inheritDoc} */ public function current() { if (!isset($this->entries[$this->key()])) { $this->entries[$this->key()] = Entry::newInstance( $this->result->current()); } return $this->entries[$this->key()]; } /** {@inheritDoc} */ public function key() { return $this->result->key(); } /** {@inheritDoc} */ public function next() { $this->result->next(); return $this->valid() ? $this->current() : null; } /** {@inheritDoc} */ public function rewind() { $this->result->rewind(); } /** {@inheritDoc} */ public function valid() { return $this->result->valid(); } } ?>