mirror of
https://github.com/Pathduck/gallery3.git
synced 2026-07-12 10:07:42 -04:00
Paginator for user manager admin view
Closes ticket #1557 Note: also optimizes the way item count is retrieved for users, saving <user_count>-1 queries when displaying this page
This commit is contained in:
26
modules/gallery/libraries/MY_Controller.php
Normal file
26
modules/gallery/libraries/MY_Controller.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
@@ -22,8 +22,40 @@ class Admin_Users_Controller extends Admin_Controller {
|
||||
$view = new Admin_View("admin.html");
|
||||
$view->page_title = t("Users and groups");
|
||||
$view->content = new View("admin_users.html");
|
||||
$view->content->users = ORM::factory("user")->order_by("name", "ASC")->find_all();
|
||||
|
||||
// @todo: add this as a config option
|
||||
$page_size = module::get_var("user", "page_size", 10);
|
||||
$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);
|
||||
|
||||
// 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)));
|
||||
}
|
||||
$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);
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
|
||||
@@ -88,7 +88,7 @@
|
||||
<?= ($user->last_login == 0) ? "" : gallery::date($user->last_login) ?>
|
||||
</td>
|
||||
<td>
|
||||
<?= db::build()->from("items")->where("owner_id", "=", $user->id)->count_records() ?>
|
||||
<?= $user->item_count ?>
|
||||
</td>
|
||||
<td>
|
||||
<a href="<?= url::site("admin/users/edit_user_form/$user->id") ?>"
|
||||
@@ -108,6 +108,35 @@
|
||||
</tr>
|
||||
<? 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>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user