Merge pull request #19095 from nishant-bhorodia/Issue#537-owner-notification-email...
[civicrm-core.git] / Civi / Api4 / Action / Setting / Get.php
CommitLineData
19b53e5b 1<?php
380f3545
TO
2
3/*
4 +--------------------------------------------------------------------+
41498ac5 5 | Copyright CiviCRM LLC. All rights reserved. |
380f3545 6 | |
41498ac5
TO
7 | This work is published under the GNU AGPLv3 license with some |
8 | permitted exceptions and without any warranty. For full license |
9 | and copyright information, see https://civicrm.org/licensing |
380f3545
TO
10 +--------------------------------------------------------------------+
11 */
12
19b53e5b
C
13namespace Civi\Api4\Action\Setting;
14
15use Civi\Api4\Generic\Result;
16
17/**
18 * Get the value of one or more CiviCRM settings.
19 *
20 * @method array getSelect
121ec912 21 * @method $this setSelect(array $settingNames)
19b53e5b
C
22 */
23class Get extends AbstractSettingAction {
24
25 /**
26 * Names of settings to retrieve
27 *
28 * @var array
29 */
30 protected $select = [];
31
32 /**
33 * @param \Civi\Api4\Generic\Result $result
34 * @param \Civi\Core\SettingsBag $settingsBag
35 * @param array $meta
36 * @param int $domain
37 * @throws \Exception
38 */
39 protected function processSettings(Result $result, $settingsBag, $meta, $domain) {
40 if ($this->select) {
41 foreach ($this->select as $name) {
42 $result[] = [
43 'name' => $name,
44 'value' => $settingsBag->get($name),
45 'domain_id' => $domain,
46 ];
47 }
48 }
49 else {
50 foreach ($settingsBag->all() as $name => $value) {
51 $result[] = [
52 'name' => $name,
53 'value' => $value,
54 'domain_id' => $domain,
55 ];
56 }
57 }
58 foreach ($result as $name => &$setting) {
59 if (isset($setting['value']) && !empty($meta[$name]['serialize'])) {
60 $setting['value'] = \CRM_Core_DAO::unSerializeField($setting['value'], $meta[$name]['serialize']);
61 }
62 }
63 }
64
121ec912
CW
65 /**
66 * Add one or more settings to be selected
67 * @param string ...$settingNames
68 * @return $this
69 */
70 public function addSelect(string ...$settingNames) {
71 $this->select = array_merge($this->select, $settingNames);
72 return $this;
73 }
74
19b53e5b 75}