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