summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorJoe7 <jozsef.rnagy@site.hu>2011-01-09 20:52:31 +0100
committerJoe7 <jozsef.rnagy@site.hu>2011-01-09 21:05:28 +0100
commit89737c09d572efe35014e668cdd06407c2c19d62 (patch)
treeea3c7fb00ea5dba5b476f040a92490b205e89277 /modules
parentd74aad072d8ccca70efb1c8b673e8368566a1974 (diff)
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
Diffstat (limited to 'modules')
-rw-r--r--modules/gallery/libraries/MY_Controller.php26
-rw-r--r--modules/user/controllers/admin_users.php34
-rw-r--r--modules/user/views/admin_users.html.php31
3 files changed, 89 insertions, 2 deletions
diff --git a/modules/gallery/libraries/MY_Controller.php b/modules/gallery/libraries/MY_Controller.php
new file mode 100644
index 00000000..ea2a7502
--- /dev/null
+++ b/modules/gallery/libraries/MY_Controller.php
@@ -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);
+ }
+} \ No newline at end of file
diff --git a/modules/user/controllers/admin_users.php b/modules/user/controllers/admin_users.php
index 23032ab3..6850f8af 100644
--- a/modules/user/controllers/admin_users.php
+++ b/modules/user/controllers/admin_users.php
@@ -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;
}
diff --git a/modules/user/views/admin_users.html.php b/modules/user/views/admin_users.html.php
index f067cae8..028d44eb 100644
--- a/modules/user/views/admin_users.html.php
+++ b/modules/user/views/admin_users.html.php
@@ -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>