PHP Class Gdn_DataSet, vanilla

This class is HEAVILY inspired by CodeIgniter (http://www.codeigniter.com). My hat is off to them.
Author: Mark O'Sullivan
Inheritance: implements IteratorAggregate
显示文件 Open project: vanilla/vanilla Class Usage Examples

Public Properties

Property Type Description
$Connection Contains a reference to the open database connection. FALSE by default. This property is passed by reference from the Database object. Do not manipulate or assign anything to this property!

Protected Properties

Property Type Description
$_DatasetType what type of result is returned from the various methods by default. Either DATASET_TYPE_OBJECT or DATASET_TYPE_ARRAY.
$_EOF boolean
$_Result An array of either objects or associative arrays with the data in this dataset.

Public Methods

Method Description
PDOStatement ( PDOStatement &$PDOStatement = false ) Assigns the pdostatement object to this object.
__construct ( $Result = null, $DataSetType = null )
__destruct ( )
clean ( ) Clean sensitive data out of the object.
count ( ) : integer Count elements of this object. This method provides support for the countable interface.
dataSeek ( integer $RowIndex ) Moves the dataset's internal cursor pointer to the specified RowIndex.
datasetType ( boolean $DatasetType = false )
expandAttributes ( string $Name = 'Attributes' )
firstRow ( string $DatasetType = false ) : boolean | array | stdClass Returns the first row or FALSE if there are no rows to return.
format ( string $FormatMethod ) : Gdn_Dataset Format the resultset with the given method.
freePDOStatement ( boolean $DestroyPDOStatement = true ) Free's the result resource referenced by $this->_PDOStatement.
getIterator ( ) Interface method for IteratorAggregate.
importDataset ( array $Resultset ) Allows you to fill this object's result set with a foreign data set in the form of an array of associative arrays (or objects).
index ( array | Traversable $Data, string | array $Columns, array $Options = [] ) : array Index a result array.
join ( array &$Data, array $Columns, array $Options = [] )
lastRow ( string $DatasetType = false ) Returns the last row in the or FALSE if there are no rows to return.
nextRow ( string $DatasetType = false ) Returns the next row or FALSE if there are no more rows.
numFields ( ) Returns the number of fields in the DataSet.
numRows ( string $DatasetType = false ) Returns the number of rows in the DataSet.
previousRow ( string $DatasetType = false ) Returns the previous row in the requested format.
result ( string $DatasetType = false ) Returns an array of data as the specified result type: object or array.
resultArray ( ) : array& Returns an array of associative arrays containing the ResultSet data.
resultObject ( $FormatType = '' ) Returns an array of objects containing the ResultSet data.
row ( integer $RowIndex ) : mixed Returns the requested row index as the requested row type.
unserialize ( array $Fields = ['Attributes', 'Data'] ) Unserialize the fields in the dataset.
value ( string $ColumnName, string $DefaultValue = null ) : mixed Advances to the next row and returns the value from a column.

Protected Methods

Method Description
_fetchAllRows ( string $DatasetType = false ) Fetches all rows from the PDOStatement object into the resultset.

Method Details

PDOStatement() public method

Assigns the pdostatement object to this object.
public PDOStatement ( PDOStatement &$PDOStatement = false )
$PDOStatement PDOStatement The PDO Statement Object being assigned.

__construct() public method

public __construct ( $Result = null, $DataSetType = null )

__destruct() public method

public __destruct ( )

_fetchAllRows() protected method

Fetches all rows from the PDOStatement object into the resultset.
protected _fetchAllRows ( string $DatasetType = false )
$DatasetType string The format in which the result should be returned: object or array. It will fill a different array depending on which type is specified.

clean() public method

Clean sensitive data out of the object.
public clean ( )

count() public method

Count elements of this object. This method provides support for the countable interface.
public count ( ) : integer
return integer

dataSeek() public method

Moves the dataset's internal cursor pointer to the specified RowIndex.
public dataSeek ( integer $RowIndex )
$RowIndex integer The index to seek in the result resource.

datasetType() public method

public datasetType ( boolean $DatasetType = false )
$DatasetType boolean

expandAttributes() public method

public expandAttributes ( string $Name = 'Attributes' )
$Name string

firstRow() public method

Returns the first row or FALSE if there are no rows to return.
public firstRow ( string $DatasetType = false ) : boolean | array | stdClass
$DatasetType string The format in which the result should be returned: object or array.
return boolean | array | stdClass False when empty result set, object or array depending on $DatasetType.

format() public method

Format the resultset with the given method.
public format ( string $FormatMethod ) : Gdn_Dataset
$FormatMethod string The method to use with Gdn_Format::To().
return Gdn_Dataset $this pointer for chaining.

freePDOStatement() public method

Free's the result resource referenced by $this->_PDOStatement.
public freePDOStatement ( boolean $DestroyPDOStatement = true )
$DestroyPDOStatement boolean

getIterator() public method

Interface method for IteratorAggregate.
public getIterator ( )

importDataset() public method

Allows you to fill this object's result set with a foreign data set in the form of an array of associative arrays (or objects).
public importDataset ( array $Resultset )
$Resultset array The array of arrays or objects that represent the data to be traversed.

index() public static method

Index a result array.
public static index ( array | Traversable $Data, string | array $Columns, array $Options = [] ) : array
$Data array | Traversable The array to index. It is formatted similar to the array returned by Gdn_DataSet::Result().
$Columns string | array The name of the column to index on or an array of columns to index on.
$Options array An array of options for the method. - Sep: The string to seperate index columns by. Default '|'. - Unique: Whether or not the results are unique. - true (default): The index is unique. - false: The index is not unique and each indexed row will be an array or arrays.
return array

join() public static method

public static join ( array &$Data, array $Columns, array $Options = [] )
$Data array
$Columns array The columns/table information for the join. Depending on the argument's index it will be interpreted differently. - numeric: This column will come be added to the resulting join. The value can be either a string or a two element array where the second element specifies an alias. - alias: The alias of the child table in the query. - child: The name of the child column. - column: The name of the column to put the joined data into. Can't be used with prefix. - parent: The name of the parent column. - table: The name of the child table in the join. - prefix: The name of the prefix to give the columns. Can't be used with column.
$Options array An array of extra options. - sql: A Gdn_SQLDriver with the child query. - type: The join type, either JOIN_INNER, JOIN_LEFT. This defaults to JOIN_LEFT.

lastRow() public method

Returns the last row in the or FALSE if there are no rows to return.
public lastRow ( string $DatasetType = false )
$DatasetType string The format in which the result should be returned: object or array.

nextRow() public method

Returns the next row or FALSE if there are no more rows.
public nextRow ( string $DatasetType = false )
$DatasetType string The format in which the result should be returned: object or array.

numFields() public method

Returns the number of fields in the DataSet.
public numFields ( )

numRows() public method

Returns the number of rows in the DataSet.
public numRows ( string $DatasetType = false )
$DatasetType string The format in which the result should be returned: object or array.

previousRow() public method

Returns the previous row in the requested format.
public previousRow ( string $DatasetType = false )
$DatasetType string The format in which the result should be returned: object or array.

result() public method

Returns an array of data as the specified result type: object or array.
public result ( string $DatasetType = false )
$DatasetType string The format in which to return a row: object or array. The following values are supported. - DATASET_TYPE_ARRAY: An array of associative arrays. - DATASET_TYPE_OBJECT: An array of standard objects. - FALSE: The current value of the DatasetType property will be used.

resultArray() public method

Returns an array of associative arrays containing the ResultSet data.
public resultArray ( ) : array&
return array&

resultObject() public method

Returns an array of objects containing the ResultSet data.
public resultObject ( $FormatType = '' )

row() public method

Returns the requested row index as the requested row type.
public row ( integer $RowIndex ) : mixed
$RowIndex integer The row to return from the result set. It is zero-based.
return mixed The row at the given index or FALSE if there is no row at the index.

unserialize() public method

Unserialize the fields in the dataset.
Since: 2.1
public unserialize ( array $Fields = ['Attributes', 'Data'] )
$Fields array

value() public method

Advances to the next row and returns the value from a column.
public value ( string $ColumnName, string $DefaultValue = null ) : mixed
$ColumnName string The name of the column to get the value from.
$DefaultValue string The value to return if there is no data.
return mixed The value from the column or $DefaultValue.

Property Details

$Connection public_oe property

Contains a reference to the open database connection. FALSE by default. This property is passed by reference from the Database object. Do not manipulate or assign anything to this property!
public $Connection

$_DatasetType protected_oe property

what type of result is returned from the various methods by default. Either DATASET_TYPE_OBJECT or DATASET_TYPE_ARRAY.
protected $_DatasetType

$_EOF protected_oe property

protected bool $_EOF
return boolean

$_Result protected_oe property

An array of either objects or associative arrays with the data in this dataset.
protected $_Result