Add BAO function and hook for checkAccess
[civicrm-core.git] / Civi / Api4 / CustomValue.php
CommitLineData
19b53e5b
C
1<?php
2
380f3545
TO
3/*
4 +--------------------------------------------------------------------+
41498ac5 5 | Copyright CiviCRM LLC. All rights reserved. |
380f3545 6 | |
41498ac5
TO
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 |
380f3545
TO
10 +--------------------------------------------------------------------+
11 */
12
13/**
14 *
15 * @package CRM
ca5cec67 16 * @copyright CiviCRM LLC https://civicrm.org/licensing
380f3545
TO
17 */
18
19b53e5b
C
19namespace Civi\Api4;
20
21/**
f63756b0
CW
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 *
136ca5bb
CW
29 * **Ex. OOP:** `\Civi\Api4\CustomValue::get('MyStuff')->addWhere('id', '=', 123);`
30 * **Non-OOP:** `civicrm_api4('Custom_MyStuff', 'get', ['where' => [['id', '=', 123]]]);`
19b53e5b 31 *
7b7c96e6 32 * Note: This class does NOT extend AbstractEntity so it doesn't get mistaken for a "real" entity.
19b53e5b
C
33 * @package Civi\Api4
34 */
7b7c96e6 35class CustomValue {
19b53e5b
C
36
37 /**
38 * @param string $customGroup
6764a9d3 39 * @param bool $checkPermissions
19b53e5b 40 * @return Action\CustomValue\Get
f63756b0 41 * @throws \API_Exception
19b53e5b 42 */
6764a9d3
CW
43 public static function get($customGroup, $checkPermissions = TRUE) {
44 return (new Action\CustomValue\Get($customGroup, __FUNCTION__))
45 ->setCheckPermissions($checkPermissions);
19b53e5b
C
46 }
47
48 /**
49 * @param string $customGroup
6764a9d3 50 * @param bool $checkPermissions
19b53e5b 51 * @return Action\CustomValue\GetFields
f63756b0 52 * @throws \API_Exception
19b53e5b 53 */
6764a9d3
CW
54 public static function getFields($customGroup = NULL, $checkPermissions = TRUE) {
55 return (new Action\CustomValue\GetFields($customGroup, __FUNCTION__))
56 ->setCheckPermissions($checkPermissions);
19b53e5b
C
57 }
58
59 /**
60 * @param string $customGroup
6764a9d3 61 * @param bool $checkPermissions
19b53e5b 62 * @return Action\CustomValue\Save
f63756b0 63 * @throws \API_Exception
19b53e5b 64 */
6764a9d3
CW
65 public static function save($customGroup, $checkPermissions = TRUE) {
66 return (new Action\CustomValue\Save($customGroup, __FUNCTION__))
67 ->setCheckPermissions($checkPermissions);
19b53e5b
C
68 }
69
70 /**
71 * @param string $customGroup
6764a9d3 72 * @param bool $checkPermissions
19b53e5b 73 * @return Action\CustomValue\Create
f63756b0 74 * @throws \API_Exception
19b53e5b 75 */
6764a9d3
CW
76 public static function create($customGroup, $checkPermissions = TRUE) {
77 return (new Action\CustomValue\Create($customGroup, __FUNCTION__))
78 ->setCheckPermissions($checkPermissions);
19b53e5b
C
79 }
80
81 /**
82 * @param string $customGroup
6764a9d3 83 * @param bool $checkPermissions
19b53e5b 84 * @return Action\CustomValue\Update
f63756b0 85 * @throws \API_Exception
19b53e5b 86 */
6764a9d3
CW
87 public static function update($customGroup, $checkPermissions = TRUE) {
88 return (new Action\CustomValue\Update($customGroup, __FUNCTION__))
89 ->setCheckPermissions($checkPermissions);
19b53e5b
C
90 }
91
92 /**
93 * @param string $customGroup
6764a9d3 94 * @param bool $checkPermissions
19b53e5b 95 * @return Action\CustomValue\Delete
f63756b0 96 * @throws \API_Exception
19b53e5b 97 */
6764a9d3
CW
98 public static function delete($customGroup, $checkPermissions = TRUE) {
99 return (new Action\CustomValue\Delete($customGroup, __FUNCTION__))
100 ->setCheckPermissions($checkPermissions);
19b53e5b
C
101 }
102
103 /**
104 * @param string $customGroup
6764a9d3 105 * @param bool $checkPermissions
a755af64 106 * @return Generic\BasicReplaceAction
f63756b0 107 * @throws \API_Exception
19b53e5b 108 */
6764a9d3 109 public static function replace($customGroup, $checkPermissions = TRUE) {
a755af64 110 return (new Generic\BasicReplaceAction("Custom_$customGroup", __FUNCTION__, ['id', 'entity_id']))
6764a9d3 111 ->setCheckPermissions($checkPermissions);
19b53e5b
C
112 }
113
114 /**
115 * @param string $customGroup
6764a9d3 116 * @param bool $checkPermissions
86fed5d7 117 * @return Action\GetActions
f63756b0 118 * @throws \API_Exception
19b53e5b 119 */
6764a9d3 120 public static function getActions($customGroup = NULL, $checkPermissions = TRUE) {
86fed5d7 121 return (new Action\GetActions("Custom_$customGroup", __FUNCTION__))
6764a9d3 122 ->setCheckPermissions($checkPermissions);
19b53e5b
C
123 }
124
125 /**
eb378b8a
CW
126 * @see \Civi\Api4\Generic\AbstractEntity::permissions()
127 * @return array
19b53e5b
C
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
eb378b8a
CW
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'],
aa998597 145 'searchable' => 'secondary',
eb378b8a
CW
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
19b53e5b 153}