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