diff options
author | Joe7 <jozsef.rnagy@site.hu> | 2011-01-11 21:28:25 +0100 |
---|---|---|
committer | Joe7 <jozsef.rnagy@site.hu> | 2011-01-11 21:28:25 +0100 |
commit | df802de6ae3cc0c294a1a3dc76db29ff21949b9f (patch) | |
tree | 662ea7192763bcb25628f48ac34120e84ee19870 | |
parent | 00b520fffd867389b5a030ddefee9f468cad044c (diff) |
Making good use of Pagination class to reduce code (removed MY_Controller which duplicated some functionality available in Pagination as well)
-rw-r--r-- | modules/gallery/libraries/MY_Controller.php | 26 | ||||
-rw-r--r-- | modules/user/controllers/admin_users.php | 24 | ||||
-rw-r--r-- | modules/user/views/admin_users.html.php | 28 |
3 files changed, 13 insertions, 65 deletions
diff --git a/modules/gallery/libraries/MY_Controller.php b/modules/gallery/libraries/MY_Controller.php deleted file mode 100644 index ea2a7502..00000000 --- a/modules/gallery/libraries/MY_Controller.php +++ /dev/null @@ -1,26 +0,0 @@ -<?php defined("SYSPATH") or die("No direct script access."); -/** - * Gallery - a web based photo album viewer and editor - * Copyright (C) 2000-2010 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 Controller extends Controller_Core { - public function get_pager_params($page, $item_count, $items_per_page) { - $offset = ($page - 1) * $items_per_page; - $max_pages = max(ceil($item_count / $items_per_page), 1); - return array($offset, $max_pages); - } -}
\ No newline at end of file diff --git a/modules/user/controllers/admin_users.php b/modules/user/controllers/admin_users.php index 2ae9788e..e11145de 100644 --- a/modules/user/controllers/admin_users.php +++ b/modules/user/controllers/admin_users.php @@ -28,32 +28,30 @@ class Admin_Users_Controller extends Admin_Controller { $page = Input::instance()->get("page", "1"); $builder = db::build(); $user_count = $builder->from("users")->count_records(); - list($offset, $max_pages) = Controller::get_pager_params($page, $user_count, $page_size); + + $view->content->pager = new Pagination(); + $view->content->pager->initialize( + array("query_string" => "page", + "total_items" => $user_count, + "items_per_page" => $page_size, + "style" => "classic")); // Make sure that the page references a valid offset if ($page < 1) { url::redirect(url::merge(array("page" => 1))); - } else if ($page > $max_pages) { - url::redirect(url::merge(array("page" => $max_pages))); + } else if ($page > $view->content->pager->total_pages) { + url::redirect(url::merge(array("page" => $view->content->pager->total_pages))); } + $view->content->users = ORM::factory("user") ->select(array("users.id", "users.admin", "users.name", "users.email", "users.full_name", "users.last_login", "users.guest", db::expr("COUNT(items.id) as item_count"))) ->join("items", "items.owner_id", "users.id", "LEFT") ->group_by("users.id") ->order_by("users.name", "ASC") - ->find_all($page_size, $offset); + ->find_all($page_size, $view->content->pager->sql_offset); $view->content->groups = ORM::factory("group")->order_by("name", "ASC")->find_all(); - $view->content->page = $page; - $view->content->max_pages = $max_pages; - - if ($page < $max_pages) { - $view->content->next_page_url = url::site(url::merge(array("page" => $page + 1))); - } - if ($page > 1) { - $view->content->previous_page_url = url::site(url::merge(array("page" => $page - 1))); - } print $view; } diff --git a/modules/user/views/admin_users.html.php b/modules/user/views/admin_users.html.php index 028d44eb..74b13ec5 100644 --- a/modules/user/views/admin_users.html.php +++ b/modules/user/views/admin_users.html.php @@ -109,32 +109,8 @@ <? endforeach ?> </table> - <div class="g-right"> - <? if (isset($previous_page_url)): ?> - <a href="<?= $previous_page_url ?>" - class="g-button ui-icon-left ui-state-default ui-corner-all" - title="<?= t("Previous page")->for_html_attr() ?>"> - <? else: ?> - <a class="g-button ui-icon-left ui-state-disabled ui-corner-all" - title="<?= t("Previous page")->for_html_attr() ?>"> - <? endif ?> - <span class="ui-icon ui-icon-circle-plus"></span> - <?= t("Previous") ?> - </a> - - <?= t("Page %current of %total", array("current"=>$page, "total"=>$max_pages)) ?> - - <? if (isset($next_page_url)): ?> - <a href="<?= $next_page_url ?>" - class="g-button ui-icon-left ui-state-default ui-corner-all" - title="<?= t("Next page")->for_html_attr() ?>"> - <? else: ?> - <a class="g-button ui-icon-left ui-state-disabled ui-corner-all" - title="<?= t("Next page")->for_html_attr() ?>"> - <? endif ?> - <span class="ui-icon ui-icon-circle-plus"></span> - <?= t("Next") ?> - </a> + <div class="g-paginator"> + <?= $pager ?> </div> </div> |