Doctrine 1.2.4
Doctrine_Collection_Offset Class Reference

Inherits Doctrine_Collection.

Public Member Functions

 __construct (Doctrine_Table $table)
 
 __get ($name)
 
 __isset ($name)
 
 __set ($name, $value)
 
 __toString ()
 
 __unset ($name)
 
 add ($value)
 
 add ($record, $key=null)
 
 bind ($name, $resource)
 
 clear ()
 
 contains ($key)
 
 count ()
 
 delete (Doctrine_Connection $conn=null, $clearColl=true)
 
 end ()
 
 exportTo ($type, $deep=true)
 
 free ($deep=false)
 
 fromArray ($array, $deep=true)
 
 get ($key)
 
 getData ()
 
 getDeleteDiff ()
 
 getFirst ()
 
 getInsertDiff ()
 
 getIterator ()
 
 getKeyColumn ()
 
 getKeys ()
 
 getLast ()
 
 getLimit ()
 
 getLocator ()
 
 getNormalIterator ()
 
 getPrimaryKeys ()
 
 getReference ()
 
 getRelation ()
 
 getSnapshot ()
 
 getTable ()
 
 importFrom ($type, $data)
 
 isModified ()
 
 key ()
 
 loadRelated ($name=null)
 
 locate ($name)
 
 merge (Doctrine_Collection $coll)
 
 offsetExists ($offset)
 
 offsetGet ($offset)
 
 offsetSet ($offset, $value)
 
 offsetUnset ($offset)
 
 populateRelated ($name, Doctrine_Collection $coll)
 
 processDiff ()
 
 remove ($key)
 
 replace (Doctrine_Connection $conn=null, $processDiff=true)
 
 save (Doctrine_Connection $conn=null, $processDiff=true)
 
 search (Doctrine_Record $record)
 
 serialize ()
 
 set ($key, $record)
 
 setArray (array $array)
 
 setData (array $data)
 
 setKeyColumn ($column)
 
 setLocator (Doctrine_Locator $locator)
 
 setReference (Doctrine_Record $record, Doctrine_Relation $relation)
 
 synchronizeWithArray (array $array)
 
 takeSnapshot ()
 
 toArray ($deep=true, $prefixKey=false)
 
 toKeyValueArray ($key, $value)
 
 unserialize ($serialized)
 

Static Public Member Functions

static getNullObject ()
 
static initNullObject (Doctrine_Null $null)
 

Protected Member Functions

 compareRecords ($a, $b)
 

Detailed Description

Definition at line 34 of file Offset.php.

Constructor & Destructor Documentation

Doctrine_Collection_Offset::__construct ( Doctrine_Table  $table)
Parameters
Doctrine_Table$table

Definition at line 44 of file Offset.php.

{
parent::__construct($table);
$this->limit = $table->getAttribute(Doctrine_Core::ATTR_COLL_LIMIT);
}

Member Function Documentation

Doctrine_Access::__get (   $name)
inherited

Get key from data

See Also
get, offsetGet
Parameters
mixed$name
Returns
mixed

Definition at line 70 of file Access.php.

{
return $this->get($name);
}
Doctrine_Access::__isset (   $name)
inherited

Check if key exists in data

Parameters
string$name
Returns
boolean whether or not this object contains $name

Definition at line 81 of file Access.php.

{
return $this->contains($name);
}
Doctrine_Access::__set (   $name,
  $value 
)
inherited

Set key and value to data

See Also
set, offsetSet
Parameters
$name
$value
Returns
void

Definition at line 58 of file Access.php.

{
$this->set($name, $value);
}
Doctrine_Collection::__toString ( )
inherited

Returns a string representation of this object

Returns
string $string

Definition at line 1038 of file Collection.php.

Doctrine_Access::__unset (   $name)
inherited

Remove key from data

Parameters
string$name
Returns
void

Definition at line 92 of file Access.php.

{
return $this->remove($name);
}
Doctrine_Access::add (   $value)
inherited

Add the value

Parameters
mixed$valueThe value to add
Returns
void

Definition at line 199 of file Access.php.

{
throw new Doctrine_Exception('Add is not supported for ' . get_class($this));
}
Doctrine_Collection::add (   $record,
  $key = null 
)
inherited

Adds a record to collection

Parameters
Doctrine_Record$recordrecord to be added
string$keyoptional key for the record
Returns
boolean

for some weird reason in_array cannot be used here (php bug ?)

if used it results in fatal error : [ nesting level too deep ]

Definition at line 451 of file Collection.php.

{
if (isset($this->referenceField)) {
$value = $this->reference->get($this->relation->getLocalFieldName());
if ($value !== null) {
$record->set($this->referenceField, $value, false);
} else {
$record->set($this->referenceField, $this->reference, false);
}
$relations = $this->relation['table']->getRelations();
foreach ($relations as $relation) {
if ($this->relation['class'] == $relation['localTable']->getOption('name') && $relation->getLocal() == $this->relation->getForeignFieldName()) {
$record->$relation['alias'] = $this->reference;
break;
}
}
}
/**
* for some weird reason in_array cannot be used here (php bug ?)
*
* if used it results in fatal error : [ nesting level too deep ]
*/
foreach ($this->data as $val) {
if ($val === $record) {
return false;
}
}
if (isset($key)) {
if (isset($this->data[$key])) {
return false;
}
$this->data[$key] = $record;
return true;
}
if (isset($this->keyColumn)) {
$value = $record->get($this->keyColumn);
if ($value === null) {
throw new Doctrine_Collection_Exception("Couldn't create collection index. Record field '".$this->keyColumn."' was null.");
}
$this->data[$value] = $record;
} else {
$this->data[] = $record;
}
return true;
}
Doctrine_Locator_Injectable::bind (   $name,
  $resource 
)
inherited

bind binds a resource to a name

Parameters
string$namethe name of the resource to bind
mixed$valuethe value of the resource
Returns
Doctrine_Locator this object

Definition at line 120 of file Injectable.php.

{
$this->_resources[$name] = $resource;
return $this;
}
Doctrine_Collection::clear ( )
inherited

Clears the collection.

Returns
void

Definition at line 994 of file Collection.php.

{
$this->data = array();
}
Doctrine_Collection::compareRecords (   $a,
  $b 
)
protectedinherited

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

Parameters
Doctrine_Record$a
Doctrine_Record$b
Returns
integer

Definition at line 878 of file Collection.php.

{
if ($a->getOid() == $b->getOid()) {
return 0;
}
return ($a->getOid() > $b->getOid()) ? 1 : -1;
}
Doctrine_Collection::contains (   $key)
inherited

Whether or not this collection contains a specified element

Parameters
mixed$keythe key of the element
Returns
boolean

Definition at line 325 of file Collection.php.

{
return isset($this->data[$key]);
}
Doctrine_Collection::count ( )
inherited

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

Returns
integer

Definition at line 423 of file Collection.php.

{
return count($this->data);
}
Doctrine_Collection::delete ( Doctrine_Connection  $conn = null,
  $clearColl = true 
)
inherited

Deletes all records from this collection

Returns
Doctrine_Collection

Definition at line 962 of file Collection.php.

{
if ($conn == null) {
$conn = $this->_table->getConnection();
}
try {
$conn->beginInternalTransaction();
$conn->transaction->addCollection($this);
foreach ($this as $key => $record) {
$record->delete($conn);
}
$conn->commit();
} catch (Exception $e) {
$conn->rollback();
throw $e;
}
if ($clearColl) {
$this->clear();
}
return $this;
}
Doctrine_Collection::end ( )
inherited

Get the last record in the collection

Returns
Doctrine_Record

Definition at line 252 of file Collection.php.

{
return end($this->data);
}
Doctrine_Collection::exportTo (   $type,
  $deep = true 
)
inherited

Export a Doctrine_Collection to one of the supported Doctrine_Parser formats

Parameters
string$type
string$deep
Returns
void

Definition at line 826 of file Collection.php.

{
if ($type == 'array') {
return $this->toArray($deep);
} else {
return Doctrine_Parser::dump($this->toArray($deep, true), $type);
}
}
Doctrine_Collection::free (   $deep = false)
inherited

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.

Returns
void

Definition at line 1006 of file Collection.php.

{
foreach ($this->getData() as $key => $record) {
if ( ! ($record instanceof Doctrine_Null)) {
$record->free($deep);
}
}
$this->data = array();
if ($this->reference) {
$this->reference->free($deep);
$this->reference = null;
}
}
Doctrine_Collection::fromArray (   $array,
  $deep = true 
)
inherited

Populate a Doctrine_Collection from an array of data

Parameters
string$array
Returns
void

Definition at line 780 of file Collection.php.

{
$data = array();
foreach ($array as $rowKey => $row) {
$this[$rowKey]->fromArray($row, $deep);
}
}
Doctrine_Collection::get (   $key)
inherited

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
  1. 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$keythe key of the element
Returns
Doctrine_Record return a specified record

Definition at line 357 of file Collection.php.

{
if ( ! isset($this->data[$key])) {
$record = $this->_table->create();
if (isset($this->referenceField)) {
$value = $this->reference->get($this->relation->getLocalFieldName());
if ($value !== null) {
$record->set($this->referenceField, $value, false);
} else {
$record->set($this->referenceField, $this->reference, false);
}
}
if ($key === null) {
$this->data[] = $record;
} else {
$this->data[$key] = $record;
}
if (isset($this->keyColumn)) {
$record->set($this->keyColumn, $key);
}
return $record;
}
return $this->data[$key];
}
Doctrine_Collection::getData ( )
inherited

Get all the records as an array

Returns
array

Definition at line 222 of file Collection.php.

{
return $this->data;
}
Doctrine_Collection::getDeleteDiff ( )
inherited

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

Returns
array $diff

Definition at line 856 of file Collection.php.

{
return array_udiff($this->_snapshot, $this->data, array($this, 'compareRecords'));
}
Doctrine_Collection::getFirst ( )
inherited

Get the first record in the collection

Returns
Doctrine_Record

Definition at line 232 of file Collection.php.

{
return reset($this->data);
}
Doctrine_Collection::getInsertDiff ( )
inherited

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

Returns
array $diff

Definition at line 866 of file Collection.php.

{
return array_udiff($this->data, $this->_snapshot, array($this, "compareRecords"));
}
Doctrine_Collection_Offset::getIterator ( )
Returns
Doctrine_Collection_Iterator_Expandable

Definition at line 61 of file Offset.php.

Doctrine_Collection::getKeyColumn ( )
inherited

Get the name of the key column

Returns
string

Definition at line 212 of file Collection.php.

{
return $this->keyColumn;
}
Doctrine_Collection::getKeys ( )
inherited

Get all keys of the data in the collection

Returns
array

Definition at line 412 of file Collection.php.

{
return array_keys($this->data);
}
Doctrine_Collection::getLast ( )
inherited

Get the last record in the collection

Returns
Doctrine_Record

Definition at line 242 of file Collection.php.

{
return end($this->data);
}
Doctrine_Collection_Offset::getLimit ( )
Returns
integer

Definition at line 53 of file Offset.php.

{
return $this->limit;
}
Doctrine_Locator_Injectable::getLocator ( )
inherited

getLocator returns the locator associated with this object

if there are no locator locally associated then this method tries to fetch the current global locator

Returns
Doctrine_Locator

Definition at line 75 of file Injectable.php.

{
if ( ! isset($this->_locator)) {
$this->_locator = Doctrine_Locator::instance();
}
return $this->_locator;
}
Doctrine_Collection::getNormalIterator ( )
inherited

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

Returns
Doctrine_Iterator_Normal $iterator

Definition at line 638 of file Collection.php.

{
}
static Doctrine_Locator_Injectable::getNullObject ( )
staticinherited

getNullObject returns the null object associated with this object

Returns
Doctrine_Null

Definition at line 145 of file Injectable.php.

{
return self::$_null;
}
Doctrine_Collection::getPrimaryKeys ( )
inherited

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

Returns
array an array containing all primary keys

Definition at line 392 of file Collection.php.

{
$list = array();
$name = $this->_table->getIdentifier();
foreach ($this->data as $record) {
if (is_array($record) && isset($record[$name])) {
$list[] = $record[$name];
} else {
$list[] = $record->getIncremented();
}
}
return $list;
}
Doctrine_Collection::getReference ( )
inherited

Get reference to Doctrine_Record instance

Returns
Doctrine_Record $reference

Definition at line 300 of file Collection.php.

{
return $this->reference;
}
Doctrine_Collection::getRelation ( )
inherited

Returns the relation object

Returns
Doctrine_Relation

Definition at line 1048 of file Collection.php.

{
return $this->relation;
}
Doctrine_Collection::getSnapshot ( )
inherited

Gets the data of the last snapshot

Returns
array returns the data in last snapshot

Definition at line 667 of file Collection.php.

{
return $this->_snapshot;
}
Doctrine_Collection::getTable ( )
inherited

Get the table this collection belongs to

Returns
Doctrine_Table

Definition at line 129 of file Collection.php.

{
return $this->_table;
}
Doctrine_Collection::importFrom (   $type,
  $data 
)
inherited

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

Parameters
string$type
string$data
Returns
void

Definition at line 842 of file Collection.php.

{
if ($type == 'array') {
return $this->fromArray($data);
} else {
return $this->fromArray(Doctrine_Parser::load($data, $type));
}
}
static Doctrine_Collection::initNullObject ( Doctrine_Null  $null)
staticinherited

Initializes the null object for this collection

Returns
void

Definition at line 107 of file Collection.php.

{
self::$null = $null;
}
Doctrine_Collection::isModified ( )
finalinherited

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

Returns
boolean

Definition at line 1059 of file Collection.php.

{
$dirty = (count($this->getInsertDiff()) > 0 || count($this->getDeleteDiff()) > 0);
if ( ! $dirty) {
foreach($this as $record) {
if ($dirty = $record->isModified()) {
break;
}
}
}
return $dirty;
}
Doctrine_Collection::key ( )
inherited

Get the current key

Returns
Doctrine_Record

Definition at line 262 of file Collection.php.

{
return key($this->data);
}
Doctrine_Collection::loadRelated (   $name = null)
inherited

Load all relationships or the named relationship passed

Parameters
mixed$name
Returns
boolean

Definition at line 528 of file Collection.php.

{
$list = array();
$query = $this->_table->createQuery();
if ( ! isset($name)) {
foreach ($this->data as $record) {
$value = $record->getIncremented();
if ($value !== null) {
$list[] = $value;
}
}
$query->where($this->_table->getComponentName() . '.id IN (' . substr(str_repeat("?, ", count($list)),0,-2) . ')');
if ( ! $list) {
$query->where($this->_table->getComponentName() . '.id IN (' . substr(str_repeat("?, ", count($list)),0,-2) . ')', $list);
}
return $query;
}
$rel = $this->_table->getRelation($name);
if ($rel instanceof Doctrine_Relation_LocalKey || $rel instanceof Doctrine_Relation_ForeignKey) {
foreach ($this->data as $record) {
$list[] = $record[$rel->getLocal()];
}
} else {
foreach ($this->data as $record) {
$value = $record->getIncremented();
if ($value !== null) {
$list[] = $value;
}
}
}
if ( ! $list) {
return;
}
$dql = $rel->getRelationDql(count($list), 'collection');
$coll = $query->query($dql, $list);
$this->populateRelated($name, $coll);
}
Doctrine_Locator_Injectable::locate (   $name)
inherited

locate locates a resource by given name and returns it

if the resource cannot be found locally this method tries to use the global locator for finding the resource

See Also
Doctrine_Locator::locate()
Exceptions
Doctrine_Locator_Exceptionif the resource could not be found
Parameters
string$namethe name of the resource
Returns
mixed the located resource

Definition at line 96 of file Injectable.php.

{
if (isset($this->_resources[$name])) {
if (is_object($this->_resources[$name])) {
return $this->_resources[$name];
} else {
// get the name of the concrete implementation
$concreteImpl = $this->_resources[$name];
return $this->getLocator()->locate($concreteImpl);
}
} else {
return $this->getLocator()->locate($name);
}
}
Doctrine_Collection::merge ( Doctrine_Collection  $coll)
inherited

Merges collection into $this and returns merged collection

Parameters
Doctrine_Collection$coll
Returns
Doctrine_Collection

Definition at line 506 of file Collection.php.

{
$localBase = $this->getTable()->getComponentName();
$otherBase = $coll->getTable()->getComponentName();
if ($otherBase != $localBase && !is_subclass_of($otherBase, $localBase) ) {
throw new Doctrine_Collection_Exception("Can't merge collections with incompatible record types");
}
foreach ($coll->getData() as $record) {
$this->add($record);
}
return $this;
}
Doctrine_Access::offsetExists (   $offset)
inherited

Check if an offset axists

Parameters
mixed$offset
Returns
boolean Whether or not this object contains $offset

Definition at line 103 of file Access.php.

{
return $this->contains($offset);
}
Doctrine_Access::offsetGet (   $offset)
inherited

An alias of get()

See Also
get, __get
Parameters
mixed$offset
Returns
mixed

Definition at line 115 of file Access.php.

{
return $this->get($offset);
}
Doctrine_Access::offsetSet (   $offset,
  $value 
)
inherited

Sets $offset to $value

See Also
set, __set
Parameters
mixed$offset
mixed$value
Returns
void

Definition at line 128 of file Access.php.

{
if ( ! isset($offset)) {
$this->add($value);
} else {
$this->set($offset, $value);
}
}
Doctrine_Access::offsetUnset (   $offset)
inherited

Unset a given offset

See Also
set, offsetSet, __set
Parameters
mixed$offset

Definition at line 143 of file Access.php.

{
return $this->remove($offset);
}
Doctrine_Collection::populateRelated (   $name,
Doctrine_Collection  $coll 
)
inherited

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

Parameters
string$name
Doctrine_Collection$coll
Returns
void

Definition at line 581 of file Collection.php.

{
$rel = $this->_table->getRelation($name);
$table = $rel->getTable();
$foreign = $rel->getForeign();
$local = $rel->getLocal();
if ($rel instanceof Doctrine_Relation_LocalKey) {
foreach ($this->data as $key => $record) {
foreach ($coll as $k => $related) {
if ($related[$foreign] == $record[$local]) {
$this->data[$key]->setRelated($name, $related);
}
}
}
} elseif ($rel instanceof Doctrine_Relation_ForeignKey) {
foreach ($this->data as $key => $record) {
if ( ! $record->exists()) {
continue;
}
$sub = Doctrine_Collection::create($table);
foreach ($coll as $k => $related) {
if ($related[$foreign] == $record[$local]) {
$sub->add($related);
$coll->remove($k);
}
}
$this->data[$key]->setRelated($name, $sub);
}
} elseif ($rel instanceof Doctrine_Relation_Association) {
$identifier = $this->_table->getIdentifier();
$asf = $rel->getAssociationFactory();
$name = $table->getComponentName();
foreach ($this->data as $key => $record) {
if ( ! $record->exists()) {
continue;
}
$sub = Doctrine_Collection::create($table);
foreach ($coll as $k => $related) {
if ($related->get($local) == $record[$identifier]) {
$sub->add($related->get($name));
}
}
$this->data[$key]->setRelated($name, $sub);
}
}
}
Doctrine_Collection::processDiff ( )
inherited

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

Returns
Doctrine_Collection

Definition at line 683 of file Collection.php.

{
foreach (array_udiff($this->_snapshot, $this->data, array($this, "compareRecords")) as $record) {
$record->delete();
}
return $this;
}
Doctrine_Collection::remove (   $key)
inherited

Removes a specified collection element

Parameters
mixed$key
Returns
boolean

Definition at line 311 of file Collection.php.

{
$removed = $this->data[$key];
unset($this->data[$key]);
return $removed;
}
Doctrine_Collection::replace ( Doctrine_Connection  $conn = null,
  $processDiff = true 
)
inherited

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

Parameters
Doctrine_Connection$connoptional connection parameter
Returns
Doctrine_Collection

Definition at line 929 of file Collection.php.

{
if ($conn == null) {
$conn = $this->_table->getConnection();
}
try {
$conn->beginInternalTransaction();
$conn->transaction->addCollection($this);
if ($processDiff) {
$this->processDiff();
}
foreach ($this->getData() as $key => $record) {
$record->replace($conn);
}
$conn->commit();
} catch (Exception $e) {
$conn->rollback();
throw $e;
}
return $this;
}
Doctrine_Collection::save ( Doctrine_Connection  $conn = null,
  $processDiff = true 
)
inherited

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

Parameters
Doctrine_Connection$connoptional connection parameter
Returns
Doctrine_Collection

Definition at line 894 of file Collection.php.

{
if ($conn == null) {
$conn = $this->_table->getConnection();
}
try {
$conn->beginInternalTransaction();
$conn->transaction->addCollection($this);
if ($processDiff) {
$this->processDiff();
}
foreach ($this->getData() as $key => $record) {
$record->save($conn);
}
$conn->commit();
} catch (Exception $e) {
$conn->rollback();
throw $e;
}
return $this;
}
Doctrine_Collection::search ( Doctrine_Record  $record)
inherited

Search a Doctrine_Record instance

Parameters
string$Doctrine_Record
Returns
void

Definition at line 336 of file Collection.php.

{
return array_search($record, $this->data, true);
}
Doctrine_Collection::serialize ( )
inherited

This method is automatically called when this Doctrine_Collection is serialized

Returns
array

Definition at line 150 of file Collection.php.

{
$vars = get_object_vars($this);
unset($vars['reference']);
unset($vars['referenceField']);
unset($vars['relation']);
unset($vars['expandable']);
unset($vars['expanded']);
unset($vars['generator']);
$vars['_table'] = $vars['_table']->getComponentName();
return serialize($vars);
}
Doctrine_Collection::set (   $key,
  $record 
)
inherited

Set a Doctrine_Record instance to the collection

Parameters
integer$key
Doctrine_Record$record
Returns
void

Definition at line 435 of file Collection.php.

{
if (isset($this->referenceField)) {
$record->set($this->referenceField, $this->reference, false);
}
$this->data[$key] = $record;
}
Doctrine_Access::setArray ( array  $array)
inherited

Set an entire aray to the data

Parameters
array$arrayAn array of key => value pairs
Returns
Doctrine_Access

Definition at line 41 of file Access.php.

{
foreach ($array as $k => $v) {
$this->set($k, $v);
}
return $this;
}
Doctrine_Collection::setData ( array  $data)
inherited

Set the data for the Doctrin_Collection instance

Parameters
array$data
Returns
Doctrine_Collection

Definition at line 140 of file Collection.php.

{
$this->data = $data;
}
Doctrine_Collection::setKeyColumn (   $column)
inherited

Sets the key column for this collection

Parameters
string$column
Returns
Doctrine_Collection $this

Definition at line 200 of file Collection.php.

{
$this->keyColumn = $column;
return $this;
}
Doctrine_Locator_Injectable::setLocator ( Doctrine_Locator  $locator)
inherited

setLocator this method can be used for setting the locator object locally

Parameters
Doctrine_Locatorthe locator object
Returns
Doctrine_Locator_Injectable this instance

Definition at line 60 of file Injectable.php.

{
$this->_locator = $locator;
return $this;
}
Doctrine_Collection::setReference ( Doctrine_Record  $record,
Doctrine_Relation  $relation 
)
inherited

Sets a reference pointer

Returns
void

Definition at line 272 of file Collection.php.

{
$this->reference = $record;
$this->relation = $relation;
if ($relation instanceof Doctrine_Relation_ForeignKey ||
$relation instanceof Doctrine_Relation_LocalKey) {
$this->referenceField = $relation->getForeignFieldName();
$value = $record->get($relation->getLocalFieldName());
foreach ($this->data as $record) {
if ($value !== null) {
$record->set($this->referenceField, $value, false);
} else {
$record->set($this->referenceField, $this->reference, false);
}
}
} elseif ($relation instanceof Doctrine_Relation_Association) {
}
}
Doctrine_Collection::synchronizeWithArray ( array  $array)
inherited

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$arrayrepresentation of a Doctrine_Collection

Definition at line 797 of file Collection.php.

{
foreach ($this as $key => $record) {
if (isset($array[$key])) {
$record->synchronizeWithArray($array[$key]);
unset($array[$key]);
} else {
// remove records that don't exist in the array
$this->remove($key);
}
}
// create new records for each new row in the array
foreach ($array as $rowKey => $row) {
$this[$rowKey]->fromArray($row);
}
}
Doctrine_Collection::takeSnapshot ( )
inherited

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.

Returns
Doctrine_Collection

Definition at line 655 of file Collection.php.

{
$this->_snapshot = $this->data;
return $this;
}
Doctrine_Collection::toArray (   $deep = true,
  $prefixKey = false 
)
inherited

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

Parameters
boolean$deep

Definition at line 697 of file Collection.php.

{
$data = array();
foreach ($this as $key => $record) {
$key = $prefixKey ? get_class($record) . '_' .$key:$key;
$data[$key] = $record->toArray($deep, $prefixKey);
}
return $data;
}
Doctrine_Collection::toKeyValueArray (   $key,
  $value 
)
inherited

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

Parameters
string$key
string$value
Returns
array $result

Definition at line 717 of file Collection.php.

{
$result = array();
foreach ($this as $record) {
$result[$record->$key] = $record->$value;
}
return $result;
}
Doctrine_Collection::unserialize (   $serialized)
inherited

This method is automatically called everytime a Doctrine_Collection object is unserialized

Returns
void

Definition at line 171 of file Collection.php.

{
$connection = $manager->getCurrentConnection();
$array = unserialize($serialized);
foreach ($array as $name => $values) {
$this->$name = $values;
}
$this->_table = $connection->getTable($this->_table);
$keyColumn = isset($array['keyColumn']) ? $array['keyColumn'] : null;
if ($keyColumn === null) {
$keyColumn = $this->_table->getBoundQueryPart('indexBy');
}
if ($keyColumn !== null) {
$this->keyColumn = $keyColumn;
}
}

The documentation for this class was generated from the following file: