[ Index ] |
PHP Cross Reference of ACL Module |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * Implements path-materilization and node-specific logic for tree-operations 5 * 6 * @author dispy <dispyfree@googlemail.com> 7 * @license LGPLv2 8 * @package acl.strategies.nestedSet.pathMaterialiization 9 */ 10 abstract class PmAclNode extends AclNode{ 11 12 /** 13 * Removes all child-nodes and their associated permissions 14 * @throws RuntimeException 15 */ 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'. 21 PmPathManager::getSeparator().'*" ', 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". 30 PmPathManager::getSeparator()."*' ", 31 array(':path' => $path)); 32 33 if($num === false) 34 throw new RuntimeException('Unable to remove associated permissions'); 35 } 36 37 38 /** 39 * This method copies all permissions assigned to another 40 * AclNode-Object of the same AclObject 41 * @param AclNode the node to take the permissions from 42 */ 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 54 /** 55 * Copies all children of $source recursively into $destination 56 * This branching is necessary because: If an AclObject is a child of another one, 57 * every AclNode of the parent object has to have one AclNode of the child AclObject 58 * as it's child (this is due to the lookup-mechanism this extension uses) 59 * If a new AclNode is created (for example because the parent object itself joins 60 * another object), the subtree of an existing node is copied to the new node 61 * 62 * In fact "copied" is the wrong term, because each node isn't cloned but 63 * a surrogate is created which is in fact another object - but a node of the same 64 * AclObject having the same children as the original one. 65 * 66 * @access public 67 * @param AclNode source 68 * @param AclNode destination 69 * @return int the number of branched nodes (recursive!) 70 */ 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 87 /** 88 * Generates the condition matching the direct AclNodes of this node 89 * @return array(string, array) the first is the condition, the second one the params 90 */ 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 99 /** 100 * Generates the condition matching the direct parent AclNodes of this node 101 * @return array(string, array) the first is the condition, the second one the params 102 */ 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 114 /** 115 * Gets the path of this node including itself 116 * @return string the own path 117 */ 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 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Jul 1 19:24:45 2012 | Cross-referenced by PHPXref 0.7.1 |