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) »
  • Be able to set a param on token (eg the year for a contribution)
Pages: [1]

Author Topic: Be able to set a param on token (eg the year for a contribution)  (Read 998 times)

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Be able to set a param on token (eg the year for a contribution)
April 13, 2012, 03:04:57 am
Hi,

We need to display the sum of all contributions of a year. Our first approach was to implement two tokendonation_sum_current and donation_sum_previous to cover this year or the previous one (used in two different templates "receipt this year" and "receipt last year".

I was wondering if it wouldn't be a better approach to create a token donation_sum_YYYY (in the token hook) that the user would rename on {donation_sum_2011} or {donation_sum_2012}

on the tokenValue hook, we'd check the list of token to see if there is one that starts with donation_sum_ and parse its name to see what year is requested.

Thought?

X+


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

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: Be able to set a param on token (eg the year for a contribution)
April 13, 2012, 07:20:20 am

there is another thread with eileen on sending parameters to tokens in the last couple of weeks. I think reusing the smarty syntax makes sense (with named params), so something like:

{donation_sum:start=2011-01-01:end=2011-12-31:}

or something like that. We should then ensure that the token parsing considers the above as one token and let the hook do the needful

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

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Be able to set a param on token (eg the year for a contribution)
April 13, 2012, 11:40:34 pm
Ah yes, Tim & I discussed this @ the sprint. Erm, no solution yet ...
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

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Be able to set a param on token (eg the year for a contribution)
April 14, 2012, 12:12:15 am
ok, for now if we agree that we always call the tokenValue, even if the name isn't in the token list, we should be futurerpoof, no matter the syntax.

I'm going to try and think about a syntax (will try if we can use space, = ...)

Something that would be super useful is being able to use variables between token.

eg

{assign:event_id=42}

You can register online <a href="/civicrm/event/register?event_id={$event_id}">...

{event_info} (new token that would fetch and display based on the event_id assigned earlier on)

Aim: having one template that is safer to reuse (the number of times the event id wasn't updated on a url...)
Risk: people likes inventing languages, and it starts smelling like it.





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

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Be able to set a param on token (eg the year for a contribution)
April 14, 2012, 12:25:57 am
OK - so one existing challenge of tokens is that the tokens available through the UI & through smarty are quite different (& sometimes the UI isn't there so people have no idea what is available anyway) so some thought about the interface would also be handy....

BTW - I started refactoring some of that code @ the sprint CRM-9996
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

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Be able to set a param on token (eg the year for a contribution)
April 14, 2012, 04:07:45 pm
Nice work Eileen.
I want to put in my little plug for efficiency. Currenly CiviMail loads tokens in bulk (a recent improvement), whereas other BAOs, (like print PDF letter) load them one at a time. I've been dreaming about a centralized token loader (rather than implementing it ad-hoc by several BAOs) which would always load in bulk.
Try asking your question on the new CiviCRM help site.

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Be able to set a param on token (eg the year for a contribution)
April 14, 2012, 04:17:02 pm
In all honesty I think I'm going to tackle tidying up the code on the one at a time logic & then think about the bulk loading ... later
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

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Be able to set a param on token (eg the year for a contribution)

This forum was archived on 2017-11-26.