* @param bool $smartGroupCache
* @param null $displayRelationshipType
* @param string $operator
+ * @param string $apiEntity
*
* @return \CRM_Contact_BAO_Query
*/
$includeContactIds = FALSE, $strict = FALSE, $mode = 1,
$skipPermission = FALSE, $searchDescendentGroups = TRUE,
$smartGroupCache = TRUE, $displayRelationshipType = NULL,
- $operator = 'AND'
+ $operator = 'AND',
+ $apiEntity = NULL
) {
+
$this->_params = &$params;
if ($this->_params == NULL) {
$this->_params = array();
}
// basically do all the work once, and then reuse it
- $this->initialize();
+ $this->initialize($apiEntity);
}
/**
* Function which actually does all the work for the constructor.
*/
- public function initialize() {
+ public function initialize($apiEntity = NULL) {
$this->_select = array();
$this->_element = array();
$this->_tables = array();
$this->_whereTables = $this->_tables;
- $this->selectClause();
+ $this->selectClause($apiEntity);
$this->_whereClause = $this->whereClause();
if (array_key_exists('civicrm_contribution', $this->_whereTables)) {
$component = 'contribution';
/**
* Some composite fields do not appear in the fields array hack to make them part of the query.
*/
- public function addSpecialFields() {
+ public function addSpecialFields($apiEntity) {
static $special = array('contact_type', 'contact_sub_type', 'sort_name', 'display_name');
+ // if get called via Contact.get API having address_id as return parameter
+ if ($apiEntity == 'Contact') {
+ $special[] = 'address_id';
+ }
foreach ($special as $name) {
if (!empty($this->_returnProperties[$name])) {
- $this->_select[$name] = "contact_a.{$name} as $name";
- $this->_element[$name] = 1;
+ if ($name == 'address_id') {
+ $this->_tables['civicrm_address'] = 1;
+ $this->_select['address_id'] = 'civicrm_address.id as address_id';
+ $this->_element['address_id'] = 1;
+ }
+ else {
+ $this->_select[$name] = "contact_a.{$name} as $name";
+ $this->_element[$name] = 1;
+ }
}
}
}
* tables, the initial attempt also retrieves all variables used
* in the params list
*/
- public function selectClause() {
+ public function selectClause($apiEntity = NULL) {
- $this->addSpecialFields();
+ $this->addSpecialFields($apiEntity);
foreach ($this->_fields as $name => $field) {
// skip component fields
$smartGroupCache = TRUE,
$count = FALSE,
$skipPermissions = TRUE,
- $mode = 1
+ $mode = 1,
+ $apiEntity = NULL
) {
$query = new CRM_Contact_BAO_Query(
$params, $returnProperties,
NULL, TRUE, FALSE, $mode,
$skipPermissions,
- TRUE, $smartGroupCache
+ TRUE, $smartGroupCache,
+ NULL, 'AND',
+ $apiEntity
);
//this should add a check for view deleted if permissions are enabled
}
/**
- * Check that address name is returned if required.
+ * Check that address name, ID is returned if required.
*/
- public function testGetReturnAddressName() {
+ public function testGetReturnAddress() {
$contactID = $this->individualCreate();
- $this->callAPISuccess('address', 'create', array(
+ $result = $this->callAPISuccess('address', 'create', array(
'contact_id' => $contactID,
'address_name' => 'My house',
'location_type_id' => 'Home',
'street_address' => '1 my road',
));
+ $addressID = $result['id'];
+
$result = $this->callAPISuccessGetSingle('contact', array(
- 'return' => 'address_name, street_address',
+ 'return' => 'address_name, street_address, address_id',
'id' => $contactID,
));
+ $this->assertEquals($addressID, $result['address_id']);
$this->assertEquals('1 my road', $result['street_address']);
$this->assertEquals('My house', $result['address_name']);