| 1 | <?php |
| 2 | // $Id$ |
| 3 | |
| 4 | /* |
| 5 | +--------------------------------------------------------------------+ |
| 6 | | CiviCRM version 4.3 | |
| 7 | +--------------------------------------------------------------------+ |
| 8 | | Copyright CiviCRM LLC (c) 2004-2013 | |
| 9 | +--------------------------------------------------------------------+ |
| 10 | | This file is a part of CiviCRM. | |
| 11 | | | |
| 12 | | CiviCRM is free software; you can copy, modify, and distribute it | |
| 13 | | under the terms of the GNU Affero General Public License | |
| 14 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | |
| 15 | | | |
| 16 | | CiviCRM is distributed in the hope that it will be useful, but | |
| 17 | | WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 18 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
| 19 | | See the GNU Affero General Public License for more details. | |
| 20 | | | |
| 21 | | You should have received a copy of the GNU Affero General Public | |
| 22 | | License and the CiviCRM Licensing Exception along | |
| 23 | | with this program; if not, contact CiviCRM LLC | |
| 24 | | at info[AT]civicrm[DOT]org. If you have questions about the | |
| 25 | | GNU Affero General Public License or the licensing of CiviCRM, | |
| 26 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | |
| 27 | +--------------------------------------------------------------------+ |
| 28 | */ |
| 29 | |
| 30 | /** |
| 31 | * File for CiviCRM APIv3 pseudoconstants |
| 32 | * |
| 33 | * @package CiviCRM_APIv3 |
| 34 | * @subpackage API_Constant |
| 35 | * @copyright CiviCRM LLC (c) 2004-2013 |
| 36 | * @version $Id: Constant.php 30171 2010-10-14 09:11:27Z mover $ |
| 37 | * |
| 38 | */ |
| 39 | |
| 40 | /** |
| 41 | * Generic file to retrieve all the constants and |
| 42 | * pseudo constants used in CiviCRM |
| 43 | * |
| 44 | * @param string Name of a public static method of |
| 45 | * CRM_Core_PseudoContant: one of |
| 46 | * <ul> |
| 47 | * <li>activityStatus</li> |
| 48 | * <li>activityType</li> |
| 49 | * <li>addressee</li> |
| 50 | * <li>allGroup</li> |
| 51 | * <li>country</li> |
| 52 | * <li>countryIsoCode</li> |
| 53 | * <li>county</li> |
| 54 | * <li>currencyCode</li> |
| 55 | * <li>currencySymbols</li> |
| 56 | * <li>customGroup</li> |
| 57 | * <li>emailGreeting</li> |
| 58 | * <li>fromEmailAddress</li> |
| 59 | * <li>gender</li> |
| 60 | * <li>group</li> |
| 61 | * <li>groupIterator</li> |
| 62 | * <li>honor</li> |
| 63 | * <li>IMProvider</li> |
| 64 | * <li>individualPrefix</li> |
| 65 | * <li>individualSuffix</li> |
| 66 | * <li>locationType</li> |
| 67 | * <li>locationVcardName</li> |
| 68 | * <li>mailProtocol</li> |
| 69 | * <li>mappingTypes</li> |
| 70 | * <li>paymentProcessor</li> |
| 71 | * <li>paymentProcessorType</li> |
| 72 | * <li>pcm</li> |
| 73 | * <li>phoneType</li> |
| 74 | * <li>postalGreeting</li> |
| 75 | * <li>priority</li> |
| 76 | * <li>relationshipType</li> |
| 77 | * <li>stateProvince</li> |
| 78 | * <li>stateProvinceAbbreviation</li> |
| 79 | * <li>stateProvinceForCountry</li> |
| 80 | * <li>staticGroup</li> |
| 81 | * <li>tag</li> |
| 82 | * <li>tasks</li> |
| 83 | * <li>ufGroup</li> |
| 84 | * <li>visibility</li> |
| 85 | * <li>worldRegion</li> |
| 86 | * <li>wysiwygEditor</li> |
| 87 | * </ul> |
| 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 | function _civicrm_api3_constant_get_spec(&$params) { |
| 132 | |
| 133 | $params = (array |
| 134 | ('name' => array( |
| 135 | 'api.required' => 1, |
| 136 | 'options' => |
| 137 | 'activityStatus', |
| 138 | 'activityType', |
| 139 | 'addressee', |
| 140 | 'allGroup', |
| 141 | 'country', |
| 142 | 'countryIsoCode', |
| 143 | 'county', |
| 144 | 'currencyCode', |
| 145 | 'currencySymbols', |
| 146 | 'customGroup', |
| 147 | 'emailGreeting', |
| 148 | 'fromEmailAddress', |
| 149 | 'gender', |
| 150 | 'group', |
| 151 | 'groupIterator', |
| 152 | 'honor', |
| 153 | 'IMProvider', |
| 154 | 'individualPrefix', |
| 155 | 'individualSuffix', |
| 156 | 'locationType', |
| 157 | 'locationVcardName', |
| 158 | 'mailProtocol', |
| 159 | 'mappingTypes', |
| 160 | 'paymentInstrument', |
| 161 | 'paymentProcessor', |
| 162 | 'paymentProcessorType', |
| 163 | 'pcm', |
| 164 | 'phoneType', |
| 165 | 'postalGreeting', |
| 166 | 'priority', |
| 167 | 'relationshipType', |
| 168 | 'stateProvince', |
| 169 | 'stateProvinceAbbreviation', |
| 170 | 'stateProvinceForCountry', |
| 171 | 'staticGroup', |
| 172 | 'tag', |
| 173 | 'tasks', |
| 174 | 'ufGroup', |
| 175 | 'visibility', |
| 176 | 'worldRegion', |
| 177 | 'wysiwygEditor', |
| 178 | )) |
| 179 | ); |
| 180 | } |
| 181 | |