Merge pull request #17203 from artfulrobot/artfulrobot-cleanup-job-improvements
[civicrm-core.git] / Civi / Api4 / Generic / AbstractUpdateAction.php
1 <?php
2
3 /*
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC. All rights reserved. |
6 | |
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 |
10 +--------------------------------------------------------------------+
11 */
12
13 /**
14 *
15 * @package CRM
16 * @copyright CiviCRM LLC https://civicrm.org/licensing
17 */
18
19
20 namespace Civi\Api4\Generic;
21
22 /**
23 * Base class for all `Update` api actions
24 *
25 * @method $this setValues(array $values) Set all field values from an array of key => value pairs.
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 /**
43 * Reload $ENTITIES after saving.
44 *
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.
47 *
48 * @var bool
49 */
50 protected $reload = FALSE;
51
52 /**
53 * @param string $fieldName
54 *
55 * @return mixed|null
56 */
57 public function getValue(string $fieldName) {
58 return $this->values[$fieldName] ?? NULL;
59 }
60
61 /**
62 * Add an item to the values array.
63 *
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;
71 }
72
73 }