summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2008-11-07 07:33:43 +0000
committerBharat Mediratta <bharat@menalto.com>2008-11-07 07:33:43 +0000
commit76436c0029f5be153f805a1be03e17ea26309906 (patch)
tree2ac99106d2600c5de8518621a22cda8702598ff2
parent50a9848f383c988b720c99945fbb91f371e02fa0 (diff)
Add automatic pagination. All you have to do is add <?= $theme->pager
?> to your theme file and you get a well formed pager. Themes can customize this any way they want. A version that matches the mockup is provided in the default theme.
-rw-r--r--core/controllers/album.php19
-rw-r--r--core/libraries/MY_Pagination.php35
-rw-r--r--core/libraries/Theme.php12
-rw-r--r--themes/default/views/album.html.php8
-rw-r--r--themes/default/views/pager.html.php28
5 files changed, 90 insertions, 12 deletions
diff --git a/core/controllers/album.php b/core/controllers/album.php
index abe9039a..788ff9e2 100644
--- a/core/controllers/album.php
+++ b/core/controllers/album.php
@@ -26,13 +26,24 @@ class Album_Controller extends Template_Controller {
return Kohana::show_404();
}
- $this->template->content = new View("album.html");
+ /** @todo: these need to be pulled from the database */
+ $theme_name = "default";
+ $page_size = 9;
+
+ $page = $this->input->get("page", "1");
+ $theme = new Theme($theme_name, $this->template);
+ $this->template->content = new View("album.html");
+ $this->template->set_global('page_size', $page_size);
$this->template->set_global('item', $item);
- $this->template->set_global('children', $item->children());
+ $this->template->set_global('children', $item->children($page_size, ($page-1) * $page_size));
$this->template->set_global('parents', $item->parents());
+ $this->template->set_global('theme', $theme);
- /** @todo: this needs to be data-driven */
- $this->template->set_global('theme', new Theme("default", $this->template));
+ /** @todo: move this up to a base class */
+ if (Session::instance()->get("use_profiler", false)) {
+ $profiler = new Profiler();
+ print $profiler->render();
+ }
}
}
diff --git a/core/libraries/MY_Pagination.php b/core/libraries/MY_Pagination.php
new file mode 100644
index 00000000..394e7be7
--- /dev/null
+++ b/core/libraries/MY_Pagination.php
@@ -0,0 +1,35 @@
+<?php defined("SYSPATH") or die("No direct script access.");
+/**
+ * Gallery - a web based photo album viewer and editor
+ * Copyright (C) 2000-2008 Bharat Mediratta
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+class Pagination extends Pagination_Core {
+ public function render($style=NULL) {
+ // Hide single page pagination
+ if ($this->auto_hide === TRUE AND $this->total_pages <= 1) {
+ return "";
+ }
+
+ if ($style === NULL) {
+ // Use default style
+ $style = $this->style;
+ }
+
+ // Return rendered pagination view
+ return View::factory("pager.html", get_object_vars($this))->render();
+ }
+}
diff --git a/core/libraries/Theme.php b/core/libraries/Theme.php
index 101cbb42..0f195d08 100644
--- a/core/libraries/Theme.php
+++ b/core/libraries/Theme.php
@@ -38,8 +38,18 @@ class Theme_Core {
return new $view_class($page_name);
}
+ public function pager() {
+ $this->pagination = new Pagination();
+ $this->pagination->initialize(
+ array('query_string' => 'page',
+ 'total_items' => $this->template->item->children_count(),
+ 'items_per_page' => $this->template->page_size,
+ 'style' => 'classic'));
+ return $this->pagination->render();
+ }
+
public function blocks() {
- /** @todo: this needs to be made data-driven */
+ /** @todo: make this data driven */
$blocks = array(
'carousel' => carousel::block($this),
'tags' => tags::block($this),
diff --git a/themes/default/views/album.html.php b/themes/default/views/album.html.php
index 0d181536..034c9a9e 100644
--- a/themes/default/views/album.html.php
+++ b/themes/default/views/album.html.php
@@ -27,10 +27,4 @@
<? endforeach ?>
</ul>
- <div id="gPagination">
- Items 1-10 of 34
- <span class="first_inactive">first</span>
- <span class="previous_inactive">previous</span>
- <a href="#" class="next">next</a>
- <a href="#" class="last">last</a>
- </div>
+ <?= $theme->pager() ?>
diff --git a/themes/default/views/pager.html.php b/themes/default/views/pager.html.php
new file mode 100644
index 00000000..bec06696
--- /dev/null
+++ b/themes/default/views/pager.html.php
@@ -0,0 +1,28 @@
+<? defined("SYSPATH") or die("No direct script access."); ?>
+<? // See http://docs.kohanaphp.com/libraries/pagination ?>
+<div id="gPagination">
+ <?= sprintf(_("Photos %d - %d of %d"), $current_first_item, $current_last_item, $total_items) ?>
+ <? if ($first_page): ?>
+ <a href="<?= str_replace('{page}', 1, $url) ?>"><?= _("first") ?></a>
+ <? else: ?>
+ <span class="first_inactive"><?= _("first") ?></span>
+ <? endif ?>
+
+ <? if ($previous_page): ?>
+ <a href="<?= str_replace('{page}', $previous_page, $url) ?>"><?= _("previous") ?></a>
+ <? else: ?>
+ <span class="previous_inactive"><?= _("previous") ?></span>
+ <? endif ?>
+
+ <? if ($next_page): ?>
+ <a href="<?= str_replace('{page}', $next_page, $url) ?>"><?= _("next") ?></a>
+ <? else: ?>
+ <span class="next_inactive"><?= _("next") ?></span>
+ <? endif ?>
+
+ <? if ($last_page): ?>
+ <a href="<?= str_replace('{page}', $last_page, $url) ?>"><?= _("last") ?></a>
+ <? else: ?>
+ <span class="last_inactive"><?= _("last") ?></span>
+ <? endif ?>
+</div>