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) »
  • CiviMail Tokens and Relationships..
Pages: [1]

Author Topic: CiviMail Tokens and Relationships..  (Read 2436 times)

vanalive

  • I post occasionally
  • **
  • Posts: 35
  • Karma: 1
CiviMail Tokens and Relationships..
March 09, 2010, 12:37:44 am
I want to pull relationship data and plunk it into CiviMail email.  I think this can be done through a hook_civicrm_tokens( &$tokens ), but I couldn't find any examples or info on the civicrm_tokens api.    Has anyone used custom tokens and have a snippet I could look at?

I was having trouble getting views to have a user filter with civicrm relationships so this is basically the code that works to expose civicrm relationship info and a few custom fields to drupal.  Would this work for a straight hook?

<?php
global $user;
civicrm_initialize(true);
require_once 'CRM/Core/Config.php';
require_once 'CRM/Core/Error.php';
$config = CRM_Core_Config::singleton( );
require_once 'api/v2/Contact.php';
require_once 'api/v2/Group.php';
require_once 'api/v2/GroupContact.php';
require_once 'api/v2/Relationship.php';
     require_once 'api/UFGroup.php';

$userID = crm_uf_get_match_id( $user->uid );



    $params = array(
                    'contact_id' => $userID,
                    );

    $result = civicrm_contact_relationship_get($params, array(), array('Federal Constituent of') );
    if ( civicrm_error ( $result )) {
        return $result['error_message'];
    } else {
extract ($result);
foreach ($result as &$relation){
$name = $relation['display_name'];
$email = $relation['email'];
$phone = $relation['phone'];
$contactid = $relation['cid'];
}
$retrieve = array( 'contact_id'             => $contactid,
 'return.sort_name'  => 1,
                                  'return.custom_13'   => 1,
 'return.street_address'   => 1,
 'return.city'   => 1,

                         );
$yourmp = civicrm_contact_get($retrieve);

extract ($yourmp);
foreach ($yourmp as &$yourmp2){
$address = $yourmp2['street_address'];
$city = $yourmp2['city'];
$party = $yourmp2['custom_13'];
}

echo 'Your MP is ' . $name . ' (' . $party . ')
<br>Their email is ' .$email  . '
<br>Their phone is ' .$phone . '
<br>Their address is ' .$address . ', ' .$city;
}
?>

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: CiviMail Tokens and Relationships..
March 09, 2010, 01:25:17 am
Have a look at this code, that implement salutation token.

http://blog.civicrm.org/blogs/sgladstone/dealing-joint-greetings-part-2-code-provided
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

vanalive

  • I post occasionally
  • **
  • Posts: 35
  • Karma: 1
Re: CiviMail Tokens and Relationships..
March 09, 2010, 01:51:45 am
Wow thanks.. What is the difference between civicrm_tokens and civicrm_tokenvalues?  And is it just a simple return on the function to get civicrm to replace the token?

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: CiviMail Tokens and Relationships..
March 09, 2010, 07:40:11 am

check:

http://civicrm.org/node/480

http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+hook+specification#CiviCRMhookspecification-hookcivicrmtokens

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

kurosevic

  • I’m new here
  • *
  • Posts: 25
  • Karma: 1
Re: CiviMail Tokens and Relationships..
May 17, 2010, 08:21:15 am
oh nice! this sounds lovely. I'm going to try to tokenize drupal node content using custom tokens instead.

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

This forum was archived on 2017-11-26.