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