Public Member Functions | Data Fields | Protected Member Functions
Pagination Class Reference

Provides automatic pagination generation. Modifies sql query to limit items. More...

Inheritance diagram for Pagination:
Dispersion

Public Member Functions

 Pagination ($current_page=1, $page_path=null)
 
 useQuery ($select_query)
 
 itemsPerPage ($items)
 
 linksPerPage ($nr)
 
 linkAttributes ($attributes)
 
 activeLinkAttributes ($attributes)
 
 setPagePath ($page_path)
 
 getCurrentPage ()
 
 setCurrentPage ($current_page)
 
 setTotalItems ($items)
 
 getTotalPages ()
 
 paginationLinks ()
 
 getItems ()
 
- Public Member Functions inherited from Dispersion
 Dispersion ()
 
 emptyLayout ()
 
 set ($name, $value)
 
 _set ($name, $value)
 
 insertView ($name, $index=-1)
 

Data Fields

 $pagination_links_per_page = 10
 
 $pagination_link_attr = array()
 
 $pagination_link_attr_active = array()
 
 $pagination_link_href = ''
 
 $current_page = 1
 
 $items_per_page = 20
 
 $total_items = null
 
 $select_query = null
 
 $total_pages = null
 
- Data Fields inherited from Dispersion
 $model_ob = null
 
 $debug_ob = null
 
 $_variables = array()
 
 $_content = array()
 
 $_content_count = 0
 
 $model
 
 $debug
 

Protected Member Functions

 getAnchorAttr ($active=false)
 
 anchorLink ($i, $active=false)
 
- Protected Member Functions inherited from Dispersion
 requireConfigFile ($file_name, $required=false)
 

Detailed Description

Provides automatic pagination generation. Modifies sql query to limit items.

Version
1.2
Author
DinuSV

Member Function Documentation

Pagination (   $current_page = 1,
  $page_path = null 
)

Constructor

Parameters
integer$current_page: the current page index, > 1
string$page_path: the page url
useQuery (   $select_query)

Set the query to be used in order to determining the page items and adding the selection

Parameters
mixed$select_query: the query to be used, can be either string or array of options
See Also
Core/Model/select
Returns
Pagination : current object
itemsPerPage (   $items)

Change the number of items to be displayed on a page

Parameters
integer$items
Returns
Pagination : current object
linksPerPage (   $nr)

Set the max number of pagination links per page

Parameters
integer$nr
Returns
Pagination : current object
linkAttributes (   $attributes)

Set link attributes

Parameters
array$attributes: keys => attribute name, values => attribute value
Exceptions
InvalidArgumentTypeException
Returns
Pagination : current object
activeLinkAttributes (   $attributes)

Set attributes to the active link

Parameters
array$attributes: keys => attribute name, values => attribute value
Exceptions
InvalidArgumentTypeException
Returns
Pagination : current object
setPagePath (   $page_path)

Sets the href the links will have

Parameters
string$page_path
Returns
Pagination : current object
getCurrentPage ( )

Gets the current page

Returns
integer
setCurrentPage (   $current_page)

Sets the current page

Parameters
integer$current_page
Returns
Pagination : current object
setTotalItems (   $items)

Set the number of items

Parameters
integer$items
Returns
Pagination : current object
getAnchorAttr (   $active = false)
protected

Get the anchor link attributes

Parameters
boolean$active: set to true if the link is active
Returns
array : the pagination link attributes
anchorLink (   $i,
  $active = false 
)
protected

Returns the anchor link as text form. This function is intended to be easily

Parameters
integer$i: the page index
boolean$active: true if this is the current page
Returns
string : the page link as html form
getTotalPages ( )
Returns
total pages either set or received by query
paginationLinks ( )

Prints the pagination links usign the helper functions above

getItems ( )

Fetches the items, executing the query

Exceptions
IndexOutOfBoundsException
Returns
resource

Field Documentation

$pagination_links_per_page = 10

int : Total allowed links per page

$pagination_link_attr = array()

array : Attributes for the pagination link

$pagination_link_attr_active = array()

int : Attributes for the active pagintion link

$pagination_link_href = ''

int : Path to the current page, without the counter

$current_page = 1

int : Page counting starts from 1

$items_per_page = 20

int : Maximum number of items per page

$total_items = null

int : Total number of items

$select_query = null

mixed : Selection query, can be either options, either string

$total_pages = null

int : Stores the number of pages the query has