Commit | Line | Data |
---|---|---|
19b53e5b C |
1 | <?php |
2 | ||
380f3545 TO |
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 | */ |
18 | ||
19 | ||
19b53e5b C |
20 | namespace Civi\Api4\Generic; |
21 | ||
22 | /** | |
fc95d9a5 | 23 | * Base class for all `Update` api actions |
19b53e5b C |
24 | * |
25 | * @method $this setValues(array $values) Set all field values from an array of key => value pairs. | |
19b53e5b C |
26 | * @method array getValues() Get field values. |
27 | * @method $this setReload(bool $reload) Specify whether complete objects will be returned after saving. | |
28 | * @method bool getReload() | |
29 | * | |
30 | * @package Civi\Api4\Generic | |
31 | */ | |
32 | abstract class AbstractUpdateAction extends AbstractBatchAction { | |
33 | ||
34 | /** | |
35 | * Field values to update. | |
36 | * | |
37 | * @var array | |
38 | * @required | |
39 | */ | |
40 | protected $values = []; | |
41 | ||
42 | /** | |
e3c6d5ff | 43 | * Reload $ENTITIES after saving. |
19b53e5b | 44 | * |
fc95d9a5 CW |
45 | * Setting to `true` will load complete records and return them as the api result. |
46 | * If `false` the api usually returns only the fields specified to be updated. | |
19b53e5b C |
47 | * |
48 | * @var bool | |
49 | */ | |
50 | protected $reload = FALSE; | |
51 | ||
52 | /** | |
121ec912 | 53 | * @param string $fieldName |
19b53e5b C |
54 | * |
55 | * @return mixed|null | |
56 | */ | |
121ec912 | 57 | public function getValue(string $fieldName) { |
2e1f50d6 | 58 | return $this->values[$fieldName] ?? NULL; |
121ec912 CW |
59 | } |
60 | ||
61 | /** | |
fc95d9a5 CW |
62 | * Add an item to the values array. |
63 | * | |
121ec912 CW |
64 | * @param string $fieldName |
65 | * @param mixed $value | |
66 | * @return $this | |
67 | */ | |
68 | public function addValue(string $fieldName, $value) { | |
69 | $this->values[$fieldName] = $value; | |
70 | return $this; | |
19b53e5b C |
71 | } |
72 | ||
73 | } |