Merge pull request #16390 from artfulrobot/tame-propbag-deprecation-logs
[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 * $Id$
18 *
19 */
20
21
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.
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 /**
55 * @param string $fieldName
56 *
57 * @return mixed|null
58 */
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;
72 }
73
74 }