PHP Class Prado\Collections\TPagedList

TPagedList implements a list with paging functionality. TPagedList works in one of two modes, managed paging or customized paging, specified by {@link setCustomPaging CustomPaging}. - Managed paging ({@link setCustomPaging CustomPaging}=false) : the list is assumed to contain all data and it will manage which page of data are available to user. - Customized paging ({@link setCustomPaging CustomPaging}=true) : the list is assumed to contain only one page of data. An {@link onFetchData OnFetchData} event will be raised if the list changes to a different page. Developers can attach a handler to the event and supply the needed data. The event handler can be written as follows, public function fetchData($sender,$param) { $offset=$param->Offset; // beginning index of the data needed $limit=$param->Limit; // maximum number of data items needed get data according to the above two parameters $param->Data=$data; } Data in TPagedList can be accessed like an integer-indexed array and can be traversed using foreach. For example, $count=$list->Count; for($index=0;$index<$count;++$index) echo $list[$index]; foreach($list as $index=>$item) // traverse each item in the list The {@link setPageSize PageSize} property specifies the number of items in each page. To access different page of data in the list, set {@link setCurrentPageIndex CurrentPageIndex} or call {@link nextPage()}, {@link previousPage()}, or {@link gotoPage()}. The total number of pages can be obtained by {@link getPageCount() PageCount}.
Since: 3.0
Author: Qiang Xue ([email protected])
Inheritance: extends TList
Mostra file Open project: pradosoft/prado Class Usage Examples

Public Methods

Method Description
__construct ( $data = null, $readOnly = false ) Constructor.
getCount ( ) : integer
getCurrentPageIndex ( ) : integer
getCustomPaging ( ) : boolean
getIsFirstPage ( ) : boolean
getIsLastPage ( ) : boolean
getIterator ( ) : Iterator
getPageCount ( ) : integer
getPageSize ( ) : integer
getVirtualCount ( ) : integer
gotoPage ( $pageIndex ) : integer | boolean Changes to a page with the specified page index.
indexOf ( $item ) : integer
itemAt ( $index ) : mixed Returns the item at the specified offset.
nextPage ( ) : integer | boolean Switches to the next page.
offsetExists ( $offset ) : boolean Returns whether there is an item at the specified offset.
offsetGet ( $offset ) : mixed Returns the item at the specified offset.
onFetchData ( $param ) Raises OnFetchData event.
onPageIndexChanged ( $param ) Raises OnPageIndexChanged event.
previousPage ( ) : integer | boolean Switches to the previous page.
setCurrentPageIndex ( $value )
setCustomPaging ( $value )
setPageSize ( $value )
setVirtualCount ( $value )
toArray ( ) : array

Method Details

__construct() public method

Constructor.
public __construct ( $data = null, $readOnly = false )

getCount() public method

public getCount ( ) : integer
return integer the number of items in current page

getCurrentPageIndex() public method

public getCurrentPageIndex ( ) : integer
return integer current page index. Defaults to 0.

getCustomPaging() public method

public getCustomPaging ( ) : boolean
return boolean whether to use custom paging. Defaults to false.

getIsFirstPage() public method

public getIsFirstPage ( ) : boolean
return boolean whether the current page is the first page

getIsLastPage() public method

public getIsLastPage ( ) : boolean
return boolean whether the current page is the last page

getIterator() public method

public getIterator ( ) : Iterator
return Iterator iterator

getPageCount() public method

public getPageCount ( ) : integer
return integer number of pages, -1 if under custom paging mode and {@link setVirtualCount VirtualCount} is not set.

getPageSize() public method

public getPageSize ( ) : integer
return integer number of items in each page. Defaults to 10.

getVirtualCount() public method

public getVirtualCount ( ) : integer
return integer user-assigned number of items in data source. Defaults to 0.

gotoPage() public method

Changes to a page with the specified page index.
public gotoPage ( $pageIndex ) : integer | boolean
return integer | boolean the new page index, false if page index is out of range.

indexOf() public method

public indexOf ( $item ) : integer
return integer the index of the item in the list (0 based), -1 if not found.

itemAt() public method

This method is exactly the same as {@link offsetGet}.
public itemAt ( $index ) : mixed
return mixed the item at the index

nextPage() public method

Switches to the next page.
public nextPage ( ) : integer | boolean
return integer | boolean the new page index, false if next page is not available.

offsetExists() public method

This method is required by the interface \ArrayAccess.
public offsetExists ( $offset ) : boolean
return boolean

offsetGet() public method

This method is required by the interface \ArrayAccess.
public offsetGet ( $offset ) : mixed
return mixed the item at the offset

onFetchData() public method

This event is raised each time when the list changes to a different page and needs the new page of data. This event can only be raised when {@link setCustomPaging CustomPaging} is true.
public onFetchData ( $param )

onPageIndexChanged() public method

This event is raised each time when the list changes to a different page.
public onPageIndexChanged ( $param )

previousPage() public method

Switches to the previous page.
public previousPage ( ) : integer | boolean
return integer | boolean the new page index, false if previous page is not available.

setCurrentPageIndex() public method

public setCurrentPageIndex ( $value )

setCustomPaging() public method

public setCustomPaging ( $value )

setPageSize() public method

public setPageSize ( $value )

setVirtualCount() public method

public setVirtualCount ( $value )

toArray() public method

public toArray ( ) : array
return array the list of items in array