Any objects used with this class must support Object::getID().
Extension of this class allows collections of objects to be collated, used and manipulated in a
convenient and consistent manner.
The child class is responsible for loading the objects and will often provide function(s) for loading and deleting objects.
An example function for loading all records as objects into the collection:
public function loadAll() {
parent::clear(); // clears any objects in collection
$rs = DataManager::loadObjects(); // load id's from the database to a var
foreach ($rs as $row) {
parent::add(ObjectClass::loadByID($row[0])); // load objects into this class. This may vary with the actual class method being called.
}
}
Methods
Add Group to collection.
add(\Group $obj) : boolean
If the object exists, a DStructGeneralException will be thrown
Parameters
Exceptions
Returns
boolean
Attach an AuthContainer to a Group.
attachAuthContainerToGroup(string $containername, string $containerid, mixed $group)
Static
Parameters
$containername
string
$containerid
string
$group
mixedGroup object or ID of a Group object
Number of objects currently in collection
count() : integer
Inherited
| inherited_from |
\ObjCollection::count() |
Returns
integer
(non-PHPdoc)
current()
Inherited
Test whether an object exists in the collection.
exists(mixed $obj) : boolean
Inherited
| inherited_from |
\ObjCollection::exists() |
Parameters
$obj
mixedObject, or it's ID
Returns
boolean
Array of objects.
getArray() : array
Inherited
| inherited_from |
\ObjCollection::getArray() |
Returns
array
Returns an object from the collection based on its ID.
getByID(integer $id) : object | false
Inherited
| inherited_from |
\ObjCollection::getByID() |
Parameters
$id
integer
Returns
objectfalse
Returns the first object in the collection.
getFirst() : object | false
Inherited
| inherited_from |
\ObjCollection::getFirst() |
Returns
objectfalse
(non-PHPdoc)
key()
Inherited
Load all groups into the collection.
loadAll()
Load groups into the collection by their IDs.
loadByArray(array $groups)
Load the groups an authcontainer object belongs to.
loadByAuthContainer(object $container)
Parameters
$container
objectContainer object
(non-PHPdoc)
next()
Inherited
Get previous object in collection.
prev() : mixed
Inherited
| inherited_from |
\ObjCollection::prev() |
Returns
mixedobject or false.
Remove Group from collection.
remove(\Group $obj) : boolean
If the object is not in the collection, a DStructGeneralException will be thrown
Parameters
Exceptions
Returns
boolean
Remove an AuthContainer from a Group
removeAuthContainerFromGroup(string $containername, string $containerid, mixed $group)
Static
Parameters
$containername
string
$containerid
string
$group
mixedGroup object or Group object's ID
(non-PHPdoc)
rewind()
Inherited
Sorts objects by attribute or return from a method.
sortObjects(string $element, integer $sort_direction, boolean $caseinsensitive, array $params, boolean $astime)
Inherited
WARNING: This method may be slow! It is advisable to use another method if one is available,
for instance, using ORDER BY in an SQL statement to create and add the objects in order.
The $element parameter can specify either an attribute or a method of
the objects in the collection. Methods should be named in full e.g. "method()".
Although this uses the PHP function usort(), the array keys are preserved.
The constants SORT_OBJECTS_ASC and SORT_OBJECTS_DESC are provided
to set the $sort_direction parameter.
If you set $astime to true, the method will try to use PHP's strtotime() function to
attempt to convert strings into time, allowing you to sort dates in the expected order. You must
ensure that all data will convert to strtotime, or that data will be evalutated as false!
Example:
class Employee {
public $name;
public function __construct($name) {$this->name = $name;}
public function getName() {return $this->name;}
}
$employees = new Employees; // create collection object
$employees->add(new Employee('neil'));
$employees->add(new Employee('David'));
$employees->add(new Employee('Shane'));
// order by name attribute
$employees->sortObjects('name');
// new order: David, neil, Shane
// order by method return, and case sensitive, and passing a single parameter of true to the method
$employees->sortObjects('getName()', Employees::SORT_ORDERS_ASC, false, array(true));
// new order: David, Shane, neil
| inherited_from |
\ObjCollection::sortObjects() |
Parameters
$element
stringElement of the objects to sort by
$sort_direction
integer1 (ascending) or -1 (descending). See above.
$caseinsensitive
booleanCase sensitivity of sort.
$params
arrayParameters to be passed on if calling a method
$astime
booleanTry to use strtotime() to sort by date
(non-PHPdoc)
valid()
Inherited
Clear the collection.
clear()
Inherited
| inherited_from |
\ObjCollection::clear() |
Callback used by usort in {@link sortObjects()} to sort by objects attributes
csort_cmp_attribute(object $a, object $b) : integer
InheritedStatic
| inherited_from |
\ObjCollection::csort_cmp_attribute() |
Parameters
$a
object
$b
object
Returns
integer0 or 1
Callback used by usort in {@link sortObjects()} to sort by the return from an objects method.
csort_cmp_method(object $a, object $b) : integer
InheritedStatic
| inherited_from |
\ObjCollection::csort_cmp_method() |
Parameters
$a
object
$b
object
Returns
integer0 or 1
Properties
$objs : array
Inherited
| inherited_from |
\ObjCollection::$$objs |
Constants
Sort ascending.
SORT_OBJECTS_ASC : integer
Inherited
| inherited_from |
\ObjCollection::SORT_OBJECTS_ASC |
Sort descending.
SORT_OBJECTS_DESC : integer
Inherited
| inherited_from |
\ObjCollection::SORT_OBJECTS_DESC |