ACL Extension  0.3
 All Data Structures Namespaces Files Functions Variables
PmAclNode Class Reference
Inheritance diagram for PmAclNode:
AclNode PmAcoNode PmAroNode

Public Member Functions

 branchNodeSubTree ($source, $destination)
 getOwnPath ()
 __clone ()
- Public Member Functions inherited from AclNode
 afterSave ()
 afterDelete ()
 getDirectChildren ()
 getDirectParents ()

Protected Member Functions

 removeFullRecursively ()
 takeOverPermissions ($node)
 generateDirectChildrenCondition ()
 generateDirectParentCondition ()
- Protected Member Functions inherited from AclNode
 takeOverSubTree (PmAclNode $node)

Detailed Description

Definition at line 10 of file PmAclNode.php.


Member Function Documentation

__clone ( )

Reimplemented from AclNode.

Definition at line 123 of file PmAclNode.php.

{
//it should be a completely new node
$this->id = NULL;
$this->isNewRecord = true;
$this->path = NULL;
}
branchNodeSubTree (   $source,
  $destination 
)

Copies all children of $source recursively into $destination This branching is necessary because: If an AclObject is a child of another one, every AclNode of the parent object has to have one AclNode of the child AclObject as it's child (this is due to the lookup-mechanism this extension uses) If a new AclNode is created (for example because the parent object itself joins another object), the subtree of an existing node is copied to the new node

In fact "copied" is the wrong term, because each node isn't cloned but a surrogate is created which is in fact another object - but a node of the same AclObject having the same children as the original one.

public

Parameters:
AclNodesource
AclNodedestination
Returns:
int the number of branched nodes (recursive!)

Reimplemented from AclNode.

Definition at line 71 of file PmAclNode.php.

{
$nodes = $source->getDirectChildren();
$count = count($nodes);
$newPath = PmPathManager::appendToPath($destination->path, $destination->id);
foreach($nodes as $node){
$newNode = clone $node;
$newNode->path = $newPath;
if(!$newNode->save())
throw new RuntimeException('Unable to branch node '.$node->id);
$count += $newNode->branchNodeSubtree($node, $newNode);
}
return $count;
}
generateDirectChildrenCondition ( )
protected

Generates the condition matching the direct AclNodes of this node

Returns:
array(string, array) the first is the condition, the second one the params

Reimplemented from AclNode.

Definition at line 91 of file PmAclNode.php.

{
$path = PmPathManager::appendToPath($this->path, $this->id);
return array(
'path = :path',
array(':path' => $path)
);
}
generateDirectParentCondition ( )
protected

Generates the condition matching the direct parent AclNodes of this node

Returns:
array(string, array) the first is the condition, the second one the params

Reimplemented from AclNode.

Definition at line 103 of file PmAclNode.php.

{
//Get Parent path and ID
$parent = PmPathManager::getParentPath($this->path);
return array(
'path = :path AND id = :id',
array(':path' => $parent['path'],
':id' => $parent['id']
)
);
}
getOwnPath ( )

Gets the path of this node including itself

Returns:
string the own path

Definition at line 118 of file PmAclNode.php.

{
return PmPathManager::appendToPath($this->path, $this->id);
}
removeFullRecursively ( )
protected

Removes all child-nodes and their associated permissions

Exceptions:
RuntimeException

Reimplemented from AclNode.

Definition at line 16 of file PmAclNode.php.

{
$path = PmPathManager::appendToPath($this->path, $this->id);
Yii::trace($path, 'trace');
//Firstly: remove nodes
$num = static::model()->deleteAll('path REGEXP "^:path'.
array(':path' => $path));
if($num === false)
throw new RuntimeException('Unable to remove child nodes');
//Secondly: remove permissions
$type = Util::getDataBaseType($this);
$num = PmPermission::model()->deleteAll($type."_path REGEXP '^:path".
array(':path' => $path));
if($num === false)
throw new RuntimeException('Unable to remove associated permissions');
}
takeOverPermissions (   $node)
protected

This method copies all permissions assigned to another AclNode-Object of the same AclObject

Parameters:
AclNodethe node to take the permissions from

Reimplemented from AclNode.

Definition at line 43 of file PmAclNode.php.

{
foreach($node->permissions as $permission){
$permission = clone $permission;
$permission->aco_id = $this->id;
$permission->aco_path = $this->path;
if(!$permission->save())
throw new RuntimeException('Unable to clone permission');
}
}

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