Commit | Line | Data |
---|---|---|
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 |
21 | namespace Civi\Api4\Action\Setting; |
22 | ||
23 | use Civi\Api4\Generic\Result; | |
24 | ||
25 | /** | |
26 | * Set the value of one or more CiviCRM settings. | |
27 | * | |
28 | * @method array getValues | |
29 | * @method $this setValues(array $value) | |
19b53e5b C |
30 | */ |
31 | class Set extends AbstractSettingAction { | |
32 | ||
33 | /** | |
34 | * Setting names/values to set. | |
35 | * | |
36 | * @var mixed | |
37 | * @required | |
38 | */ | |
39 | protected $values = []; | |
40 | ||
41 | /** | |
42 | * @param \Civi\Api4\Generic\Result $result | |
43 | * @param \Civi\Core\SettingsBag $settingsBag | |
44 | * @param array $meta | |
45 | * @param int $domain | |
46 | * @throws \Exception | |
47 | */ | |
48 | protected function processSettings(Result $result, $settingsBag, $meta, $domain) { | |
49 | foreach ($this->values as $name => $value) { | |
50 | if (isset($value) && !empty($meta[$name]['serialize'])) { | |
51 | $value = \CRM_Core_DAO::serializeField($value, $meta[$name]['serialize']); | |
52 | } | |
53 | $settingsBag->set($name, $value); | |
54 | $result[] = [ | |
55 | 'name' => $name, | |
56 | 'value' => $this->values[$name], | |
57 | 'domain_id' => $domain, | |
58 | ]; | |
59 | } | |
60 | } | |
61 | ||
121ec912 CW |
62 | /** |
63 | * Add an item to the values array | |
64 | * @param string $settingName | |
65 | * @param mixed $value | |
66 | * @return $this | |
67 | */ | |
68 | public function addValue($settingName, $value) { | |
69 | $this->values[$settingName] = $value; | |
70 | return $this; | |
71 | } | |
72 | ||
19b53e5b | 73 | } |