}
$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 {
}
// 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]);
}
else {
$field = 'civicrm_address.postal_code';
- $val = CRM_Utils_Type::escape($value, 'String');
+ // Per CRM-17060 we might be looking at an 'IN' syntax so don't case arrays to string.
+ if (!is_array($value)) {
+ $val = CRM_Utils_Type::escape($value, 'String');
+ }
+ else {
+ // Do we need to escape values here? I would expect buildClause does.
+ $val = $value;
+ }
}
$this->_tables['civicrm_address'] = $this->_whereTables['civicrm_address'] = 1;
$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;
$clause = " (NULLIF($field, '') IS NOT NULL) ";
return $clause;
+ case 'IN':
+ case 'NOT IN':
+ // I feel like this would be escaped properly if passed through $queryString = CRM_Core_DAO::createSqlFilter.
+ if (!empty($value) && is_array($value) && !array_key_exists($op, $value)) {
+ $value = array($op => $value);
+ }
+
default:
if (empty($dataType)) {
$dataType = 'String';
}
}
else {
+ $op = 'IN';
$dragonPlace = $iAmAnIntentionalENoticeThatWarnsOfAProblemYouShouldReportUsingOldFormat;
if (($queryString = CRM_Core_DAO::createSqlFilter($field, array($op => array_keys($value)), $dataType)) != FALSE) {
return $queryString;
*
* @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;
}
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)) {
}
// 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']);
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());
}