Merge pull request #17815 from spalmstr/dev/core#1812
[civicrm-core.git] / Civi / Api4 / CustomValue.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;
21
22 /**
23 * Provides virtual api entities for every multi-record custom group.
24 *
25 * This class is different from other apis in that it is not itself an entity, but allows every
26 * multi-record custom group to act like an entity.
27 *
28 * Each action takes the name of the custom group as a parameter, or in traditional syntax the entity is prefixed with 'Custom_'
29 *
30 * **Ex. OOP:** `\Civi\Api4\CustomValue::get('MyStuff')->addWhere('id', '=', 123);`
31 * **Non-OOP:** `civicrm_api4('Custom_MyStuff', 'get', ['where' => [['id', '=', 123]]]);`
32 *
33 * Note: This class does NOT extend AbstractEntity so it doesn't get mistaken for a "real" entity.
34 * @package Civi\Api4
35 */
36 class CustomValue {
37
38 /**
39 * @param string $customGroup
40 * @return Action\CustomValue\Get
41 * @throws \API_Exception
42 */
43 public static function get($customGroup) {
44 return new Action\CustomValue\Get($customGroup, __FUNCTION__);
45 }
46
47 /**
48 * @param string $customGroup
49 * @return Action\CustomValue\GetFields
50 * @throws \API_Exception
51 */
52 public static function getFields($customGroup = NULL) {
53 return new Action\CustomValue\GetFields($customGroup, __FUNCTION__);
54 }
55
56 /**
57 * @param string $customGroup
58 * @return Action\CustomValue\Save
59 * @throws \API_Exception
60 */
61 public static function save($customGroup) {
62 return new Action\CustomValue\Save($customGroup, __FUNCTION__);
63 }
64
65 /**
66 * @param string $customGroup
67 * @return Action\CustomValue\Create
68 * @throws \API_Exception
69 */
70 public static function create($customGroup) {
71 return new Action\CustomValue\Create($customGroup, __FUNCTION__);
72 }
73
74 /**
75 * @param string $customGroup
76 * @return Action\CustomValue\Update
77 * @throws \API_Exception
78 */
79 public static function update($customGroup) {
80 return new Action\CustomValue\Update($customGroup, __FUNCTION__);
81 }
82
83 /**
84 * @param string $customGroup
85 * @return Action\CustomValue\Delete
86 * @throws \API_Exception
87 */
88 public static function delete($customGroup) {
89 return new Action\CustomValue\Delete($customGroup, __FUNCTION__);
90 }
91
92 /**
93 * @param string $customGroup
94 * @return Action\CustomValue\Replace
95 * @throws \API_Exception
96 */
97 public static function replace($customGroup) {
98 return new Action\CustomValue\Replace($customGroup, __FUNCTION__);
99 }
100
101 /**
102 * @param string $customGroup
103 * @return Action\CustomValue\GetActions
104 * @throws \API_Exception
105 */
106 public static function getActions($customGroup = NULL) {
107 return new Action\CustomValue\GetActions($customGroup, __FUNCTION__);
108 }
109
110 /**
111 * @inheritDoc
112 */
113 public static function permissions() {
114 $entity = 'contact';
115 $permissions = \CRM_Core_Permission::getEntityActionPermissions();
116
117 // Merge permissions for this entity with the defaults
118 return \CRM_Utils_Array::value($entity, $permissions, []) + $permissions['default'];
119 }
120
121 }