CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Location API and shares address with
Pages: [1]

Author Topic: Location API and shares address with  (Read 969 times)

SarahG (FountainTribe)

  • Ask me questions
  • ****
  • Posts: 782
  • Karma: 29
  • CiviCRM version: 4.4.7
  • CMS version: Drupal 6, Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.3
Location API and shares address with
January 10, 2011, 07:02:55 am
I am using the location API described at:
http://wiki.civicrm.org/confluence/display/CRMDOC33/Location+APIs

It is working correctly as far as creating a new address for an existing contact.  But the flag for "shares address with" is not being set. 

My current code is:
$loc_params = array('version'    => '3.0',
                        'contact_id' => $cid,
                        'address'    => $tmp_address2
                        );
       
$newLocation =& civicrm_location_add($loc_params);

---------------------
To verify the results, I am running the SQL query:
SELECT contact_id_a AS c_id, contact_id_b AS hh_id
FROM  `civicrm_relationship` rel, civicrm_address addr
WHERE relationship_type_id =  '7'
AND rel.contact_id_a = addr.contact_id
AND is_active =  '1'
AND master_id IS NOT NULL
ORDER BY rel.contact_id_a
LIMIT 0 , 30
Did I help you? Please donate to the Civi-Make-It-Happen campaign  CiviCRM for mobile devices! 

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Location API and shares address with
January 10, 2011, 11:40:55 pm
Sarah - what is in $tmp_address2 ?
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

SarahG (FountainTribe)

  • Ask me questions
  • ****
  • Posts: 782
  • Karma: 29
  • CiviCRM version: 4.4.7
  • CMS version: Drupal 6, Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.3
Re: Location API and shares address with
January 12, 2011, 07:58:11 pm

  $tmp_address2 = array( 1 => array( 'location_type_id'       => 1,
                                      'is_primary'             => 1,
                                      'city'                   => $tmp_address[city],
                                      'state_province'         => $tmp_address[state_province_id],
                                      'street_address'         => $tmp_address[street_address],
                                      'supplemental_address_1' => $tmp_address[supplemental_address_1],
                                      'postal_code'          => $tmp_address[postal_code]                                   
                                       )
                        );
Did I help you? Please donate to the Civi-Make-It-Happen campaign  CiviCRM for mobile devices! 

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Location API and shares address with
January 12, 2011, 08:13:56 pm
You might need to pass in what you want master_id to be too - it won't just pick up that it's the same address it needs you to pass the address id in
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

SarahG (FountainTribe)

  • Ask me questions
  • ****
  • Posts: 782
  • Karma: 29
  • CiviCRM version: 4.4.7
  • CMS version: Drupal 6, Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.3
Re: Location API and shares address with
January 12, 2011, 09:20:31 pm
Eileen - Your suggestion did the trick.   Originally I was passing a parameter on the "contact" API not the Address API, to indicated that the contact shares its address with the household.

This seems like a case where the API version number did not change, yet the behavior changed in a way that was not backward compatible. 



Did I help you? Please donate to the Civi-Make-It-Happen campaign  CiviCRM for mobile devices! 

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Location API and shares address with
January 12, 2011, 09:52:35 pm
the underlying DB (& BAO) changed  - these changes feed through to the api.

The answer to preventing (minimising) things like this in future is to extend our testing so that more attributes are included in the tests and BAO changes cause api tests to fail and we write code in the API for backward compatibility.

Basically each API version release the input params will match the field names (or prefererably their unique names) as the DB changes over time the api will hopefully compensate for changes with some handling code & gradually get messier. When the next version of the api comes out all the messy handling code should get dumped & people would need to switch to an API that reflects the new structure.
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Location API and shares address with

This forum was archived on 2017-11-26.