Merge pull request #16005 from magnolia61/Contribution_Invoice_Privacy
[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
13/**
14 *
15 * @package CRM
ca5cec67 16 * @copyright CiviCRM LLC https://civicrm.org/licensing
380f3545
TO
17 * $Id$
18 *
19 */
20
19b53e5b
C
21namespace Civi\Api4\Action\Setting;
22
23use Civi\Api4\Generic\Result;
24
25/**
26 * Get the value of one or more CiviCRM settings.
27 *
28 * @method array getSelect
121ec912 29 * @method $this setSelect(array $settingNames)
19b53e5b
C
30 */
31class Get extends AbstractSettingAction {
32
33 /**
34 * Names of settings to retrieve
35 *
36 * @var array
37 */
38 protected $select = [];
39
40 /**
41 * @param \Civi\Api4\Generic\Result $result
42 * @param \Civi\Core\SettingsBag $settingsBag
43 * @param array $meta
44 * @param int $domain
45 * @throws \Exception
46 */
47 protected function processSettings(Result $result, $settingsBag, $meta, $domain) {
48 if ($this->select) {
49 foreach ($this->select as $name) {
50 $result[] = [
51 'name' => $name,
52 'value' => $settingsBag->get($name),
53 'domain_id' => $domain,
54 ];
55 }
56 }
57 else {
58 foreach ($settingsBag->all() as $name => $value) {
59 $result[] = [
60 'name' => $name,
61 'value' => $value,
62 'domain_id' => $domain,
63 ];
64 }
65 }
66 foreach ($result as $name => &$setting) {
67 if (isset($setting['value']) && !empty($meta[$name]['serialize'])) {
68 $setting['value'] = \CRM_Core_DAO::unSerializeField($setting['value'], $meta[$name]['serialize']);
69 }
70 }
71 }
72
121ec912
CW
73 /**
74 * Add one or more settings to be selected
75 * @param string ...$settingNames
76 * @return $this
77 */
78 public function addSelect(string ...$settingNames) {
79 $this->select = array_merge($this->select, $settingNames);
80 return $this;
81 }
82
19b53e5b 83}