Class CoughCollection

Description

CoughCollection collects CoughObjects.

  • abstract:

Located in /cough/CoughCollection.class.php (line 8)

ArrayObject
   |
   --CoughCollection
Variable Summary
Method Summary
static string getTemporaryKey ()
CoughCollection __construct ()
void add (CoughObject $object)
mixed get (mixed $key)
CoughAbstractDatabaseAdapter getDb ()
CoughKeyValueIterator getKeyValueIterator ( $value, [ $key = 'getKeyId'])
mixed getLoadSql ()
mixed getPosition (int $n)
boolean isEmpty ()
void load ()
void loadBySql ( $sql)
mixed remove (CoughObject|int|string $objectOrId)
mixed removeByKey ( $key)
mixed removeByReference ( $objectToRemove)
void save ()
void sortByKeys (array $keys)
void sortByMethod (string $methodName, [int $direction = SORT_ASC])
void sortByMethods (string $methodName, int $direction, int $type)
Variables
string $elementClassName (line 18)

The name of the element class that will be used when adding new elements to the collection

Override this in sub class.

  • access: protected
array $removedElements = array() (line 25)

Holds all the (unsaved) removed elements

  • var: of CoughObjects
  • access: protected
Methods
static method getTemporaryKey (line 226)

Returns a temporary key for adding an object that does not have a key ID yet.

  • author: Anthony Bush
  • access: protected
static string getTemporaryKey ()
Constructor __construct (line 27)
  • access: public
CoughCollection __construct ()

Redefinition of:
ArrayObject::constructor __construct ( $array )
add (line 211)

Adds a single element (even if it doesn't have a key ID yet).

  • author: Anthony Bush
  • access: public
void add (CoughObject $object)
get (line 193)

Returns the element at the given key.

  • return: the CoughObject if found, null if not.
  • author: Anthony Bush
  • access: public
mixed get (mixed $key)
  • mixed $key: the result from the element's CoughObject::getKeyId() method (which always returns a flattened string/integer) or the result from the element's CoughObject::getPk() method (which always returns the array form of the key).
getDb (line 54)

Returns a reference to the database object to use for queries.

  • access: public
CoughAbstractDatabaseAdapter getDb ()
getFirst (line 154)

The first element in the array/collection.

  • return: null if collection is empty
  • author: Anthony Bush
  • since: 2008-10-08
  • access: public
CoughObject|null getFirst ()
getIterator (line 36)

Returns a new iterator for the collection.

  • access: public
CoughIterator getIterator ()

Redefinition of:
ArrayObject::getIterator ( )
getKeyValueIterator (line 45)

Returns a new key-value iterator for the collection.

  • access: public
CoughKeyValueIterator getKeyValueIterator ( $value, [ $key = 'getKeyId'])
  • $value
  • $key
getLast (line 165)

The last element in the array/collection.

  • return: null if collection is empty
  • author: Anthony Bush
  • since: 2008-10-08
  • access: public
CoughObject|null getLast ()
getLoadSql (line 67)

Returns the base SQL to use for the collection.

Defaults to just calling the object's getLoadSql() static method.

Override in sub class to use different SQL.

  • return: return value of CoughObject::getLoadSql()
  • access: public
mixed getLoadSql ()
getPosition (line 136)

Get the $n-th position in the array, regardless of key indices.

$n = 0 gets first element, $n = (count - 1) gets last element.

  • return: nth element in array.
  • author: Anthony Bush
  • access: public
mixed getPosition (int $n)
  • int $n: which element to get (in range 0 to count - 1).
isEmpty (line 175)

Find out whether or not the collection is empty.

  • return: true if nothing is in the collection, false otherwise.
  • author: Anthony Bush
  • access: public
boolean isEmpty ()
load (line 76)

Loads the collection using the SQL provided by getLoadSql()

  • access: public
void load ()
loadBySql (line 85)

Loads the collection using the provided SQL

  • access: public
void loadBySql ( $sql)
  • $sql
remove (line 239)

Removes a single element given either an ID or the object itself.

  • return: CoughObject that was removed, or false if no element could be found/removed.
  • author: Anthony Bush
  • access: public
mixed remove (CoughObject|int|string $objectOrId)
  • CoughObject|int|string $objectOrId: object or ID to remove (ID must be result from $object->getKeyId()).
removeByKey (line 263)

Removes a single element from the collection by key.

Due to a bug in PHP 5.2.1 and earlier, we do not use offsetExists()... This has the drawback of not working when a value exists, but is null, but if that ever happens behavior is UNDEFINED anyway (i.e. how do you have a null element in a CoughCollection? It makes no sense.) See http://bugs.php.net/bug.php?id=40872 for more details.

  • return: CoughObject that was removed, or false if no element could be found/removed.
  • author: Anthony Bush
  • access: protected
mixed removeByKey ( $key)
  • $key
removeByReference (line 279)

Removes a single element from the collection by comparing references.

  • return: CoughObject that was removed, or false if no element could be found/removed.
  • author: Anthony Bush
  • access: protected
mixed removeByReference ( $objectToRemove)
  • $objectToRemove
save (line 103)

Run save on each collected (or removed) element.

  • author: Anthony Bush
  • access: public
void save ()
sortByKeys (line 298)

Sort the collection from an array of keys (where the keys are in the desired order).

  • author: Anthony Bush
  • access: public
void sortByKeys (array $keys)
  • array $keys: ordered key IDs for the elements in the collection.
sortByMethod (line 323)

Sort the collection from the return value of the specified method name of the collected objects.

Examples:

  1.      $collection->sortByMethod('getProductName');
  2.      $collection->sortByMethod('getProductName'SORT_ASC);
  3.      $collection->sortByMethod('getProductName'SORT_DESC);

  • author: Anthony Bush
  • access: public
void sortByMethod (string $methodName, [int $direction = SORT_ASC])
  • string $methodName
  • int $direction: SORT_ASC or SORT_DESC (PHP sort order constant)
sortByMethods (line 360)

Sort the collection from the return value of the specified method names of the collected objects.

Examples:

  1.      $collection->sortByMethods('getManufacturerName''getProductName');
  2.      $collection->sortByMethods('getManufacturerName'SORT_DESC'getProductName'SORT_DESC);
  3.      $collection->sortByMethods('getManufacturerName'SORT_DESC'getProductName'SORT_ASC);
  4.      $collection->sortByMethods('getManufacturerName'SORT_DESCSORT_STRING'getProductName'SORT_STRING);

void sortByMethods (string $methodName, int $direction, int $type)
  • string $methodName
  • int $direction: SORT_ASC or SORT_DESC (PHP sort order constant)
  • int $type: SORT_REGULAR, SORT_STRING, or SORT_NUMERIC (PHP sort type constant)

Inherited Methods

Inherited From ArrayObject (Internal Class)

constructor __construct ( $array )
append ( $value )
asort ( )
count ( )
exchangeArray ( $array )
getArrayCopy ( )
getFlags ( )
getIterator ( )
getIteratorClass ( )
ksort ( )
natcasesort ( )
natsort ( )
offsetExists ( $index )
offsetGet ( $index )
offsetSet ( $index, $newval )
offsetUnset ( $index )
setFlags ( $flags )
setIteratorClass ( $iteratorClass )
uasort ( $cmp_function )
uksort ( $cmp_function )
Class Constants

Inherited Constants

Inherited from ArrayObject (Internal Class)

ARRAY_AS_PROPS = 2
STD_PROP_LIST = 1

Documentation generated on Sun, 19 Oct 2008 11:56:32 -0500 by phpDocumentor 1.4.0