From: monishdeb Date: Wed, 3 Jun 2015 08:07:50 +0000 (+0530) Subject: QA changes X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=efb8861279f239a873eef7f3537bcd907a61fcb2;p=civicrm-core.git QA changes --- diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index 99eebf297a..b0a743bb99 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -2168,7 +2168,45 @@ class CRM_Contact_BAO_Query { $this->_where[$grouping][] = self::buildClause("contact_a.is_deleted", $op, $value); $this->_qill[$grouping][] = "$field[title] $op \"$value\""; } - else { + elseif (!empty($field['where'])) { + $type = NULL; + if (!empty($field['type'])) { + $type = CRM_Utils_Type::typeToString($field['type']); + } + + list($tableName, $fieldName) = explode('.', $field['where'], 2); + + if (isset($locType[1]) && + is_numeric($locType[1]) + ) { + $setTables = FALSE; + + //get the location name + list($tName, $fldName) = self::getLocationTableName($field['where'], $locType); + + $fieldName = "LOWER(`$tName`.$fldName)"; + + // we set both _tables & whereTables because whereTables doesn't seem to do what the name implies it should + $this->_tables[$tName] = $this->_whereTables[$tName] = 1; + + } + else { + if ($tableName == 'civicrm_contact') { + $fieldName = "LOWER(contact_a.{$fieldName})"; + } + else { + if ($op != 'IN' && !is_numeric($value)) { + $fieldName = "LOWER({$field['where']})"; + } + else { + $fieldName = "{$field['where']}"; + } + } + } + + list($qillop, $qillVal) = self::buildQillForFieldValue(NULL, $field['title'], $value, $op); + $this->_qill[$grouping][] = "$field[title] $qillop '$qillVal'"; + if (is_array($value)) { // traditionally an array being passed has been a fatal error. We can take advantage of this to add support // for api style operators for functions that hit this point without worrying about regression @@ -2177,16 +2215,20 @@ class CRM_Contact_BAO_Query { $operations = array_keys($value); foreach ($operations as $operator) { if (!in_array($operator, CRM_Core_DAO::acceptedSQLOperators())) { + //Via Contact get api value is not in array(operator => array(values)) format ONLY for IN/NOT IN operators + //so this condition will satisfy the search for now + if (strstr('IN', $op)) { + $value = array($op => $value); + } // we don't know when this might happen - CRM_Core_Error::fatal(); + else { + CRM_Core_Error::fatal(ts("%1 is not a valid operator", array(1 => $operator))); + } } } - $this->_where[$grouping][] = CRM_Core_DAO::createSQLFilter($name, $value, NULL); - //since this is not currently being called by the form layer we can skip worrying about the 'qill' for now - return; + $this->_where[$grouping][] = CRM_Core_DAO::createSQLFilter($fieldName, $value, $type); } - - if (!empty($field['where'])) { + else { if ($op != 'IN') { $value = $strtolower($value); } @@ -2195,43 +2237,7 @@ class CRM_Contact_BAO_Query { $op = 'LIKE'; } - if (isset($locType[1]) && - is_numeric($locType[1]) - ) { - $setTables = FALSE; - - //get the location name - list($tName, $fldName) = self::getLocationTableName($field['where'], $locType); - - $where = "`$tName`.$fldName"; - - $this->_where[$grouping][] = self::buildClause("LOWER($where)", $op, $value); - // we set both _tables & whereTables because whereTables doesn't seem to do what the name implies it should - $this->_tables[$tName] = $this->_whereTables[$tName] = 1; - $this->_qill[$grouping][] = "$field[title] $op '$value'"; - } - else { - list($tableName, $fieldName) = explode('.', $field['where'], 2); - if ($tableName == 'civicrm_contact') { - $fieldName = "LOWER(contact_a.{$fieldName})"; - } - else { - if ($op != 'IN' && !is_numeric($value)) { - $fieldName = "LOWER({$field['where']})"; - } - else { - $fieldName = "{$field['where']}"; - } - } - - $type = NULL; - if (!empty($field['type'])) { - $type = CRM_Utils_Type::typeToString($field['type']); - } - - $this->_where[$grouping][] = self::buildClause($fieldName, $op, $value, $type); - $this->_qill[$grouping][] = "$field[title] $op $value"; - } + $this->_where[$grouping][] = self::buildClause($fieldName, $op, $value, $type); } } @@ -4966,14 +4972,10 @@ SELECT COUNT( conts.total_amount ) as cancel_count, ) { list($name, $op, $value, $grouping, $wildcard) = $values; - if (!$value) { - return; - } - if ($name == "{$fieldName}_low" || $name == "{$fieldName}_high" ) { - if (isset($this->_rangeCache[$fieldName])) { + if (isset($this->_rangeCache[$fieldName]) || !$value) { return; } $this->_rangeCache[$fieldName] = 1; @@ -5048,6 +5050,7 @@ SELECT COUNT( conts.total_amount ) as cancel_count, $value = $value[$op]; } + $date = $format = NULL; if (strstr($op, 'IN')) { $format = array(); foreach ($value as &$date) { @@ -5060,13 +5063,13 @@ SELECT COUNT( conts.total_amount ) as cancel_count, $date = "('" . implode("','", $value) . "')"; $format = implode(', ', $format); } - else { + elseif ($value) { $date = CRM_Utils_Date::processDate($value); if (!$appendTimeStamp) { $date = substr($date, 0, 8); } - $date = "'$date'"; $format = CRM_Utils_Date::customFormat($date); + $date = "'$date'"; } if ($date) { @@ -5075,10 +5078,11 @@ SELECT COUNT( conts.total_amount ) as cancel_count, else { $this->_where[$grouping][] = "{$tableName}.{$dbFieldName} $op"; } + $this->_tables[$tableName] = $this->_whereTables[$tableName] = 1; $op = CRM_Utils_Array::value($op, CRM_Core_SelectValues::getSearchBuilderOperators(), $op); - $this->_qill[$grouping][] = "$fieldTitle $op \"$format\""; + $this->_qill[$grouping][] = "$fieldTitle $op $format"; } } @@ -5681,7 +5685,7 @@ AND displayRelType.is_active = 1 * * @return array */ - public static function buildQillForFieldValue($daoName, $fieldName, $fieldValue, $op, $pseduoExtraParam = array()) { + public static function buildQillForFieldValue($daoName = NULL, $fieldName, $fieldValue, $op, $pseduoExtraParam = array()) { $qillOperators = CRM_Core_SelectValues::getSearchBuilderOperators(); if ($fieldName == 'activity_type_id') { @@ -5690,35 +5694,28 @@ AND displayRelType.is_active = 1 elseif ($daoName == 'CRM_Event_DAO_Event' && $fieldName == 'id') { $pseduoOptions = CRM_Event_BAO_Event::getEvents(0, $fieldValue, TRUE, TRUE, TRUE); } - else { + elseif ($daoName) { $pseduoOptions = CRM_Core_PseudoConstant::get($daoName, $fieldName, $pseduoExtraParam = array()); } - //For those $fieldName which don't have any associated pseudoconstant defined - if (empty($pseduoOptions)) { - if (is_array($fieldValue)) { - $op = key($fieldValue); - $fieldValue = $fieldValue[$op]; - if (is_array($fieldValue)) { - $fieldValue = implode(', ', $fieldValue); - } - } - } - elseif (is_array($fieldValue)) { + if (is_array($fieldValue)) { $qillString = array(); if (in_array(key($fieldValue), CRM_Core_DAO::acceptedSQLOperators(), TRUE)) { $op = key($fieldValue); $fieldValue = $fieldValue[$op]; } - foreach ((array) $fieldValue as $val) { - $qillString[] = $pseduoOptions[$val]; + if (!empty($pseduoOptions)) { + foreach ((array) $fieldValue as $val) { + $qillString[] = $pseduoOptions[$val]; + } + $fieldValue = implode(', ', $qillString); + } + else { + $fieldValue = implode(', ', $fieldValue); } - $fieldValue = implode(', ', $qillString); } - else { - if (array_key_exists($fieldValue, $pseduoOptions)) { - $fieldValue = $pseduoOptions[$fieldValue]; - } + elseif (!empty($pseduoOptions) && array_key_exists($fieldValue, $pseduoOptions)) { + $fieldValue = $pseduoOptions[$fieldValue]; } return array(CRM_Utils_Array::value($op, $qillOperators, $op), $fieldValue); diff --git a/CRM/Contact/Form/Search/Builder.php b/CRM/Contact/Form/Search/Builder.php index 7fab36c8c3..033114b650 100644 --- a/CRM/Contact/Form/Search/Builder.php +++ b/CRM/Contact/Form/Search/Builder.php @@ -269,7 +269,7 @@ class CRM_Contact_Form_Search_Builder extends CRM_Contact_Form_Search { // Validate each value in parenthesis to avoid db errors if (empty($errorMsg)) { $parenValues = array(); - $parenValues = is_array($v[2]) ? $v[2] : explode(',', trim($inVal, "(..)")); + $parenValues = is_array($v[2]) ? (array_key_exists($v[1], $v[2])) ? $v[2][$v[1]] : $v[2] : explode(',', trim($inVal, "(..)")); foreach ($parenValues as $val) { if ($type == 'Date' || $type == 'Timestamp') { $val = CRM_Utils_Date::processDate($val); diff --git a/CRM/Core/BAO/Mapping.php b/CRM/Core/BAO/Mapping.php index 52d5581114..47b1dcfae4 100644 --- a/CRM/Core/BAO/Mapping.php +++ b/CRM/Core/BAO/Mapping.php @@ -1062,7 +1062,8 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping { // CRM-14983: verify if values are comma separated convert to array if (strstr($params['operator'][$key][$k], 'IN') && !is_array($value) && (strpos($value, ',') !== FALSE || strstr($value, '(') || !empty($value)) && empty($isCustomField)) { - $value = explode(',', str_replace(array('(', ')'), '', $value)); + $value = explode(',', trim($value, "(..)")); + $value = array($params['operator'][$key][$k] => $value); } if ($row) {