ACL Extension  0.3
 All Data Structures Namespaces Files Functions Variables
PmAclNode.php
Go to the documentation of this file.
1 <?php
2 
10 abstract class PmAclNode extends AclNode{
11 
16  protected function removeFullRecursively(){
17  $path = PmPathManager::appendToPath($this->path, $this->id);
18  Yii::trace($path, 'trace');
19  //Firstly: remove nodes
20  $num = static::model()->deleteAll('path REGEXP "^:path'.
22  array(':path' => $path));
23 
24  if($num === false)
25  throw new RuntimeException('Unable to remove child nodes');
26 
27  //Secondly: remove permissions
28  $type = Util::getDataBaseType($this);
29  $num = PmPermission::model()->deleteAll($type."_path REGEXP '^:path".
31  array(':path' => $path));
32 
33  if($num === false)
34  throw new RuntimeException('Unable to remove associated permissions');
35  }
36 
37 
43  protected function takeOverPermissions($node){
44  foreach($node->permissions as $permission){
45  $permission = clone $permission;
46  $permission->aco_id = $this->id;
47  $permission->aco_path = $this->path;
48  if(!$permission->save())
49  throw new RuntimeException('Unable to clone permission');
50  }
51  }
52 
53 
71  public function branchNodeSubTree( $source, $destination){
72  $nodes = $source->getDirectChildren();
73  $count = count($nodes);
74 
75  $newPath = PmPathManager::appendToPath($destination->path, $destination->id);
76  foreach($nodes as $node){
77  $newNode = clone $node;
78  $newNode->path = $newPath;
79  if(!$newNode->save())
80  throw new RuntimeException('Unable to branch node '.$node->id);
81  $count += $newNode->branchNodeSubtree($node, $newNode);
82  }
83 
84  return $count;
85  }
86 
91  protected function generateDirectChildrenCondition(){
92  $path = PmPathManager::appendToPath($this->path, $this->id);
93  return array(
94  'path = :path',
95  array(':path' => $path)
96  );
97  }
98 
103  protected function generateDirectParentCondition(){
104  //Get Parent path and ID
105  $parent = PmPathManager::getParentPath($this->path);
106  return array(
107  'path = :path AND id = :id',
108  array(':path' => $parent['path'],
109  ':id' => $parent['id']
110  )
111  );
112  }
113 
118  public function getOwnPath(){
119  return PmPathManager::appendToPath($this->path, $this->id);
120  }
121 
122 
123  public function __clone(){
124  //it should be a completely new node
125  $this->id = NULL;
126  $this->isNewRecord = true;
127  $this->path = NULL;
128  }
129 }
130 
131 ?>