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) »
  • $cids in hook tokenvalues always array of size one
Pages: [1]

Author Topic: $cids in hook tokenvalues always array of size one  (Read 740 times)

civi5

  • I post occasionally
  • **
  • Posts: 39
  • Karma: 3
  • CiviCRM version: 4.1
  • CMS version: Drupal 7
  • MySQL version: MySQL 5
  • PHP version: 5.3.6
$cids in hook tokenvalues always array of size one
November 27, 2012, 01:53:50 pm
I have been playing around with creating a few custom tokens in CIVI per this blog
hxxp://civicrm.org/blogs/colemanw/create-your-own-tokens-fun-and-profit

I noticed the the value for $cids is always an array of size one when creating letters.  It seem as though the token_values routine is called multiple times for each item in the search but in each instance $cids is an array with just the current cid as the only member.  On the blog there is always a foreach loop on $cids but it seems to be that it never has more than one item.  Is this just a piece of leftover from when $cid used to be a single value or an array? 

I am trying to optimize the code and I dont want to run 500 independant update queries but it seems that is the case when it executes for letters.  The note on the blog says it updates all in one query but it actually seems to run for each item that was in the search results.

As an aside I noticed that if I send emails then all the contacts get added into the $cids and tokenvalues() is only executed one time.

It seems to me I need to program for 2 cases.  One where $cids is of size 1 and the other where its greater than one.  Does this seem to be correct?  It makes a difference when updating the database if I know that its going to be called once for each item or once for the full search set.

Thanks

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: $cids in hook tokenvalues always array of size one
November 27, 2012, 09:29:03 pm

except for CiviMail all other processes use a fairly inefficient tokens per contact approach and hence u see it for every PDF letter

would be a good optimization to do this in bulk. If you are interested in working on this, ping us on IRC and we can get u started

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

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: $cids in hook tokenvalues always array of size one
February 11, 2013, 05:00:50 pm
When I wrote that blog I was hopeful that this optimization would happen someday (I still am). The hook is forward-thinking in supplying contacts as an array, and your hook implementation should be as well so that a future optimization doesn't break your code.
Try asking your question on the new CiviCRM help site.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • $cids in hook tokenvalues always array of size one

This forum was archived on 2017-11-26.