Collection of Right objects
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.
}
}
| package | dstruct_auth |
|---|
add(\Right $right) : boolean
If the object exists, a DStructGeneralException will be thrown
\Right
\DStructGeneralException |
|---|
booleancount() : integer
| inherited_from | \ObjCollection::count() |
|---|
integerexists(mixed $obj) : boolean
| inherited_from | \ObjCollection::exists() |
|---|
mixedObject, or it's ID
booleangetArray() : array
| inherited_from | \ObjCollection::getArray() |
|---|
arraygetByID(integer $id) : object | false
| inherited_from | \ObjCollection::getByID() |
|---|
integer
objectfalse
getFirst() : object | false
| inherited_from | \ObjCollection::getFirst() |
|---|
objectfalse
loadAll()
loadByRight(\Right $right)
\Right
prev() : mixed
| inherited_from | \ObjCollection::prev() |
|---|
mixedobject or false.remove(\Right $right) : boolean
If the object is not in the collection, a DStructGeneralException will be thrown
\DStructGeneralException |
|---|
booleansortObjects(string $element, integer $sort_direction, boolean $caseinsensitive, array $params, boolean $astime)
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() |
|---|
stringElement of the objects to sort by
integer1 (ascending) or -1 (descending). See above.
booleanCase sensitivity of sort.
arrayParameters to be passed on if calling a method
booleanTry to use strtotime() to sort by date
clear()
| inherited_from | \ObjCollection::clear() |
|---|
csort_cmp_attribute(object $a, object $b) : integer
| inherited_from | \ObjCollection::csort_cmp_attribute() |
|---|
object
object
integer0 or 1csort_cmp_method(object $a, object $b) : integer
| inherited_from | \ObjCollection::csort_cmp_method() |
|---|
object
object
integer0 or 1$objs : array
| inherited_from | \ObjCollection::$$objs |
|---|
SORT_OBJECTS_ASC : integer
| inherited_from | \ObjCollection::SORT_OBJECTS_ASC |
|---|
SORT_OBJECTS_DESC : integer
| inherited_from | \ObjCollection::SORT_OBJECTS_DESC |
|---|