PageRenderTime 45ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/banned/include/class.Pager.php

http://globalban-spanish.googlecode.com/
PHP | 94 lines | 56 code | 16 blank | 22 comment | 0 complexity | 363ed87cdde1e8b561449b3b46bbacfe MD5 | raw file
  1. <?php
  2. /*
  3. This file is part of GlobalBan.
  4. Written by Stefan Jonasson <soynuts@unbuinc.net>
  5. Copyright 2008 Stefan Jonasson
  6. GlobalBan is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. GlobalBan is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with GlobalBan. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * This class is used for creating paging
  19. */
  20. class Pager
  21. {
  22. var $total; // Total number of items
  23. var $limit; // Number of items per page
  24. var $page; // The page number
  25. var $numPages;
  26. var $offset;
  27. function __construct($total, $limit, $page) {
  28. $this->init($total, $limit, $page);
  29. }
  30. function Pager($total, $limit, $page) {
  31. $this->init($total, $limit, $page);
  32. }
  33. function init($total, $limit, $page)
  34. {
  35. $this->total = (int) $total; //Total number of items
  36. $this->limit = max((int) $limit, 1); //Items per page
  37. $this->page = (int) $page; //Page Number
  38. $this->numPages = ceil($total / $limit);
  39. $this->page = max($page, 1);
  40. $this->page = min($page, $numPages);
  41. $this->offset = ($page - 1) * $limit;
  42. }
  43. function getTotal() {
  44. return $this->total;
  45. }
  46. function setTotal($total) {
  47. $this->total = $total;
  48. }
  49. function getLimit() {
  50. return $this->limit;
  51. }
  52. function setLimit($limit) {
  53. $this->limit = $limit;
  54. }
  55. function getPage() {
  56. return $this->page;
  57. }
  58. function setPage($page) {
  59. $this->page = $page;
  60. }
  61. function getNumPages() {
  62. return $this->numPages;
  63. }
  64. function setNumPages($numPages) {
  65. $this->numPages = $numPages;
  66. }
  67. function getOffset() {
  68. return $this->offset;
  69. }
  70. function setOffset($offset) {
  71. $this->offset = $offset;
  72. }
  73. }
  74. ?>