Doctrine


Doctrine\Doctrine_Collection
/Doctrine/Collection.php at line 34

Class Doctrine_Collection

Class:Doctrine_Collection - Superclass: Doctrine_Access
Class:Doctrine_Access - Superclass: Doctrine_Locator_Injectable
Doctrine_Locator_Injectable
⌊ Doctrine_Access
⌊ Doctrine_Collection

public class Doctrine_Collection
extends Doctrine_Access

Doctrine_Collection Collection of Doctrine_Record objects.

Package:
Doctrine
Subpackage:
Collection
License:
http://www.opensource.org/licenses/lgpl-license.php LGPL
See Also:
www.doctrine-project.org
Since:
1.0
Version:
$Revision: 7490 $
Author:
Konsta Vesterinen
Category:
Locator

Field Summary
protected array $_snapshot a snapshot of the fetched data

$_snapshot

.

protected Doctrine_Table $table each collection has only records of specified table

$_table

.

protected array $data an array containing the records of this collection

$data

.

protected string $keyColumn the name of the column that is used for collection key mapping

$keyColumn

.

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

$null

.

protected Doctrine_Record $reference collection can belong to a record

$reference

.

protected string $referenceField the reference field of the collection

$referenceField

.

protected Doctrine_Relation the record this collection is related to, if any

$relation

.

Constructor Summary

Doctrine_Collection(Doctrine_Table|string table, mixed keyColumn)

constructor.

Method Summary
boolean

add(Doctrine_Record record, string key, mixed value)

Adds a record to collection.

void

clear()

Clears the collection..

protected integer

compareRecords(Doctrine_Record a, Doctrine_Record b)

Compares two records.

boolean

contains(mixed key, mixed offset)

Whether or not this collection contains a specified element.

integer

count()

Gets the number of records in this collection This class implements interface countable.

static void

create(mixed table, mixed keyColumn, mixed class)

Doctrine_Collection

delete(mixed conn, mixed clearColl)

Deletes all records from this collection.

Doctrine_Record

end()

Get the last record in the collection.

void

exportTo(string type, string deep)

Export a Doctrine_Collection to one of the supported Doctrine_Parser formats.

void

free(mixed deep)

Frees the resources used by the collection.

void

fromArray(string array, mixed deep)

Populate a Doctrine_Collection from an array of data.

Doctrine_Record

get(mixed key, mixed offset)

Gets a record for given key.

array

getData()

Get all the records as an array.

array

getDeleteDiff()

Perform a delete diff between the last snapshot and the current data.

Doctrine_Record

getFirst()

Get the first record in the collection.

array

getInsertDiff()

Perform a insert diff between the last snapshot and the current data.

Iterator

getIterator()

Get collection data iterator.

string

getKeyColumn()

Get the name of the key column.

array

getKeys()

Get all keys of the data in the collection.

Doctrine_Record

getLast()

Get the last record in the collection.

Doctrine_Iterator_Normal

getNormalIterator()

Get normal iterator - an iterator that will not expand this collection.

array

getPrimaryKeys()

Get array of primary keys for all the records in the collection.

Doctrine_Record

getReference()

Get reference to Doctrine_Record instance.

Doctrine_Relation

getRelation()

Returns the relation object.

array

getSnapshot()

Gets the data of the last snapshot.

Doctrine_Table

getTable()

Get the table this collection belongs to.

void

importFrom(string type, string data)

Import data to a Doctrine_Collection from one of the supported Doctrine_Parser formats.

static void

initNullObject(Doctrine_Null null)

Initializes the null object for this collection.

final boolean

isModified()

checks if one of the containing records is modified returns true if modified, false otherwise.

Doctrine_Record

key()

Get the current key.

boolean

loadRelated(mixed name)

Load all relationships or the named relationship passed.

Doctrine_Collection

merge(Doctrine_Collection coll)

Merges collection into $this and returns merged collection.

void

populateRelated(string name, Doctrine_Collection coll)

Populate the relationship $name for all records in the passed collection.

Doctrine_Collection

processDiff()

Processes the difference of the last snapshot and the current data.

boolean

remove(mixed key, mixed offset)

Removes a specified collection element.

Doctrine_Collection

save(Doctrine_Connection conn, mixed processDiff)

Saves all records of this collection and processes the difference of the last snapshot and the current data.

void

search(mixed record, string Doctrine_Record)

Search a Doctrine_Record instance.

array

serialize()

This method is automatically called when this Doctrine_Collection is serialized.

void

set(integer key, Doctrine_Record record, mixed offset, mixed value)

Set a Doctrine_Record instance to the collection.

Doctrine_Collection

setData(array data)

Set the data for the Doctrin_Collection instance.

Doctrine_Collection

setKeyColumn(string column)

Sets the key column for this collection.

void

setReference(mixed record, mixed relation)

Sets a reference pointer.

void

synchronizeFromArray(mixed array)

void

synchronizeWithArray(array array)

synchronizes a Doctrine_Collection with data from an array.

Doctrine_Collection

takeSnapshot()

Takes a snapshot from this collection.

void

toArray(boolean deep, mixed prefixKey)

Mimics the result of a $query->execute(array(), Doctrine_Core::HYDRATE_ARRAY);.

void

toHierarchy()

array

toKeyValueArray(string key, string value)

Build an array made up of the values from the 2 specified columns.

void

unserialize(mixed serialized)

This method is automatically called everytime a Doctrine_Collection object is unserialized.

Methods inherited from Doctrine\Doctrine_Access
add, contains, get, offsetExists, offsetGet, offsetSet, offsetUnset, remove, set, setArray
Methods inherited from Doctrine\Doctrine_Locator_Injectable
bind, getLocator, getNullObject, initNullObject, locate, setLocator

Field Detail

/Doctrine/Collection.php at line 49

_snapshot

protected array $_snapshot a snapshot of the fetched data $_snapshot = array()


/Doctrine/Collection.php at line 44

_table

protected Doctrine_Table $table each collection has only records of specified table $_table


/Doctrine/Collection.php at line 39

data

protected array $data an array containing the records of this collection $data = array()


/Doctrine/Collection.php at line 69

keyColumn

protected string $keyColumn the name of the column that is used for collection key mapping $keyColumn


/Doctrine/Collection.php at line 74

null

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


/Doctrine/Collection.php at line 54

reference

protected Doctrine_Record $reference collection can belong to a record $reference


/Doctrine/Collection.php at line 59

referenceField

protected string $referenceField the reference field of the collection $referenceField


/Doctrine/Collection.php at line 64

relation

protected Doctrine_Relation the record this collection is related to, if any $relation


Constructor Detail

/Doctrine/Collection.php at line 81

Doctrine_Collection

public Doctrine_Collection(Doctrine_Table|string table, mixed keyColumn)

constructor


Method Detail

/Doctrine/Collection.php at line 451

add

public boolean add(Doctrine_Record record, string key, mixed value)

Adds a record to collection

Parameters:
record - record to be added
key - optional key for the record

/Doctrine/Collection.php at line 959

clear

public void clear()

Clears the collection.


/Doctrine/Collection.php at line 878

compareRecords

protected integer compareRecords(Doctrine_Record a, Doctrine_Record b)

Compares two records. To be used on _snapshot diffs using array_udiff


/Doctrine/Collection.php at line 325

contains

public boolean contains(mixed key, mixed offset)

Whether or not this collection contains a specified element

Parameters:
key - the key of the element

/Doctrine/Collection.php at line 423

count

public integer count()

Gets the number of records in this collection This class implements interface countable


/Doctrine/Collection.php at line 112

create

public static void create(mixed table, mixed keyColumn, mixed class)

/Doctrine/Collection.php at line 927

delete

public Doctrine_Collection delete(mixed conn, mixed clearColl)

Deletes all records from this collection


/Doctrine/Collection.php at line 252

end

public Doctrine_Record end()

Get the last record in the collection


/Doctrine/Collection.php at line 826

exportTo

public void exportTo(string type, string deep)

Export a Doctrine_Collection to one of the supported Doctrine_Parser formats


/Doctrine/Collection.php at line 971

free

public void free(mixed deep)

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.


/Doctrine/Collection.php at line 780

fromArray

public void fromArray(string array, mixed deep)

Populate a Doctrine_Collection from an array of data


/Doctrine/Collection.php at line 357

get

public Doctrine_Record get(mixed key, mixed offset)

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:
key - the key of the element
Returns:
return a specified record

/Doctrine/Collection.php at line 222

getData

public array getData()

Get all the records as an array


/Doctrine/Collection.php at line 856

getDeleteDiff

public array getDeleteDiff()

Perform a delete diff between the last snapshot and the current data

Returns:
$diff

/Doctrine/Collection.php at line 232

getFirst

public Doctrine_Record getFirst()

Get the first record in the collection


/Doctrine/Collection.php at line 866

getInsertDiff

public array getInsertDiff()

Perform a insert diff between the last snapshot and the current data

Returns:
$diff

/Doctrine/Collection.php at line 992

getIterator

public Iterator getIterator()

Get collection data iterator


/Doctrine/Collection.php at line 212

getKeyColumn

public string getKeyColumn()

Get the name of the key column


/Doctrine/Collection.php at line 412

getKeys

public array getKeys()

Get all keys of the data in the collection


/Doctrine/Collection.php at line 242

getLast

public Doctrine_Record getLast()

Get the last record in the collection


/Doctrine/Collection.php at line 638

getNormalIterator

public Doctrine_Iterator_Normal getNormalIterator()

Get normal iterator - an iterator that will not expand this collection

Returns:
$iterator

/Doctrine/Collection.php at line 392

getPrimaryKeys

public array getPrimaryKeys()

Get array of primary keys for all the records in the collection

Returns:
an array containing all primary keys

/Doctrine/Collection.php at line 300

getReference

public Doctrine_Record getReference()

Get reference to Doctrine_Record instance

Returns:
$reference

/Doctrine/Collection.php at line 1013

getRelation

public Doctrine_Relation getRelation()

Returns the relation object


/Doctrine/Collection.php at line 667

getSnapshot

public array getSnapshot()

Gets the data of the last snapshot

Returns:
returns the data in last snapshot

/Doctrine/Collection.php at line 129

getTable

public Doctrine_Table getTable()

Get the table this collection belongs to


/Doctrine/Collection.php at line 842

importFrom

public void importFrom(string type, string data)

Import data to a Doctrine_Collection from one of the supported Doctrine_Parser formats


/Doctrine/Collection.php at line 107

initNullObject

public static void initNullObject(Doctrine_Null null)

Initializes the null object for this collection


/Doctrine/Collection.php at line 1024

isModified

public final boolean isModified()

checks if one of the containing records is modified returns true if modified, false otherwise


/Doctrine/Collection.php at line 262

key

public Doctrine_Record key()

Get the current key


/Doctrine/Collection.php at line 528

loadRelated

public boolean loadRelated(mixed name)

Load all relationships or the named relationship passed


/Doctrine/Collection.php at line 506

merge

public Doctrine_Collection merge(Doctrine_Collection coll)

Merges collection into $this and returns merged collection


/Doctrine/Collection.php at line 581

populateRelated

public void populateRelated(string name, Doctrine_Collection coll)

Populate the relationship $name for all records in the passed collection


/Doctrine/Collection.php at line 683

processDiff

public Doctrine_Collection 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


/Doctrine/Collection.php at line 311

remove

public boolean remove(mixed key, mixed offset)

Removes a specified collection element


/Doctrine/Collection.php at line 894

save

public Doctrine_Collection save(Doctrine_Connection conn, mixed processDiff)

Saves all records of this collection and processes the difference of the last snapshot and the current data

Parameters:
conn - optional connection parameter

/Doctrine/Collection.php at line 336

search

public void search(mixed record, string Doctrine_Record)

Search a Doctrine_Record instance


/Doctrine/Collection.php at line 150

serialize

public array serialize()

This method is automatically called when this Doctrine_Collection is serialized


/Doctrine/Collection.php at line 435

set

public void set(integer key, Doctrine_Record record, mixed offset, mixed value)

Set a Doctrine_Record instance to the collection


/Doctrine/Collection.php at line 140

setData

public Doctrine_Collection setData(array data)

Set the data for the Doctrin_Collection instance


/Doctrine/Collection.php at line 200

setKeyColumn

public Doctrine_Collection setKeyColumn(string column)

Sets the key column for this collection

Returns:
$this

/Doctrine/Collection.php at line 272

setReference

public void setReference(mixed record, mixed relation)

Sets a reference pointer


/Doctrine/Collection.php at line 814

synchronizeFromArray

public void synchronizeFromArray(mixed array)

/Doctrine/Collection.php at line 797

synchronizeWithArray

public void 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 - representation of a Doctrine_Collection

/Doctrine/Collection.php at line 655

takeSnapshot

public Doctrine_Collection 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.


/Doctrine/Collection.php at line 697

toArray

public void toArray(boolean deep, mixed prefixKey)

Mimics the result of a $query->execute(array(), Doctrine_Core::HYDRATE_ARRAY);


/Doctrine/Collection.php at line 726

toHierarchy

public void toHierarchy()

/Doctrine/Collection.php at line 717

toKeyValueArray

public array toKeyValueArray(string key, string value)

Build an array made up of the values from the 2 specified columns

Returns:
$result

/Doctrine/Collection.php at line 171

unserialize

public void unserialize(mixed serialized)

This method is automatically called everytime a Doctrine_Collection object is unserialized


Doctrine