<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.4 |
+ | CiviCRM version 4.5 |
+--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013 |
+ | Copyright CiviCRM LLC (c) 2004-2014 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
/**
*
* @package CRM
- * @copyright CiviCRM LLC (c) 2004-2013
+ * @copyright CiviCRM LLC (c) 2004-2014
* $Id$
*
*/
*/
public static $_openedPanes = array();
+ /**
+ * For search builder - which custom fields are location-dependent
+ * @var array
+ */
+ public $_locationSpecificCustomFields = array();
+
/**
* The tables which have a dependency on location and/or address
*
// also get the id of the tableName
$tName = substr($tableName, 8);
if (in_array($tName, array('country', 'state_province', 'county'))) {
- $pf = ($tName == 'state_province') ? 'state_province_name' : $name;
- $this->_pseudoConstantsSelect[$pf] =
- array('pseudoField' => "{$tName}_id", 'idCol' => "{$tName}_id", 'bao' => 'CRM_Core_BAO_Address',
- 'table' => "civicrm_{$tName}", 'join' => " LEFT JOIN civicrm_{$tName} ON civicrm_address.{$tName}_id = civicrm_{$tName}.id ");
-
if ($tName == 'state_province') {
+ $this->_pseudoConstantsSelect['state_province_name'] =
+ array('pseudoField' => "{$tName}", 'idCol' => "{$tName}_id", 'bao' => 'CRM_Core_BAO_Address',
+ 'table' => "civicrm_{$tName}", 'join' => " LEFT JOIN civicrm_{$tName} ON civicrm_address.{$tName}_id = civicrm_{$tName}.id ");
+
$this->_pseudoConstantsSelect[$tName] =
array('pseudoField' => 'state_province_abbreviation', 'idCol' => "{$tName}_id",
'table' => "civicrm_{$tName}", 'join' => " LEFT JOIN civicrm_{$tName} ON civicrm_address.{$tName}_id = civicrm_{$tName}.id ");
}
+ else {
+ $this->_pseudoConstantsSelect[$name] =
+ array('pseudoField' => "{$tName}_id", 'idCol' => "{$tName}_id", 'bao' => 'CRM_Core_BAO_Address',
+ 'table' => "civicrm_{$tName}", 'join' => " LEFT JOIN civicrm_{$tName} ON civicrm_address.{$tName}_id = civicrm_{$tName}.id ");
+ }
$this->_select["{$tName}_id"] = "civicrm_address.{$tName}_id as {$tName}_id";
$this->_element["{$tName}_id"] = 1;
$this->_select[$name] = "contact_a.{$fieldName} as `$name`";
}
}
- elseif (in_array($tName, array('state_province', 'country', 'county'))) {
- $this->_pseudoConstantsSelect[$pf]['select'] = "{$field['where']} as `$name`";
- $this->_pseudoConstantsSelect[$pf]['element'] = $name;
- if ($tName == 'state_province') {
- $this->_pseudoConstantsSelect[$tName]['select'] = "{$field['where']} as `$name`";
- $this->_pseudoConstantsSelect[$tName]['element'] = $name;
- }
+ elseif (in_array($tName, array('country', 'county'))) {
+ $this->_pseudoConstantsSelect[$name]['select'] = "{$field['where']} as `$name`";
+ $this->_pseudoConstantsSelect[$name]['element'] = $name;
+ }
+ elseif ($tName == 'state_province') {
+ $this->_pseudoConstantsSelect[$tName]['select'] = "{$field['where']} as `$name`";
+ $this->_pseudoConstantsSelect[$tName]['element'] = $name;
}
else {
$this->_select[$name] = "{$field['where']} as `$name`";
CRM_Contact_BAO_Query_Hook::singleton()->alterSearchQuery($this, 'select');
if (!empty($this->_cfIDs)) {
- $this->_customQuery = new CRM_Core_BAO_CustomQuery($this->_cfIDs, TRUE);
+ $this->_customQuery = new CRM_Core_BAO_CustomQuery($this->_cfIDs, TRUE, $this->_locationSpecificCustomFields);
$this->_customQuery->query();
$this->_select = array_merge($this->_select, $this->_customQuery->_select);
$this->_element = array_merge($this->_element, $this->_customQuery->_element);
}
foreach ($this->_params as $id => $values) {
- if ($values[0] == $nm ||
+ if ((is_array($values) && $values[0] == $nm) ||
(in_array($elementName, array('phone', 'im'))
&& (strpos($values[0], $nm) !== FALSE)
)
}
if (!empty($addressCustomFieldIds)) {
- $cfIDs = $addressCustomFieldIds;
- $customQuery = new CRM_Core_BAO_CustomQuery($cfIDs);
+ $customQuery = new CRM_Core_BAO_CustomQuery($addressCustomFieldIds);
foreach ($addressCustomFieldIds as $cfID => $locTypeName) {
foreach ($locTypeName as $name => $dnc) {
+ $this->_locationSpecificCustomFields[$cfID] = array($name, array_search($name, $locationTypes));
$fieldName = "$name-custom_{$cfID}";
$tName = "$name-address-custom-{$cfID}";
$aName = "`$name-address-custom-{$cfID}`";
case 'activity_subject':
case 'test_activities':
case 'activity_type_id':
+ case 'activity_type':
case 'activity_survey_id':
case 'activity_tags':
case 'activity_taglist':
if ($returnQuery) {
return $query;
}
-
if ($count) {
return CRM_Core_DAO::singleValueQuery($query);
}