Merge pull request #23119 from eileenmcnaughton/silly6
[civicrm-core.git] / Civi / Api4 / CustomValue.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11 namespace Civi\Api4;
12
13 /**
14 * Provides virtual api entities for every multi-record custom group.
15 *
16 * This class is different from other apis in that it is not itself an entity, but allows every
17 * multi-record custom group to act like an entity.
18 *
19 * Each action takes the name of the custom group as a parameter, or in traditional syntax the entity is prefixed with 'Custom_'
20 *
21 * **Ex. OOP:** `\Civi\Api4\CustomValue::get('MyStuff')->addWhere('id', '=', 123);`
22 * **Non-OOP:** `civicrm_api4('Custom_MyStuff', 'get', ['where' => [['id', '=', 123]]]);`
23 *
24 * Note: This class does NOT extend AbstractEntity so it doesn't get mistaken for a "real" entity.
25 * @package Civi\Api4
26 */
27 class CustomValue {
28
29 /**
30 * @param string $customGroup
31 * @param bool $checkPermissions
32 * @return Action\CustomValue\Get
33 * @throws \API_Exception
34 */
35 public static function get($customGroup, $checkPermissions = TRUE) {
36 return (new Action\CustomValue\Get($customGroup, __FUNCTION__))
37 ->setCheckPermissions($checkPermissions);
38 }
39
40 /**
41 * @param string $customGroup
42 * @param bool $checkPermissions
43 * @return Action\CustomValue\GetFields
44 * @throws \API_Exception
45 */
46 public static function getFields($customGroup = NULL, $checkPermissions = TRUE) {
47 return (new Action\CustomValue\GetFields($customGroup, __FUNCTION__))
48 ->setCheckPermissions($checkPermissions);
49 }
50
51 /**
52 * @param string $customGroup
53 * @param bool $checkPermissions
54 * @return Action\CustomValue\Save
55 * @throws \API_Exception
56 */
57 public static function save($customGroup, $checkPermissions = TRUE) {
58 return (new Action\CustomValue\Save($customGroup, __FUNCTION__))
59 ->setCheckPermissions($checkPermissions);
60 }
61
62 /**
63 * @param string $customGroup
64 * @param bool $checkPermissions
65 * @return Action\CustomValue\Create
66 * @throws \API_Exception
67 */
68 public static function create($customGroup, $checkPermissions = TRUE) {
69 return (new Action\CustomValue\Create($customGroup, __FUNCTION__))
70 ->setCheckPermissions($checkPermissions);
71 }
72
73 /**
74 * @param string $customGroup
75 * @param bool $checkPermissions
76 * @return Action\CustomValue\Update
77 * @throws \API_Exception
78 */
79 public static function update($customGroup, $checkPermissions = TRUE) {
80 return (new Action\CustomValue\Update($customGroup, __FUNCTION__))
81 ->setCheckPermissions($checkPermissions);
82 }
83
84 /**
85 * @param string $customGroup
86 * @param bool $checkPermissions
87 * @return Action\CustomValue\Delete
88 * @throws \API_Exception
89 */
90 public static function delete($customGroup, $checkPermissions = TRUE) {
91 return (new Action\CustomValue\Delete($customGroup, __FUNCTION__))
92 ->setCheckPermissions($checkPermissions);
93 }
94
95 /**
96 * @param string $customGroup
97 * @param bool $checkPermissions
98 * @return Generic\BasicReplaceAction
99 * @throws \API_Exception
100 */
101 public static function replace($customGroup, $checkPermissions = TRUE) {
102 return (new Generic\BasicReplaceAction("Custom_$customGroup", __FUNCTION__))
103 ->setCheckPermissions($checkPermissions);
104 }
105
106 /**
107 * @param string $customGroup
108 * @param bool $checkPermissions
109 * @return Action\GetActions
110 * @throws \API_Exception
111 */
112 public static function getActions($customGroup = NULL, $checkPermissions = TRUE) {
113 return (new Action\GetActions("Custom_$customGroup", __FUNCTION__))
114 ->setCheckPermissions($checkPermissions);
115 }
116
117 /**
118 * @return \Civi\Api4\Generic\CheckAccessAction
119 */
120 public static function checkAccess($customGroup) {
121 return new Generic\CheckAccessAction("Custom_$customGroup", __FUNCTION__);
122 }
123
124 /**
125 * @see \Civi\Api4\Generic\AbstractEntity::permissions()
126 * @return array
127 */
128 public static function permissions() {
129 // Permissions are managed by ACLs
130 return [
131 'create' => [],
132 'update' => [],
133 'delete' => [],
134 'get' => [],
135 ];
136 }
137
138 /**
139 * @see \Civi\Api4\Generic\AbstractEntity::getInfo()
140 * @return array
141 */
142 public static function getInfo() {
143 return [
144 'class' => __CLASS__,
145 'type' => ['CustomValue'],
146 'searchable' => 'secondary',
147 'primary_key' => ['id'],
148 'see' => [
149 'https://docs.civicrm.org/user/en/latest/organising-your-data/creating-custom-fields/#multiple-record-fieldsets',
150 '\Civi\Api4\CustomGroup',
151 ],
152 ];
153 }
154
155 }