Merge pull request #14981 from eileenmcnaughton/load_extract
[civicrm-core.git] / api / v3 / Constant.php
CommitLineData
6a488035 1<?php
6a488035
TO
2/*
3 +--------------------------------------------------------------------+
fee14197 4 | CiviCRM version 5 |
6a488035 5 +--------------------------------------------------------------------+
6b83d5bd 6 | Copyright CiviCRM LLC (c) 2004-2019 |
6a488035
TO
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
26 */
27
28/**
16414f90 29 * CiviCRM APIv3 pseudoconstants
6a488035 30 *
16414f90 31 * @deprecated
244bbdd8 32 * The Constant api is deprecated as of CiviCRM 4.4. Please use the getoptions api action instead.
6a488035 33 * @package CiviCRM_APIv3
6a488035
TO
34 */
35
a14e9d08 36/**
dc64d047
EM
37 * Declare deprecated api entity.
38 *
a14e9d08 39 * @deprecated api notice
a6c01b45 40 * @return string
72b3a70c 41 * to indicate this entire api entity is deprecated
a14e9d08
CW
42 */
43function _civicrm_api3_constant_deprecation() {
244bbdd8 44 return 'The Constant api is deprecated as of CiviCRM 4.4. Please use the getoptions api action instead.';
a14e9d08
CW
45}
46
6a488035 47/**
dc64d047
EM
48 * Get constant values (deprecated).
49 *
16414f90 50 * @deprecated as of CiviCRM 4.4.
ee2b1c1c 51 * It's recommended to use the api getoptions action instead
6a488035 52 *
decce855
EM
53 * @param array $params
54 * Name of a public static method of
b081365f 55 * CRM_Core_PseudoConstant: one of
244bbdd8
CW
56 * activityStatus
57 * activityType
58 * addressee
59 * allGroup
60 * country
61 * countryIsoCode
62 * county
63 * currencyCode
64 * currencySymbols
65 * customGroup
66 * emailGreeting
67 * fromEmailAddress
68 * gender
69 * group
70 * groupIterator
71 * honor
72 * IMProvider
73 * individualPrefix
74 * individualSuffix
75 * locationType
76 * locationVcardName
77 * mailProtocol
78 * mappingTypes
79 * paymentProcessor
80 * paymentProcessorType
81 * pcm
82 * phoneType
83 * postalGreeting
84 * priority
85 * relationshipType
86 * stateProvince
87 * stateProvinceAbbreviation
88 * stateProvinceForCountry
89 * staticGroup
90 * tag
91 * tasks
92 * ufGroup
93 * visibility
94 * worldRegion
95 * wysiwygEditor
22242c87 96 *
16414f90 97 * @return array
6a488035
TO
98 */
99function civicrm_api3_constant_get($params) {
100
101 $name = $params['name'];
102 // all the stuff about classes should be adequately replaced by the bit in the 'else'
103 //ie $values = call_user_func(array('CRM_Utils_PseudoConstant', 'getConstant'), $name);
104 // once tests are 100% can try removing the first block & a similar block from Generic:getoptions
105
6a488035 106 // Whitelist approach is safer
cf8f0fff 107 $allowedClasses = [
6a488035
TO
108 'CRM_Core_PseudoConstant',
109 'CRM_Event_PseudoConstant',
110 'CRM_Contribute_PseudoConstant',
111 'CRM_Member_PseudoConstant',
cf8f0fff 112 ];
6a488035
TO
113 $className = $allowedClasses[0];
114 if (!empty($params['class']) && in_array($params['class'], $allowedClasses)) {
115 $className = $params['class'];
116 }
117 $callable = "$className::$name";
118 if (is_callable($callable)) {
119 if (empty($params)) {
cf8f0fff 120 $values = call_user_func([$className, $name]);
6a488035
TO
121 }
122 else {
cf8f0fff 123 $values = call_user_func([$className, $name]);
6a488035
TO
124 //@TODO XAV take out the param the COOKIE, Entity, Action and so there are only the "real param" in it
125 //$values = call_user_func_array( array( $className, $name ), $params );
126 }
244bbdd8 127 return civicrm_api3_create_success($values, $params, 'Constant');
6a488035 128 }
92e4c2a5 129 else {
cf8f0fff 130 $values = call_user_func(['CRM_Utils_PseudoConstant', 'getConstant'], $name);
9b873358 131 if (!empty($values)) {
244bbdd8 132 return civicrm_api3_create_success($values, $params, 'Constant');
6a488035
TO
133 }
134 }
135 return civicrm_api3_create_error('Unknown civicrm constant or method not callable');
136}
137
aa1b1481 138/**
dc64d047
EM
139 * Adjust metadata for constant get action.
140 *
c490a46a 141 * @param array $params
aa1b1481 142 */
6a488035 143function _civicrm_api3_constant_get_spec(&$params) {
cf8f0fff 144 $options = [
a14e9d08
CW
145 'activityStatus',
146 'activityType',
147 'addressee',
148 'allGroup',
149 'country',
150 'countryIsoCode',
151 'county',
152 'currencyCode',
153 'currencySymbols',
154 'customGroup',
155 'emailGreeting',
156 'fromEmailAddress',
157 'gender',
158 'group',
a14e9d08
CW
159 'honor',
160 'IMProvider',
161 'individualPrefix',
162 'individualSuffix',
163 'locationType',
164 'locationVcardName',
165 'mailProtocol',
166 'mappingTypes',
167 'paymentInstrument',
168 'paymentProcessor',
169 'paymentProcessorType',
170 'pcm',
171 'phoneType',
172 'postalGreeting',
173 'priority',
174 'relationshipType',
175 'stateProvince',
176 'stateProvinceAbbreviation',
177 'stateProvinceForCountry',
178 'staticGroup',
179 'tag',
180 'tasks',
181 'ufGroup',
182 'visibility',
183 'worldRegion',
184 'wysiwygEditor',
cf8f0fff
CW
185 ];
186 $params = [
187 'name' => [
4c41ecb2 188 'title' => 'Constant Name',
a14e9d08 189 'name' => 'name',
6a488035 190 'api.required' => 1,
a1a2a83d 191 'options' => array_combine($options, $options),
d142432b 192 'type' => CRM_Utils_Type::T_STRING,
cf8f0fff
CW
193 ],
194 ];
6a488035 195}