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) »
  • how to use php/api to get total participants for an event? [solved]
Pages: [1]

Author Topic: how to use php/api to get total participants for an event? [solved]  (Read 2010 times)

BusinessMediaCenter

  • I post occasionally
  • **
  • Posts: 82
  • Karma: 2
  • CiviCRM version: 4.1.x
  • CMS version: Drupal 6 & 7
  • MySQL version: 5
  • PHP version: 5
how to use php/api to get total participants for an event? [solved]
August 17, 2012, 09:53:25 am
As the title suggests, I need to use php to get the total number of participants registered for an event.  Can anyone help with this?
« Last Edit: August 21, 2012, 11:18:19 pm by BusinessMediaCenter »

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: how to use php/api to get total participants for an event?
August 19, 2012, 11:25:07 pm
You can use the API to get all participants for an event:
Code: [Select]
$results=civicrm_api("Participant","get", array (version => '3', 'event_id' =>'1'));
You can always have a play with the API using the API explorer
<yoursite./civicrm/api/explorer
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: how to use php/api to get total participants for an event?
August 21, 2012, 02:44:09 pm
also try the using get_count instead of get
Try asking your question on the new CiviCRM help site.

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: how to use php/api to get total participants for an event?
August 21, 2012, 03:14:26 pm
typo: it's getcount not get_count.

by default, there is an implicit limit of 25 on how many records are included (both for get or getcount), so you will need to override this default value.

I don't have a civicrm with enough participants to confirm, but I think you need to add a "options.limit" =>9999 param

(try with or without s at option, should work).

Would be great  if you could update the wiki once you have the code working, let us know

X+

-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: how to use php/api to get total participants for an event?
August 21, 2012, 04:29:51 pm
There is also an 'is_full' option on event api which includes available_places & max_participants - you might be able to work with that

http://svn.civicrm.org/civicrm/branches/settingsapi/api/v3/examples/Event/IsFullOption.php
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

BusinessMediaCenter

  • I post occasionally
  • **
  • Posts: 82
  • Karma: 2
  • CiviCRM version: 4.1.x
  • CMS version: Drupal 6 & 7
  • MySQL version: 5
  • PHP version: 5
Re: how to use php/api to get total participants for an event?
August 21, 2012, 10:39:06 pm
Quote from: Erik Hommel on August 19, 2012, 11:25:07 pm
You can use the API to get all participants for an event:
Code: [Select]
$results=civicrm_api("Participant","get", array (version => '3', 'event_id' =>'1'));
You can always have a play with the API using the API explorer
<yoursite./civicrm/api/explorer

Aha! This is exactly what i was looking for.  I have not had a chance to test but am pretty confident this is it.  I will post results back in next day or so.

BusinessMediaCenter

  • I post occasionally
  • **
  • Posts: 82
  • Karma: 2
  • CiviCRM version: 4.1.x
  • CMS version: Drupal 6 & 7
  • MySQL version: 5
  • PHP version: 5
Re: how to use php/api to get total participants for an event?
August 21, 2012, 10:47:17 pm
Quote from: xavier on August 21, 2012, 03:14:26 pm
typo: it's getcount not get_count.

by default, there is an implicit limit of 25 on how many records are included (both for get or getcount), so you will need to override this default value.

I don't have a civicrm with enough participants to confirm, but I think you need to add a "options.limit" =>9999 param

(try with or without s at option, should work).

Would be great  if you could update the wiki once you have the code working, let us know

X+

Thanks for the getcount catch, I had noticed that as well.  I am very happy to post this to the wicki once sorted, Ill be working this tomorrow first thing.  FWIW I recently posted a tutorial on how to get the max participants using php in drupal views, would this be of interest to the wicki as well?  IMO these two go hand in hand.
http://forum.civicrm.org/index.php/topic,25604.msg108258.html

BusinessMediaCenter

  • I post occasionally
  • **
  • Posts: 82
  • Karma: 2
  • CiviCRM version: 4.1.x
  • CMS version: Drupal 6 & 7
  • MySQL version: 5
  • PHP version: 5
Re: how to use php/api to get total participants for an event?
August 21, 2012, 10:47:53 pm
Quote from: Eileen on August 21, 2012, 04:29:51 pm
There is also an 'is_full' option on event api which includes available_places & max_participants - you might be able to work with that

http://svn.civicrm.org/civicrm/branches/settingsapi/api/v3/examples/Event/IsFullOption.php

Thanks Eileen, interesting you mention this as I had actually used the is full from BAO participant.php function as a starting point, then noticed the getContactParticipantCount function, but could never get the participant data to pull in-  Im pretty sure Erik Hommel's suggestion is the missing link.  Will report back once sorted, thanks!!!

BusinessMediaCenter

  • I post occasionally
  • **
  • Posts: 82
  • Karma: 2
  • CiviCRM version: 4.1.x
  • CMS version: Drupal 6 & 7
  • MySQL version: 5
  • PHP version: 5
Re: how to use php/api to get total participants for an event?
August 21, 2012, 11:18:04 pm
Quote from: Erik Hommel on August 19, 2012, 11:25:07 pm
You can use the API to get all participants for an event:
Code: [Select]
$results=civicrm_api("Participant","get", array (version => '3', 'event_id' =>'1'));
You can always have a play with the API using the API explorer
<yoursite./civicrm/api/explorer

Im happy to report this worked!!  Ill work up a full step by step tut for the wicki, but in the meantime here's what worked for me.  Thanks once again for the help!

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);
  $getParticipants= civicrm_api("Participant","getcount", $params);
  $total=$getParticipants;
  return $total; 
« Last Edit: August 21, 2012, 11:29:27 pm by BusinessMediaCenter »

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: how to use php/api to get total participants for an event? [solved]
August 22, 2012, 02:21:32 pm
grumble grumble - nonstandard param names - grumble grumble
getcount is neither camelCase nor underscore_sepearated   >:(
Try asking your question on the new CiviCRM help site.

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: how to use php/api to get total participants for an event? [solved]
August 22, 2012, 02:25:20 pm
The decision we made early on was that api actions would be one-word lower case - I think some got added to the job api that aren't like 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

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: how to use php/api to get total participants for an event? [solved]
August 22, 2012, 02:30:10 pm
Ah well, as long as its consistent
Hey, we could also teach the civicrm_api() wrapper function to remove underscores and uppercase before constructing the function name... or is that just encouraging sloppyness in making api calls?
Try asking your question on the new CiviCRM help site.

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: how to use php/api to get total participants for an event? [solved]
August 22, 2012, 11:06:15 pm
I would not advocate the support of sloppy api behaviour  :P
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: how to use php/api to get total participants for an event? [solved]
August 22, 2012, 11:52:34 pm
It might lead to warm beer & forum threads that deteriorate into bad jokes.
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

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviEvent (Moderator: Yashodha Chaku) »
  • how to use php/api to get total participants for an event? [solved]

This forum was archived on 2017-11-26.