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) »
  • Need better approach for custom token that deals with relationships
Pages: [1]

Author Topic: Need better approach for custom token that deals with relationships  (Read 1017 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
Need better approach for custom token that deals with relationships
August 21, 2010, 04:31:09 am
I  have already implemented a custom mail merge token that deals with relationships.   The current setup is that I have a custom relationship type called "observes in memory of"  that is many-to-many for individuals.  I also have implemented a custom search and a custom mail merge token that utilizes this relationship.

Lets say I have a contact "Josh Smith" who has a "observes in memory of" relationship with "Harry Smith" and "Elana Smith"

When I run my custom search, I will get 2 rows:
mourner        name of deceased
Josh Smith      Harry Smith
Josh Smith      Elana Smith


Next I choose the "send email" action to send emails to Josh Smith. ( Yes, I know he will get 2 emails.) and compose the email using my custom mail merge token.  Currently the token logic grabs every contact that Josh has the "observes in memory of" relationship with. The email then looks like this:
----------------------------
Dear Josh,

blah blah

Name of deceased:
Harry Smith
Elana Smith
--------------------------

Now the issue is I would like to change the mail-merge token to only display "Harry Smith" for the first email for Josh, and only Elana for the second email for Josh.    But the token logic does not seem to have any means of knowing its on the first letter or the second letter.   Any ideas on how to accomplish this?

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

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: Need better approach for custom token that deals with relationships
August 21, 2010, 11:33:13 am

i suspect the easiest way is to do this manipulation in your hook. Remember the number of times the hook was called for a specific id, and only return the n'th result for the n'th call

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

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: Need better approach for custom token that deals with relationships
August 21, 2010, 04:56:52 pm
How would I code my hook to remember how many times it had been called? Where would I store $n, $cid so that I can read its value on the next iteration?
Did I help you? Please donate to the Civi-Make-It-Happen campaign  CiviCRM for mobile devices! 

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Need better approach for custom token that deals with relationships
August 22, 2010, 12:10:03 am
Doesn't work by simply put it in a global variable ?

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

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: Need better approach for custom token that deals with relationships
August 22, 2010, 07:16:02 am
I could put it a global variable, but how would I ensure that when a different user is using the same token ( or the same end-user, running a new search ) does not get the value from the previous or different search?
Did I help you? Please donate to the Civi-Make-It-Happen campaign  CiviCRM for mobile devices! 

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Need better approach for custom token that deals with relationships
August 22, 2010, 07:21:26 am
Quote from: sgladstone on August 22, 2010, 07:16:02 am
I could put it a global variable, but how would I ensure that when a different user is using the same token ( or the same end-user, running a new search ) does not get the value from the previous or different search?

Not sure I understand: a global variable is per page (script) in PHP. So different searches will have different global variables.
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Need better approach for custom token that deals with relationships

This forum was archived on 2017-11-26.