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) »
  • EntityRef - How to do multiple value parameters as "OR"
Pages: [1]

Author Topic: EntityRef - How to do multiple value parameters as "OR"  (Read 740 times)

lee.gooding

  • I post occasionally
  • **
  • Posts: 83
  • Karma: 1
    • Clear River Church
  • CiviCRM version: 4.5
  • CMS version: Drupal 7
  • MySQL version: 5.7
  • PHP version: 5.3
EntityRef - How to do multiple value parameters as "OR"
October 07, 2014, 01:39:36 pm
Is there any way to do an API call with parameters that are "OR"? I would like to return only groups that have parents X or Y or Z.

More specifically, I want to do this with the entityRef. I've created an entityRef that is limited to groups. I want to take it a step further and only show groups that have a specific parent (where there are multiple parents that I want children from).

Is there any way to do this?

More detail: I have groups for each day of the week that are parents of small groups that are on that specific day. I'm using the entityRef to look up the small groups so that I can add a contact to the group. I want to keep the list limited to only small groups in order to keep it clean. 

Example group structure:
Wednesday
- Small Group 1
- Small Group 2
Thursday
- Small Group 3
- Small Group 4

I want the entityRef to only list Small Group 1-4.

As a quick fix I've been able to filter based on:
'title'  => array('LIKE' => "%Small Group%")

I'm adding my entity to a form with the following code:
Code: [Select]
$this->addEntityRef('field_smallGroupGroup', ts('Select Small Group'), array(
            'api' => array(
                'params' => array(
               'parents' => 34, // this is one of the several parents I want children returned from
                )),
            'create' => FALSE,
            'entity' => 'group',
            TRUE)
        );
« Last Edit: October 07, 2014, 01:46:08 pm by lee.gooding »

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: EntityRef - How to do multiple value parameters as "OR"
October 07, 2014, 02:45:36 pm
Hey cool, you're the first 3rd party developer I've heard of who is using my new EntityRef code :)
(I'm not counting CiviVolunteer and CiviHR but maybe technically they were first)
Anyway, have you tried exploring it in the api explorer? It provides a choice of operators for each field, I think you want to use the IN operator.
Try asking your question on the new CiviCRM help site.

lee.gooding

  • I post occasionally
  • **
  • Posts: 83
  • Karma: 1
    • Clear River Church
  • CiviCRM version: 4.5
  • CMS version: Drupal 7
  • MySQL version: 5.7
  • PHP version: 5.3
Re: EntityRef - How to do multiple value parameters as "OR"
October 08, 2014, 07:16:49 am
Coleman,

That is pretty cool! EntityRef is great :). Thanks for implementing it!

I have never used the "IN" operator. Is there a specific format I need to set the value as? In the API Explorer setting "Group IDs IN 29" does not return any results. Whereas "Group IDs = 29" returns 7 results.

Quote from: Coleman Watts on October 07, 2014, 02:45:36 pm
Hey cool, you're the first 3rd party developer I've heard of who is using my new EntityRef code :)
(I'm not counting CiviVolunteer and CiviHR but maybe technically they were first)
Anyway, have you tried exploring it in the api explorer? It provides a choice of operators for each field, I think you want to use the IN operator.

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: EntityRef - How to do multiple value parameters as "OR"
October 08, 2014, 10:41:30 am
The API Explorer (being a javascript app) takes input in JSON format. Like this:
Try asking your question on the new CiviCRM help site.

lee.gooding

  • I post occasionally
  • **
  • Posts: 83
  • Karma: 1
    • Clear River Church
  • CiviCRM version: 4.5
  • CMS version: Drupal 7
  • MySQL version: 5.7
  • PHP version: 5.3
Re: EntityRef - How to do multiple value parameters as "OR"
October 08, 2014, 10:57:36 am
That works like a charm. Thanks a ton for this help. This is going to help me in a lot of other ways. I always thought it wasn't possible to do this sort of thing!

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: EntityRef - How to do multiple value parameters as "OR"
October 08, 2014, 10:55:17 pm
Making the impossible plausible - that's what we do on the core team :)

And here's an improvement to make working with these operators a bit easier: https://github.com/civicrm/civicrm-core/pull/4331
Try asking your question on the new CiviCRM help site.

ChrisChinchilla

  • I post occasionally
  • **
  • Posts: 104
  • Karma: 3
  • CiviCRM version: 4.1.2
  • CMS version: Drupal 6 & 7
Re: EntityRef - How to do multiple value parameters as "OR"
November 06, 2014, 03:46:16 am
Any ideas why I can't get this to work? I just get the error

    [message] => IN is not of the type Integer

Here's my code -

   $result = civicrm_api3('Contribution', 'get', array(
    'sequential' => 1,
    'financial_type_id' => array('IN' => array(1,2)),
    'options' => array (
      'limit' => 5,
      'sort' => 'receive_date ASC' // Sets sort order
      ),
    ));
Melbourne CiviCRM meetup group - http://www.meetup.com/MelbourneCiviCRM/

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: EntityRef - How to do multiple value parameters as "OR"
November 06, 2014, 08:42:04 am
Yep, sadly the api is not as standardized as we would all like, and not all fields support every syntax.
But hey, it's way better than apiv2 was, and apiv4 will be even better (yay Doctrine).

Oh, and it looks like a very similar issue was just fixed for another api, maybe this is a good model for how to fix such problems on a field-by-field basis?
https://github.com/civicrm/civicrm-core/pull/4519
Try asking your question on the new CiviCRM help site.

ChrisChinchilla

  • I post occasionally
  • **
  • Posts: 104
  • Karma: 3
  • CiviCRM version: 4.1.2
  • CMS version: Drupal 6 & 7
Re: EntityRef - How to do multiple value parameters as "OR"
November 06, 2014, 11:59:18 pm
So is there any way to have multiple values for a parameter right now?
Melbourne CiviCRM meetup group - http://www.meetup.com/MelbourneCiviCRM/

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • EntityRef - How to do multiple value parameters as "OR"

This forum was archived on 2017-11-26.