wCMF  3.6
 All Classes Namespaces Files Functions Variables Groups Pages
class.PagingInfo.php
Go to the documentation of this file.
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2014 wemove digital solutions GmbH
5  *
6  * Licensed under the terms of any of the following licenses
7  * at your choice:
8  *
9  * - GNU Lesser General Public License (LGPL)
10  * http://www.gnu.org/licenses/lgpl.html
11  * - Eclipse Public License (EPL)
12  * http://www.eclipse.org/org/documents/epl-v10.php
13  *
14  * See the license.txt file distributed with this work for
15  * additional information.
16  *
17  * $Id: class.PagingInfo.php 1462 2014-02-04 23:52:27Z iherwig $
18  */
19 
20 /**
21  * @class PagingInfo
22  * @ingroup Persistence
23  * @brief PagingInfo contains information about a paged list.
24  *
25  * @author ingo herwig <ingo@wemove.com>
26  */
28 {
29  var $_pageSize = 10;
30  var $_index = 0;
31  var $_totalCount = 0;
32 
33  /**
34  * Creates a PagingInfo object.
35  * @param pageSize The pageSize (-1 to set no page size)
36  */
37  function PagingInfo($pageSize)
38  {
39  $this->_pageSize = intval($pageSize);
40  }
41 
42  /**
43  * Set the number of list items.
44  * @param totalCount The number of list items.
45  */
46  function setTotalCount($totalCount)
47  {
48  $this->_totalCount = intval($totalCount);
49  }
50 
51  /**
52  * Get the number of list items.
53  * @return The number of list items.
54  */
55  function getTotalCount()
56  {
57  return $this->_totalCount;
58  }
59 
60  /**
61  * Set the current page (1-based).
62  * @param page The current page.
63  */
64  function setPage($page)
65  {
66  $this->_index = (intval($page)-1) * $this->_pageSize;
67  }
68 
69  /**
70  * Get the current page (1-based).
71  * @return The current page.
72  */
73  function getPage()
74  {
75  return intval($this->_index / $this->_pageSize)+1;
76  }
77 
78  /**
79  * Get the size of a pages.
80  * @return The size of a pages.
81  */
82  function getPageSize()
83  {
84  return $this->_pageSize;
85  }
86 
87  /**
88  * Get the number of pages.
89  * @return The number of pages.
90  */
91  function getPageCount()
92  {
93  return ceil($this->_totalCount / $this->_pageSize);
94  }
95 
96  /**
97  * Set the current index (0-based).
98  * @param index The current list index.
99  */
100  function setIndex($index)
101  {
102  $this->_index = $index;
103  }
104 
105  /**
106  * Get the current index (0-based).
107  */
108  function getIndex()
109  {
110  return $this->_index;
111  }
112 
113  /**
114  * Determine if we are on the first page.
115  * @return True/false.
116  */
117  function isOnFirstPage()
118  {
119  return $this->getPage() == 1;
120  }
121 
122  /**
123  * Determine if we are on the first page.
124  * @return True/false.
125  */
126  function isOnLastPage()
127  {
128  return $this->getPage() == $this->getPageCount();
129  }
130 }
131 ?>
PagingInfo($pageSize)
setTotalCount($totalCount)
PagingInfo contains information about a paged list.