+--------------------------------------------------------------------+
| CiviCRM version 4.6 |
+--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014 |
+ | Copyright CiviCRM LLC (c) 2004-2015 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
-*/
+ */
/**
*
* @package CRM
- * @copyright CiviCRM LLC (c) 2004-2014
+ * @copyright CiviCRM LLC (c) 2004-2015
* $Id$
*
*/
class CRM_Core_BAO_CustomValue extends CRM_Core_DAO {
/**
- * Validate a value against a CustomField type
+ * Validate a value against a CustomField type.
*
- * @param string $type The type of the data
- * @param string $value The data to be validated
+ * @param string $type
+ * The type of the data.
+ * @param string $value
+ * The data to be validated.
*
- * @return boolean True if the value is of the specified type
- * @static
+ * @return bool
+ * True if the value is of the specified type
*/
public static function typecheck($type, $value) {
switch ($type) {
$mulValues = explode(',', $value);
foreach ($mulValues as $key => $state) {
$valid = array_key_exists(strtolower(trim($state)),
- array_change_key_case(array_flip(CRM_Core_PseudoConstant::stateProvinceAbbreviation()), CASE_LOWER)
- ) || array_key_exists(strtolower(trim($state)),
- array_change_key_case(array_flip(CRM_Core_PseudoConstant::stateProvince()), CASE_LOWER)
- );
+ array_change_key_case(array_flip(CRM_Core_PseudoConstant::stateProvinceAbbreviation()), CASE_LOWER)
+ ) || array_key_exists(strtolower(trim($state)),
+ array_change_key_case(array_flip(CRM_Core_PseudoConstant::stateProvince()), CASE_LOWER)
+ );
if (!$valid) {
break;
}
$mulValues = explode(',', $value);
foreach ($mulValues as $key => $country) {
$valid = array_key_exists(strtolower(trim($country)),
- array_change_key_case(array_flip(CRM_Core_PseudoConstant::countryIsoCode()), CASE_LOWER)
- ) || array_key_exists(strtolower(trim($country)),
- array_change_key_case(array_flip(CRM_Core_PseudoConstant::country()), CASE_LOWER)
- );
+ array_change_key_case(array_flip(CRM_Core_PseudoConstant::countryIsoCode()), CASE_LOWER)
+ ) || array_key_exists(strtolower(trim($country)),
+ array_change_key_case(array_flip(CRM_Core_PseudoConstant::country()), CASE_LOWER)
+ );
if (!$valid) {
break;
}
/**
* Given a 'civicrm' type string, return the mysql data store area
*
- * @param string $type the civicrm type string
+ * @param string $type
+ * The civicrm type string.
*
- * @return the mysql data store placeholder
- * @static
+ * @return string|null
+ * the mysql data store placeholder
*/
public static function typeToField($type) {
switch ($type) {
/**
- * @param $formValues
+ * @param array $formValues
+ * @return null
*/
- public static function fixFieldValueOfTypeMemo(&$formValues) {
+ public static function fixCustomFieldValue(&$formValues) {
if (empty($formValues)) {
return NULL;
}
$htmlType = CRM_Core_DAO::getFieldValue('CRM_Core_BAO_CustomField',
substr($key, 7), 'html_type'
);
- if (($htmlType == 'TextArea') &&
+ $dataType = CRM_Core_DAO::getFieldValue('CRM_Core_BAO_CustomField',
+ substr($key, 7), 'data_type'
+ );
+
+ if (is_array($formValues[$key])) {
+ if (!in_array(key($formValues[$key]), CRM_Core_DAO::acceptedSQLOperators(), TRUE)) {
+ $formValues[$key] = array('IN' => $formValues[$key]);
+ }
+ }
+ elseif (($htmlType == 'TextArea' ||
+ ($htmlType == 'Text' && $dataType == 'String')
+ ) &&
!((substr($formValues[$key], 0, 1) == '%') ||
(substr($formValues[$key], -1, 1) == '%')
)
) {
- $formValues[$key] = '%' . $formValues[$key] . '%';
+ $formValues[$key] = array('LIKE' => '%' . $formValues[$key] . '%');
}
-
}
}
/**
- * Delet option value give an option value and custom group id
+ * Delete option value give an option value and custom group id.
*
- * @param int $customValueID custom value ID
- * @param int $customGroupID custom group ID
+ * @param int $customValueID
+ * Custom value ID.
+ * @param int $customGroupID
+ * Custom group ID.
*
* @return void
- * @static
*/
public static function deleteCustomValue($customValueID, $customGroupID) {
// first we need to find custom value table, from custom group ID
$customValueID
);
}
+
}