mirror of
https://github.com/Pathduck/gallery3.git
synced 2026-04-27 07:59:14 -04:00
Making good use of Pagination class to reduce code (removed MY_Controller which duplicated some functionality available in Pagination as well)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user