From 23d6731bb85e78734b0a8671067ac08a2e8e01c9 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Thu, 6 Jul 2017 17:11:58 -0700 Subject: [PATCH] CRM-20816 - XMLProcessor - Consolidate implementation of setting-lookup --- CRM/Case/XMLProcessor/Process.php | 35 +++++++++++++++---------------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/CRM/Case/XMLProcessor/Process.php b/CRM/Case/XMLProcessor/Process.php index b230cdd928..541b7a486b 100644 --- a/CRM/Case/XMLProcessor/Process.php +++ b/CRM/Case/XMLProcessor/Process.php @@ -634,12 +634,7 @@ AND a.is_deleted = 0 * @return int */ public function getRedactActivityEmail() { - $setting = Civi::settings()->get('civicaseRedactActivityEmail'); - if ($setting !== 'default') { - return (int) $setting; - } - $xml = $this->retrieve("Settings"); - return ( string ) $xml->RedactActivityEmail ? 1 : 0; + return $this->getBoolSetting('civicaseRedactActivityEmail', 'RedactActivityEmail'); } /** @@ -649,15 +644,7 @@ AND a.is_deleted = 0 * 1 if allowed, 0 if not */ public function getAllowMultipleCaseClients() { - $setting = Civi::settings()->get('civicaseAllowMultipleCaseClients'); - if ($setting !== 'default') { - return (int) $setting; - } - $xml = $this->retrieve("Settings"); - if ($xml) { - return ( string ) $xml->AllowMultipleCaseClients ? 1 : 0; - } - return 0; + return $this->getBoolSetting('civicaseAllowMultipleCaseClients', 'AllowMultipleCaseClients'); } /** @@ -667,12 +654,24 @@ AND a.is_deleted = 0 * 1 if natural, 0 if alphabetic */ public function getNaturalActivityTypeSort() { - $setting = Civi::settings()->get('civicaseNaturalActivityTypeSort'); + return $this->getBoolSetting('civicaseNaturalActivityTypeSort', 'NaturalActivityTypeSort'); + } + + /** + * @param string $settingKey + * @param string $xmlTag + * @param mixed $default + * @return int + */ + private function getBoolSetting($settingKey, $xmlTag, $default = 0) { + $setting = Civi::settings()->get($settingKey); if ($setting !== 'default') { return (int) $setting; } - $xml = $this->retrieve("Settings"); - return ( string ) $xml->NaturalActivityTypeSort ? 1 : 0; + if ($xml = $this->retrieve("Settings")) { + return (string) $xml->{$xmlTag} ? 1 : 0; + } + return $default; } } -- 2.25.1