Merge pull request #19550 from eileenmcnaughton/msg_tpl_convert
[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 namespace Civi\Api4;
20
21 /**
22 * Provides virtual api entities for every multi-record custom group.
23 *
24 * This class is different from other apis in that it is not itself an entity, but allows every
25 * multi-record custom group to act like an entity.
26 *
27 * Each action takes the name of the custom group as a parameter, or in traditional syntax the entity is prefixed with 'Custom_'
28 *
29 * **Ex. OOP:** `\Civi\Api4\CustomValue::get('MyStuff')->addWhere('id', '=', 123);`
30 * **Non-OOP:** `civicrm_api4('Custom_MyStuff', 'get', ['where' => [['id', '=', 123]]]);`
31 *
32 * Note: This class does NOT extend AbstractEntity so it doesn't get mistaken for a "real" entity.
33 * @package Civi\Api4
34 */
35 class CustomValue {
36
37 /**
38 * @param string $customGroup
39 * @param bool $checkPermissions
40 * @return Action\CustomValue\Get
41 * @throws \API_Exception
42 */
43 public static function get($customGroup, $checkPermissions = TRUE) {
44 return (new Action\CustomValue\Get($customGroup, __FUNCTION__))
45 ->setCheckPermissions($checkPermissions);
46 }
47
48 /**
49 * @param string $customGroup
50 * @param bool $checkPermissions
51 * @return Action\CustomValue\GetFields
52 * @throws \API_Exception
53 */
54 public static function getFields($customGroup = NULL, $checkPermissions = TRUE) {
55 return (new Action\CustomValue\GetFields($customGroup, __FUNCTION__))
56 ->setCheckPermissions($checkPermissions);
57 }
58
59 /**
60 * @param string $customGroup
61 * @param bool $checkPermissions
62 * @return Action\CustomValue\Save
63 * @throws \API_Exception
64 */
65 public static function save($customGroup, $checkPermissions = TRUE) {
66 return (new Action\CustomValue\Save($customGroup, __FUNCTION__))
67 ->setCheckPermissions($checkPermissions);
68 }
69
70 /**
71 * @param string $customGroup
72 * @param bool $checkPermissions
73 * @return Action\CustomValue\Create
74 * @throws \API_Exception
75 */
76 public static function create($customGroup, $checkPermissions = TRUE) {
77 return (new Action\CustomValue\Create($customGroup, __FUNCTION__))
78 ->setCheckPermissions($checkPermissions);
79 }
80
81 /**
82 * @param string $customGroup
83 * @param bool $checkPermissions
84 * @return Action\CustomValue\Update
85 * @throws \API_Exception
86 */
87 public static function update($customGroup, $checkPermissions = TRUE) {
88 return (new Action\CustomValue\Update($customGroup, __FUNCTION__))
89 ->setCheckPermissions($checkPermissions);
90 }
91
92 /**
93 * @param string $customGroup
94 * @param bool $checkPermissions
95 * @return Action\CustomValue\Delete
96 * @throws \API_Exception
97 */
98 public static function delete($customGroup, $checkPermissions = TRUE) {
99 return (new Action\CustomValue\Delete($customGroup, __FUNCTION__))
100 ->setCheckPermissions($checkPermissions);
101 }
102
103 /**
104 * @param string $customGroup
105 * @param bool $checkPermissions
106 * @return Action\CustomValue\Replace
107 * @throws \API_Exception
108 */
109 public static function replace($customGroup, $checkPermissions = TRUE) {
110 return (new Action\CustomValue\Replace($customGroup, __FUNCTION__))
111 ->setCheckPermissions($checkPermissions);
112 }
113
114 /**
115 * @param string $customGroup
116 * @param bool $checkPermissions
117 * @return Action\CustomValue\GetActions
118 * @throws \API_Exception
119 */
120 public static function getActions($customGroup = NULL, $checkPermissions = TRUE) {
121 return (new Action\CustomValue\GetActions($customGroup, __FUNCTION__))
122 ->setCheckPermissions($checkPermissions);
123 }
124
125 /**
126 * @see \Civi\Api4\Generic\AbstractEntity::permissions()
127 * @return array
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 /**
138 * @see \Civi\Api4\Generic\AbstractEntity::getInfo()
139 * @return array
140 */
141 public static function getInfo() {
142 return [
143 'class' => __CLASS__,
144 'type' => ['CustomValue'],
145 'searchable' => TRUE,
146 'see' => [
147 'https://docs.civicrm.org/user/en/latest/organising-your-data/creating-custom-fields/#multiple-record-fieldsets',
148 '\Civi\Api4\CustomGroup',
149 ],
150 ];
151 }
152
153 }