From 611627231b6a712053e05734d7509b1d3751151b Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 20 Nov 2008 02:59:43 +0000 Subject: Clean up the MediaRSS module a little bit: * Media_RSS_Controller::$LIMIT is now self::$page_size * We use ORM_MPTT descendant_counts() * If the page is out of bounds, put it on a boundary * Move pub_date into the controller to simplify the mrss file * Put all the view assignment in one block for easier reading * Removed stray ; from the end of lines in the mrss file Clean up ORM_MPTT a bit: * fix spelling: decendent -> descendant * Remove unnecessary order_by() clauses * Set the default for $type to null (not "all"). --- modules/media_rss/controllers/media_rss.php | 30 +++++++++++++++++--------- modules/media_rss/views/feed.mrss.php | 33 ++++++++++++++--------------- 2 files changed, 36 insertions(+), 27 deletions(-) (limited to 'modules') diff --git a/modules/media_rss/controllers/media_rss.php b/modules/media_rss/controllers/media_rss.php index 68025259..10d9741b 100644 --- a/modules/media_rss/controllers/media_rss.php +++ b/modules/media_rss/controllers/media_rss.php @@ -18,26 +18,36 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class Media_RSS_Controller extends Controller { - public static $LIMIT = 10; + public static $page_size = 10; + public function feed($id) { $item = ORM::factory("item", $id)->find(); if (!$item->loaded) { return Kohana::show_404(); } - $view = new View("feed.mrss"); - $view->item = $item; + $page = $this->input->get("page", 1); + if ($page < 1) { + url::redirect("media_rss/feed/{$item->id}"); + } - $offset = $this->input->get("offset", 0); - $view->children = $item->decendents(Media_RSS_Controller::$LIMIT, $offset, "photo"); + $children = $item->descendants(self::$page_size, ($page - 1) * self::$page_size, "photo"); + $count = $item->descendants_count("photo"); + $max_pages = ceil($item->descendants_count("photo") / self::$page_size); - if (!empty($offset)) { - $view->prevOffset = $offset - Media_RSS_Controller::$LIMIT; - } - if ($view->children->count() >= Media_RSS_Controller::$LIMIT) { - $view->nextOffset = $offset + Media_RSS_Controller::$LIMIT; + if ($page > $max_pages) { + url::redirect("media_rss/feed/{$item->id}?page=$max_pages"); } + $view = new View("feed.mrss"); + $view->item = $item; + $view->children = $children; + $view->previous_page = $page > 1 ? $page - 1 : null; + $view->next_page = $page < $max_pages ? $page + 1 : null; + + // @todo do we want to add an upload date to the items table? + $view->pub_date = date("D, d M Y H:i:s T"); + header("Content-type: application/rss+xml"); print $view; } diff --git a/modules/media_rss/views/feed.mrss.php b/modules/media_rss/views/feed.mrss.php index 8c88b8a2..b3f44a17 100644 --- a/modules/media_rss/views/feed.mrss.php +++ b/modules/media_rss/views/feed.mrss.php @@ -1,5 +1,5 @@ -"; ?> +" ?> @@ -7,21 +7,20 @@ id}") ?> description ?> en-us - id}") ?>" type="application/rss+xml" /> - - id}?offset={$prevOffset}") ?>" - type="application/rss+xml" /> - - - -- cgit v1.2.3