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) »
  • How to add existing addresses to event 'existing locations'
Pages: [1]

Author Topic: How to add existing addresses to event 'existing locations'  (Read 580 times)

jere

  • I post occasionally
  • **
  • Posts: 41
  • Karma: 1
  • CiviCRM version: 4.3.3
  • CMS version: Drupal 7.22
  • MySQL version: 5.5.31
  • PHP version: 5.3.10
How to add existing addresses to event 'existing locations'
November 07, 2013, 08:10:05 am
I would like to add addresses for selected organization contacts who serve as venues to the "use existing location" drop down for easy selection by administrative users entering events. I was looking at using triggers to manage adding or removing them to/from the loc_block table  based on either a new location_type (say "Venue" type) for the address or a contact_sub_type for the associated contact. I was thinking of also using triggers for emails and phones that would find existing loc_block entries for addresses and update those entries on inserts, update or deletions.

I was ready to try it, but found you are already using the triggers for updating the modified date on the contact table, and I would have to modify your triggers to add my own functionality.

The effects of upgrades makes this a less attractive option. Is there an easier or better way? Can I use a hook?

Thanks
« Last Edit: November 07, 2013, 08:27:08 am by jere »

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: How to add existing addresses to event 'existing locations'
November 07, 2013, 09:23:17 am

You can use the trigger hook to add your "custom trigger code" to civicrm triggers (and get around the mysql allows only one trigger rule)

civi collects all the trigger info and creates one trigger (with multiple statements if needed)

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

jere

  • I post occasionally
  • **
  • Posts: 41
  • Karma: 1
  • CiviCRM version: 4.3.3
  • CMS version: Drupal 7.22
  • MySQL version: 5.5.31
  • PHP version: 5.3.10
Re: How to add existing addresses to event 'existing locations'
November 07, 2013, 11:11:00 am
I don't find  the trigger hook in the hook documentation. When I google Trigger and Hook I find references to it, but do not see a way to use it.

I did find this in the CRM_Utils_Hook class:
Code: [Select]
/**
   * This hook collects the trigger definition from all components
   *
   * @param $triggerInfo reference to an array of trigger information
   *   each element has 4 fields:
   *     table - array of tableName
   *     when  - BEFORE or AFTER
   *     event - array of eventName - INSERT OR UPDATE OR DELETE
   *     sql   - array of statements optionally terminated with a ;
   *             a statement can use the tokes {tableName} and {eventName}
   *             to do token replacement with the table / event. This allows
   *             templatizing logging and other hooks
   * @param string $tableName (optional) the name of the table that we are interested in only
   */
  static function triggerInfo(&$info, $tableName = NULL) {
    return self::singleton()->invoke(2, $info, $tableName,
      self::$_nullObject, self::$_nullObject,
      self::$_nullObject,
      'civicrm_triggerInfo'
    );
  }

Would I use this in this in my module in this form: mymodule_civicrm_triggerInfo($info, $tableName) and use the information  in comments above the function declaration to add my information to the $info array like this: $info['table'] = 'civicrm_address'; $info['when'] = 'AFTER'; ...ETC?  In the $info['sql'] would I start with 'BEGIN' and end with 'END' or just list the statements?

When is it called?

Thanks
------------------- modified
This does not seem right. I see that there is an array of tablenames passed, the string either 'BEFORE' or 'AFTER', array of events, and an array of sql (From "BEGIN" to "END?). I only need 'AFTER' , but otherwise it would need to be called twice it seems. So $info is an array with the 1st, 3rd, 4th elements being arrays and the second a string. Is it called in the custom module like other hooks? Is the hook called every time an INSERT, UPDATE, or DELETE action takes place on one of the tables?

« Last Edit: November 07, 2013, 12:18:29 pm by jere »

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • How to add existing addresses to event 'existing locations'

This forum was archived on 2017-11-26.