Merge pull request #19566 from eileenmcnaughton/mem_recur
[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
19
19b53e5b
C
20namespace Civi\Api4;
21
22/**
f63756b0
CW
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 *
136ca5bb
CW
30 * **Ex. OOP:** `\Civi\Api4\CustomValue::get('MyStuff')->addWhere('id', '=', 123);`
31 * **Non-OOP:** `civicrm_api4('Custom_MyStuff', 'get', ['where' => [['id', '=', 123]]]);`
19b53e5b 32 *
7b7c96e6 33 * Note: This class does NOT extend AbstractEntity so it doesn't get mistaken for a "real" entity.
19b53e5b
C
34 * @package Civi\Api4
35 */
7b7c96e6 36class CustomValue {
19b53e5b
C
37
38 /**
39 * @param string $customGroup
6764a9d3 40 * @param bool $checkPermissions
19b53e5b 41 * @return Action\CustomValue\Get
f63756b0 42 * @throws \API_Exception
19b53e5b 43 */
6764a9d3
CW
44 public static function get($customGroup, $checkPermissions = TRUE) {
45 return (new Action\CustomValue\Get($customGroup, __FUNCTION__))
46 ->setCheckPermissions($checkPermissions);
19b53e5b
C
47 }
48
49 /**
50 * @param string $customGroup
6764a9d3 51 * @param bool $checkPermissions
19b53e5b 52 * @return Action\CustomValue\GetFields
f63756b0 53 * @throws \API_Exception
19b53e5b 54 */
6764a9d3
CW
55 public static function getFields($customGroup = NULL, $checkPermissions = TRUE) {
56 return (new Action\CustomValue\GetFields($customGroup, __FUNCTION__))
57 ->setCheckPermissions($checkPermissions);
19b53e5b
C
58 }
59
60 /**
61 * @param string $customGroup
6764a9d3 62 * @param bool $checkPermissions
19b53e5b 63 * @return Action\CustomValue\Save
f63756b0 64 * @throws \API_Exception
19b53e5b 65 */
6764a9d3
CW
66 public static function save($customGroup, $checkPermissions = TRUE) {
67 return (new Action\CustomValue\Save($customGroup, __FUNCTION__))
68 ->setCheckPermissions($checkPermissions);
19b53e5b
C
69 }
70
71 /**
72 * @param string $customGroup
6764a9d3 73 * @param bool $checkPermissions
19b53e5b 74 * @return Action\CustomValue\Create
f63756b0 75 * @throws \API_Exception
19b53e5b 76 */
6764a9d3
CW
77 public static function create($customGroup, $checkPermissions = TRUE) {
78 return (new Action\CustomValue\Create($customGroup, __FUNCTION__))
79 ->setCheckPermissions($checkPermissions);
19b53e5b
C
80 }
81
82 /**
83 * @param string $customGroup
6764a9d3 84 * @param bool $checkPermissions
19b53e5b 85 * @return Action\CustomValue\Update
f63756b0 86 * @throws \API_Exception
19b53e5b 87 */
6764a9d3
CW
88 public static function update($customGroup, $checkPermissions = TRUE) {
89 return (new Action\CustomValue\Update($customGroup, __FUNCTION__))
90 ->setCheckPermissions($checkPermissions);
19b53e5b
C
91 }
92
93 /**
94 * @param string $customGroup
6764a9d3 95 * @param bool $checkPermissions
19b53e5b 96 * @return Action\CustomValue\Delete
f63756b0 97 * @throws \API_Exception
19b53e5b 98 */
6764a9d3
CW
99 public static function delete($customGroup, $checkPermissions = TRUE) {
100 return (new Action\CustomValue\Delete($customGroup, __FUNCTION__))
101 ->setCheckPermissions($checkPermissions);
19b53e5b
C
102 }
103
104 /**
105 * @param string $customGroup
6764a9d3 106 * @param bool $checkPermissions
19b53e5b 107 * @return Action\CustomValue\Replace
f63756b0 108 * @throws \API_Exception
19b53e5b 109 */
6764a9d3
CW
110 public static function replace($customGroup, $checkPermissions = TRUE) {
111 return (new Action\CustomValue\Replace($customGroup, __FUNCTION__))
112 ->setCheckPermissions($checkPermissions);
19b53e5b
C
113 }
114
115 /**
116 * @param string $customGroup
6764a9d3 117 * @param bool $checkPermissions
19b53e5b 118 * @return Action\CustomValue\GetActions
f63756b0 119 * @throws \API_Exception
19b53e5b 120 */
6764a9d3
CW
121 public static function getActions($customGroup = NULL, $checkPermissions = TRUE) {
122 return (new Action\CustomValue\GetActions($customGroup, __FUNCTION__))
123 ->setCheckPermissions($checkPermissions);
19b53e5b
C
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}