Merge pull request #17878 from civicrm/5.28
[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 * @param bool $checkPermissions
41 * @return Action\CustomValue\Get
42 * @throws \API_Exception
43 */
44 public static function get($customGroup, $checkPermissions = TRUE) {
45 return (new Action\CustomValue\Get($customGroup, __FUNCTION__))
46 ->setCheckPermissions($checkPermissions);
47 }
48
49 /**
50 * @param string $customGroup
51 * @param bool $checkPermissions
52 * @return Action\CustomValue\GetFields
53 * @throws \API_Exception
54 */
55 public static function getFields($customGroup = NULL, $checkPermissions = TRUE) {
56 return (new Action\CustomValue\GetFields($customGroup, __FUNCTION__))
57 ->setCheckPermissions($checkPermissions);
58 }
59
60 /**
61 * @param string $customGroup
62 * @param bool $checkPermissions
63 * @return Action\CustomValue\Save
64 * @throws \API_Exception
65 */
66 public static function save($customGroup, $checkPermissions = TRUE) {
67 return (new Action\CustomValue\Save($customGroup, __FUNCTION__))
68 ->setCheckPermissions($checkPermissions);
69 }
70
71 /**
72 * @param string $customGroup
73 * @param bool $checkPermissions
74 * @return Action\CustomValue\Create
75 * @throws \API_Exception
76 */
77 public static function create($customGroup, $checkPermissions = TRUE) {
78 return (new Action\CustomValue\Create($customGroup, __FUNCTION__))
79 ->setCheckPermissions($checkPermissions);
80 }
81
82 /**
83 * @param string $customGroup
84 * @param bool $checkPermissions
85 * @return Action\CustomValue\Update
86 * @throws \API_Exception
87 */
88 public static function update($customGroup, $checkPermissions = TRUE) {
89 return (new Action\CustomValue\Update($customGroup, __FUNCTION__))
90 ->setCheckPermissions($checkPermissions);
91 }
92
93 /**
94 * @param string $customGroup
95 * @param bool $checkPermissions
96 * @return Action\CustomValue\Delete
97 * @throws \API_Exception
98 */
99 public static function delete($customGroup, $checkPermissions = TRUE) {
100 return (new Action\CustomValue\Delete($customGroup, __FUNCTION__))
101 ->setCheckPermissions($checkPermissions);
102 }
103
104 /**
105 * @param string $customGroup
106 * @param bool $checkPermissions
107 * @return Action\CustomValue\Replace
108 * @throws \API_Exception
109 */
110 public static function replace($customGroup, $checkPermissions = TRUE) {
111 return (new Action\CustomValue\Replace($customGroup, __FUNCTION__))
112 ->setCheckPermissions($checkPermissions);
113 }
114
115 /**
116 * @param string $customGroup
117 * @param bool $checkPermissions
118 * @return Action\CustomValue\GetActions
119 * @throws \API_Exception
120 */
121 public static function getActions($customGroup = NULL, $checkPermissions = TRUE) {
122 return (new Action\CustomValue\GetActions($customGroup, __FUNCTION__))
123 ->setCheckPermissions($checkPermissions);
124 }
125
126 /**
127 * @inheritDoc
128 */
129 public static function permissions() {
130 $entity = 'contact';
131 $permissions = \CRM_Core_Permission::getEntityActionPermissions();
132
133 // Merge permissions for this entity with the defaults
134 return \CRM_Utils_Array::value($entity, $permissions, []) + $permissions['default'];
135 }
136
137 }