Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
a30c801b | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
a30c801b 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 | | |
6a488035 TO |
9 | +--------------------------------------------------------------------+ |
10 | */ | |
11 | ||
12 | /** | |
16414f90 | 13 | * CiviCRM APIv3 pseudoconstants |
6a488035 | 14 | * |
16414f90 | 15 | * @deprecated |
244bbdd8 | 16 | * The Constant api is deprecated as of CiviCRM 4.4. Please use the getoptions api action instead. |
6a488035 | 17 | * @package CiviCRM_APIv3 |
6a488035 TO |
18 | */ |
19 | ||
a14e9d08 | 20 | /** |
dc64d047 EM |
21 | * Declare deprecated api entity. |
22 | * | |
a14e9d08 | 23 | * @deprecated api notice |
a6c01b45 | 24 | * @return string |
72b3a70c | 25 | * to indicate this entire api entity is deprecated |
a14e9d08 CW |
26 | */ |
27 | function _civicrm_api3_constant_deprecation() { | |
244bbdd8 | 28 | return 'The Constant api is deprecated as of CiviCRM 4.4. Please use the getoptions api action instead.'; |
a14e9d08 CW |
29 | } |
30 | ||
6a488035 | 31 | /** |
dc64d047 EM |
32 | * Get constant values (deprecated). |
33 | * | |
16414f90 | 34 | * @deprecated as of CiviCRM 4.4. |
ee2b1c1c | 35 | * It's recommended to use the api getoptions action instead |
6a488035 | 36 | * |
decce855 EM |
37 | * @param array $params |
38 | * Name of a public static method of | |
b081365f | 39 | * CRM_Core_PseudoConstant: one of |
244bbdd8 CW |
40 | * activityStatus |
41 | * activityType | |
42 | * addressee | |
43 | * allGroup | |
44 | * country | |
45 | * countryIsoCode | |
46 | * county | |
47 | * currencyCode | |
48 | * currencySymbols | |
49 | * customGroup | |
50 | * emailGreeting | |
51 | * fromEmailAddress | |
52 | * gender | |
53 | * group | |
54 | * groupIterator | |
55 | * honor | |
56 | * IMProvider | |
57 | * individualPrefix | |
58 | * individualSuffix | |
59 | * locationType | |
60 | * locationVcardName | |
61 | * mailProtocol | |
62 | * mappingTypes | |
63 | * paymentProcessor | |
64 | * paymentProcessorType | |
65 | * pcm | |
66 | * phoneType | |
67 | * postalGreeting | |
68 | * priority | |
69 | * relationshipType | |
70 | * stateProvince | |
71 | * stateProvinceAbbreviation | |
72 | * stateProvinceForCountry | |
73 | * staticGroup | |
74 | * tag | |
75 | * tasks | |
76 | * ufGroup | |
77 | * visibility | |
78 | * worldRegion | |
79 | * wysiwygEditor | |
22242c87 | 80 | * |
16414f90 | 81 | * @return array |
6a488035 TO |
82 | */ |
83 | function civicrm_api3_constant_get($params) { | |
84 | ||
85 | $name = $params['name']; | |
86 | // all the stuff about classes should be adequately replaced by the bit in the 'else' | |
87 | //ie $values = call_user_func(array('CRM_Utils_PseudoConstant', 'getConstant'), $name); | |
88 | // once tests are 100% can try removing the first block & a similar block from Generic:getoptions | |
89 | ||
6a488035 | 90 | // Whitelist approach is safer |
cf8f0fff | 91 | $allowedClasses = [ |
6a488035 TO |
92 | 'CRM_Core_PseudoConstant', |
93 | 'CRM_Event_PseudoConstant', | |
94 | 'CRM_Contribute_PseudoConstant', | |
95 | 'CRM_Member_PseudoConstant', | |
cf8f0fff | 96 | ]; |
6a488035 TO |
97 | $className = $allowedClasses[0]; |
98 | if (!empty($params['class']) && in_array($params['class'], $allowedClasses)) { | |
99 | $className = $params['class']; | |
100 | } | |
101 | $callable = "$className::$name"; | |
102 | if (is_callable($callable)) { | |
103 | if (empty($params)) { | |
cf8f0fff | 104 | $values = call_user_func([$className, $name]); |
6a488035 TO |
105 | } |
106 | else { | |
cf8f0fff | 107 | $values = call_user_func([$className, $name]); |
6a488035 TO |
108 | //@TODO XAV take out the param the COOKIE, Entity, Action and so there are only the "real param" in it |
109 | //$values = call_user_func_array( array( $className, $name ), $params ); | |
110 | } | |
244bbdd8 | 111 | return civicrm_api3_create_success($values, $params, 'Constant'); |
6a488035 | 112 | } |
92e4c2a5 | 113 | else { |
cf8f0fff | 114 | $values = call_user_func(['CRM_Utils_PseudoConstant', 'getConstant'], $name); |
9b873358 | 115 | if (!empty($values)) { |
244bbdd8 | 116 | return civicrm_api3_create_success($values, $params, 'Constant'); |
6a488035 TO |
117 | } |
118 | } | |
119 | return civicrm_api3_create_error('Unknown civicrm constant or method not callable'); | |
120 | } | |
121 | ||
aa1b1481 | 122 | /** |
dc64d047 EM |
123 | * Adjust metadata for constant get action. |
124 | * | |
c490a46a | 125 | * @param array $params |
aa1b1481 | 126 | */ |
6a488035 | 127 | function _civicrm_api3_constant_get_spec(&$params) { |
cf8f0fff | 128 | $options = [ |
a14e9d08 CW |
129 | 'activityStatus', |
130 | 'activityType', | |
131 | 'addressee', | |
132 | 'allGroup', | |
133 | 'country', | |
134 | 'countryIsoCode', | |
135 | 'county', | |
136 | 'currencyCode', | |
137 | 'currencySymbols', | |
138 | 'customGroup', | |
139 | 'emailGreeting', | |
140 | 'fromEmailAddress', | |
141 | 'gender', | |
142 | 'group', | |
a14e9d08 CW |
143 | 'honor', |
144 | 'IMProvider', | |
145 | 'individualPrefix', | |
146 | 'individualSuffix', | |
147 | 'locationType', | |
148 | 'locationVcardName', | |
149 | 'mailProtocol', | |
150 | 'mappingTypes', | |
151 | 'paymentInstrument', | |
152 | 'paymentProcessor', | |
153 | 'paymentProcessorType', | |
154 | 'pcm', | |
155 | 'phoneType', | |
156 | 'postalGreeting', | |
157 | 'priority', | |
158 | 'relationshipType', | |
159 | 'stateProvince', | |
160 | 'stateProvinceAbbreviation', | |
161 | 'stateProvinceForCountry', | |
162 | 'staticGroup', | |
163 | 'tag', | |
164 | 'tasks', | |
165 | 'ufGroup', | |
166 | 'visibility', | |
167 | 'worldRegion', | |
168 | 'wysiwygEditor', | |
cf8f0fff CW |
169 | ]; |
170 | $params = [ | |
171 | 'name' => [ | |
4c41ecb2 | 172 | 'title' => 'Constant Name', |
a14e9d08 | 173 | 'name' => 'name', |
6a488035 | 174 | 'api.required' => 1, |
a1a2a83d | 175 | 'options' => array_combine($options, $options), |
d142432b | 176 | 'type' => CRM_Utils_Type::T_STRING, |
cf8f0fff CW |
177 | ], |
178 | ]; | |
6a488035 | 179 | } |