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) »
  • Address fragment fields
Pages: [1]

Author Topic: Address fragment fields  (Read 663 times)

xcf33

  • I post frequently
  • ***
  • Posts: 181
  • Karma: 7
  • CiviCRM version: 3.3.2
  • CMS version: Drupal 6.19/6.20
  • MySQL version: 5.x
  • PHP version: 5.2.6
Address fragment fields
May 31, 2011, 02:52:00 pm
Hi Guys,

In Civi's database we have

street_number
street_number_suffix
street_number_predirectional
street_name
street_type

etc etc

which are address fragments, however I don't think these fields are exposed to the API (at least not API v2).

I'm looking to import address fragments because it's easier to use civicampaign, proximately search etc if you have address broken out.

I can always write a cron script to parse the "street_address" out but it would not always be reliable.

I already have all the fields broken out in my import file , is there any easy way to do this?


Thank you,


Cheers!

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Address fragment fields
May 31, 2011, 02:56:17 pm
Hi,

those fields are available to the create api (in v3 anyway -not sure v2). But you have to build up the 'street_address' field yourself. Here's a piece out of some code I am using (
https://svn.fuzion.co.nz/repos/fuzion-code/trunk/drupal/modules/custom/civimigrate/civimigrate.address.inc)

    $params['version'] = '3.0';
    $params['check_permissions'] = $params['check_permission'] = FALSE;

   if (empty($params['street_address'])) {
               $addressComponents = array();
               if(!empty($params['street_number'])){
                $addressComponents[] = $params['street_number']  ;
               }
                 if(!empty($params['street_number_suffix'])){
                $addressComponents[] = $params['street_number_suffix']  ;
               }
                if(!empty($params['street_unit'])){
                $addressComponents[] = $params['street_unit']  ;
               }
                if(!empty($params['street_name'])){
                $addressComponents[] = $params['street_name']  ;
               }
          $params['street_address'] = implode(" ",  $addressComponents);
             }
             if (empty($params['street_address']))unset ($params['street_address']);

        $result  = civicrm_api('Address', 'Create',$params);

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

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: Address fragment fields
June 01, 2011, 09:56:54 am
The only other thing you could do is customize the streetParse function in CRM/Core/BAO/Adress.php. I have done that to support Dutch street parsing formats (which I still need to adapt for core....hopefully next month.... ;D). But the easiest bit is to create street_address yourself in your wrapper
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Address fragment fields

This forum was archived on 2017-11-26.