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 (Moderator: Dave Greenberg) »
  • display events page
Pages: [1]

Author Topic: display events page  (Read 3018 times)

Inc

  • Guest
display events page
January 20, 2008, 09:50:30 am
Is there anyway to display a list of events and their dates plus a list of contribution projects/pages on another page on my drupal site? so that anon users can just see a list?

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: display events page
January 20, 2008, 02:37:55 pm
There's sample code for creating a block with a list of events here:
http://wiki.civicrm.org/confluence/display/CRMDOC/List+of+Upcoming+CiviEvents+or+Feed+of+Events?focusedCommentId=15248#comment-15248

CiviEvent also can provide an RSS or iCal feed of public events (check out the links on your site or the demo at CiviEvent >> Manage Events).
Protect your investment in CiviCRM by  becoming a Member!

webcomm

  • Guest
Re: display events page
February 19, 2008, 08:38:21 am
I am using the Upcoming CiviEvents block provided here.

I'm not sure how to add location details to my display.  From looking at the events db table, it appears the location details are not in that table... and if I var_dump the $myEvents array in the Upcoming CiviEvents block, there is nothing in the array for location name, street address, etc.  I'm not sure what table those things are pulled from, and how best to access that data from this block.

Thanks in advance for any help with this.
Ryan

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: display events page
February 19, 2008, 09:29:57 am

i assume this is civicrm v1.9 or lower.

The location details are in civicrm_location (and civicrm_address). You'll need to do a LEFT JOIN with those two tables and use entity_table (civicrm_event) and entity_id in your LEFT JOIN clause

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

webcomm

  • Guest
Re: display events page
February 19, 2008, 12:01:44 pm
yes, version 1.9.

Initially I'm not sure why it needs to be a left join.  Unless I'm missing something, it seems like a simple join would work, like so...

$result = db_query('SELECT * FROM civicrm_location AS l, civicrm_address AS a WHERE l.entity_id = $eventid AND l.entity_table = \'civicrm_event\' AND l.id = a.location_id');
while ($row = db_fetch_object($result)) {
...
}


What is the best way to query the civicrm database in a Drupal block?  The above doesn't work because db_query() queries the drupal database.  I have a separate database for civicrm.

My plan is to put the above query in the foreach loop in the Upcoming CiviEvents block.

Thanks.


« Last Edit: February 19, 2008, 12:06:51 pm by webcomm »

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: display events page
February 19, 2008, 12:09:37 pm

You need a left join IF you were trying to get the data along with the event data, since some events might not have a location entry (its optional)

here's the equivalent civicrm code

Code: [Select]
civicrm_initialize( );
$query = "....";
require_once 'CRM/Core/DAO.php';
$dao = CRM_Core_DAO::executeQuery( $query, CRM_Core_DAO::$_nullArray );
while ( $dao->fetch( ) ) {
   var_dump( $dao );
}
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

webcomm

  • Guest
Re: display events page
February 19, 2008, 02:43:47 pm
awesome... thanks.  Is there a php function or drupal function for getting the string value of a state_province_id?

Here's the whole block as of now...

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;
}

if (
module_exists('civicrm')) {
  
civicrm_initialize(TRUE);
  require_once 
'api/v2/Event.php';
  
// This example limits listing to public and active events
  
$params = array ('is_public'     => 1, 'is_active'     => 1);
  
$myEvents = civicrm_event_search( $params );
  if (
$myEvents) {
    
$count = 0;
    
$last = '';
    
usort($myEvents,'cmp_date');
    foreach (
$myEvents as $event) {
      
$eventid = $event['id'];
      
$the_city = '';
      
$the_state_province_id = '';
      
      
civicrm_initialize( );
      
$query = 'SELECT * FROM civicrm_location AS l, civicrm_address AS a WHERE l.entity_id = '.$eventid.' AND l.entity_table = \'civicrm_event\' AND l.id = a.location_id';
      require_once 
'CRM/Core/DAO.php';
      
$the_event = CRM_Core_DAO::executeQuery( $query, CRM_Core_DAO::$_nullArray );
  while ( $the_event->fetch( ) ) {
          
$the_location = $the_event->name;
          if (!empty(
$the_event->city)) {
$the_city = ', ' . $the_event->city;
}
  if (!empty($the_event->city)) {
$the_state_province_id = ', ' . $the_event->state_province_id;
}   
  }

      
$now = date('Y-m-d H:i:s');
      if (
$now > $event['start_date']) continue;
      
$startdate = date('F j, Y',strtotime($event['start_date']));
      
$enddate = date('F j, Y',strtotime($event['end_date']));
             
      list(
$title_place, $title_desc) = split(":",$event['title'],2);
      if (
$last != $startdate) {
        
$display = '<div class="pod"><p class="date">'.$startdate.'</p>';
      }
      
$display .= '<p class="event_name">' . l($title_place.' '.$title_desc, 'civicrm/event/info', array(), 'reset=1&id='.$event['id']).'<br /><strong>'.$the_location.$the_city.$the_state_province_id.'</strong></p></div>';
      echo 
$display;
      
$count++;
      
$last = $startdate;
      if (
$count > 8) break;
// this limits the number of events to 8 - put in whatever number suits you
    
}
    if (
$count > 0) {

    } else {
      echo 
'No events found.';
    }
  } else {
    echo 
'No events found.';
  }
}
?>
« Last Edit: February 19, 2008, 02:45:47 pm by webcomm »

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: display events page
February 19, 2008, 04:22:33 pm

require_once 'CRM/Core/PseudoConstant.php';
$stateName = CRM_Core_PseudoConstant::stateProvince( $stateProvinceID );

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

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM (Moderator: Dave Greenberg) »
  • display events page

This forum was archived on 2017-11-26.