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) »
  • civicrm_participant_search is only searching on contact_id
Pages: [1]

Author Topic: civicrm_participant_search is only searching on contact_id  (Read 1348 times)

dafeder

  • I’m new here
  • *
  • Posts: 20
  • Karma: 0
  • CiviCRM version: 3.3
  • CMS version: Drupal 6
  • MySQL version: 5.092
  • PHP version: 5.2
civicrm_participant_search is only searching on contact_id
May 03, 2011, 06:39:03 am
I'm trying to get a list of events that the logged-in user is a participant in with a certain role. I can get a list of all events the user is a participant in using civicrm_participant_search(), but no params except contact_id make it into the query.

Code: [Select]
if ( $contactID ) {
  require_once "api/v2/Participant.php";
  $params = array(
    'contact_id' => $contactID,
    'role_id' => 6,
  );
  $participants =& civicrm_participant_search($params);
  [...]
}

However, this gets me the list of all events this contact is registered for, not just the ones where he has role 6. When I debug the where clause in the sql, this is what it shows me:

Code: [Select]
WHERE  ( contact_a.id = 1 )

and that's it.

Any ideas? I've tried this with other params too. Why is cleaning all my params except contact_id?

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: civicrm_participant_search is only searching on contact_id
May 03, 2011, 02:08:11 pm
I wrote a test for this to see how it works against v3 api - passing in role_id resulted in no filtering. Passing in participant_role_id gave error "Illegal offset type"

So, I guess there is definitely something broken.

So, ideally you would upgrade to v3 & debug it....

The errror is somewhere in here  - in the utils.php file

        case 'participant_role':
            $role = CRM_Event_PseudoConstant::participantRole();
            $participantRoles = explode( ",", $value );
            foreach ( $participantRoles as $k => $v ) {
                $v = trim( $v );
                if (  $key == 'participant_role' ) {
                    $participantRoles[$k] = CRM_Utils_Array::key( $v, $role );
                } else {
                    $participantRoles[$k] = $v;
                }
            }
            require_once 'CRM/Core/DAO.php';
            $values['role_id'] = implode( CRM_Core_DAO::VALUE_SEPARATOR, $participantRoles );
            unset( $values[$key] );
            break;


Pasted below is the v3 test.

    /**
     * check get with role id - create 2 registrations with different roles.
     * Test that get without role var returns 2 & with returns one
     */
    function testGetParamsRole()
    {
       $participantRole2 = civicrm_api('Participant', 'Create', array('version' => 3, 'id' => $this->_participantID2, 'role_id' => 2));
       
        $params = array(
                       
                        'version'                     => $this->_apiversion,
                     
                        );
        $result = & civicrm_api3_participant_get($params);
        $this->assertEquals($result['is_error'], 0);
        $this->assertEquals($result['count'], 3);
     
        $params['participant_role_id'] =2;
        $result = & civicrm_api3_participant_get($params);
        $this->assertEquals($result['is_error'], 0, $result['error_message'] . "in line  " . __LINE__);
        $this->assertEquals(2,$result['count'], "in line  " . __LINE__);     
        $this->documentMe($params,$result ,__FUNCTION__,__FILE__);
   }
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

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: civicrm_participant_search is only searching on contact_id
May 03, 2011, 03:11:34 pm
Actually - it's possible that it's a test suite problem as this seems to be the failure in the test suite

            $role = CRM_Event_PseudoConstant::participantRole();

So, try with $params['participant_role_id']
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

dafeder

  • I’m new here
  • *
  • Posts: 20
  • Karma: 0
  • CiviCRM version: 3.3
  • CMS version: Drupal 6
  • MySQL version: 5.092
  • PHP version: 5.2
Re: civicrm_participant_search is only searching on contact_id
May 03, 2011, 06:25:11 pm
I also get an illegal offset type if I user participant_role_id.

I'll do my best to debug and report the results here.

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: civicrm_participant_search is only searching on contact_id
May 03, 2011, 06:28:02 pm
Cool - I logged an issue:

http://issues.civicrm.org/jira/browse/CRM-8023
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

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: civicrm_participant_search is only searching on contact_id
May 03, 2011, 08:56:45 pm

try this way:

Code: [Select]
    require_once "api/v2/Participant.php";
    $params = array(
                    'participant_role_id' => array( 3 => 1 ),
                    );
    $participants =& civicrm_participant_search($params);
    print_r( $participants );


You can also send in a contact_id / other parameters to restrict it further

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

dafeder

  • I’m new here
  • *
  • Posts: 20
  • Karma: 0
  • CiviCRM version: 3.3
  • CMS version: Drupal 6
  • MySQL version: 5.092
  • PHP version: 5.2
Re: civicrm_participant_search is only searching on contact_id
May 03, 2011, 09:00:24 pm
Hi Donald - sorry if I'm missing something, but what do the key and value of that array represent? Is it always [role_id] => 1?

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: civicrm_participant_search is only searching on contact_id
May 03, 2011, 09:05:03 pm

oops sorry, yes, its an array of

[role_id 1] => 1
[role_id 2] => 1
...

u can send in more than one role id, and it does an OR on them

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: civicrm_participant_search is only searching on contact_id
May 03, 2011, 09:06:17 pm
Note that we'll probably tweak this in apiv3 to being either

'role_id' = 3,
or

'role_id' = array(1,2,3),

Will update this thread later with that
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

dafeder

  • I’m new here
  • *
  • Posts: 20
  • Karma: 0
  • CiviCRM version: 3.3
  • CMS version: Drupal 6
  • MySQL version: 5.092
  • PHP version: 5.2
Re: civicrm_participant_search is only searching on contact_id
May 04, 2011, 10:32:12 am
THank you! So, this got rid of the error message and works (using participant_role_id and the array structure described).

Now, I have something else very strange going on. I'm using this to customize the options in a custom select list field, in hook_civicrm_customFieldOptions(). When I add a participant_role_id param, it replaces my $options array with a list of active roles after running civicrm_participant_search()! Here is the relevant code so you can see where I'm debugging:

Code: [Select]

        require_once "api/v2/Participant.php";
        $params = array(
          'contact_id' => $contactID,
          'participant_role_id' => array(6 => 1),
        );
        dsm(print_r($options, true));
        $participants = civicrm_participant_search($params);
        dsm(print_r($options, true));

The output from those two dsm()s is:

Code: [Select]
Array
(
    [0] => None
)
Array
(
    [1] => Attendee
    [5] => Instructor
    [6] => Student
)

Now, of course I can correct this by just clearing the $options array after calling civicrm_participant_search and building it from scratch, so I don't really need any more help. But I'm very curious how this is happening, and how it's even possible.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • civicrm_participant_search is only searching on contact_id

This forum was archived on 2017-11-26.