INFRA-132 - Remove extra spaces around '.'
[civicrm-core.git] / api / v3 / Constant.php
CommitLineData
6a488035 1<?php
6a488035
TO
2
3/*
4 +--------------------------------------------------------------------+
39de6fd5 5 | CiviCRM version 4.6 |
6a488035 6 +--------------------------------------------------------------------+
731a0992 7 | Copyright CiviCRM LLC (c) 2004-2014 |
6a488035
TO
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/**
16414f90 30 * CiviCRM APIv3 pseudoconstants
6a488035 31 *
16414f90 32 * @deprecated
6a488035
TO
33 * @package CiviCRM_APIv3
34 * @subpackage API_Constant
731a0992 35 * @copyright CiviCRM LLC (c) 2004-2014
6a488035 36 * @version $Id: Constant.php 30171 2010-10-14 09:11:27Z mover $
6a488035
TO
37 */
38
a14e9d08
CW
39/**
40 * @deprecated api notice
41 * @return string to indicate this entire api entity is deprecated
42 */
43function _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
6a488035 47/**
16414f90 48 * @deprecated as of CiviCRM 4.4.
ee2b1c1c 49 * It's recommended to use the api getoptions action instead
6a488035 50 *
35671d00 51 * @param string Name of a public static method of
c206647d 52 * CRM_Core_PseudoConstant: one of
6a488035
TO
53 * <ul>
54 * <li>activityStatus</li>
55 * <li>activityType</li>
56 * <li>addressee</li>
57 * <li>allGroup</li>
58 * <li>country</li>
59 * <li>countryIsoCode</li>
60 * <li>county</li>
61 * <li>currencyCode</li>
62 * <li>currencySymbols</li>
63 * <li>customGroup</li>
64 * <li>emailGreeting</li>
65 * <li>fromEmailAddress</li>
66 * <li>gender</li>
67 * <li>group</li>
68 * <li>groupIterator</li>
69 * <li>honor</li>
70 * <li>IMProvider</li>
71 * <li>individualPrefix</li>
72 * <li>individualSuffix</li>
73 * <li>locationType</li>
74 * <li>locationVcardName</li>
75 * <li>mailProtocol</li>
76 * <li>mappingTypes</li>
77 * <li>paymentProcessor</li>
78 * <li>paymentProcessorType</li>
79 * <li>pcm</li>
80 * <li>phoneType</li>
81 * <li>postalGreeting</li>
82 * <li>priority</li>
83 * <li>relationshipType</li>
84 * <li>stateProvince</li>
85 * <li>stateProvinceAbbreviation</li>
86 * <li>stateProvinceForCountry</li>
87 * <li>staticGroup</li>
88 * <li>tag</li>
89 * <li>tasks</li>
90 * <li>ufGroup</li>
91 * <li>visibility</li>
92 * <li>worldRegion</li>
93 * <li>wysiwygEditor</li>
94 * </ul>
16414f90 95 * @return array
35671d00 96 * @example ConstantGet.php
6a488035
TO
97 * {@getfields constant_get}
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
TO
106 // Whitelist approach is safer
107 $allowedClasses = array(
108 'CRM_Core_PseudoConstant',
109 'CRM_Event_PseudoConstant',
110 'CRM_Contribute_PseudoConstant',
111 'CRM_Member_PseudoConstant',
112 );
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)) {
120 $values = call_user_func(array($className, $name));
121 }
122 else {
123 $values = call_user_func(array($className, $name));
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 }
a14e9d08 127 return civicrm_api3_create_success($values, $params, 'constant');
6a488035
TO
128 }
129 else{
130 $values = call_user_func(array('CRM_Utils_PseudoConstant', 'getConstant'), $name);
9b873358 131 if (!empty($values)) {
a14e9d08 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/**
c490a46a 139 * @param array $params
aa1b1481 140 */
6a488035 141function _civicrm_api3_constant_get_spec(&$params) {
a14e9d08
CW
142 $options = array(
143 'activityStatus',
144 'activityType',
145 'addressee',
146 'allGroup',
147 'country',
148 'countryIsoCode',
149 'county',
150 'currencyCode',
151 'currencySymbols',
152 'customGroup',
153 'emailGreeting',
154 'fromEmailAddress',
155 'gender',
156 'group',
157 'groupIterator',
158 'honor',
159 'IMProvider',
160 'individualPrefix',
161 'individualSuffix',
162 'locationType',
163 'locationVcardName',
164 'mailProtocol',
165 'mappingTypes',
166 'paymentInstrument',
167 'paymentProcessor',
168 'paymentProcessorType',
169 'pcm',
170 'phoneType',
171 'postalGreeting',
172 'priority',
173 'relationshipType',
174 'stateProvince',
175 'stateProvinceAbbreviation',
176 'stateProvinceForCountry',
177 'staticGroup',
178 'tag',
179 'tasks',
180 'ufGroup',
181 'visibility',
182 'worldRegion',
183 'wysiwygEditor',
184 );
35671d00
TO
185 $params = (array(
186 'name' => array(
4c41ecb2 187 'title' => 'Constant Name',
a14e9d08 188 'name' => 'name',
6a488035 189 'api.required' => 1,
a14e9d08 190 'options' => array_combine($options, $options)
6a488035
TO
191 ))
192 );
193}