CDataProvider

Package system.web
Inheritance abstract class CDataProvider » CComponent
Implements IDataProvider
Subclasses CActiveDataProvider
Since 1.1
Version $Id: CDataProvider.php 1916 2010-03-15 15:07:01Z qiang.xue $
CDataProvider is a base class that implements the IDataProvider interface.

Derived classes mainly need to implement three methods: fetchData, fetchKeys and calculateTotalItemCount.

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
data array Returns the data items currently available. CDataProvider
id string the unique ID that uniquely identifies the data provider among all data providers. CDataProvider
itemCount integer Returns the number of data items in the current page. CDataProvider
keys array Returns the key values associated with the data items. CDataProvider
pagination CPagination the pagination object. CDataProvider
sort CSort the sorting object. CDataProvider
totalItemCount integer Returns the total number of data items. CDataProvider

Public Methods

Hide inherited methods

MethodDescriptionDefined By
__call() Calls the named method which is not a class method. CComponent
__get() Returns a property value, an event handler list or a behavior based on its name. CComponent
__isset() Checks if a property value is null. CComponent
__set() Sets value of a component property. CComponent
__unset() Sets a component property to be null. CComponent
asa() Returns the named behavior object. CComponent
attachBehavior() Attaches a behavior to this component. CComponent
attachBehaviors() Attaches a list of behaviors to the component. CComponent
attachEventHandler() Attaches an event handler to an event. CComponent
canGetProperty() Determines whether a property can be read. CComponent
canSetProperty() Determines whether a property can be set. CComponent
detachBehavior() Detaches a behavior from the component. CComponent
detachBehaviors() Detaches all behaviors from the component. CComponent
detachEventHandler() Detaches an existing event handler. CComponent
disableBehavior() Disables an attached behavior. CComponent
disableBehaviors() Disables all behaviors attached to this component. CComponent
enableBehavior() Enables an attached behavior. CComponent
enableBehaviors() Enables all behaviors attached to this component. CComponent
evaluateExpression() Evaluates a PHP expression or callback under the context of this component. CComponent
getData() Returns the data items currently available. CDataProvider
getEventHandlers() Returns the list of attached event handlers for an event. CComponent
getId() CDataProvider
getItemCount() Returns the number of data items in the current page. CDataProvider
getKeys() Returns the key values associated with the data items. CDataProvider
getPagination() CDataProvider
getSort() CDataProvider
getTotalItemCount() Returns the total number of data items. CDataProvider
hasEvent() Determines whether an event is defined. CComponent
hasEventHandler() Checks whether the named event has attached handlers. CComponent
hasProperty() Determines whether a property is defined. CComponent
raiseEvent() Raises an event. CComponent
setData() CDataProvider
setId() CDataProvider
setKeys() CDataProvider
setPagination() CDataProvider
setSort() CDataProvider
setTotalItemCount() Sets the total number of data items. CDataProvider

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
calculateTotalItemCount() Calculates the total number of data items. CDataProvider
fetchData() Fetches the data from the persistent data storage. CDataProvider
fetchKeys() Fetches the data item keys from the persistent data storage. CDataProvider

Property Details

data property
public array getData(boolean $refresh=false)
public void setData(array $value)

Returns the data items currently available.

id property
public string getId()
public void setId(string $value)

the unique ID that uniquely identifies the data provider among all data providers.

itemCount property read-only
public integer getItemCount(boolean $refresh=false)

Returns the number of data items in the current page. This is equivalent to count($provider->getData()). When pagination is set false, this returns the same value as totalItemCount.

keys property
public array getKeys(boolean $refresh=false)
public void setKeys(array $value)

Returns the key values associated with the data items.

pagination property
public CPagination getPagination()
public void setPagination(mixed $value)

the pagination object. If this is false, it means the pagination is disabled.

sort property
public CSort getSort()
public void setSort(mixed $value)

the sorting object. If this is false, it means the sorting is disabled.

totalItemCount property
public integer getTotalItemCount(boolean $refresh=false)
public void setTotalItemCount(integer $value)

Returns the total number of data items. When pagination is set false, this returns the same value as itemCount.

Method Details

calculateTotalItemCount() method
abstract protected integer calculateTotalItemCount()
{return} integer the total number of data items.

Calculates the total number of data items.

fetchData() method
abstract protected array fetchData()
{return} array list of data items

Fetches the data from the persistent data storage.

fetchKeys() method
abstract protected array fetchKeys()
{return} array list of data item keys.

Fetches the data item keys from the persistent data storage.

getData() method
public array getData(boolean $refresh=false)
$refresh boolean whether the data should be re-fetched from persistent storage.
{return} array the list of data items currently available in this data provider.

Returns the data items currently available.

getId() method
public string getId()
{return} string the unique ID that uniquely identifies the data provider among all data providers.

getItemCount() method
public integer getItemCount(boolean $refresh=false)
$refresh boolean whether the number of data items should be re-calculated.
{return} integer the number of data items in the current page.

Returns the number of data items in the current page. This is equivalent to count($provider->getData()). When pagination is set false, this returns the same value as totalItemCount.

getKeys() method
public array getKeys(boolean $refresh=false)
$refresh boolean whether the keys should be re-calculated.
{return} array the list of key values corresponding to data. Each data item in data is uniquely identified by the corresponding key value in this array.

Returns the key values associated with the data items.

getPagination() method
public CPagination getPagination()
{return} CPagination the pagination object. If this is false, it means the pagination is disabled.

getSort() method
public CSort getSort()
{return} CSort the sorting object. If this is false, it means the sorting is disabled.

getTotalItemCount() method
public integer getTotalItemCount(boolean $refresh=false)
$refresh boolean whether the total number of data items should be re-calculated.
{return} integer total number of possible data items.

Returns the total number of data items. When pagination is set false, this returns the same value as itemCount.

setData() method
public void setData(array $value)
$value array put the data items into this provider.

setId() method
public void setId(string $value)
$value string the unique ID that uniquely identifies the data provider among all data providers.

setKeys() method
public void setKeys(array $value)
$value array put the data item keys into this provider.

setPagination() method
public void setPagination(mixed $value)
$value mixed the pagination to be used by this data provider. This could be a CPagination object or an array used to configure the pagination object. If this is false, it means the pagination should be disabled.

setSort() method
public void setSort(mixed $value)
$value mixed the sorting to be used by this data provider. This could be a CSort object or an array used to configure the sorting object. If this is false, it means the sorting should be disabled.

setTotalItemCount() method (available since v1.1.1)
public void setTotalItemCount(integer $value)
$value integer the total number of data items.

Sets the total number of data items. This method is provided in case when the total number cannot be determined by calculateTotalItemCount.