X-Git-Url: http://git.roojs.org/?p=Pman.Core;a=blobdiff_plain;f=DataObjects%2FCore_person_settings.php;h=be3035e4c53c448d1d26c4e56d5f0f4b59bebe3d;hp=0dd1ac7ebcc027487266fa4a7dd166d2b0e66ffe;hb=HEAD;hpb=ee1b0a9d018f5fa6cc582773ead32ff4c24a3ce9 diff --git a/DataObjects/Core_person_settings.php b/DataObjects/Core_person_settings.php index 0dd1ac7e..be3035e4 100644 --- a/DataObjects/Core_person_settings.php +++ b/DataObjects/Core_person_settings.php @@ -20,23 +20,62 @@ class Pman_Core_DataObjects_Core_person_settings extends DB_DataObject function beforeInsert($q, $roo) { - if( - !$roo->authUser || - (!empty($this->person_id) && $this->person_id != $roo->authUser->id) - ) { + if(!$this->hasPermission($roo)) { $roo->jerr('Access Dennied'); } + $o = $this->isExist(); + + if(!empty($o)) { + $oo = clone ($o); + $o->setFrom(array( + 'data' => $this->data + )); + $o->update($oo); + $roo->jok('OK'); + } + } function beforeUpdate($old, $q, $roo) + { + if(!$this->hasPermission($roo)) { + $roo->jerr('Access Dennied'); + } + } + + function beforeDelete($dependants_array, $roo) + { + if(!$this->hasPermission($roo)) { + $roo->jerr('Access Dennied'); + } + } + + function hasPermission($roo) { if( !$roo->authUser || (!empty($this->person_id) && $this->person_id != $roo->authUser->id) ) { - $roo->jerr('Access Dennied'); + return false; + } + + return true; + } + + function isExist() + { + $core_person_settings = DB_DataObject::factory('core_person_settings'); + $core_person_settings->setFrom(array( + 'scope' => $this->scope, + 'person_id' => $this->person_id + )); + + if($core_person_settings->find(true)) { + return $core_person_settings; } + + return false; } }