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