ACL Extension  0.3
 All Data Structures Namespaces Files Functions Variables
RestrictedTreeActiveRecord.php
Go to the documentation of this file.
1 <?php
2 
13 
18  protected $oldParentId = NULL;
19 
20  public function afterFind() {
22  $this->oldParentId = $this->parent_id;
23 
24  return true;
25  }
26 
31  public function afterSave() {
33  //If the Owner has changed - quit old parent in permission system and move to new!
34  if ($this->oldParentId != $this->parent_id) {
35 
36  $acoClass = new CGroup();
37  //First: find the aco-Object of yourself
38  $aco = $acoClass->loadObject($this);
39  if($aco === NULL)
40  throw new RuntimeException('Aco-object does not exist');
41 
42  //If we moved to another parent and we had an old one
43  if($this->oldParentId !== NULL){
44  if (!$aco->leave(array('model' => get_class($this), 'foreign_key' => $this->oldParentId)))
45  throw new RuntimeException('Unable to leave old parent-aco-object');
46  }
47 
48  //Only choose a new parent if we have a new one - we don't necessarily have one :)
49  if($this->parent_id !== NULL){
50  $aco2 = $acoClass->loadObject(
51  array('model' => get_class($this), 'foreign_key' => $this->parent_id));
52  if (!$aco->join($aco2))
53  throw new RuntimeException('Unable to choose new parent-aco');
54  }
55 
56  //In the end, save the change
57  $this->oldParentId = $this->parent_id;
58  }
59 
60  return true;
61  }
62 }
63 
64 ?>