summaryrefslogtreecommitdiff
path: root/modules/media_rss/controllers
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2008-11-20 02:59:43 +0000
committerBharat Mediratta <bharat@menalto.com>2008-11-20 02:59:43 +0000
commit611627231b6a712053e05734d7509b1d3751151b (patch)
tree84ef749090c5d43582b9b93f02b50104176a6d17 /modules/media_rss/controllers
parentc3fc1cb7ec91783a7953486c8a83aa8008dd5406 (diff)
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").
Diffstat (limited to 'modules/media_rss/controllers')
-rw-r--r--modules/media_rss/controllers/media_rss.php30
1 files changed, 20 insertions, 10 deletions
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;
}