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

 Methods

Add a {@link Right} to the collection.

add(\Right $right) : boolean

If the object exists, a DStructGeneralException will be thrown

Parameters

$right

\Right

Exceptions

\DStructGeneralException

Returns

boolean

Number of objects currently in collection

count() : integer
Inherited
inherited_from \ObjCollection::count()

Returns

integer

(non-PHPdoc)

current() 
Inherited
see \Iterator::current()
inherited_from \ObjCollection::current()

Test whether an object exists in the collection.

exists(mixed $obj) : boolean
Inherited
inherited_from \ObjCollection::exists()

Parameters

$obj

mixed

Object, 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
see \Iterator::key()
inherited_from \ObjCollection::key()

Load all {@link Right} objects in the database into the collection.

loadAll() 

Load {@Right} objects by {@link Group}.

loadByGroup(\Group $group) 

Parameters

$group

\Group

Load {@link Right} objects by Right (Implied Rights).

loadByRight(\Right $right) 

Parameters

$right

\Right

(non-PHPdoc)

next() 
Inherited
see \Iterator::next()
inherited_from \ObjCollection::next()

Get previous object in collection.

prev() : mixed
Inherited
inherited_from \ObjCollection::prev()

Returns

mixedobject or false.

Remove an object from the collection.

remove(\Right $right) : boolean

If the object is not in the collection, a DStructGeneralException will be thrown

Parameters

$right

\Right

{@link Right} object

Exceptions

\DStructGeneralException

Returns

boolean

(non-PHPdoc)

rewind() 
Inherited
see \Iterator::rewind()
inherited_from \ObjCollection::rewind()

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

string

Element of the objects to sort by

$sort_direction

integer

1 (ascending) or -1 (descending). See above.

$caseinsensitive

boolean

Case sensitivity of sort.

$params

array

Parameters to be passed on if calling a method

$astime

boolean

Try to use strtotime() to sort by date

(non-PHPdoc)

valid() 
Inherited
see \Iterator::valid()
inherited_from \ObjCollection::valid()

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