Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. <!-- User model -->
  2. <?php
  3.  
  4.     class User extends AppModel {
  5.         var $name = 'User';
  6.    
  7.         var $belongsTo = array (
  8.             'Group'
  9.         );
  10.    
  11.         var $actsAs = array('Acl' => array('type' => 'requester'));
  12.    
  13.         function parentNode(){
  14.                 if (!$this->id && empty($this->data)) {
  15.                     return null;
  16.                 }
  17.                 $data = $this->data;
  18.                 if(empty($this->data)) {
  19.             $data = $this->read();
  20.             }
  21.  
  22.         if (empty($data['User']['group_id'])){
  23.             return null;
  24.         } else {
  25.             return array('Group' => array('id' => $data['User']['group_id']));
  26.         }
  27.    
  28.         // Update de db "After save"
  29.         function afterSave($created) {
  30.             if (!$created) {
  31.                 $parent = $this->parentNode();
  32.                 $parent = $this->node($parent);
  33.                 $node = $this->node();
  34.                 $aro = $node[0];
  35.                 $aro['Aro']['parent_id'] = $parent[0]['Aro']['id'];
  36.                 $this->Aro->save($aro);
  37.             }
  38.             }
  39.     }
  40.  
  41. ?>
  42.  
  43. <!-- Group Model -->
  44.  
  45. <?php
  46.  
  47.     class Group extends AppModel {
  48.         var $name = 'Group';
  49.        
  50.         var $hasMany = array (
  51.             'User'
  52.         );
  53.        
  54.         var $actsAs = array('Acl' => array('type' => 'requester'));
  55.      
  56.         function parentNode() {
  57.             return 'root_node';
  58.         }
  59.     }
  60.  
  61. ?>