[ Index ]

PHP Cross Reference of ACL Module

title

Body

[close]

/models/ -> RestrictedTreeActiveRecord.php (source)

   1  <?php
   2  
   3  /**

   4   * This class is intended for objects which are located in a tree structure

   5   * themselves if the tree-structure should also use the permission system.

   6   * This way, the permission-tree is mirrored to the orginal tree.  

   7   *

   8   * @author dispy <dispyfree@googlemail.com>

   9   * @license LGPLv2

  10   * @package acl.base

  11   */
  12  abstract class RestrictedTreeActiveRecord extends RestrictedActiveRecord{
  13     
  14     /**

  15      * @var int the parent-ID: we track changes and if they occur, we also move

  16      * the object in the ACL-tree

  17      */
  18      protected $oldParentId = NULL;
  19      
  20      public function afterFind() {
  21          parent::afterFind();
  22          $this->oldParentId = $this->parent_id;
  23          
  24          return true;
  25      }
  26      
  27      /**

  28       * If the parent has changed, adjust the permissions

  29       * @throws RuntimeException 

  30       */
  31      public function afterSave() {
  32          parent::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  ?>


Generated: Sun Jul 1 19:24:45 2012 Cross-referenced by PHPXref 0.7.1