Hi,

I'm using the event module to show a calendar and list of upcoming events and would like the events to remove themselves from the Upcoming Events list once the day is finished. e.g On 26th Dec the Christmas Day event is automatically removed.

Once they've expired we need them to go into a "Past Events" section/list.

I've looked around at various posts and the closest one is this http://drupal.org/node/77166 which expires the events by changing their date. This would be OK but it will mess up the Past Events section.

Anyone got any ideas how I can do this?

Thanks
Chris

Comments

Dublin Drupaller’s picture

Hi Chris,

Here's 2 simple page snippets that pulls up a CCK content type for upcoming/previous events.

Notes:
-------

a) this has been tested with the latest Drupal 4.7.4 and the latest cck.module (for version 4.7)
b) the snippet lists node teasers sorted by a date field and only those with a date after today's date (upcoming events).

Previous (cck) Events snippet

/** 
* this snippet will list 10 CCK content type titles & teasers and sort them based on a 
* date field from that same CCK content type, only displaying teasers from events taking place
* before todays date
*
* change the $imit to increase the length of the list
* Change the $contentname to the cck content type
* change the $sortbyfield to be the field name you want the list sorted by.
*
* IMPORTANT NOTE: this bypasses the Drupal access check to see if a user has permission 
* to view the content type
*
**/

//define limit, cck content type and the cck content field I want to sort the query by
$nlimit = 10; 
$contentname = 'node_content_event'; 
$sortbyfield = 'field_date_value';

// construct the query
$query = "SELECT * FROM $contentname WHERE `$contentname`.`$sortbyfield` <= CURdate() ORDER BY `$contentname`.`$sortbyfield` ASC";

// run the query
$result1 = pager_query(db_rewrite_sql ($query), variable_get('default_nodes_main', $nlimit)); 

//extract the output
while ($node = db_fetch_object($result1)) {
  $ccknode = node_load($node->nid);
  $output2 .= node_view(node_load(array('nid' => $node->nid)), 1);
};


 // print the results.
print '<h1>Previous Events</h1>';
print $output2;

Upcoming Events version of the same snippet

Same as above, except it lists events coming up after todays date

/** 
* this snippet will list 10 CCK content type titles & teasers and sort them based on a 
* date field from that same CCK content type, only displaying teasers from events taking place
* after todays date
*
* change the $imit to increase the length of the list
* Change the $contentname to the cck content type
* change the $sortbyfield to be the field name you want the list sorted by.
*
* IMPORTANT NOTE: this bypasses the Drupal access check to see if a user has permission 
* to view the content type
*
**/

//define limit, cck content type and the cck content field I want to sort the query by
$nlimit = 10; 
$contentname = 'node_content_event'; 
$sortbyfield = 'field_date_value';

// construct the query
$query = "SELECT * FROM $contentname WHERE `$contentname`.`$sortbyfield` >= CURdate() ORDER BY `$contentname`.`$sortbyfield` ASC";

// run the query
$result1 = pager_query(db_rewrite_sql ($query), variable_get('default_nodes_main', $nlimit)); 

//extract the output
while ($node = db_fetch_object($result1)) {
  $ccknode = node_load($node->nid);
  $output2 .= node_view(node_load(array('nid' => $node->nid)), 1);
};
// print the results.
print '<h1>Upcoming Events</h1>';
print $output2;

hope that helps

Dub

Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate

Chris_Allen’s picture

Yes, that's done the trick!

A note to other newbees: I initially got a MySQL error saying it couldn't find the table. It took me a little while to figure out that I needed to retain the "node_" in front of my content type name when replacing the $contentname variable and retain "_value" at the end of the $sortbyfield variable.

Thanks Dub!

Dublin Drupaller’s picture

Hi Chris,

Here's an updated version that uses the EVENT.MODULE date field, instead of a cck.module date field. I

UPCOMING EVENTS SNIPPET.

<?php
/** 
* this snippet will list 10 "upcoming events" CCK nodes titles & teasers and sort them based on a 
* date field (using the event.module)
*
* Change the $contentname to the cck content type name
*
* IMPORTANT NOTE: this bypasses the Drupal access check to see if a user has permission 
* to view the content type
*
* Tested with Drupal 4.7.4  
*
**/

//define cck content type 
$contentname = 'node_content_event'; 

$time = time() - (2 * 60 * 60);

// construct the query
$query = "SELECT * FROM {$contentname} n INNER JOIN {event} e ON n.nid = e.nid WHERE e.event_start >= $time ORDER BY event_start";

// run the query
$result1 = pager_query(db_rewrite_sql ($query), variable_get('default_nodes_main', $nlimit)); 

//extract the output
while ($node = db_fetch_object($result1)) {
  $ccknode = node_load($node->nid);
//  $output2 .= "<h1>". $ccknode->title ."</h1>";  
  $output2 .= node_view(node_load(array('nid' => $node->nid)), 1);
};

 // print the results.
print $output2;
?>

PREVIOUS EVENTS SNIPPET

<?php
/** 
* this snippet will display a list of "previous events" CCK nodes titles & teasers 
* and sort them based on a 
* date field (using the event.module)
*
* Change the $contentname to the cck content type name
*
* IMPORTANT NOTE: this bypasses the Drupal access check to see if a user has permission 
* to view the content type
*
* Tested with Drupal 4.7.4  
*
**/

//define cck content type 
$contentname = 'node_content_event'; 


$time = time() - (2 * 60 * 60);

// construct the query
$query = "SELECT * FROM {$contentname} n INNER JOIN {event} e ON n.nid = e.nid WHERE e.event_start <= $time ORDER BY event_start";

// run the query
$result1 = pager_query(db_rewrite_sql ($query), variable_get('default_nodes_main', $nlimit)); 

//extract the output
while ($node = db_fetch_object($result1)) {
  $ccknode = node_load($node->nid);
//  $output2 .= "<h1>". $ccknode->title ."</h1>";  
  $output2 .= node_view(node_load(array('nid' => $node->nid)), 1);
};

 // print the results.
print $output2;
?>

hope that helps

Dub

Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate

onecreative’s picture

Drupal 4.7

boreg’s picture

Sorry to others. I only want to contact onecreative...

my solution 4u: http://drupal.org/node/109985