[ Index ] |
PHP Cross Reference of ACL Module |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * AclNode 5 * This is the base class for all Nodes of the trees, providing basic functionality 6 * 7 * @author dispy <dispyfree@googlemail.com> 8 * @package acl.base 9 * @license LGPLv2 10 */ 11 abstract class AclNode extends CActiveRecord{ 12 /** 13 * This will take over the permissions of another node belonging to the same 14 * AclObject, if the record is a new one 15 */ 16 public function afterSave(){ 17 parent::afterSave(); 18 if($this->isNewRecord){ 19 //First, find a random node of the same object 20 $node = $this::model()->find('collection_id = :col_id AND id != :id', 21 array(':col_id' => $this->collection_id, ':id' => $this->id)); 22 23 //If there exists a node... otherwise we don't have to overtake anything 24 if($node !== NULL){ 25 //Take over permissions of the the node 26 $this->takeOverPermissions($node); 27 $this->takeOverSubTree($node); 28 } 29 } 30 } 31 32 /** 33 * Runs post-deletion errands 34 */ 35 public function afterDelete(){ 36 parent::afterDelete(); 37 38 //First of all: delete all child-nodes and permissions 39 $this->removeFullRecursively(); 40 } 41 42 /** 43 * Removes all child-nodes and their associated permissions 44 * @throws RuntimeException 45 */ 46 abstract protected function removeFullRecursively(); 47 48 /** 49 * This method copies all permissions assigned to another 50 * AclNode-Object of the same AclObject 51 * @param AclNode the node to take the permissions from 52 */ 53 abstract protected function takeOverPermissions($node); 54 55 /** 56 * Copies the subtree of the given other node of the same object to this 57 * new node 58 * @param PmAclNode $node the node to take subtree from 59 */ 60 protected function takeOverSubTree(PmAclNode $node){ 61 $this->branchNodeSubTree($node, $this); 62 } 63 64 /** 65 * Copies all children of $source recursively into $destination 66 * This branching is necessary because: If an AclObject is a child of another one, 67 * every AclNode of the parent object has to have one AclNode of the child AclObject 68 * as it's child (this is due to the lookup-mechanism this extension uses) 69 * If a new AclNode is created (for example because the parent object itself joins 70 * another object), the subtree of an existing node is copied to the new node 71 * 72 * In fact "copied" is the wrong term, because each node isn't cloned but 73 * a surrogate is created which is in fact another object - but a node of the same 74 * AclObject having the same children as the original one. 75 * 76 * @access public 77 * @param AclNode source 78 * @param AclNode destination 79 * @return int the number of branched nodes (recursive!) 80 */ 81 abstract public function branchNodeSubTree( $source, $destination); 82 83 /** 84 * Generates the condition matching the direct AclNodes of this node 85 * @return array(string, array) the first is the condition, the second one the params 86 */ 87 abstract protected function generateDirectChildrenCondition(); 88 89 /** 90 * Generates the condition matching the direct parent AclNodes of this node 91 * @return array(string, array) the first is the condition, the second one the params 92 */ 93 abstract protected function generateDirectParentCondition(); 94 95 /** 96 * Returns all the direct children of the given Node 97 * 98 * @access public 99 * @return array[AclNode] 100 */ 101 public function getDirectChildren(){ 102 list($condition, $params) = $this->generateDirectChildrenCondition(); 103 return $this->findAll($condition, $params); 104 } 105 106 /** 107 * Returns the direct parent AclNodes of this node 108 * 109 * @access public 110 * @param AclNode node 111 * @return array[AclNode] 112 */ 113 public function getDirectParents(){ 114 list($condition, $params) = $this->generateDirectParentCondition(); 115 return $this->findAll($condition, $params); 116 } 117 118 abstract public function __clone(); 119 } 120 121 ?>
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 |