}
}
elseif (substr($id, 0, 7) == 'custom_'
- && (
- substr($id, -9, 9) == '_relative'
- || substr($id, -5, 5) == '_from'
- || substr($id, -3, 3) == '_to'
- )
+ && (
+ substr($id, -9, 9) == '_relative'
+ || substr($id, -5, 5) == '_from'
+ || substr($id, -3, 3) == '_to'
+ )
) {
- self::convertCustomDateRelativeFields($formValues, $params, $values, $id);
+ self::convertCustomRelativeFields($formValues, $params, $values, $id);
}
elseif (preg_match('/_date_relative$/', $id) ||
$id == 'event_relative' ||
}
/**
- * Convert submitted values for relative custom date fields to query object format.
+ * Convert submitted values for relative custom fields to query object format.
*
* The query will support the sqlOperator format so convert to that format.
*
* @param string $fieldName
* Submitted field name. (Matches form field not DB field.)
*/
- protected static function convertCustomDateRelativeFields(&$formValues, &$params, $values, $fieldName) {
+ protected static function convertCustomRelativeFields(&$formValues, &$params, $values, $fieldName) {
if (empty($values)) {
// e.g we might have relative set & from & to empty. The form flow is a bit funky &
// this function gets called again after they fields have been converted which can get ugly.
return;
}
- list($from, $to) = CRM_Utils_Date::getFromTo(
- NULL,
- (empty($formValues[$customFieldName . '_from']) ? NULL : $formValues[$customFieldName . '_from']),
- CRM_Utils_Array::value($customFieldName . '_to', $formValues)
- );
+ $from = CRM_Utils_Array::value($customFieldName . '_from', $formValues, NULL);
+ $to = CRM_Utils_Array::value($customFieldName . '_to', $formValues, NULL);
+
+ $customFieldID = CRM_Core_BAO_CustomField::getKeyID($customFieldName);
+ $customFieldType = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $customFieldName, 'data_type');
+ if ($customFieldType == 'Date') {
+ list($from, $to) = CRM_Utils_Date::getFromTo(NULL, $from, $to);
+ }
}
if ($from) {
case 'Country':
if ($field['is_search_range'] && is_array($value)) {
- $this->searchRange($field['id'],
- $field['label'],
- $field['data_type'],
- $fieldName,
- $value,
- $grouping
- );
+ //didn't found any field under any of these three data-types as searchable by range
}
else {
// fix $value here to escape sql injection attacks
break;
case 'Int':
- if ($field['is_search_range'] && is_array($value)) {
- $this->searchRange($field['id'], $field['label'], $field['data_type'], $fieldName, $value, $grouping);
- }
- else {
- $this->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause($fieldName, $op, $value, 'Integer');
- $this->_qill[$grouping][] = ts("%1 %2 %3", array(1 => $field['label'], 2 => $qillOp, 3 => $qillValue));;
- }
+ $this->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause($fieldName, $op, $value, 'Integer');
+ $this->_qill[$grouping][] = ts("%1 %2 %3", array(1 => $field['label'], 2 => $qillOp, 3 => $qillValue));;
break;
case 'Boolean':
}
case 'Float':
- if ($field['is_search_range']) {
- $this->searchRange($field['id'], $field['label'], $field['data_type'], $fieldName, $value, $grouping);
- }
- else {
- $this->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause($fieldName, $op, $value, 'Float');
- $this->_qill[$grouping][] = ts("%1 %2 %3", array(1 => $field['label'], 2 => $qillOp, 3 => $qillValue));
- }
+ $this->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause($fieldName, $op, $value, 'Float');
+ $this->_qill[$grouping][] = ts("%1 %2 %3", array(1 => $field['label'], 2 => $qillOp, 3 => $qillValue));
break;
case 'Date':
- if (in_array($op, CRM_Core_DAO::acceptedSQLOperators())) {
- $this->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause($fieldName, $op, $value, 'String');
- list($qillOp, $qillVal) = CRM_Contact_BAO_Query::buildQillForFieldValue(NULL, $field['label'], $value,
- $op, array(), CRM_Utils_Type::T_DATE);
- $this->_qill[$grouping][] = "{$field['label']} $qillOp '$qillVal'";
- break;
- }
-
- $fromValue = CRM_Utils_Array::value('from', $value);
- $toValue = CRM_Utils_Array::value('to', $value);
- $value = CRM_Utils_Array::value($op, $value, $value);
-
- if (!$fromValue && !$toValue) {
- if (!is_array($value) && !CRM_Utils_Date::processDate($value) && !in_array($op, array('IS NULL', 'IS NOT NULL', 'IS EMPTY', 'IS NOT EMPTY'))) {
- continue;
- }
-
- // hack to handle yy format during search
- if (is_numeric($value) && strlen($value) == 4) {
- $value = "01-01-{$value}";
- }
-
- if (is_array($value)) {
- $date = $qillValue = array();
- foreach ($value as $key => $val) {
- $date[$key] = CRM_Utils_Date::processDate($val);
- $qillValue[$key] = CRM_Utils_Date::customFormat($date[$key]);
- }
- }
- else {
- $date = CRM_Utils_Date::processDate($value);
- $qillValue = CRM_Utils_Date::customFormat($date);
- }
-
- $this->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause($fieldName, $op, $date, 'String');
- $this->_qill[$grouping][] = $field['label'] . " {$qillOp} " . implode(', ', (array) $qillValue);
- }
- else {
- if (is_numeric($fromValue) && strlen($fromValue) == 4) {
- $fromValue = "01-01-{$fromValue}";
- }
-
- if (is_numeric($toValue) && strlen($toValue) == 4) {
- $toValue = "01-01-{$toValue}";
- }
-
- // TO DO: add / remove time based on date parts
- $fromDate = CRM_Utils_Date::processDate($fromValue);
- $toDate = CRM_Utils_Date::processDate($toValue);
- if (!$fromDate && !$toDate) {
- continue;
- }
- if ($fromDate) {
- $this->_where[$grouping][] = "$fieldName >= $fromDate";
- $this->_qill[$grouping][] = $field['label'] . ' >= ' . CRM_Utils_Date::customFormat($fromDate);
- }
- if ($toDate) {
- $this->_where[$grouping][] = "$fieldName <= $toDate";
- $this->_qill[$grouping][] = $field['label'] . ' <= ' . CRM_Utils_Date::customFormat($toDate);
- }
- }
+ $this->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause($fieldName, $op, $value, 'String');
+ list($qillOp, $qillVal) = CRM_Contact_BAO_Query::buildQillForFieldValue(NULL, $field['label'], $value, $op, array(), CRM_Utils_Type::T_DATE);
+ $this->_qill[$grouping][] = "{$field['label']} $qillOp '$qillVal'";
break;
case 'File':
);
}
- /**
- * @param int $id
- * @param $label
- * @param $type
- * @param string $fieldName
- * @param $value
- * @param $grouping
- */
- public function searchRange(&$id, &$label, $type, $fieldName, &$value, &$grouping) {
- $qill = array();
-
- if (isset($value['from'])) {
- $val = CRM_Utils_Type::escape($value['from'], $type);
-
- if ($type == 'String') {
- $this->_where[$grouping][] = "$fieldName >= '$val'";
- }
- else {
- $this->_where[$grouping][] = "$fieldName >= $val";
- }
- $qill[] = ts('greater than or equal to \'%1\'', array(1 => $value['from']));
- }
-
- if (isset($value['to'])) {
- $val = CRM_Utils_Type::escape($value['to'], $type);
- if ($type == 'String') {
- $this->_where[$grouping][] = "$fieldName <= '$val'";
- }
- else {
- $this->_where[$grouping][] = "$fieldName <= $val";
- }
- $qill[] = ts('less than or equal to \'%1\'', array(1 => $value['to']));
- }
-
- if (!empty($qill)) {
- $this->_qill[$grouping][] = $label . ' - ' . implode(' ' . ts('and') . ' ', $qill);
- }
- }
-
}