Merge pull request #20698 from colemanw/limit25ForGet
[civicrm-core.git] / Civi / Api4 / CustomValue.php
CommitLineData
19b53e5b 1<?php
380f3545
TO
2/*
3 +--------------------------------------------------------------------+
41498ac5 4 | Copyright CiviCRM LLC. All rights reserved. |
380f3545 5 | |
41498ac5
TO
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 |
380f3545
TO
9 +--------------------------------------------------------------------+
10 */
19b53e5b
C
11namespace Civi\Api4;
12
13/**
f63756b0
CW
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 *
136ca5bb
CW
21 * **Ex. OOP:** `\Civi\Api4\CustomValue::get('MyStuff')->addWhere('id', '=', 123);`
22 * **Non-OOP:** `civicrm_api4('Custom_MyStuff', 'get', ['where' => [['id', '=', 123]]]);`
19b53e5b 23 *
7b7c96e6 24 * Note: This class does NOT extend AbstractEntity so it doesn't get mistaken for a "real" entity.
19b53e5b
C
25 * @package Civi\Api4
26 */
7b7c96e6 27class CustomValue {
19b53e5b
C
28
29 /**
30 * @param string $customGroup
6764a9d3 31 * @param bool $checkPermissions
19b53e5b 32 * @return Action\CustomValue\Get
f63756b0 33 * @throws \API_Exception
19b53e5b 34 */
6764a9d3
CW
35 public static function get($customGroup, $checkPermissions = TRUE) {
36 return (new Action\CustomValue\Get($customGroup, __FUNCTION__))
37 ->setCheckPermissions($checkPermissions);
19b53e5b
C
38 }
39
40 /**
41 * @param string $customGroup
6764a9d3 42 * @param bool $checkPermissions
19b53e5b 43 * @return Action\CustomValue\GetFields
f63756b0 44 * @throws \API_Exception
19b53e5b 45 */
6764a9d3
CW
46 public static function getFields($customGroup = NULL, $checkPermissions = TRUE) {
47 return (new Action\CustomValue\GetFields($customGroup, __FUNCTION__))
48 ->setCheckPermissions($checkPermissions);
19b53e5b
C
49 }
50
51 /**
52 * @param string $customGroup
6764a9d3 53 * @param bool $checkPermissions
19b53e5b 54 * @return Action\CustomValue\Save
f63756b0 55 * @throws \API_Exception
19b53e5b 56 */
6764a9d3
CW
57 public static function save($customGroup, $checkPermissions = TRUE) {
58 return (new Action\CustomValue\Save($customGroup, __FUNCTION__))
59 ->setCheckPermissions($checkPermissions);
19b53e5b
C
60 }
61
62 /**
63 * @param string $customGroup
6764a9d3 64 * @param bool $checkPermissions
19b53e5b 65 * @return Action\CustomValue\Create
f63756b0 66 * @throws \API_Exception
19b53e5b 67 */
6764a9d3
CW
68 public static function create($customGroup, $checkPermissions = TRUE) {
69 return (new Action\CustomValue\Create($customGroup, __FUNCTION__))
70 ->setCheckPermissions($checkPermissions);
19b53e5b
C
71 }
72
73 /**
74 * @param string $customGroup
6764a9d3 75 * @param bool $checkPermissions
19b53e5b 76 * @return Action\CustomValue\Update
f63756b0 77 * @throws \API_Exception
19b53e5b 78 */
6764a9d3
CW
79 public static function update($customGroup, $checkPermissions = TRUE) {
80 return (new Action\CustomValue\Update($customGroup, __FUNCTION__))
81 ->setCheckPermissions($checkPermissions);
19b53e5b
C
82 }
83
84 /**
85 * @param string $customGroup
6764a9d3 86 * @param bool $checkPermissions
19b53e5b 87 * @return Action\CustomValue\Delete
f63756b0 88 * @throws \API_Exception
19b53e5b 89 */
6764a9d3
CW
90 public static function delete($customGroup, $checkPermissions = TRUE) {
91 return (new Action\CustomValue\Delete($customGroup, __FUNCTION__))
92 ->setCheckPermissions($checkPermissions);
19b53e5b
C
93 }
94
95 /**
96 * @param string $customGroup
6764a9d3 97 * @param bool $checkPermissions
a755af64 98 * @return Generic\BasicReplaceAction
f63756b0 99 * @throws \API_Exception
19b53e5b 100 */
6764a9d3 101 public static function replace($customGroup, $checkPermissions = TRUE) {
a755af64 102 return (new Generic\BasicReplaceAction("Custom_$customGroup", __FUNCTION__, ['id', 'entity_id']))
6764a9d3 103 ->setCheckPermissions($checkPermissions);
19b53e5b
C
104 }
105
106 /**
107 * @param string $customGroup
6764a9d3 108 * @param bool $checkPermissions
86fed5d7 109 * @return Action\GetActions
f63756b0 110 * @throws \API_Exception
19b53e5b 111 */
6764a9d3 112 public static function getActions($customGroup = NULL, $checkPermissions = TRUE) {
86fed5d7 113 return (new Action\GetActions("Custom_$customGroup", __FUNCTION__))
6764a9d3 114 ->setCheckPermissions($checkPermissions);
19b53e5b
C
115 }
116
929a9585
CW
117 /**
118 * @return \Civi\Api4\Generic\CheckAccessAction
119 */
120 public static function checkAccess($customGroup) {
121 return new Generic\CheckAccessAction("Custom_$customGroup", __FUNCTION__);
122 }
123
19b53e5b 124 /**
eb378b8a
CW
125 * @see \Civi\Api4\Generic\AbstractEntity::permissions()
126 * @return array
19b53e5b
C
127 */
128 public static function permissions() {
129 $entity = 'contact';
130 $permissions = \CRM_Core_Permission::getEntityActionPermissions();
131
132 // Merge permissions for this entity with the defaults
133 return \CRM_Utils_Array::value($entity, $permissions, []) + $permissions['default'];
134 }
135
eb378b8a
CW
136 /**
137 * @see \Civi\Api4\Generic\AbstractEntity::getInfo()
138 * @return array
139 */
140 public static function getInfo() {
141 return [
142 'class' => __CLASS__,
143 'type' => ['CustomValue'],
aa998597 144 'searchable' => 'secondary',
eb378b8a
CW
145 'see' => [
146 'https://docs.civicrm.org/user/en/latest/organising-your-data/creating-custom-fields/#multiple-record-fieldsets',
147 '\Civi\Api4\CustomGroup',
148 ],
149 ];
150 }
151
19b53e5b 152}