3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2014
37 * Business objects for managing custom data values.
40 class CRM_Core_BAO_CustomValue
extends CRM_Core_DAO
{
43 * Validate a value against a CustomField type
45 * @param string $type The type of the data
46 * @param string $value The data to be validated
48 * @return boolean True if the value is of the specified type
52 public static function typecheck($type, $value) {
58 return CRM_Utils_Rule
::string($value);
61 return CRM_Utils_Rule
::integer($value);
65 return CRM_Utils_Rule
::numeric($value);
68 if (is_numeric($value)) {
69 return CRM_Utils_Rule
::dateTime($value);
72 return CRM_Utils_Rule
::date($value);
75 return CRM_Utils_Rule
::boolean($value);
77 case 'ContactReference':
78 return CRM_Utils_Rule
::validContact($value);
82 //fix for multi select state, CRM-3437
84 $mulValues = explode(',', $value);
85 foreach ($mulValues as $key => $state) {
86 $valid = array_key_exists(strtolower(trim($state)),
87 array_change_key_case(array_flip(CRM_Core_PseudoConstant
::stateProvinceAbbreviation()), CASE_LOWER
)
88 ) ||
array_key_exists(strtolower(trim($state)),
89 array_change_key_case(array_flip(CRM_Core_PseudoConstant
::stateProvince()), CASE_LOWER
)
99 //fix multi select country, CRM-3437
101 $mulValues = explode(',', $value);
102 foreach ($mulValues as $key => $country) {
103 $valid = array_key_exists(strtolower(trim($country)),
104 array_change_key_case(array_flip(CRM_Core_PseudoConstant
::countryIsoCode()), CASE_LOWER
)
105 ) ||
array_key_exists(strtolower(trim($country)),
106 array_change_key_case(array_flip(CRM_Core_PseudoConstant
::country()), CASE_LOWER
)
115 return CRM_Utils_Rule
::url($value);
121 * given a 'civicrm' type string, return the mysql data store area
123 * @param string $type the civicrm type string
125 * @return the mysql data store placeholder
129 public static function typeToField($type) {
137 case 'StateProvince':
139 case 'Auto-complete':
146 return 'decimal_data';
163 public static function fixFieldValueOfTypeMemo(&$formValues) {
164 if (empty($formValues)) {
167 foreach (array_keys($formValues) as $key) {
168 if (substr($key, 0, 7) != 'custom_') {
171 elseif (empty($formValues[$key])) {
175 $htmlType = CRM_Core_DAO
::getFieldValue('CRM_Core_BAO_CustomField',
176 substr($key, 7), 'html_type'
178 if (($htmlType == 'TextArea') &&
179 !((substr($formValues[$key], 0, 1) == '%') ||
180 (substr($formValues[$key], -1, 1) == '%')
183 $formValues[$key] = '%' . $formValues[$key] . '%';
186 $dataType = CRM_Core_DAO
::getFieldValue('CRM_Core_BAO_CustomField',
187 substr($key, 7), 'data_type'
189 if (($dataType == 'ContactReference') && ($htmlType == 'Autocomplete-Select')) {
190 $formValues[$key] = $formValues[$key . '_id'];
196 * Function to delet option value give an option value and custom group id
198 * @param int $customValueID custom value ID
199 * @param int $customGroupID custom group ID
204 static function deleteCustomValue($customValueID, $customGroupID) {
205 // first we need to find custom value table, from custom group ID
206 $tableName = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_CustomGroup', $customGroupID, 'table_name');
208 // delete custom value from corresponding custom value table
209 $sql = "DELETE FROM {$tableName} WHERE id = {$customValueID}";
210 CRM_Core_DAO
::executeQuery($sql);
212 CRM_Utils_Hook
::custom('delete',