Inheritances
Files
Overview
FRAMES
NO FRAMES

Class Doctrine_Collection

Doctrine
|-Doctrine_Collection
|- class Doctrine_Collection extends Doctrine_Access implements Countable, IteratorAggregate, Serializable
Doctrine_Collection
Collection of Doctrine_Record objects.
PackageDoctrine
SubpackageCollection
Licensehttp://www.opensource.org/licenses/lgpl-license.php LGPL
Linkwww.phpdoctrine.org
Since1.0
Version$Revision: 5801 $
AuthorKonsta Vesterinen

Summary

Static fields
# $null
Instance fields
# $_snapshot
# $_table
# $data
# $keyColumn
# $reference
# $referenceField
# $relation
Static methods
+ initNullObject() Initializes the null object for this collection
Instance methods
+ __construct() constructor
+ __toString() Returns a string representation of this object
+ add() Adds a record to collection
+ clear() Clears the collection
# compareRecords() Compares two records
+ contains() Whether or not this collection contains a specified element
+ count() Gets the number of records in this collection
+ delete() Deletes all records from this collection
+ end() Get the last record in the collection
+ exportTo() Export a Doctrine_Collection to one of the supported Doctrine_Parser formats
+ free() Frees the resources used by the collection.
+ fromArray() Populate a Doctrine_Collection from an array of data
+ get() Gets a record for given key
+ getData() Get all the records as an array
+ getDeleteDiff() Perform a delete diff between the last snapshot and the current data
+ getFirst() Get the first record in the collection
+ getInsertDiff() Perform a insert diff between the last snapshot and the current data
+ getIterator() Get collection data iterator
+ getKeyColumn() Get the name of the key column
+ getKeys() Get all keys of the data in the collection
+ getLast() Get the last record in the collection
+ getNormalIterator() Get normal iterator - an iterator that will not expand this collection
+ getPrimaryKeys() Get array of primary keys for all the records in the collection
+ getReference() Get reference to Doctrine_Record instance
+ getRelation() Returns the relation object
+ getSnapshot() Gets the data of the last snapshot
+ getTable() Get the table this collection belongs to
+ importFrom() Import data to a Doctrine_Collection from one of the supported Doctrine_Parser formats
+ key() Get the current key
+ loadRelated() Load all relationships or the named relationship passed
+ merge() Merges collection into $this and returns merged collection
+ populateRelated() Populate the relationship $name for all records in the passed collection
+ processDiff() Processes the difference of the last snapshot and the current data
+ remove() Removes a specified collection element
+ save() Saves all records of this collection and processes the
+ search() Search a Doctrine_Record instance
+ serialize() This method is automatically called when this Doctrine_Collection is serialized
+ set() Set a Doctrine_Record instance to the collection
+ setData() Set the data for the Doctrin_Collection instance
+ setKeyColumn() Sets the key column for this collection
+ setReference() Sets a reference pointer
+ synchronizeFromArray()
+ synchronizeWithArray() synchronizes a Doctrine_Collection with data from an array
+ takeSnapshot() Takes a snapshot from this collection
+ toArray() Mimics the result of a $query->execute(array(), Doctrine::HYDRATE_ARRAY);
+ unserialize() This method is automatically called everytime a Doctrine_Collection object is unserialized

Details

Static fields

$null
protected static $null
Var Doctrine_Null $null used for extremely fast null value testing

Instance fields

$_snapshot
protected $_snapshot = array()
Var array $_snapshot a snapshot of the fetched data
$_table
protected $_table
Var Doctrine_Table $table each collection has only records of specified table
$data
protected $data = array()
Var array $data an array containing the records of this collection
$keyColumn
protected $keyColumn
Var string $keyColumn the name of the column that is used for collection key mapping
$reference
protected $reference
Var Doctrine_Record $reference collection can belong to a record
$referenceField
protected $referenceField
Var string $referenceField the reference field of the collection
$relation
protected $relation
Var Doctrine_Relation the record this collection is related to, if any

Static methods

initNullObject()
public static function initNullObject( Doctrine_Null $null)
Initializes the null object for this collection
Parameters
Doctrine_Null $null
Returns void

Instance methods

__construct()
public function __construct( $table
$keyColumn = null
)
constructor
Parameters
Doctrine_Table|string $table
$keyColumn
Overriden by __construct() in class : Doctrine_Collection_Offset
__toString()
public function __toString( )
Returns a string representation of this object
Returns string $string
add()
public function add( $record
$key = null
)
Adds a record to collection
Parameters
Doctrine_Record $record record to be added
string $key optional key for the record
Returns boolean
clear()
public function clear( )
Clears the collection.
Returns void
compareRecords()
protected function compareRecords( $a
$b
)
Compares two records. To be used on _snapshot diffs using array_udiff
Parameters
Doctrine_Record $a
Doctrine_Record $b
Returns integer
contains()
public function contains( $key)
Whether or not this collection contains a specified element
Parameters
mixed $key the key of the element
Returns boolean
count()
public function count( )
Gets the number of records in this collection
This class implements interface countable
Returns integer
delete()
public function delete( Doctrine_Connection $conn = null
$clearColl = true
)
Deletes all records from this collection
Parameters
Doctrine_Connection $conn
$clearColl
end()
public function end( )
Get the last record in the collection
Returns mixed
exportTo()
public function exportTo( $type
$deep = false
)
Export a Doctrine_Collection to one of the supported Doctrine_Parser formats
Parameters
string $type
string $deep
Returns void
free()
public function free( $deep = false)
Frees the resources used by the collection.
WARNING: After invoking free() the collection is no longer considered to
be in a useable state. Subsequent usage may result in unexpected behavior.
Parameters
$deep
Returns void
fromArray()
public function fromArray( $array
$deep = true
)
Populate a Doctrine_Collection from an array of data
Parameters
string $array
$deep
Returns void
get()
public function get( $key)
Gets a record for given key

There are two special cases:

1. if null is given as a key a new record is created and attached
at the end of the collection

2. if given key does not exist, then a new record is create and attached
to the given key

Collection also maps referential information to newly created records
Parameters
mixed $key the key of the element
Returns Doctrine_Record return a specified record
getData()
public function getData( )
Get all the records as an array
Returns array
getDeleteDiff()
public function getDeleteDiff( )
Perform a delete diff between the last snapshot and the current data
Returns array $diff
getFirst()
public function getFirst( )
Get the first record in the collection
Returns mixed
getInsertDiff()
public function getInsertDiff( )
Perform a insert diff between the last snapshot and the current data
Returns array $diff
getIterator()
public function getIterator( )
Get collection data iterator
Returns object ArrayIterator
Overriden by getIterator() in class : Doctrine_Collection_Offset
getKeyColumn()
public function getKeyColumn( )
Get the name of the key column
Returns string
getKeys()
public function getKeys( )
Get all keys of the data in the collection
Returns array
getLast()
public function getLast( )
Get the last record in the collection
Returns mixed
getNormalIterator()
public function getNormalIterator( )
Get normal iterator - an iterator that will not expand this collection
Returns Doctrine_Iterator_Normal $iterator
getPrimaryKeys()
public function getPrimaryKeys( )
Get array of primary keys for all the records in the collection
Returns array an array containing all primary keys
getReference()
public function getReference( )
Get reference to Doctrine_Record instance
Returns Doctrine_Record $reference
getRelation()
public function getRelation( )
Returns the relation object
Returns object Doctrine_Relation
getSnapshot()
public function getSnapshot( )
Gets the data of the last snapshot
Returns array returns the data in last snapshot
getTable()
public function getTable( )
Get the table this collection belongs to
importFrom()
public function importFrom( $type
$data
)
Import data to a Doctrine_Collection from one of the supported Doctrine_Parser formats
Parameters
string $type
string $data
Returns void
key()
public function key( )
Get the current key
Returns mixed
loadRelated()
public function loadRelated( $name = null)
Load all relationships or the named relationship passed
Parameters
mixed $name
Returns boolean
merge()
public function merge( Doctrine_Collection $coll)
Merges collection into $this and returns merged collection
Parameters
Doctrine_Collection $coll
populateRelated()
public function populateRelated( $name
Doctrine_Collection $coll
)
Populate the relationship $name for all records in the passed collection
Parameters
string $name
Doctrine_Collection $coll
Returns void
processDiff()
public function processDiff( )
Processes the difference of the last snapshot and the current data

an example:
Snapshot with the objects 1, 2 and 4
Current data with objects 2, 3 and 5

The process would remove object 4
remove()
public function remove( $key)
Removes a specified collection element
Parameters
mixed $key
Returns boolean
save()
public function save( Doctrine_Connection $conn = null
$processDiff = true
)
Saves all records of this collection and processes the
difference of the last snapshot and the current data
Parameters
Doctrine_Connection $conn
$processDiff
search()
public function search( Doctrine_Record $record)
Search a Doctrine_Record instance
Parameters
Doctrine_Record $record
Returns void
serialize()
public function serialize( )
This method is automatically called when this Doctrine_Collection is serialized
Returns array
set()
public function set( $key
$record
)
Set a Doctrine_Record instance to the collection
Parameters
integer $key
Doctrine_Record $record
Returns void
setData()
public function setData( array $data)
Set the data for the Doctrin_Collection instance
Parameters
array $data
setKeyColumn()
public function setKeyColumn( $column)
Sets the key column for this collection
Parameters
string $column
Returns Doctrine_Collection $this
setReference()
public function setReference( Doctrine_Record $record
Doctrine_Relation $relation
)
Sets a reference pointer
Parameters
Doctrine_Record $record
Doctrine_Relation $relation
Returns void
synchronizeFromArray()
public function synchronizeFromArray( array $array)
Parameters
array $array
synchronizeWithArray()
public function synchronizeWithArray( array $array)
synchronizes a Doctrine_Collection with data from an array

it expects an array representation of a Doctrine_Collection similar to the return
value of the toArray() method. It will create Dectrine_Records that don't exist
on the collection, update the ones that do and remove the ones missing in the $array
Parameters
array $array
takeSnapshot()
public function takeSnapshot( )
Takes a snapshot from this collection

snapshots are used for diff processing, for example
when a fetched collection has three elements, then two of those
are being removed the diff would contain one element

Doctrine_Collection::save() attaches the diff with the help of last
snapshot.
toArray()
public function toArray( $deep = false
$prefixKey = false
)
Mimics the result of a $query->execute(array(), Doctrine::HYDRATE_ARRAY);
Parameters
boolean $deep
$prefixKey
unserialize()
public function unserialize( $serialized)
This method is automatically called everytime a Doctrine_Collection object is unserialized
Parameters
$serialized
Returns void