DataObjects/Core_person_settings.php
[Pman.Core] / DataObjects / Core_person_settings.php
1 <?php
2 /**
3  * Table Definition for Core_person_settings
4  */
5 class_exists('DB_DataObject') ? '' : require_once 'DB/DataObject.php';
6
7 class Pman_Core_DataObjects_Core_person_settings extends DB_DataObject 
8 {
9     ###START_AUTOCODE
10     /* the code below is auto generated do not remove the above tag */
11
12     public $__table = 'core_person_settings';
13     public $id;
14     public $person_id;
15     public $scope;
16     public $data;
17     
18     /* the code above is auto generated do not remove the tag below */
19     ###END_AUTOCODE
20     
21     function beforeInsert($q, $roo)
22     {
23         if(!$this->hasPermission($roo)) {
24             $roo->jerr('Access Dennied');
25         }
26         
27         $o = $this->isExist();
28         
29         if(!empty($o)) {
30             $oo = clone ($o);
31             $o->setFrom(array(
32                 'data' => $this->data
33             ));
34             $o->update($oo);
35             $roo->jok('OK');
36         }
37         
38     }
39     
40     function beforeUpdate($old, $q, $roo)
41     {
42         if(!$this->hasPermission($roo)) {
43             $roo->jerr('Access Dennied');
44         }
45         
46         
47     }
48     
49     function beforeDelete($dependants_array, $roo)
50     {
51         if(!$this->hasPermission($roo)) {
52             $roo->jerr('Access Dennied');
53         }
54     }
55     
56     function hasPermission($roo)
57     {
58         if(
59                 !$roo->authUser ||
60                 (!empty($this->person_id) && $this->person_id != $roo->authUser->id)
61         ) {
62             return false;
63         }
64         
65         return true;
66     }
67     
68     function isExist()
69     {
70         $core_person_settings = DB_DataObject::factory('core_person_settings');
71         $core_person_settings->setFrom(array(
72             'scope' => $this->scope,
73             'person_id' => $this->person_id
74         ));
75         
76         if($core_person_settings->find(true)) {
77             return $core_person_settings;
78         }
79         
80         return false;
81     }
82     
83  }