Use markdown in php docblocks & display in APIv4 Explorer
[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 * $Id$
18 *
19 */
20
21
19b53e5b
C
22namespace Civi\Api4;
23
24/**
f63756b0
CW
25 * Provides virtual api entities for every multi-record custom group.
26 *
27 * This class is different from other apis in that it is not itself an entity, but allows every
28 * multi-record custom group to act like an entity.
29 *
30 * Each action takes the name of the custom group as a parameter, or in traditional syntax the entity is prefixed with 'Custom_'
31 *
136ca5bb
CW
32 * **Ex. OOP:** `\Civi\Api4\CustomValue::get('MyStuff')->addWhere('id', '=', 123);`
33 * **Non-OOP:** `civicrm_api4('Custom_MyStuff', 'get', ['where' => [['id', '=', 123]]]);`
19b53e5b 34 *
7b7c96e6 35 * Note: This class does NOT extend AbstractEntity so it doesn't get mistaken for a "real" entity.
19b53e5b
C
36 * @package Civi\Api4
37 */
7b7c96e6 38class CustomValue {
19b53e5b
C
39
40 /**
41 * @param string $customGroup
42 * @return Action\CustomValue\Get
f63756b0 43 * @throws \API_Exception
19b53e5b
C
44 */
45 public static function get($customGroup) {
46 return new Action\CustomValue\Get($customGroup, __FUNCTION__);
47 }
48
49 /**
50 * @param string $customGroup
51 * @return Action\CustomValue\GetFields
f63756b0 52 * @throws \API_Exception
19b53e5b
C
53 */
54 public static function getFields($customGroup = NULL) {
55 return new Action\CustomValue\GetFields($customGroup, __FUNCTION__);
56 }
57
58 /**
59 * @param string $customGroup
60 * @return Action\CustomValue\Save
f63756b0 61 * @throws \API_Exception
19b53e5b
C
62 */
63 public static function save($customGroup) {
64 return new Action\CustomValue\Save($customGroup, __FUNCTION__);
65 }
66
67 /**
68 * @param string $customGroup
69 * @return Action\CustomValue\Create
f63756b0 70 * @throws \API_Exception
19b53e5b
C
71 */
72 public static function create($customGroup) {
73 return new Action\CustomValue\Create($customGroup, __FUNCTION__);
74 }
75
76 /**
77 * @param string $customGroup
78 * @return Action\CustomValue\Update
f63756b0 79 * @throws \API_Exception
19b53e5b
C
80 */
81 public static function update($customGroup) {
82 return new Action\CustomValue\Update($customGroup, __FUNCTION__);
83 }
84
85 /**
86 * @param string $customGroup
87 * @return Action\CustomValue\Delete
f63756b0 88 * @throws \API_Exception
19b53e5b
C
89 */
90 public static function delete($customGroup) {
91 return new Action\CustomValue\Delete($customGroup, __FUNCTION__);
92 }
93
94 /**
95 * @param string $customGroup
96 * @return Action\CustomValue\Replace
f63756b0 97 * @throws \API_Exception
19b53e5b
C
98 */
99 public static function replace($customGroup) {
100 return new Action\CustomValue\Replace($customGroup, __FUNCTION__);
101 }
102
103 /**
104 * @param string $customGroup
105 * @return Action\CustomValue\GetActions
f63756b0 106 * @throws \API_Exception
19b53e5b
C
107 */
108 public static function getActions($customGroup = NULL) {
109 return new Action\CustomValue\GetActions($customGroup, __FUNCTION__);
110 }
111
112 /**
113 * @inheritDoc
114 */
115 public static function permissions() {
116 $entity = 'contact';
117 $permissions = \CRM_Core_Permission::getEntityActionPermissions();
118
119 // Merge permissions for this entity with the defaults
120 return \CRM_Utils_Array::value($entity, $permissions, []) + $permissions['default'];
121 }
122
123}