X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FContact%2FBAO%2FQuery.php;h=f9efcaaf50a32ff26b0eb55f25735af1813e523f;hb=b5d9496b80de7cb199d66140e16ef94c854f9c3c;hp=e291aadaaa1917c1127bc47f79a021611ff3f5c5;hpb=715277e775c784fea1aee24f679011b728c00518;p=civicrm-core.git diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index e291aadaaa..f9efcaaf50 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -1601,7 +1601,9 @@ class CRM_Contact_BAO_Query { } $result = array($id, 'IN', $values, 0, 0); } - elseif ($id == 'contact_type') { + elseif ($id == 'contact_type' || + (!empty($values) && is_array($values) && !in_array(key($values), CRM_Core_DAO::acceptedSQLOperators(), TRUE)) + ) { $result = array($id, 'IN', $values, 0, $wildcard); } else { @@ -1865,26 +1867,7 @@ class CRM_Contact_BAO_Query { } // check for both id and contact_id if ($this->_params[$id][0] == 'id' || $this->_params[$id][0] == 'contact_id') { - if ( - $this->_params[$id][1] == 'IS NULL' || - $this->_params[$id][1] == 'IS NOT NULL' - ) { - $this->_where[0][] = "contact_a.id {$this->_params[$id][1]}"; - } - elseif (is_array($this->_params[$id][2])) { - $idList = implode("','", $this->_params[$id][2]); - //why on earth do they put ' in the middle & not on the outside? We have to assume it's - //to support 'something' so lets add them conditionally to support the api (which is a tested flow - // so if you are looking to alter this check api test results - if (strpos(trim($idList), "'") > 0) { - $idList = "'" . $idList . "'"; - } - - $this->_where[0][] = "contact_a.id IN ({$idList})"; - } - else { - $this->_where[0][] = self::buildClause("contact_a.id", "{$this->_params[$id][1]}", "{$this->_params[$id][2]}"); - } + $this->_where[0][] = self::buildClause("contact_a.id", $this->_params[$id][1], $this->_params[$id][2]); } else { $this->whereClauseSingle($this->_params[$id]); @@ -3589,45 +3572,9 @@ WHERE $smartGroupClause $this->_tables['civicrm_address'] = 1; $this->_whereTables['civicrm_address'] = 1; - $countries = CRM_Core_PseudoConstant::country(); - if (is_numeric($value)) { - $countryClause = self::buildClause( - 'civicrm_address.country_id', - $op, - $value, - 'Positive' - ); - $countryName = $countries[(int ) $value]; - } - - else { - $intValues = self::parseSearchBuilderString($value); - if ($intValues && ($op == 'IN' || $op == 'NOT IN')) { - $countryClause = self::buildClause( - 'civicrm_address.country_id', - $op, - $intValues, - 'Positive' - ); - $countryNames = array(); - foreach ($intValues as $v) { - $countryNames[] = $countries[$v]; - } - $countryName = implode(',', $countryNames); - } - else { - $countries = CRM_Core_PseudoConstant::country(); - $intVal = CRM_Utils_Array::key($value, $countries); - $countryClause = self::buildClause( - 'civicrm_address.country_id', - $op, - $intVal, - 'Integer' - ); - $countryName = $value; - } - } - $countryQill = ts('Country') . " {$op} '$countryName'"; + $countryClause = self::buildClause('civicrm_address.country_id', $op, $value, 'Positive'); + list($qillop, $qillVal) = CRM_Contact_BAO_Query::buildQillForFieldValue(NULL, 'country_id', $value, $op); + $countryQill = ts("%1 %2 %3", array(1 => 'Country', 2 => $qillop, 3 => $qillVal)); if (!$fromStateProvince) { $this->_where[$grouping][] = $countryClause; @@ -5213,6 +5160,7 @@ SELECT COUNT( conts.total_amount ) as cancel_count, } } else { + $op = 'IN'; $dragonPlace = $iAmAnIntentionalENoticeThatWarnsOfAProblemYouShouldReportUsingOldFormat; if (($queryString = CRM_Core_DAO::createSqlFilter($field, array($op => array_keys($value)), $dataType)) != FALSE) { return $queryString; @@ -5535,10 +5483,11 @@ AND displayRelType.is_active = 1 * * @param CRM_Core_DAO $dao * @param bool $return + * @param bool $usedForAPI * * @return array|NULL */ - public function convertToPseudoNames(&$dao, $return = FALSE) { + public function convertToPseudoNames(&$dao, $return = FALSE, $usedForAPI = FALSE) { if (empty($this->_pseudoConstantsSelect)) { return NULL; } @@ -5548,7 +5497,7 @@ AND displayRelType.is_active = 1 continue; } - if (property_exists($dao, $value['idCol'])) { + if (is_object($dao) && property_exists($dao, $value['idCol'])) { $val = $dao->$value['idCol']; if (CRM_Utils_System::isNull($val)) { @@ -5571,13 +5520,16 @@ AND displayRelType.is_active = 1 } // FIX ME: we should potentially move this to component Query and write a wrapper function that // handles pseudoconstant fixes for all component - elseif (in_array($value['pseudoField'], array('participant_status', 'participant_role'))) { - $pseudoOptions = $viewValues = array(); - $pseudoOptions = CRM_Core_PseudoConstant::get('CRM_Event_DAO_Participant', $value['pseudoField'], array('flip' => 1)); - foreach (explode(CRM_Core_DAO::VALUE_SEPARATOR, $val) as $k => $v) { - $viewValues[] = $pseudoOptions[$v]; + elseif (in_array($value['pseudoField'], array('participant_role_id', 'participant_role'))) { + $viewValues = explode(CRM_Core_DAO::VALUE_SEPARATOR, $val); + + if ($value['pseudoField'] == 'participant_role') { + $pseudoOptions = CRM_Core_PseudoConstant::get('CRM_Event_DAO_Participant', 'role_id'); + foreach ($viewValues as $k => $v) { + $viewValues[$k] = $pseudoOptions[$v]; + } } - $dao->$key = implode(', ', $viewValues); + $dao->$key = ($usedForAPI && count($viewValues) > 1) ? $viewValues : implode(', ', $viewValues); } else { $labels = CRM_Core_OptionGroup::values($value['pseudoField']); @@ -5683,6 +5635,9 @@ AND displayRelType.is_active = 1 elseif ($daoName == 'CRM_Contact_DAO_Group' && $fieldName == 'id') { $pseduoOptions = CRM_Core_PseudoConstant::group(); } + elseif ($fieldName == 'country_id') { + $pseduoOptions = CRM_Core_PseudoConstant::country(); + } elseif ($daoName) { $pseduoOptions = CRM_Core_PseudoConstant::get($daoName, $fieldName, $pseduoExtraParam = array()); }