From e23b32f79cb4707fa20a80a30c39d8c2d10aeb51 Mon Sep 17 00:00:00 2001 From: Alan Date: Wed, 22 Feb 2023 14:43:24 +0800 Subject: [PATCH] Fix #7590 - use core setting to store if user will send email. --- DataObjects/Core_person.php | 64 +++++++++++++++++++++++++++++++------ 1 file changed, 55 insertions(+), 9 deletions(-) diff --git a/DataObjects/Core_person.php b/DataObjects/Core_person.php index 5d23392f..80187c3c 100644 --- a/DataObjects/Core_person.php +++ b/DataObjects/Core_person.php @@ -767,18 +767,28 @@ class Pman_Core_DataObjects_Core_person extends DB_DataObject $oath_require = $s->lookup('core', 'two_factor_auth_required'); $aur['require_oath'] = $oath_require ? $oath_require->val : 0; - $aur['core_person_settings'] = array(); - - $core_person_settings = DB_DataObject::factory('core_person_settings'); - $core_person_settings->setFrom(array( - 'person_id' => $this->id - )); - - $aur['core_person_settings'] = $core_person_settings->fetchAll('scope', 'data'); + $aur['core_person_settings'] = $this->settings(); return $aur; } + function settings($return_obj = false) + { + $cs = DB_DataObject::factory('core_person_settings'); + $cs->setFrom(array( + 'person_id' => $this->id + )); + return $return_obj ? $cs->fetchAll() : $cs->fetchAll('scope', 'data');; + } + function toRooSingleArray($authUser, $request) + { + $ret = $this->toArray(); + foreach( $this->settings() as $k=>$v) { + $ret['core_person_settings['. $k .']'] = $v; + } + + return $ret; + } // ----------PERMS------ ---------------- function getPerms() { @@ -1494,9 +1504,45 @@ class Pman_Core_DataObjects_Core_person extends DB_DataObject $pd->company_id = $this->company_id; $pd->insert(); } - + if (!empty($req['core_person_settings'])) { + $this->updateSettings($req['core_person_settings'], $roo); + } + } + + function onUpdate($old, $req,$roo, $event) + { + if (!empty($req['core_person_settings'])) { + $this->updateSettings($req['core_person_settings'], $roo); + } + } + + // there should really be a registry of valid scope values!? + function updateSettings($ar, $roo) + { + //DB_DataObject::debugLevel(1); + $old = array(); + foreach($this->settings(true) as $o) { + $old[$o->scope] = $o; + } + foreach($ar as $k=>$v) { + if (isset($old[$k])) { + $oo = clone($old[$k]); + $old[$k]->data = $v; + $old[$k]->update($oo); + continue; + } + $cs = DB_DataObject::Factory('core_person_settings'); + $cs->setFrom(array( + 'person_id' =>$this->id, + 'scope' => $k, + 'data' => $v + )); + $cs->insert(); + } + // we dont delete old stuff.... } + function importFromArray($roo, $persons, $opts) { if (empty($opts['prefix'])) { -- 2.39.2