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 (Moderator: Donald Lobo) »
  • using civicrm_location_get API
Pages: [1]

Author Topic: using civicrm_location_get API  (Read 1687 times)

lcdweb

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1620
  • Karma: 116
    • www.lcdservices.biz
  • CiviCRM version: many versions...
  • CMS version: Joomla/Drupal
  • MySQL version: 5.1+
  • PHP version: 5.2+
using civicrm_location_get API
December 12, 2008, 12:31:50 pm
I would like to add address information to the Dashboard page so that admins can use it as a printable summary of the user details.

So I'm messing with CRM/Contact/Page/View/UserDashBoard.php around line 180, trying to add some code to retrieve the users primary address. I thought I could use the civicrm_location_get API, but I'm thinking it doesn't do what I want it to do. My code chunk looks something like this:

Code: [Select]
require_once 'api/v2/Location.php';
$result = civicrm_location_get( $this->_contactId );

     foreach($result as $key => $value) {
$this->assign( 'LocationId', $value['location_type_id'] );
$this->assign( 'City', $value['city'] );
     }

(I would add additional fields and a conditional clause to retrieve just the primary location info.)

But the only value I've been able to retrieve is the location_type_id. Based on the description of the API, I thought it returned an array with the full set of location fields. Am I wrong in that?
support CiviCRM through 'make it happen' initiatives!
http://civicrm.org/mih

Kurund Jalmi

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4169
  • Karma: 128
    • CiviCRM
  • CiviCRM version: 4.x, future
  • CMS version: Drupal 7, Joomla 3.x
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: using civicrm_location_get API
December 13, 2008, 12:04:28 am
As documented on: http://wiki.civicrm.org/confluence/display/CRMDOC/Location+APIs#LocationAPIs-civicrmlocationget(%24contact)

Quote
// Get all available location details for a contact.
// Pass the Contact Id in proper Name / Value Pair.
$myLocations = civicrm_location_get( array('contact_id' => $contactId) );

Quote
Array
(
    [1] => Array
        (
            [location_type_id] => 3
            [phone] => Array
                (
                    [1] => Array
                        (
                            [id] => 54
                            [contact_id] => 100
                            [location_type_id] => 3
                            [is_primary] => 1
                            [is_billing] => 0
                            [phone] => 21749657
                            [phone_type] => Phone
                            [phone_type_display] => Phone
                        )
          .............

                     [address] => Array
                (
                    [id] => 38
                    [contact_id] => 100
                    [location_type_id] => 3
                    [is_primary] => 1
                    [is_billing] => 0
                    [street_address] => SE 875U Second Rd SE
                    [street_number] => 875
                    ...........
                    ...........

HTh

Kurund
Found this reply helpful? Support CiviCRM

lcdweb

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1620
  • Karma: 116
    • www.lcdservices.biz
  • CiviCRM version: many versions...
  • CMS version: Joomla/Drupal
  • MySQL version: 5.1+
  • PHP version: 5.2+
Re: using civicrm_location_get API
December 13, 2008, 07:05:06 am
Thanks -- that was helpful. I didn't realize the address block was a subarray. I've added this to the wiki doc.

Question --
Since Civi does not allow you to have more than one of the same location_type per contact, why isn't the address information just stored in the first level array?

Also, for this API, it would be useful if it rendered the state_province and country values, instead of just the ids.

support CiviCRM through 'make it happen' initiatives!
http://civicrm.org/mih

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: using civicrm_location_get API
December 13, 2008, 07:35:29 am

1. the restriction on location type is more an artifact of the edit screen rather than the model. That is due for a change in a future 2.x/3.x release

2. We are trying to map the api to how we use functions internally. As such translation option value ids to option value labels is the responsibility of the caller (since in many a case they dont need the translation)

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

lcdweb

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1620
  • Karma: 116
    • www.lcdservices.biz
  • CiviCRM version: many versions...
  • CMS version: Joomla/Drupal
  • MySQL version: 5.1+
  • PHP version: 5.2+
Re: using civicrm_location_get API
December 13, 2008, 07:38:45 am
1.) That's good. I actually prefer the greater flexibility.

2.) Understood. The other location APIs will process name values (add/update), so it seemed strange that "get" wouldn't retrieve the name value, only the id.
support CiviCRM through 'make it happen' initiatives!
http://civicrm.org/mih

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • using civicrm_location_get API

This forum was archived on 2017-11-26.