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) »
  • Smarty crmAPI sequential
Pages: [1]

Author Topic: Smarty crmAPI sequential  (Read 846 times)

chriscant

  • I post occasionally
  • **
  • Posts: 66
  • Karma: 4
    • PHDCC
  • CiviCRM version: 4.2.19
Smarty crmAPI sequential
December 10, 2012, 10:12:59 am
I'm checking a template after a trial upgrade from 4.0.7 to 4.2.6.
It looks like the results are now returned as sequential.
I tried adding sequential="0" but this didn't work.
Is it true that his change has happened?
How can get a non-sequential associative list back?

Code: [Select]
{crmAPI var="CustomValueS" entity="CustomValue" action="get" version="3" entity_id=$cid sequential="0"}
Thanks Chris

PS This also returns sequential data:
Code: [Select]
{crmAPI var="ContactS" entity="Contact" action="get" version="3" contact_id=$cid }

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Smarty crmAPI sequential
December 10, 2012, 10:38:00 am
Hi,

Probably a while ago the default was modified indeed. Can't recall if before or after 4.0.7, but seems after.

Have you tried sequential=0 (without the quote?) I'm pretty sure I did test and that was a mode "non sequential"

Out of curiosity, could you explain your use case for a non sequential result?  We didn't find it when discussing the best default value
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

chriscant

  • I post occasionally
  • **
  • Posts: 66
  • Karma: 4
    • PHDCC
  • CiviCRM version: 4.2.19
Re: Smarty crmAPI sequential
December 10, 2012, 12:00:15 pm
Using sequential=0 doesn't change the result.

For the Contact case I can change it easily to use array[0].

For the custom values my current code looks like this:
{assign var='Whatever' value=$CustomValueS.values.47.0}
If I got a sequential array I'd have to trawl through each index to find the one with id=47 and then get the latest or 0 value.
(There isn't any field name in the array element to avoid having to have a hard-coded custom value.)
Is there a better way of doing this?

Ta Chris

chriscant

  • I post occasionally
  • **
  • Posts: 66
  • Karma: 4
    • PHDCC
  • CiviCRM version: 4.2.19
Re: Smarty crmAPI sequential
December 11, 2012, 01:12:04 am
Can someone point me in the direction of the crmAPI smarty plugin - or whatever it is called.

Looks like I'd best check all my uses of the api if the default has changed to sequential.

Chris

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Smarty crmAPI sequential
December 11, 2012, 03:09:33 am
It's in CRM/Core/Smarty/plugins/function.crmAPI.php

The relevant code:

Code: [Select]
  if (empty($params['sequential'])) {
    $params['sequential'] = 1;
  }
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

chriscant

  • I post occasionally
  • **
  • Posts: 66
  • Karma: 4
    • PHDCC
  • CiviCRM version: 4.2.19
Re: Smarty crmAPI sequential
December 11, 2012, 07:36:58 am
Unfortunately empty(0) etc returns true.  This works instead:

Code: [Select]
if (!isset($params['sequential']))

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Smarty crmAPI sequential
December 11, 2012, 11:00:37 am
duh, of course!

Could you create an issue?
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

chriscant

  • I post occasionally
  • **
  • Posts: 66
  • Karma: 4
    • PHDCC
  • CiviCRM version: 4.2.19
Re: Smarty crmAPI sequential
December 11, 2012, 11:32:38 am
I've created http://issues.civicrm.org/jira/browse/CRM-11448
but am not set up to make a patch easily.
I said it would take 1h though it may well take less given my proposed solution.
Chris

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Smarty crmAPI sequential
December 30, 2012, 06:38:21 am
Done

X+
-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 »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Smarty crmAPI sequential

This forum was archived on 2017-11-26.