$where = "`$tName`.$fldName";
$this->_where[$grouping][] = self::buildClause("LOWER($where)", $op, $value);
- $this->_whereTables[$tName] = $this->_tables[$tName];
+ // 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 {
)
)) {
//fix for search by profile with address fields.
- $tName = "{$locationType[$locType[1]]}-address";
+ $tName = "{$locationType[$locType[1]]}_address";
}
elseif ($locType[0] == 'on_hold') {
$tName = "{$locationType[$locType[1]]}-email";
}
/**
+ * Where tables is sometimes used to create the from clause, but, not reliably, set this AND set tables
+ * It's unclear the intent - there is a 'simpleFrom' clause which takes whereTables into account & a fromClause which doesn't
+ * logic may have eroded
* @return array
*/
function whereTables() {
$from .= " $side JOIN civicrm_address ON ( contact_a.id = civicrm_address.contact_id AND civicrm_address.is_primary = 1 )";
}
else {
+ //CRM-14263 further handling of address joins further down...
$from .= " $side JOIN civicrm_address ON ( contact_a.id = civicrm_address.contact_id ) ";
}
continue;
continue;
default:
- $from .= CRM_Core_Component::from($name, $mode, $side);
+ if (strpos($name, '_address') != 0) {
+ //we have a join on an address table - possibly in conjunction with search builder - CRM-14263
+ $parts = explode('_', $name);
+ $locationID = array_search($parts[0], CRM_Core_BAO_Address::buildOptions('location_type_id', 'get', array('name' => $parts[0])));
+ $from .= " $side JOIN civicrm_address $name ON ( contact_a.id = {$name}.contact_id ) and location_type_id = $locationID ";
+ }
+ else {
+ $from .= CRM_Core_Component::from($name, $mode, $side);
+ }
$from .= CRM_Contact_BAO_Query_Hook::singleton()->buildSearchfrom($name, $mode, $side);
continue;
}
}
-
return $from;
}
$this->assertEquals($ids, $contacts, 'In line ' . __LINE__);
}
+
+ /**
+ * CRM-14263 search builder failure with search profile & address in criteria
+ */
+ function testSearchProfile()
+ {
+ $contactID = $this->individualCreate();
+ CRM_Core_Config::singleton()->defaultSearchProfileID = 1;
+ $this->callAPISuccess('address', 'create', array('contact_id' => $contactID, 'city' => 'Cool City', 'location_type_id' => 1,));
+ $params = array(
+ 0 => array(
+ 0 => 'city-1',
+ 1 => '=',
+ 2 => 'Cool City',
+ 3 => 1,
+ 4 => 0,
+ )
+ );
+ $returnProperties = array(
+ 'contact_type' => 1,
+ 'contact_sub_type' => 1,
+ 'sort_name' => 1,
+ );
+
+ $queryObj = new CRM_Contact_BAO_Query($params, $returnProperties);
+ try {
+ $queryObj->searchQuery(0, 0, NULL,
+ FALSE, FALSE,
+ FALSE, FALSE,
+ FALSE);
+ }
+ catch (PEAR_Exception $e) {
+ $err = $e->getCause();
+ $this->fail('invalid SQL created' . $e->getMessage() . " " . $err->userinfo);
+
+ }
+
+}
}
$this->assertEquals($contacts['count'], CRM_Core_DAO::singleValueQuery('select count(*) FROM civicrm_contact WHERE legal_name IS NULL'));
}
- /**
/**
* CRM-14743 - test api respects search operators
*/
$this->assertEquals($contacts['count'], $preExistingContactCount);
}
- /**
/**
* CRM-14743 - test api respects search operators
*/
$contacts = $this->callAPISuccess('contact', 'get', array('created_date' => array('>' => '2014-01-01')));
$this->assertEquals($contacts['count'], $preExistingContactCount);
}
+
+ /**
+ * CRM-14263 check that API is not affected by search profile related bug
+ */
+ function testReturnCityProfile () {
+ $contactID = $this->individualCreate();
+ CRM_Core_Config::singleton()->defaultSearchProfileID = 1;
+ $this->callAPISuccess('address', 'create', array('contact_id' => $contactID, 'city' => 'Cool City', 'location_type_id' => 1,));
+ $result = $this->callAPISuccess('contact', 'get', array('city' => 'Cool City', 'return' => 'contact_type'));
+ $this->assertEquals(1, $result['count']);
+ }
}