Merge pull request #5096 from totten/master-prettify-desert
[civicrm-core.git] / api / v3 / Constant.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 /**
29 * CiviCRM APIv3 pseudoconstants
30 *
31 * @deprecated
32 * The constant api is deprecated as of CiviCRM 4.4. Please use the getoptions api action instead.
33 * @package CiviCRM_APIv3
34 */
35
36 /**
37 * Declare deprecated api entity.
38 *
39 * @deprecated api notice
40 * @return string
41 * to indicate this entire api entity is deprecated
42 */
43 function _civicrm_api3_constant_deprecation() {
44 return 'The constant api is deprecated as of CiviCRM 4.4. Please use the getoptions api action instead.';
45 }
46
47 /**
48 * Get constant values (deprecated).
49 *
50 * @deprecated as of CiviCRM 4.4.
51 * It's recommended to use the api getoptions action instead
52 *
53 * @param array $params
54 * Name of a public static method of
55 * CRM_Core_PseudoConstant: one of
56 * <ul>
57 * <li>activityStatus</li>
58 * <li>activityType</li>
59 * <li>addressee</li>
60 * <li>allGroup</li>
61 * <li>country</li>
62 * <li>countryIsoCode</li>
63 * <li>county</li>
64 * <li>currencyCode</li>
65 * <li>currencySymbols</li>
66 * <li>customGroup</li>
67 * <li>emailGreeting</li>
68 * <li>fromEmailAddress</li>
69 * <li>gender</li>
70 * <li>group</li>
71 * <li>groupIterator</li>
72 * <li>honor</li>
73 * <li>IMProvider</li>
74 * <li>individualPrefix</li>
75 * <li>individualSuffix</li>
76 * <li>locationType</li>
77 * <li>locationVcardName</li>
78 * <li>mailProtocol</li>
79 * <li>mappingTypes</li>
80 * <li>paymentProcessor</li>
81 * <li>paymentProcessorType</li>
82 * <li>pcm</li>
83 * <li>phoneType</li>
84 * <li>postalGreeting</li>
85 * <li>priority</li>
86 * <li>relationshipType</li>
87 * <li>stateProvince</li>
88 * <li>stateProvinceAbbreviation</li>
89 * <li>stateProvinceForCountry</li>
90 * <li>staticGroup</li>
91 * <li>tag</li>
92 * <li>tasks</li>
93 * <li>ufGroup</li>
94 * <li>visibility</li>
95 * <li>worldRegion</li>
96 * <li>wysiwygEditor</li>
97 * </ul>
98 *
99 * @return array
100 */
101 function civicrm_api3_constant_get($params) {
102
103 $name = $params['name'];
104 // all the stuff about classes should be adequately replaced by the bit in the 'else'
105 //ie $values = call_user_func(array('CRM_Utils_PseudoConstant', 'getConstant'), $name);
106 // once tests are 100% can try removing the first block & a similar block from Generic:getoptions
107
108 // Whitelist approach is safer
109 $allowedClasses = array(
110 'CRM_Core_PseudoConstant',
111 'CRM_Event_PseudoConstant',
112 'CRM_Contribute_PseudoConstant',
113 'CRM_Member_PseudoConstant',
114 );
115 $className = $allowedClasses[0];
116 if (!empty($params['class']) && in_array($params['class'], $allowedClasses)) {
117 $className = $params['class'];
118 }
119 $callable = "$className::$name";
120 if (is_callable($callable)) {
121 if (empty($params)) {
122 $values = call_user_func(array($className, $name));
123 }
124 else {
125 $values = call_user_func(array($className, $name));
126 //@TODO XAV take out the param the COOKIE, Entity, Action and so there are only the "real param" in it
127 //$values = call_user_func_array( array( $className, $name ), $params );
128 }
129 return civicrm_api3_create_success($values, $params, 'constant');
130 }
131 else {
132 $values = call_user_func(array('CRM_Utils_PseudoConstant', 'getConstant'), $name);
133 if (!empty($values)) {
134 return civicrm_api3_create_success($values, $params, 'constant');
135 }
136 }
137 return civicrm_api3_create_error('Unknown civicrm constant or method not callable');
138 }
139
140 /**
141 * Adjust metadata for constant get action.
142 *
143 * @param array $params
144 */
145 function _civicrm_api3_constant_get_spec(&$params) {
146 $options = array(
147 'activityStatus',
148 'activityType',
149 'addressee',
150 'allGroup',
151 'country',
152 'countryIsoCode',
153 'county',
154 'currencyCode',
155 'currencySymbols',
156 'customGroup',
157 'emailGreeting',
158 'fromEmailAddress',
159 'gender',
160 'group',
161 'groupIterator',
162 'honor',
163 'IMProvider',
164 'individualPrefix',
165 'individualSuffix',
166 'locationType',
167 'locationVcardName',
168 'mailProtocol',
169 'mappingTypes',
170 'paymentInstrument',
171 'paymentProcessor',
172 'paymentProcessorType',
173 'pcm',
174 'phoneType',
175 'postalGreeting',
176 'priority',
177 'relationshipType',
178 'stateProvince',
179 'stateProvinceAbbreviation',
180 'stateProvinceForCountry',
181 'staticGroup',
182 'tag',
183 'tasks',
184 'ufGroup',
185 'visibility',
186 'worldRegion',
187 'wysiwygEditor',
188 );
189 $params = array(
190 'name' => array(
191 'title' => 'Constant Name',
192 'name' => 'name',
193 'api.required' => 1,
194 'options' => array_combine($options, $options),
195 ),
196 );
197 }