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

Public Member Functions

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

Static Public Member Functions

static buildTreeQueryCondition ($source, $destination, $disableInheritance=false)
- Static Public Member Functions inherited from AclObject
static loadObjectStatic ($identifier, $model)
static loadObjectsStatic ($identifier, $model=NULL, $onlyFirst=true)

Protected Member Functions

 createNode ($parent=NULL)
- Protected Member Functions inherited from AclObject
 beforeJoin (&$obj)
 beforeLeave (&$obj)
 beforeIs (&$obj)
 assureSaved ()
 assureSafety (&$obj)

Detailed Description

Definition at line 12 of file PmAclObject.php.


Member Function Documentation

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

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 from AclObject.

Definition at line 86 of file PmAclObject.php.

{
//Positions == paths in this case
$preparedConditions = ' ( ';
foreach($positions as $key =>$position){
if($key > 0)
$preparedConditions .= ' OR ';
$preparedConditions .= sprintf( " ( '%s' REGEXP CONCAT('^', %s.%s_path ))",
$position, $table, $type);
}
$preparedConditions .= ' ) ';
return $preparedConditions;
}
beforeDelete ( )

Processes post-deletion tasks

Definition at line 204 of file PmAclObject.php.

{
//Delete all associated AclNodes
$class = Util::getNodeNameOfObject($this);
$paths = $this->getPaths();
//Now, deletes nodes including their subnodes
$condition = PmPathManager::buildMultiplePathCondition("path", $paths);
$num = $class::model()->deleteAll($condition);
if($num === false)
throw new RuntimeException('Unable to delete all nodes of '.$this->id);
//Finally, delete all associated permissions
if(PmPermission::deleteByObject($this, $paths) === false)
throw new RuntimeException('Unable to delete associated permissions of '.$this->id);
return $num !== false;
}
static buildTreeQueryCondition (   $source,
  $destination,
  $disableInheritance = false 
)
static

Builds (string) condition which matches all destinations, which are children of source field should be either aco or aro

Parameters:
array$sourcearray('field' => '', 'table' => '')
array$destinationarray('field' => '', 'table' => '')
boolean$disableInheritanceif set to true, no inheritance will be used, that means no node will acquire the rights of it's parent

Definition at line 54 of file PmAclObject.php.

{
$source['field'] = 'path';
$sourcePrefix = $source['table'].'.'.$source['field'];
$pathExpression = 'CONCAT("^", '.$sourcePrefix.', '
.$source['table'].'.id, '
$method = !$disableInheritance ? 'REGEX' : '=';
return $destination['table'].'.'.$destination['field'].'_path'
.' '.$method.' '.$pathExpression;
}
createNode (   $parent = NULL)
protected

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 from AclObject.

Definition at line 108 of file PmAclObject.php.

{
$class = Util::getNodeNameOfObject($this);
//First, create the node itself and place it in the tree
$node = new $class();
$node->collection_id = $this->id;
if($parent !== NULL)
$node->path = PmPathManager::appendToPath($parent->path, $parent->id);
else
$node->path = PmPathManager::getSeparator();
if(!$node->save())
throw new RuntimeException('Unable to create Node');
return $node;
}
fetchComprisedPositions ( )

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 from AclObject.

Definition at line 74 of file PmAclObject.php.

{
return $this->getPaths();
}
getDirectChildNodes ( AclObject  $child = NULL)

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 from AclObject.

Definition at line 139 of file PmAclObject.php.

{
$nodeName = Util::getNodeNameOfObject($this);
$type = Util::getDataBaseType($this);
//It's easy: fetch all nodes and get the paths their childs will have
$nodes = $this->getNOdes();
$resPaths = array();
foreach($nodes as $node){
$resPaths[] = PmPathManager::appendToPath($node->path, $node->id);
}
$condition = Util::generateInStatement($resPaths);
$params = array();
if($child !== NULL){
$condition .= ' AND t.collection_id = :id ';
$params[':id'] = $parent->id;
}
return $nodeName::model()->with($type)->findAll(' t.path '.$condition);
}
getDirectParentNodes ( AclObject  $parent = NULL)

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 from AclObject.

Definition at line 174 of file PmAclObject.php.

{
$nodeName = Util::getNodeNameOfObject($this);
$type = Util::getDataBaseType($this);
//This time it's easy: fetch all paths and search only by the IDs
$paths = $this->getPaths();
$ids = array();
foreach($paths as $path){
//We have to apply it twice - the getPaths() returns full paths
$info = PmPathManager::getParentPath($info['path']);
//If it has a parent ^^
if($info['id'])
$ids[] = $info['id'];
}
$condition = Util::generateInStatement($ids);
$params = array();
if($parent !== NULL){
$condition .= ' AND collection_id = :id ';
$params[':id'] = $parent->id;
}
return $nodeName::model()->with($type)->findAll(' t.id '.$condition);
}
getFreeNodes ( )

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

public

Parameters:
AclObjectobject
Returns:
array[AclNode]

Reimplemented from AclObject.

Definition at line 22 of file PmAclObject.php.

{
$class = Util::getNodeNameOfObject($this);
return $class::findAll('collection_id = :id AND path =""', array(':id' => $this->id));
}
getPaths ( )

Fetches all Paths of the nodes of this object

Returns:
array[string] the paths of the nodes

Definition at line 33 of file PmAclObject.php.

{
$nodeClass = Util::getNodeNameOfObject($this);
$nodes = $nodeClass::model()->findAll('collection_id = :id', array(':id' => $this->id));
$paths = array();
foreach($nodes as $node){
$paths[] = PmPathManager::appendToPath($node->path, $node->id);
}
unset($nodes);
return $paths;
}
is (   $obj)

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

Parameters:
mixed$obj
Returns:
boolean

Reimplemented from AclObject.

Definition at line 290 of file PmAclObject.php.

{
//Get all nodes of the object
$paths = $obj->getPaths();
$nodeClass = Util::getNodeNameOfObject($this);
//We only want to leave usign the DIRECT child-nodes of this collection
$pathCondition = PmPathManager::buildMultiplePathCondition('path', $paths);
return $nodeClass::model()->find('collection_id = :id AND'.$pathCondition,
array(':id' => $this->id)) !== NULL;
}
join (   $obj)

Joins the given object (now called: group)

Parameters:
mixed$obj
Returns:
boolean

Reimplemented from AclObject.

Definition at line 230 of file PmAclObject.php.

{
//Get all nodes of the object
$objNodes = $obj->getNodes();
$transaction = Yii::app()->db->beginTransaction();
try{
foreach($objNodes as $objNode){
$this->createNode($objNode);
}
$transaction->commit();
}
catch(Exception $e){
$transaction->rollback();
throw $e;
}
return true;
}
leave (   $obj)

Leaves the given group

Parameters:
mixed$obj
Returns:
boolean

Reimplemented from AclObject.

Definition at line 256 of file PmAclObject.php.

{
//Get all nodes of the object
$paths = $obj->getPaths();
$nodeClass = Util::getNodeNameOfObject($this);
//We only want to leave usign the DIRECT child-nodes of this collection
$oneLevelCondition = 'path = ":path"';
$pathCondition = PmPathManager::buildMultiplePathCondition('path', $paths, $oneLevelCondition);
$transaction = Yii::app()->db->beginTransaction();
try{
$nodes = $nodeClass::model()->findAll('collection_id = :id AND '.$pathCondition,
array(':id' => $this->id));
foreach($nodes as $node){
if(!$node->delete())
throw new RuntimeException('Unable to delete node');
}
$transaction->commit();
return true;
}
catch(Exception $e){
$transaction->rollback();
throw $e;
}
}

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