Propel API
Class

PropelCollection

class PropelCollection extends ArrayObject implements Serializable

Class for iterating over a list of Propel elements The collection keys must be integers - no associative array accepted

Methods

array getData()

Get the data in the collection

setData(array $data)

Set the data in the collection

integer getPosition()

Gets the position of the internal pointer This position can be later used in seek()

mixed getFirst()

Move the internal pointer to the beginning of the list And get the first element in the collection

boolean isFirst()

Check whether the internal pointer is at the beginning of the list

mixed getPrevious()

Move the internal pointer backward And get the previous element in the collection

mixed getCurrent()

Get the current element in the collection

mixed getNext()

Move the internal pointer forward And get the next element in the collection

mixed getLast()

Move the internal pointer to the end of the list And get the last element in the collection

boolean isLast()

Check whether the internal pointer is at the end of the list

boolean isEmpty()

Check if the collection is empty

boolean isOdd()

Check if the current index is an odd integer

boolean isEven()

Check if the current index is an even integer

mixed get(mixed $key)

Get an element from its key Alias for ArrayObject::offsetGet()

mixed pop()

Pops an element off the end of the collection

mixed shift()

Pops an element off the beginning of the collection

integer prepend(mixed $value)

Prepend one or more elements to the beginning of the collection

set(mixed $key, mixed $value)

Add an element to the collection with the given key Alias for ArrayObject::offsetSet()

mixed remove(mixed $key)

Removes a specified collection element Alias for ArrayObject::offsetUnset()

array clear()

Clears the collection

boolean contains(mixed $element)

Whether or not this collection contains a specified element

mixed search(mixed $element)

Search an element in the collection

PropelCollection diff(PropelCollection $collection)

Returns an array of objects present in the collection that are not presents in the given collection.

string serialize()

void unserialize(string $data)

ArrayIterator getIterator()

Overrides ArrayObject::getIterator() to save the iterator object for internal use e.g.

ArrayIterator getInternalIterator()

clearIterator()

Clear the internal Iterator.

setModel(string $model)

Set the model of the elements in the collection

string getModel()

Get the model of the elements in the collection

string getPeerClass()

Get the peer class of the elements in the collection

setFormatter(PropelFormatter $formatter)

PropelFormatter getFormatter()

PropelPDO getConnection(string $type = Propel::CONNECTION_READ)

Get a connection object for the database containing the elements of the collection

BaseObject importFrom(mixed $parser, string $data)

Populate the current collection from a string, using a given parser format <code> $coll = new PropelObjectCollection(); $coll->setModel('Book'); $coll->importFrom('JSON', '{{"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}}'); </code>

string exportTo(mixed $parser, boolean $usePrefix = true, boolean $includeLazyLoadColumns = true)

Export the current collection to a string, using a given parser format <code> $books = BookQuery::create()->find(); echo $book->exportTo('JSON'); => {{"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}}'); </code>

array|string __call(string $name, mixed $params)

Catches calls to undefined methods.

string __toString()

Returns a string representation of the current collection.

array toArray(string $keyColumn = null, boolean $usePrefix = false, string $keyType = BasePeer::TYPE_PHPNAME, boolean $includeLazyLoadColumns = true, array $alreadyDumpedObjects = array())

Get an array representation of the collection Each object is turned into an array and the result is returned

Details

at line 52
public array getData()

Get the data in the collection

Return Value

array

at line 62
public setData(array $data)

Set the data in the collection

Parameters

array $data

at line 73
public integer getPosition()

Gets the position of the internal pointer This position can be later used in seek()

Return Value

integer

at line 84
public mixed getFirst()

Move the internal pointer to the beginning of the list And get the first element in the collection

Return Value

mixed

at line 96
public boolean isFirst()

Check whether the internal pointer is at the beginning of the list

Return Value

boolean

at line 107
public mixed getPrevious()

Move the internal pointer backward And get the previous element in the collection

Return Value

mixed

at line 124
public mixed getCurrent()

Get the current element in the collection

Return Value

mixed

at line 135
public mixed getNext()

Move the internal pointer forward And get the next element in the collection

Return Value

mixed

at line 148
public mixed getLast()

Move the internal pointer to the end of the list And get the last element in the collection

Return Value

mixed

at line 165
public boolean isLast()

Check whether the internal pointer is at the end of the list

Return Value

boolean

at line 181
public boolean isEmpty()

Check if the collection is empty

Return Value

boolean

at line 191
public boolean isOdd()

Check if the current index is an odd integer

Return Value

boolean

at line 201
public boolean isEven()

Check if the current index is an even integer

Return Value

boolean

at line 215
public mixed get(mixed $key)

Get an element from its key Alias for ArrayObject::offsetGet()

Parameters

mixed $key

Return Value

mixed The element

Exceptions

PropelException

at line 229
public mixed pop()

Pops an element off the end of the collection

Return Value

mixed The popped element

at line 246
public mixed shift()

Pops an element off the beginning of the collection

Return Value

mixed The popped element

at line 263
public integer prepend(mixed $value)

Prepend one or more elements to the beginning of the collection

Parameters

mixed $value the element to prepend

Return Value

integer The number of new elements in the array

at line 281
public set(mixed $key, mixed $value)

Add an element to the collection with the given key Alias for ArrayObject::offsetSet()

Parameters

mixed $key
mixed $value

at line 295
public mixed remove(mixed $key)

Removes a specified collection element Alias for ArrayObject::offsetUnset()

Parameters

mixed $key

Return Value

mixed The removed element

Exceptions

PropelException

at line 309
public array clear()

Clears the collection

Return Value

array The previous collection

at line 320
public boolean contains(mixed $element)

Whether or not this collection contains a specified element

Parameters

mixed $element

Return Value

boolean

Search an element in the collection

Parameters

mixed $element

Return Value

mixed Returns the key for the element if it is found in the collection, FALSE otherwise

at line 343
public PropelCollection diff(PropelCollection $collection)

Returns an array of objects present in the collection that are not presents in the given collection.

Parameters

PropelCollection $collection A Propel collection.

Return Value

PropelCollection An array of Propel objects from the collection that are not presents in the given collection.

at line 362
public string serialize()

Return Value

string

at line 377
public void unserialize(string $data)

Parameters

string $data

Return Value

void

at line 392
public ArrayIterator getIterator()

Overrides ArrayObject::getIterator() to save the iterator object for internal use e.g.

getNext(), isOdd(), etc.

Return Value

ArrayIterator

at line 402
public ArrayIterator getInternalIterator()

Return Value

ArrayIterator

at line 417
public clearIterator()

Clear the internal Iterator.

PHP 5.3 doesn't know how to free a PropelCollection object if it has an attached
Iterator, so this must be done manually to avoid memory leaks.

See also

http://www.propelorm.org/ticket/1232

at line 429
public setModel(string $model)

Set the model of the elements in the collection

Parameters

string $model Name of the Propel object classes stored in the collection

at line 439
public string getModel()

Get the model of the elements in the collection

Return Value

string Name of the Propel object class stored in the collection

at line 451
public string getPeerClass()

Get the peer class of the elements in the collection

Return Value

string Name of the Propel peer class stored in the collection

Exceptions

PropelException

at line 463
public setFormatter(PropelFormatter $formatter)

Parameters

PropelFormatter $formatter

at line 471
public PropelFormatter getFormatter()

Return Value

PropelFormatter

at line 482
public PropelPDO getConnection(string $type = Propel::CONNECTION_READ)

Get a connection object for the database containing the elements of the collection

Parameters

string $type The connection type (Propel::CONNECTION_READ by default; can be Propel::connection_WRITE)

Return Value

PropelPDO A PropelPDO connection object

at line 502
public BaseObject importFrom(mixed $parser, string $data)

Populate the current collection from a string, using a given parser format <code> $coll = new PropelObjectCollection(); $coll->setModel('Book'); $coll->importFrom('JSON', '{{"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}}'); </code>

Parameters

mixed $parser A PropelParser instance, or a format name ('XML', 'YAML', 'JSON', 'CSV')
string $data The source data to import from

Return Value

BaseObject The current object, for fluid interface

at line 531
public string exportTo(mixed $parser, boolean $usePrefix = true, boolean $includeLazyLoadColumns = true)

Export the current collection to a string, using a given parser format <code> $books = BookQuery::create()->find(); echo $book->exportTo('JSON'); => {{"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}}'); </code>

A PropelOnDemandCollection cannot be exported. Any attempt will result in a PropelExecption being thrown.

Parameters

mixed $parser A PropelParser instance, or a format name ('XML', 'YAML', 'JSON', 'CSV')
boolean $usePrefix (optional) If true, the returned element keys will be prefixed with the model class name ('Article_0', 'Article_1', etc). Defaults to TRUE. Not supported by PropelArrayCollection, as PropelArrayFormatter has already created the array used here with integers as keys.
boolean $includeLazyLoadColumns (optional) Whether to include lazy load(ed) columns. Defaults to TRUE. Not supported by PropelArrayCollection, as PropelArrayFormatter has already included lazy-load columns in the array used here.

Return Value

string The exported data

at line 553
public array|string __call(string $name, mixed $params)

Catches calls to undefined methods.

Provides magic import/export method support (fromXML()/toXML(), fromYAML()/toYAML(), etc.).
Allows to define default __call() behavior if you use a custom BaseObject

Parameters

string $name
mixed $params

Return Value

array|string

Exceptions

PropelException

at line 574
public string __toString()

Returns a string representation of the current collection.

Based on the string representation of the underlying objects, defined in
the Peer::DEFAULT_STRING_FORMAT constant

Return Value

string

at line 613
public array toArray(string $keyColumn = null, boolean $usePrefix = false, string $keyType = BasePeer::TYPE_PHPNAME, boolean $includeLazyLoadColumns = true, array $alreadyDumpedObjects = array())

Get an array representation of the collection Each object is turned into an array and the result is returned

Parameters

string $keyColumn If null, the returned array uses an incremental index. Otherwise, the array is indexed using the specified column
boolean $usePrefix If true, the returned array prefixes keys with the model class name ('Article_0', 'Article_1', etc).
string $keyType (optional) One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME, BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM. Defaults to BasePeer::TYPE_PHPNAME.
boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE.
array $alreadyDumpedObjects List of objects to skip to avoid recursion <code> $bookCollection->toArray(); array( 0 => array('Id' => 123, 'Title' => 'War And Peace'), 1 => array('Id' => 456, 'Title' => 'Don Juan'), ) $bookCollection->toArray('Id'); array( 123 => array('Id' => 123, 'Title' => 'War And Peace'), 456 => array('Id' => 456, 'Title' => 'Don Juan'), ) $bookCollection->toArray(null, true); array( 'Book_0' => array('Id' => 123, 'Title' => 'War And Peace'), 'Book_1' => array('Id' => 456, 'Title' => 'Don Juan'), ) </code>

Return Value

array