ACL Extension  0.3
 All Data Structures Namespaces Files Functions Variables
AclObject Class Reference
Inheritance diagram for AclObject:
PmAclObject PmAco PmAro

Public Member Functions

 join ($obj)
 leave ($obj)
 is ($obj)
 getFreeNodes ()
 fetchComprisedPositions ()
 addPositionCheck ($positions, $type, $table= 't')
 getDirectChildNodes (AclObject $child=NULL)
 getDirectParentNodes (AclObject $parent=NULL)
 getChildObjects ()
 getParentObjects ()
 loadObject ($identifier, $model=NULL)
 loadObjects ($identifier, $model=NULL, $onlyFirst=true)
 getNodes ()
 afterSave ()
 getAssociatedObject ()

Static Public Member Functions

static loadObjectStatic ($identifier, $model)
static loadObjectsStatic ($identifier, $model=NULL, $onlyFirst=true)

Protected Member Functions

 beforeJoin (&$obj)
 beforeLeave (&$obj)
 beforeIs (&$obj)
 createNode ($parent=NULL)
 assureSaved ()
 assureSafety (&$obj)

Detailed Description

Definition at line 16 of file AclObject.php.


Member Function Documentation

addPositionCheck (   $positions,
  $type,
  $table = 't' 
)
abstract

Builds a single SQL-statement comprising all given positions and their parents This SQL-statement will match all those rows being located above the given positions including themselves

Parameters:
array$positionsAll positions to include in our statement
string$typeaco/aro
string$tablethe table comprising the map between objects and permissions
Returns:
string the finished SQL-statement

Reimplemented in PmAclObject.

afterSave ( )

Processes post-saving tasks

Definition at line 311 of file AclObject.php.

{
//If we're new here, we also need a new node for the permissions :)
if($this->isNewRecord){
$this->createNode();
}
}
assureSafety ( $obj)
protected

Assures that:

  • the object is of a proper class
  • all involved objects have been saved before they interact
    Parameters:
    AclObject$obj

Definition at line 351 of file AclObject.php.

{
$obj = $this->loadObject($obj);
//Assure that objects have been saved
$this->assureSaved($this, $obj);
}
assureSaved ( )
protected

Reassures that all passed objects have been saved

Definition at line 335 of file AclObject.php.

{
$args = func_get_args();
foreach($args as $arg){
if(is_object($arg) && is_a($arg, "CActiveRecord") && $arg->getIsNewRecord()){
if(!$arg->save())
throw new RuntimeException('Unable to save object');
}
}
}
beforeIs ( $obj)
protected

Callback being executed before every childhood-check Usage of this method allows common behavior for several strategies with respect to object transformations and a secure environment

Parameters:
AclObject$obj

Definition at line 51 of file AclObject.php.

{
$this->assureSafety($obj);
}
beforeJoin ( $obj)
protected

Callback being executed before every join Usage of this method allows common behavior for several strategies with respect to object transformations and a secure environment

Parameters:
AclObject$obj

Definition at line 31 of file AclObject.php.

{
$this->assureSafety($obj);
}
beforeLeave ( $obj)
protected

Callback being executed before every leave Usage of this method allows common behavior for several strategies with respect to object transformations and a secure environment

Parameters:
AclObject$obj

Definition at line 41 of file AclObject.php.

{
$this->assureSafety($obj);
}
createNode (   $parent = NULL)
abstractprotected

Creates a new node of this collection This new node will be a children of the given AclNode

Parameters:
AclNode$parentparent of the new node, if NULL, it has no parent
Returns:
AclNode the new node

Reimplemented in PmAclObject.

fetchComprisedPositions ( )
abstract

Fetches and returns positions of all nodes of this object which denote them In this case, it's really easy because we've done that anyway :)

Returns:
array[string]

Reimplemented in PmAclObject.

getAssociatedObject ( )

Loads the associated object, if possible, and returns it

Returns:
mixed NULL or a child of CActiveREcord

Definition at line 324 of file AclObject.php.

{
if(is_subclass_of($this->model, "CActiveRecord")){
$model = $this->model;
return $model::model()->findByPk($this->foreign_key);
}
return NULL;
}
getChildObjects ( )

Fetches all child-objects and returns them in an array

Returns:
array[AclObject] the child-objects

Definition at line 136 of file AclObject.php.

{
$childNodes = $this->getDirectChildNodes(NULL);
$objects = array();
$type = Util::getDataBaseType($this);
foreach($childNodes as $node){
$obj = $node->{$type};
//Why this way? Several nodes may be associated to the same object
$objects[$obj->id] = $obj;
}
return $objects;
}
getDirectChildNodes ( AclObject  $child = NULL)
abstract

Returns all of the (direct) AclNodes whose parent AclNode is a node of this AclObject.

If the $child AclObject is specified, only nodes having the given AclObject as owner will be returned.

public

Parameters:
AclObjectchild
Integer
Returns:
array[AclNode]

Reimplemented in PmAclObject.

getDirectParentNodes ( AclObject  $parent = NULL)
abstract

Returns all of the (direct) AclNodes whose child AclNode is a node of this AclObject.

If the $child AclObject is specified, only nodes having the given AclObject as owner will be returned.

public

Parameters:
AclObjectchild
Integer
Returns:
array[AclNode]

Reimplemented in PmAclObject.

getFreeNodes ( )
abstract

Returns all of the AclNodes of this object which do not have a parent yet

public

Parameters:
AclObjectobject
Returns:
array[AclNode]

Reimplemented in PmAclObject.

getNodes ( )

This method returns all AclNodes being associated with this

public

Parameters:
AclObjectobject
Returns:
array[AclNode]

Definition at line 302 of file AclObject.php.

{
$class = Util::getNodeNameOfObject($this);
return $class::model()->findAll('collection_id = :id', array(':id' => $this->id));
}
getParentObjects ( )

Fetches all parent-objects and returns them in an array

Returns:
array[AclObject] the parent-objects

Definition at line 154 of file AclObject.php.

{
$parentNodes = $this->getDirectParentNodes(NULL);
$objects = array();
$type = Util::getDataBaseType($this);
foreach($parentNodes as $node){
$obj = $node->{$type};
//Why this way? Several nodes may be associated to the same object
$objects[$obj->id] = $obj;
}
return $objects;
}
is (   $obj)
abstract

Checks whether this object is somehow a child of the given object

Parameters:
mixed$obj
Returns:
boolean

Reimplemented in PmAclObject.

join (   $obj)
abstract

Joins the given object (now called: group)

Parameters:
mixed$obj
Returns:
boolean

Reimplemented in PmAclObject.

leave (   $obj)
abstract

Leaves the given group

Parameters:
mixed$obj
Returns:
boolean

Reimplemented in PmAclObject.

loadObject (   $identifier,
  $model = NULL 
)

Just a convenient wrapper to loadObjects

Parameters:
mixed$identifierThe Identifier denoting the associated row in the ACL-system.
string$model- the class-Name of the expected object (Aro or Aco)

Definition at line 182 of file AclObject.php.

{
if(!$model)
$model = get_class($this);
return self::loadObjectsStatic($identifier, $model, true);
}
loadObjects (   $identifier,
  $model = NULL,
  $onlyFirst = true 
)

Just a convenient wrapper to loadObjects

Parameters:
mixed$identifierThe Identifier denoting the associated row in the ACL-system.
string$model- the class-Name of the expected object (Aro or Aco)

Definition at line 193 of file AclObject.php.

{
if(!$model)
$model = get_class($this);
return self::loadObjects($identifier, $model, $onlyFirst);
}
static loadObjectsStatic (   $identifier,
  $model = NULL,
  $onlyFirst = true 
)
static

This method is used to load Objects (either Aco or Aro) using convenient identifiers.

Parameters:
mixed$identifierThe Identifier denoting the associated row in the ACL-system. Supported identifiers: 1) Array syntax: array('model' => 'MyModel', 'foreign_key' => myId) e.g.: model => User, foreign_key => the ID of the user (presumably AUTO_INCREMENT INT from the user row) 2) alias syntax: "MyAlias" e.g.: "Visitors", "Admins", "Authors" 3) direct syntax: pass your object derived from CActiveRecord directly e.g.: loadObject(User::model()->find(....)) This will be automatically resolved to the first syntax. Please be aware that auto-creation of associated ACL-objects only happens if the strict-mode is disabled So if you pass a new object which has no corresponding aco/aro-row, this will lead to an exception if the strict-mode is enabled. 4) Of course, you can pass the finished object directly. As many methods call this method without check, this is natural.
string$model- the class-Name of the expected object (Aro or Aco)
boolean$onlyFirstDetermines whether to fetch only the first matching object, or all of them.
Returns:
type

Definition at line 221 of file AclObject.php.

{
//There are several ways to define the object in question
if(is_string($model)){
$class = Strategy::getClass($model);
$model = new $class();
}
if($onlyFirst)
$method = 'find';
else
$method = 'findAll';
//An alias is being used
if(is_string($identifier)){
$objects = $model->$method('alias=:alias', array('alias' => $identifier));
if(!$objects){
if(Strategy::get('strictMode')){
throw new Exception('Unknown alias for ACL-ObjectCollection');
}
else{
$obj = new $model;
$obj->alias = $identifier;
$obj->save();
$objects = $onlyFirst ? $obj : array($obj);
}
}
}
//The object is searched by its model
elseif(
is_array($identifier) &&
(isset($identifier['foreign_key']) && isset($identifier['model']))
){
$objects = $model->$method('foreign_key = :foreign_key AND model = :model',
array(':foreign_key' => $identifier['foreign_key'], ':model' => $identifier['model']));
if(!$objects){
if(Strategy::get('strictMode')){
throw new Exception('Unknown foreign key and/or model for ACL-ObjectCollection');
}
else{
$obj = new $model;
$obj->foreign_key = $identifier['foreign_key'];
$obj->model = $identifier['model'];
$obj->save();
$objects = $onlyFirst ? $obj : array($obj);
}
}
}
//The object is passed directly - do not do anything
elseif(is_a($identifier, "AclObject") || (
is_a($identifier, "HiddenClass")
&& is_subclass_of($identifier->pretends(), "Aclobject")
)){
$objects = $identifier;
}
elseif(is_a($identifier, "CActiveRecord")){
return self::loadObjectsStatic( array('model' => get_class($identifier), 'foreign_key' => $identifier->id), $model, $onlyFirst);
}
else{
throw new Exception('Unknown ACL-Object specification');
}
return $objects;
}
static loadObjectStatic (   $identifier,
  $model 
)
static

Just a convenient wrapper to loadObjects

Parameters:
mixed$identifierThe Identifier denoting the associated row in the ACL-system.
string$model- the class-Name of the expected object (Aro or Aco)

Definition at line 173 of file AclObject.php.

{
return self::loadObjectsStatic($identifier, $model, true);
}

The documentation for this class was generated from the following file: