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) »
  • Support »
  • Using CiviCRM »
  • Using CiviEvent (Moderator: Yashodha Chaku) »
  • listing some participants using API
Pages: [1]

Author Topic: listing some participants using API  (Read 717 times)

amidinette

  • I’m new here
  • *
  • Posts: 6
  • Karma: 0
  • CiviCRM version: 4.4.5
  • CMS version: drupal 7.x
  • MySQL version: 5.5
  • PHP version: 5.4
listing some participants using API
June 17, 2014, 05:00:11 am
Hi,

I'm trying create a view in Drupal to list some participants using the api.
I've started with the function from this thread http://forum.civicrm.org/index.php/topic,25690.msg108782.html#msg108782 which works fine but I wanted to add a couple of filters : only attendee and only certain status: registered, pending etc.

using this :

Code: [Select]
$params['id']=$row->id; //$row->id is the civi event id variable supplied by drupal views
  $params = array('event_id' => $params['id'], 'version' => 3,'participant_status_id' => 1, 'participant_role_id' => 1,);
  $getParticipants= civicrm_api("Participant","getcount", $params);
  $total=$getParticipants;
  return $total;

I get the list of participants with status registered and attendee role. but I can't work out how to add other participant status ids.
is there a way to list participants with status 1 or 2 or 5 etc ?
'participant_status_id' => ('1' OR '2')  something like that ?

sorry if this is a silly question ; I have to add I don't know much about PHP... I'm learning (the hard way)

thanks
 

petednz

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4899
  • Karma: 193
    • Fuzion
  • CiviCRM version: 3.x - 4.x
  • CMS version: Drupal 6 and 7
Re: listing some participants using API
June 17, 2014, 02:08:08 pm
is this something that the normal Views - Civi integration doesn't provide?
Sign up to StackExchange and get free expert advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

pete davis : www.fuzion.co.nz : connect + campaign + communicate

amidinette

  • I’m new here
  • *
  • Posts: 6
  • Karma: 0
  • CiviCRM version: 4.4.5
  • CMS version: drupal 7.x
  • MySQL version: 5.5
  • PHP version: 5.4
Re: listing some participants using API
June 18, 2014, 02:54:28 am
Hi petednz
yes its is possible to filter participant type/ roles etc if I create a view for Participant, but in that case I only manage to get the list of events which have participants.
To list all events I create a view for Event but then I don't have the option to use the view filter for participant status.

is there a way to use AND / OR with 'participant_status_id'?
otherwise is it possible to use 'participant_status_id'  or maybe ParticipantStatusType is_counted (although not exactly the same thing in my case) as a php filter in view?

thanks

petednz

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4899
  • Karma: 193
    • Fuzion
  • CiviCRM version: 3.x - 4.x
  • CMS version: Drupal 6 and 7
Re: listing some participants using API
June 18, 2014, 01:27:52 pm
from memory is there a Relationships that is needing to be created for Views so that one can have an Event based View but still get access to all the Participant data?

if so, are you up for the challenge ;-)
Sign up to StackExchange and get free expert advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

pete davis : www.fuzion.co.nz : connect + campaign + communicate

amidinette

  • I’m new here
  • *
  • Posts: 6
  • Karma: 0
  • CiviCRM version: 4.4.5
  • CMS version: drupal 7.x
  • MySQL version: 5.5
  • PHP version: 5.4
Re: listing some participants using API
June 18, 2014, 06:09:08 pm
Hi
The only two relationships I can see listed  if I create an Event view are :
 CiviCRM Events: Campaign
CiviCRM Phone Details: Contact ID
.....I think I'm going to eat that gauntlet you've thrown down.

What I'm trying to do should be straight forward : list all events and display a count of attendees (registered or pending to pay later. ) and the number of available space for each event. If there is no attendees return the max participants.

As I said I can do this in a view of Participant with event id as relationship, using aggregation to count participant ids then using filter for selecting status and maths expression to subtract from the max participant.

But as I mentioned this only return events which have participants. Am I missing something here ?

Anyway that's why I'm trying to use the php function to filter by status, (which might be useful for non Views user too.) is it possible or am I chasing a wild goose ?

Thanks
« Last Edit: June 18, 2014, 06:15:14 pm by amidinette »

petednz

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4899
  • Karma: 193
    • Fuzion
  • CiviCRM version: 3.x - 4.x
  • CMS version: Drupal 6 and 7
Re: listing some participants using API
June 18, 2014, 07:38:13 pm
My views-expert colleague if off sick currently - but take a look at the views_civicrm module code, check the relationships that exist, and see if you can figure the pattern for adding a Relationship that will get you Participants from an Events-based view.

and yes it makes sense (to me) that you won't get a list of events from a Participant based view if the event has no participants
Sign up to StackExchange and get free expert advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

pete davis : www.fuzion.co.nz : connect + campaign + communicate

amidinette

  • I’m new here
  • *
  • Posts: 6
  • Karma: 0
  • CiviCRM version: 4.4.5
  • CMS version: drupal 7.x
  • MySQL version: 5.5
  • PHP version: 5.4
Re: listing some participants using API
June 19, 2014, 03:10:37 am
Hi Pete

I appreciate you giving me pointers ( and I'm looking into the civi views files just now) but I'm not sure that modifying any of these files is a better solution for me than simply using the API.
(mainly from a maintenance point of view)

Although I think it would be useful to have this relationship setup "by default" ( maybe it's already on someone huge to do list) and will definitely post back if I manage to do it.

But in the mean time ...is it possible to use AND / OR with the Api ? :)

Thanks

amidinette

  • I’m new here
  • *
  • Posts: 6
  • Karma: 0
  • CiviCRM version: 4.4.5
  • CMS version: drupal 7.x
  • MySQL version: 5.5
  • PHP version: 5.4
Re: listing some participants using API
June 19, 2014, 05:27:45 am
 Hi
almost there with Views

I've added to the civicrm.event.inc :

    $data['civicrm_participant']['table']['join'] = array(
    'civicrm_event' => array(
      'left_field' => 'id',
      'left' => 'event_id',
    ),
  );

and now have the option for participants in the relationship and participants fields .. but I get this error too :

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LEFT JOIN civicrm_event civicrm_event_civicrm_participant ON civicrm_participant' at line 2

« Last Edit: June 19, 2014, 07:39:48 am by amidinette »

amidinette

  • I’m new here
  • *
  • Posts: 6
  • Karma: 0
  • CiviCRM version: 4.4.5
  • CMS version: drupal 7.x
  • MySQL version: 5.5
  • PHP version: 5.4
Re: listing some participants using API
June 19, 2014, 08:34:07 am
right, haven't moved very far with view. managed to get rid of error messages but just get some nonsense in the query.
I can see the join is already there and a relationship is already defined in civicrm.event.inc but I can't make it work.

petednz

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4899
  • Karma: 193
    • Fuzion
  • CiviCRM version: 3.x - 4.x
  • CMS version: Drupal 6 and 7
Re: listing some participants using API
June 19, 2014, 02:13:10 pm
it really would be better imo to get this fixed in the module - but i am no expert in such matters
Sign up to StackExchange and get free expert advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

pete davis : www.fuzion.co.nz : connect + campaign + communicate

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviEvent (Moderator: Yashodha Chaku) »
  • listing some participants using API

This forum was archived on 2017-11-26.