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) »
  • Getting most recent event?
Pages: [1]

Author Topic: Getting most recent event?  (Read 1306 times)

lentilsoup

  • I post frequently
  • ***
  • Posts: 134
  • Karma: 6
Getting most recent event?
October 26, 2009, 02:18:30 pm
Is raw SQL the only way to get the ID of the event with the latest start date?  I'm not seeing any documented way to search on all records via the API, nor to sort them.

Thanks!

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Getting most recent event?
October 26, 2009, 04:40:11 pm
I think you can use api/v2/Event.php civicrm_event_search() - if you pass sort param (state_date DESC) and limit param (limit of 1) - that should do it (caveat = haven't tried it).
Protect your investment in CiviCRM by  becoming a Member!

lentilsoup

  • I post frequently
  • ***
  • Posts: 134
  • Karma: 6
Re: Getting most recent event?
October 27, 2009, 10:22:42 am
So use the following for $params?

Code: [Select]
$params = array(
  'sort' => 'start_date DESC',
  'limit' => 1,
);

lentilsoup

  • I post frequently
  • ***
  • Posts: 134
  • Karma: 6
Re: Getting most recent event?
October 27, 2009, 10:32:28 am
I'm getting a fatal PHP error when trying to run that query:

Code: [Select]
Class 'CRM_Core_Action' not found in [path]/civicrm/CRM/Core/BAO/CustomGroup.php on line 488

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: Getting most recent event?
October 27, 2009, 11:10:31 am

can u add:

require_once 'CRM/Core/Action.php'

on line 487 or so

i'll fix the error for 3.1

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

lentilsoup

  • I post frequently
  • ***
  • Posts: 134
  • Karma: 6
Re: Getting most recent event?
October 27, 2009, 11:16:14 am
Did that - getting another error:

Code: [Select]
Class 'CRM_Utils_String' not found in [path]/civicrm/CRM/Core/Action.php on line 245
also adding require_once('CRM/Utils/String.php'); to CRM/Core/Action.php at line 245 seems to have fixed it.

lentilsoup

  • I post frequently
  • ***
  • Posts: 134
  • Karma: 6
Re: Getting most recent event?
October 27, 2009, 11:21:19 am
The query is working now, but there's no way to limit the number of results in 3.0 -- I'll have to handle that in PHP for now.  Interestingly, civicrm_event_search() seems to return event templates as well as bona fide events.

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: Getting most recent event?
October 27, 2009, 11:42:09 am

i fixed this for 3.1

the changeset is at this link:

http://fisheye2.atlassian.com/changelog/CiviCRM/?cs=24585

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

lentilsoup

  • I post frequently
  • ***
  • Posts: 134
  • Karma: 6
Re: Getting most recent event?
October 27, 2009, 11:44:56 am
Thanks!

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviEvent (Moderator: Yashodha Chaku) »
  • Getting most recent event?

This forum was archived on 2017-11-26.