Hello. I'm pretty new to drupal, but I hope I can get my question answered. I was using the calendar module to try to display a calendar list of events. But I found it to be pretty gnarly and kind of ugly. I've been using Calendar Block, but I'm not sure if it can display events on the calendar. IE, I have a content type "event" with a CCK of "eventdate" - I'd like the calendar to highlight all days with an event on them. When the user clicks on the date, it takes them to the node associated with the event. Pretty simple, really.

Any thoughts? I really love the look of this calendar and would love to make it work.

Thansk

Comments

skilip’s picture

The calendar_block module is developed for other modules to use it. From within other modules, using hook_calendar_block, you can alter the markup of each generated date. So instead of displaying just the date, which is just text, you can easily change it to an link, an image or even some markup which places a tooltip on a particular date.

Here's a little example of how it's done: http://drupal.org/node/319768#comment-1054246

drjonez’s picture

Well, I successfully added it on. This is my first module, but I thought I'd share

It works great!

A few issues
I tried to do the DB queries in LOAD, but had a hard time figuring out how to get my array to go global. I tried "global $dateDates" to no avail

As it sits now, it will call 31 DB queries every time the calendar loads. As it sits, it goes through ALL dates in the EVENT content type. I want to eventually tweak the SQL query to only grab events from the day that is being loaded by the block.

Anyway, here's my code for now. Sorry it's so messy. Hope it helps someone :)

// $Id$
/**
* @file
* Implementation of hook_calendar_block().
*/ 
function CalDates_calendar_block(&$date, $op) {
  

  switch ($op) {
	
    case 'alter':
		$sql = "SELECT content_type_event.field_eventdate_value, content_type_event.nid FROM content_type_event;";
		$result = db_query( $sql );
		
		
		$dateDates = array();
		while ($node = db_fetch_object( $result))
		{	
			$dateDates[] = node_load ( array( 'nid' => $node->nid));
		}
		
			
		
		foreach ($dateDates as $var){
				$thisPath = $var->path;
				$thisDate = substr($var->field_eventdate[0]['value'],0,10);
				$realDate = substr($thisDate, 5, 2) . "-" . substr($thisDate, 8,2)."-". substr($thisDate, 0, 4);
				
				
				if ($date->date == $realDate) {
				
					$date->content = l($date->day, "event-calendar/".$thisDate);
				
				}
			
				
			}
	      
		  break;
		  
		  
    case 'load':
	/*	$sql = "SELECT content_type_event.field_eventdate_value, content_type_event.nid FROM content_type_event;";
		$result = db_query( $sql );
				
		while ($node = db_fetch_object( $result))
		{	
			$dateDates[] = node_load ( array( 'nid' => $node->nid));
		}
	
		
		
		foreach ($dateDates as $var){
		
			print $var->field_eventdate[0]['value'] . " - " . $var->path . "<br>";
			$thisPath = $var->path;
			$thisDate = $var->field_eventdate[0]['value'];
			$realDate = substr($thisDate, 5, 2) . "-" . substr($thisDate, 8,2)."-". substr($thisDate, 0, 4);
			print "-".$realDate . "-<br/>";
		}
		
		*/


	
      break;
  }
}

Thanks a lot for providing this module. It looks about 500 times better than the views calendar! I would like to eventually change the start day from Monday to Sunday

skilip’s picture

Hey drjonez,

Nice to hear you got it all working! A few comments on your code above;

The operation 'load' is only intended to do some 'load' specific stuff. It's added to change the title of the block or to set the date on which the module should be loaded. Here's a little example:

/**
* Implementation of hook_calendar_block().
*/
function YOUR_MODULE_NAME_calendar_block(&$date, $op, &$block) {
  switch ($op) {
    case 'load':
      $block['subject'] = 'Calendar for the current department';
      $date->Year = 2007; // Sets the year of the calendar to 2007 on initialization. 
      $date->month = 9; // Sets the month of the calendar to september on initialization. 
      break;
  }
}

Using the operation 'load' this way, tells the calendar to start on september 2007.

In the operation 'alter', you'd better only load the nodes of a specific day, instead of loading all the nodes and doing a conditional check on all loaded nodes. Here's an example query for selecting all node ids of a specific day of creation:

$start_date = gmmktime(0,0,0, $date->month, $date->day, $date->year);
$end_date = gmmktime(23,59,59, $date->month, $date->day, $date->year);
$result = db_query("SELECT nid FROM {node} WHERE (created > %d) AND (created < %d)", $start_date, $end_date);
while ($row = db_fetch_object($result)) {
   $nids[] = $row->nid;
}
skilip’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

bcobin’s picture

Title: Display events in Calendar block? » Display events in Calendar block - almost working!
Version: 6.x-1.x-dev » 6.x-2.2
Priority: Critical » Normal

I've been trying to get this to work for a while - thank you, drjonez, for the code! I am not a coder, so please forgive if this sounds dumb; I'm hoping that someone who knows what they're doing can help with the two biggest problems I have.

1 - Past events are highlighted and linkable on the calendar (yay!); future events don't show up. :-(

UPDATE: this looks like a problem with a previously entered future event - new events do, indeed appear, but with a time zone error described in a different post.

2 - Currently, the path has to be defined as /events/YYYY-MM-DD - ("events/" is necessary for other reasons on this site) it would be great if the highlighted date could just link to the node ID, so the client doesn't have to worry about URL naming conventions.

I have a custom content type (event) with a custom datetime field - everything's working nicely with Calendar and it would be great to be able to use Calendar Block, too. I've pasted this code at the end of the CCK (Content) module.

OK - here we go:

function content_calendar_block(&$calendar, &$date, $op) {
  switch($op) {
    case 'alter':
    $sql = "SELECT content_type_event.field_datetime_value, content_type_event.nid FROM content_type_event;";
 $result = db_query( $sql );
 $dateDates = array();
 while ($node = db_fetch_object( $result))
 { 
 $dateDates[] = node_load ( array( 'nid' => $node->nid));
 }
  
 foreach ($dateDates as $var){
 $thisPath = $var->path;
 $thisDate = substr($var->field_datetime[0]['value'],0,10);
 $realDate = substr($thisDate, 5, 2) . "-" . substr($thisDate, 8,2)."-". substr($thisDate, 0, 4);
  
 if ($date->date == $realDate) {
 
 $date->content = l($date->day, "events/".$thisDate); 
 } 
 } 
 break;
  }
}

Calendar Block looks so much better than other calendar blocks; I'd love to be able to use it! Hoping someone can help me out here; thanks for all the work on this really cool thingie...