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) »
  • Public CiviEvent listings code
Pages: [1]

Author Topic: Public CiviEvent listings code  (Read 1509 times)

emilyf

  • Ask me questions
  • ****
  • Posts: 696
  • Karma: 54
  • CiviCRM version: 2.x - 4.x
  • CMS version: Drupal 5, 6, 7
Public CiviEvent listings code
April 04, 2008, 08:50:15 am
hi,

I have a block that's displaying all upcoming events in CiviEvent. I used the code at this page:

http://wiki.civicrm.org/confluence/display/CRMDOC/List+of+Upcoming+CiviEvents+or+Feed+of+Events

it works great.

I also want a page that displays all upcoming events, and I figured I could use the same code. however, when I put in that code to a drupal php page and submit, i get the wonderful white screen. No errors in my apache log, no errors in drupal admin log. any idea what i might need to change?

thanks,
emily

emilyf

  • Ask me questions
  • ****
  • Posts: 696
  • Karma: 54
  • CiviCRM version: 2.x - 4.x
  • CMS version: Drupal 5, 6, 7
Re: Public CiviEvent listings code
April 04, 2008, 10:23:32 am
FYI, I figured out that it's the sorting function provided on the first snippet that is breaking the page:

Code: [Select]
<?php
function cmp_date($a,$b) {
  if (
$a['start_date'] > $b['start_date']) return 1;
  if (
$a['start_date'] < $b['start_date']) return -1;
  return 
0;
} 
?>


I don't know why it works in the block but not the page.

emilyf

  • Ask me questions
  • ****
  • Posts: 696
  • Karma: 54
  • CiviCRM version: 2.x - 4.x
  • CMS version: Drupal 5, 6, 7
Re: Public CiviEvent listings code
April 04, 2008, 10:35:20 am
So in trying to take another route to sorting, I found some sort snippets on the API. However, I can't get them to work for my search. I am just trying to use a
Code: [Select]
<?php 
    $sort 
= array('start_date' => 'ASC');
    
// Search API returns a nested array
    
$myEvents = & civicrm_event_search( $params, $sort ); ?>

but it doesn't change the listings to sort that way. Here's my full code:

Code: [Select]
<?php
if (module_exists('civicrm')) {
    
civicrm_initialize(TRUE);
    require_once 
'api/v2/Event.php';
    
$params = array ('is_public'     => 1, 'is_active'     => 1);
     
$sort = array('start_date' => 'ASC');
    
// Search API returns a nested array
    
$myEvents = & civicrm_event_search( $params, $sort );

    
// Uncomment this line if you want to see all array items returned from your search
    // var_dump($myEvents);

    
if ($myEvents) {

        foreach (
$myEvents as $event) {

 
$now = date('Y-m-d H:i:s');
      if (
$now > $event['start_date']) continue;
      
$startdate = date('F jS, Y \a\t g:i a',strtotime($event['start_date']));
      
$enddate = date('F jS \a\t g:i a',strtotime($event['end_date']));

$eventid = $event['id'];
      list(
$title_place, $title_desc) = split(":",$event['title'],2);

            
$display =  l($title_place.' '.$title_desc, 'civicrm/event/info', array(), 'reset=1&id='.$event['id']) . '<br />Date: ' .
                       
$startdate . ' - ' .
                       
$enddate. '<br /><hr>';
        echo 
$display;
        }
    } else {
        echo 
'No events found.';
    }
}
?>

Any suggestions? Thanks!

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: Public CiviEvent listings code
April 04, 2008, 10:49:21 am

its confliciting with another function in some drupal module called cmp_date. Just rename the function to eventpage_cmp_date and search for cmp_date in that file (it should appear at least once more, line 71) and rename it there too

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

emilyf

  • Ask me questions
  • ****
  • Posts: 696
  • Karma: 54
  • CiviCRM version: 2.x - 4.x
  • CMS version: Drupal 5, 6, 7
Re: Public CiviEvent listings code
April 04, 2008, 11:16:18 am
Thanks, Lobo :)

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviEvent (Moderator: Yashodha Chaku) »
  • Public CiviEvent listings code

This forum was archived on 2017-11-26.