This post is a suggestion to the module authors, and a hack for anyone else who wants to color-code the mini calendar block based on taxonomy terms. You can do this very simply (with no additional DB calls). NOTE: This hack only works as expected for nodes possessing a single taxonomy term: it returns only the first tid in the array. It would be a simple matter to make it return the whole array, but then the question of which term/color to display becomes an issue.

First you must add "Taxonomy Term Id" to the Fields in the Calendar View. You can exclude it from the display.

Next, edit includes/calendar.inc and look around Line 130 (I used version 6.x-2.x-dev):

        (empty($items[$curday_date]) ? ' has-no-events' : ' has-events');
    }
+    if($items[$curday_date]) {
+      $class .= ' tid' . $items[$curday_date]['00:00:00'][0]->raw->term_data_tid;
+    }
    $rows[$week][] = array(
      'data' => $content,
      'class' => $class, 'id' => $view->name . '-' . $curday_date);
    date_modify($curday, '+1 day');

Now your mini calendar will create extra classes that can be themed in your style.css file:

.tid1 { background: limegreen; }
.tid2 { background: yellow; }
.tid3 { background: cyan; }

Comments

milos.kroulik’s picture

Unfortunately, this isn't the right solution, because it only works for multi-day events (hapenning in 00:00:00). Is there any way to build $items[$curday_date] array for, say, 08:00:00?

As If’s picture

Everything is possible with PHP ;-) You just have to be willing to make the hacks yourself. I realize this isn't a "solution" that fits all circumstances. That's why I called it a "suggestion" (for the module authors) not a "patch" or anything like that. I figured the authors might decide to take this idea as a starting point and develop it more fully (as it would have to be, to be considered worthy of committing). For everyone else, it's just a "hack". So hack away, brother!

milos.kroulik’s picture

OK, thanks for explanation. So here is my ugly (and probably lame) hack (I am not really a programmer).

I even can't make proper patch, so I enclose the code from my calendar.inc directly (same lines as above):

 if($items[$curday_date]) {
$classbackup = $class;
$class .= ' tid' . $items[$curday_date]['00:00:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['06:00:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['06:05:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['06:10:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['06:15:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['06:20:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['06:25:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['06:30:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['06:35:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['06:40:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['06:45:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['06:50:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['06:55:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['07:00:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['07:05:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['07:10:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['07:15:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['07:20:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['07:25:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['07:30:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['07:35:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['07:40:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['07:45:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['07:50:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['07:55:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['08:00:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['08:05:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['08:10:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['08:15:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['08:20:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['08:25:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['08:30:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['08:35:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['08:40:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['08:45:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['08:50:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['08:55:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['09:00:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['09:05:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['09:10:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['09:15:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['09:20:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['09:25:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['09:30:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['09:35:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['09:40:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['09:45:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['09:50:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['09:55:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['10:00:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['10:05:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['10:10:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['10:15:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['10:20:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['10:25:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['10:30:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['10:35:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['10:40:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['10:45:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['10:50:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['10:55:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['11:00:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['11:05:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['11:10:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['11:15:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['11:20:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['11:25:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['11:30:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['11:35:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['11:40:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['11:45:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['11:50:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['11:55:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['12:00:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['12:05:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['12:10:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['12:15:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['12:20:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['12:25:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['12:30:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['12:35:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['12:40:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['12:45:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['12:50:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['12:55:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['13:00:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['13:05:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['13:10:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['13:15:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['13:20:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['13:25:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['13:30:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['13:35:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['13:40:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['13:45:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['13:50:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['13:55:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['14:00:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['14:05:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['14:10:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['14:15:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['14:20:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['14:25:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['14:30:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['14:35:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['14:40:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['14:45:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['14:50:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['14:55:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['15:00:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['15:05:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['15:10:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['15:15:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['15:20:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['15:25:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['15:30:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['15:35:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['15:40:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['15:45:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['15:50:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['15:55:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['16:00:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['16:05:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['16:10:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['16:15:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['16:20:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['16:25:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['16:30:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['16:35:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['16:40:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['16:45:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['16:50:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['16:55:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['17:00:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['17:05:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['17:10:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['17:15:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['17:20:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['17:25:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['17:30:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['17:35:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['17:40:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['17:45:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['17:50:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['17:55:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['18:00:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['18:05:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['18:10:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['18:15:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['18:20:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['18:25:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['18:30:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['18:35:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['18:40:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['18:45:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['18:50:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['18:55:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['19:00:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['19:05:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['19:10:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['19:15:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['19:20:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['19:25:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['19:30:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['19:35:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['19:40:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['19:45:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['19:50:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['19:55:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['20:00:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['20:05:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['20:10:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['20:15:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['20:20:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['20:25:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['20:30:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['20:35:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['20:40:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['20:45:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['20:50:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['20:55:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['21:00:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['21:05:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['21:10:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['21:15:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['21:20:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['21:25:00'][0]->raw->term_data_tid;
$class.=' tid'.$items[$curday_date]['21:30:00'][0]->raw->term_data_tid;
$class = preg_replace('/.*(tid\d*).*$/','$1', $class) . ' ' . $classbackup;
    }

I assume, that granularity of event start dates is 5 mins and that events start during the day, not night (of course, you can also generate those, if you wish).

lucio.ferrari’s picture

I have already posted something like this in http://drupal.org/node/674126 , but then improved the code a little bit.

To export any taxonomy vocabulary as a CSS class:

* added a 'taxonomy:term' hidden field in my calendar view;

* overrode calendar.mini.tpl.php by placing this in my theme's folder:

<?php
// $Id: calendar-mini.tpl.php,v 1.1.2.7 2010/11/21 13:19:37 karens Exp $
/**
 * @file
 * Template to display a view as a mini calendar month.
 * 
 * @see template_preprocess_calendar_mini.
 *
 * $day_names: An array of the day of week names for the table header.
 * $rows: An array of data for each day of the week.
 * $view: The view.
 * $min_date_formatted: The minimum date for this calendar in the format YYYY-MM-DD HH:MM:SS.
 * $max_date_formatted: The maximum date for this calendar in the format YYYY-MM-DD HH:MM:SS.
 * 
 * $show_title: If the title should be displayed. Normally false since the title is incorporated
 *   into the navigation, but sometimes needed, like in the year view of mini calendars.
 * 
 */
//dsm('Display: '. $display_type .': '. $min_date_formatted .' to '. $max_date_formatted);

?>
<div class="calendar-calendar"><div class="month-view">
<?php if ($view->date_info->show_title): ?>
  <?php print theme('date_navigation', $view); ?>
<?php endif; ?>
<?php

// Define things

$terms = array();
$obj = $view->result;

$classes = array( // terms by tid
  1 => 'my_term_1',
  2 => 'my_term_2',
  3 => 'my_term_3',
  4 => 'my_term_4',
  );

// This foreach loop creates an array 'day' => 'terms for this day' 

foreach($obj as $result) {

// grabs raw data
  $tid = $result->term_data_tid;
  $inizio = $result->calendar_fields->node_data_field_myfield_field_myfield_value;
  $fine = $result->calendar_fields->node_data_field_myfield_field_myfield_value2;

// start & end day
  $from = substr($inizio,8,2); 
  $till = substr($fine,8,2); 

// start & end month
  $from_m = substr($inizio,5,2); 
  $till_m = substr($fine,5,2);

// what month is this?
  $this_m = substr($rows[1][0]['id'], -5, 2);

// Takes care of events spanning multiple months 
  if ($till_m != $from_m) { 
	if ($this_m == $from_m) {
		$till += 31;
		}
	if ($this_m == $till_m) {
		$from = 1;	
		}
		
	if (($this_m != $from_m)&&($this_m != $till_m)) { // in case the event spans the whole month
		$from = 1; $till = 31;
		}
	}
// Populates the array
  for ($day = $from; $day <= $till; $day += 1) {
	$terms[$day] .= $classes[$tid].' ';
	}
  }

?> 
<table class="mini">
  <thead>
    <tr>
      <?php foreach ($day_names as $cell): ?>
        <th class="<?php print $cell['class']; ?>">
          <?php print $cell['data']; ?>
        </th>
      <?php endforeach; ?>
    </tr>
  </thead>
  <tbody>
    <?php foreach ((array) $rows as $row): ?>
      <tr>
        <?php foreach ($row as $cell): ?>
          <td class="<?php print $cell['class']; ?> <?php print $cell['id']; ?> 
		  <?php
// prints all classes for today
			foreach($terms as $day => $class) {
				$today = substr($cell['id'],-2);
				if ($day == $today) {print $class;} 
			}
		
		  ?>">
            <?php print $cell['data']; ?>
          </td>
        <?php endforeach; ?>
      </tr>
    <?php endforeach; ?>
  </tbody>
</table>
</div></div>

To handle multiple terms, one should resort the $view->result before the foreach loop, as to have the most important/specific tid as the last one, since the last class overrides the others in the style sheet.

Or one just writes a CSS rule for each combination ( .my_term_1 .my_term_2 { ... ; } ).

Regards

L.F.

luffy48’s picture

Hi !

Sorry I'm new user of Drupal and I would like to know what do you mean by "* added a 'taxonomy:term' hidden field in my calendar view;" ?

Thanks

lucio.ferrari’s picture

Hi, I hope I'm not too late ;-)

in calendar view's edit page (admin/build/views/edit/event_calendar - or whatever)
I added a field: 'taxonomy: term', in which I checked 'Exclude from display'.

Then, to find out what variable I needed, I put in my template:

<?php print dpm($view->result); ?>

which is a great way to find out how views works under the hood :-)

Wassim Ghannoum’s picture

How to do it for the calendar page and not mini calendar, what is the code?

N.b: for drupal 6

lucio.ferrari’s picture

Check this out:

<?php
// $Id: calendar-month.tpl.php,v 1.6.2.3 2008/06/19 22:55:56 karens Exp $
/**
 * @file
 * Template to display a view as a calendar month.
 * 
 * @see template_preprocess_calendar_month.
 *
 * $day_names: An array of the day of week names for the table header.
 * $rows: An array of data for each day of the week.
 * $view: The view.
 * $calendar_links: Array of formatted links to other calendar displays - year, month, week, day.
 * $display_type: year, month, day, or week.
 * $block: Whether or not this calendar is in a block.
 * $min_date_formatted: The minimum date for this calendar in the format YYYY-MM-DD HH:MM:SS.
 * $max_date_formatted: The maximum date for this calendar in the format YYYY-MM-DD HH:MM:SS.
 * $date_id: a css id that is unique for this date, 
 *   it is in the form: calendar-nid-field_name-delta
 * 
 */
//dsm('Display: '. $display_type .': '. $min_date_formatted .' to '. $max_date_formatted);
?>

<?php

// Define things

$terms = array();
$obj = $view->result;

$classes = array( // terms by tid
  1 => 'my_term_1',
  2 => 'my_term_2',
  3 => 'my_term_3',
  4 => 'my_term_4',
  );

// This foreach loop creates an array 'day' => 'terms for this day' 

foreach($obj as $result) {

// grabs raw data
  $tid = $result->term_data_tid;
  $inizio = $result->calendar_fields->node_data_field_myfield_field_myfield_value;
  $fine = $result->calendar_fields->node_data_field_myfield_field_myfield_value2;

// start & end day
  $from = substr($inizio,8,2); 
  $till = substr($fine,8,2); 

// start & end month
  $from_m = substr($inizio,5,2); 
  $till_m = substr($fine,5,2);

// what month is this?
  $this_m = substr($rows[1][0]['id'], -5, 2);

// Takes care of events spanning multiple months 
  if ($till_m != $from_m) { 
    if ($this_m == $from_m) {
        $till += 31;
        }
    if ($this_m == $till_m) {
        $from = 1;    
        }
        
    if (($this_m != $from_m)&&($this_m != $till_m)) { // in case the event spans the whole month
        $from = 1; $till = 31;
        }
    }
// Populates the array
  for ($day = $from; $day <= $till; $day += 1) {
    $terms[$day] .= $classes[$tid].' ';
    }
  }

?> 

<div class="calendar-calendar"><div class="month-view">
<table>
  <thead>
    <tr>
      <?php foreach ($day_names as $cell): ?>
        <th class="<?php print $cell['class']; ?>">
          <?php print $cell['data']; ?>
        </th>
      <?php endforeach; ?>
    </tr>
  </thead>
  <tbody>
    <?php foreach ((array) $rows as $row): ?>
      <tr>
        <?php foreach ($row as $cell): ?>
          <td id="<?php print $cell['id']; ?>" class="<?php print $cell['class']; ?>
		  		  <?php
					// prints all classes for today
						foreach($terms as $day => $class) {
							$today = substr($cell['id'],-2);
							if ($day == $today) {print $class;} 
						}
					?>">
            <?php print $cell['data']; ?>
          </td>
        <?php endforeach; ?>
      </tr>
    <?php endforeach; ?>
  </tbody>
</table>
</div></div>

I didn't check if it actually works, I only pasted the relevant code in the seemingly appropriate area of calendar-month.tpl.php.

Replace "my_term_1" etc. with your actual tids/terms, replace "node_data_field_myfield_field_myfield_value" with your actual date field name, then save the code as calendar-month.tpl.php, move it in your theme folder, clear theme cache and you're done.
Please let me know if it works!

Regards

L.F.

Wassim Ghannoum’s picture

thank you for your reply,

i tried the following:

- in the view i create a term id field in the view and marked is a excluded
- i create a calendar-month.tpl.php in my theme and pasted the following code in it:

<?php
// $Id: calendar-month.tpl.php,v 1.6.2.3 2008/06/19 22:55:56 karens Exp $
/**
* @file
* Template to display a view as a calendar month.
*
* @see template_preprocess_calendar_month.
*
* $day_names: An array of the day of week names for the table header.
* $rows: An array of data for each day of the week.
* $view: The view.
* $calendar_links: Array of formatted links to other calendar displays - year, month, week, day.
* $display_type: year, month, day, or week.
* $block: Whether or not this calendar is in a block.
* $min_date_formatted: The minimum date for this calendar in the format YYYY-MM-DD HH:MM:SS.
* $max_date_formatted: The maximum date for this calendar in the format YYYY-MM-DD HH:MM:SS.
* $date_id: a css id that is unique for this date,
*   it is in the form: calendar-nid-field_name-delta
*
*/
//dsm('Display: '. $display_type .': '. $min_date_formatted .' to '. $max_date_formatted);
?>


<?php

// Define things

  dsm($view->result);

$terms = array();
$obj = $view->result;

$classes = array( // terms by tid
  1 => 'Bulletins',
  2 => 'Compositions',
  3 => 'Congés',
  4 => 'Examen d\'entrée Sec+Cycle 1',
  5 => 'Examen d\'entrée Sec+Cycle 2',
  6 => 'Examen d\'entrée Sec+Cycle 3',
  7 => 'Examens',
  8 => 'Rentrée Cycle2',
  9 => 'Rentrée EB1',
  10 => 'Rentrée EB2 + EB3',
  11 => 'Rentrée EB7 + EB8',
  12 => 'Rentrée G.S',
  13 => 'Rentrée M.S',
  14 => 'Rentrée P.S',
  15 => 'Rentrée Sec + EB9',
  );

// This foreach loop creates an array 'day' => 'terms for this day'

foreach($obj as $result) {

// grabs raw data
  $tid = $result->term_data_tid;
  $inizio = $result->calendar_fields->field_date;
  $fine = $result->calendar_fields->field_date;

// start & end day
  $from = substr($inizio,8,2);
  $till = substr($fine,8,2);

// start & end month
  $from_m = substr($inizio,5,2);
  $till_m = substr($fine,5,2);

// what month is this?
  $this_m = substr($rows[1][0]['id'], -5, 2);

// Takes care of events spanning multiple months
  if ($till_m != $from_m) {
    if ($this_m == $from_m) {
        $till += 31;
        }
    if ($this_m == $till_m) {
        $from = 1;   
        }
       
    if (($this_m != $from_m)&&($this_m != $till_m)) { // in case the event spans the whole month
        $from = 1; $till = 31;
        }
    }
// Populates the array
  for ($day = $from; $day <= $till; $day += 1) {
    $terms[$day] .= $classes[$tid].' ';
    }
  }

?>

<div class="calendar-calendar"><div class="month-view">
<table>
  <thead>
    <tr>
      <?php foreach ($day_names as $cell): ?>
        <th class="<?php print $cell['class']; ?>">
          <?php print $cell['data']; ?>
        </th>
      <?php endforeach; ?>
    </tr>
  </thead>
  <tbody>
    <?php foreach ((array) $rows as $row): ?>
      <tr>
        <?php foreach ($row as $cell): ?>
          <td id="<?php print $cell['id']; ?>" class="<?php print $cell['class']; ?>
    <?php
                    // prints all classes for today
                        foreach($terms as $day => $class) {
                            $today = substr($cell['id'],-2);
                            if ($day == $today) {print $class;}
                        }
                    ?>">
            <?php print $cell['data']; ?>
          </td>
        <?php endforeach; ?>
      </tr>
    <?php endforeach; ?>
  </tbody>
</table>
</div></div>

- then i cleared the cache but it's not working

lucio.ferrari’s picture

Are you positive the field name is actually only "field_date"? Mine is "node_data_field_data_evento_field_data_evento_value"...
That and the term names (like "Congés") are not valid CSS class names: only (a-z, "-", "_").

Hope this helps

L.

Wassim Ghannoum’s picture

Thanks for your help,

i was using the field_date (name of the field name from the content type).. now i printed all variables using <?php print dpm($view->result); ?>

and i changed term names, so my code is the following:

<?php
// $Id: calendar-month.tpl.php,v 1.6.2.3 2008/06/19 22:55:56 karens Exp $
/**
* @file
* Template to display a view as a calendar month.
*
* @see template_preprocess_calendar_month.
*
* $day_names: An array of the day of week names for the table header.
* $rows: An array of data for each day of the week.
* $view: The view.
* $calendar_links: Array of formatted links to other calendar displays - year, month, week, day.
* $display_type: year, month, day, or week.
* $block: Whether or not this calendar is in a block.
* $min_date_formatted: The minimum date for this calendar in the format YYYY-MM-DD HH:MM:SS.
* $max_date_formatted: The maximum date for this calendar in the format YYYY-MM-DD HH:MM:SS.
* $date_id: a css id that is unique for this date,
*   it is in the form: calendar-nid-field_name-delta
*
*/
//dsm('Display: '. $display_type .': '. $min_date_formatted .' to '. $max_date_formatted);
?>


<?php

// Define things

 print dpm($view->result);

$terms = array();
$obj = $view->result;

$classes = array( // terms by tid
  1 => ' bulletins',
  2 => 'compositions',
  3 => 'conges',
  4 => 'examen_entree_cycle1',
  5 => 'examen_entree_sec_cycle2',
  6 => 'examen_entree_sec_cycle3',
  7 => 'examens',
  8 => 'rentrer_cycle2',
  9 => 'rentrer_eb1',
  10 => 'rentrer_eb2_eb3',
  11 => 'rentrer_eb7_eb8',
  12 => 'rentrer_gs',
  13 => 'rentrer_ms',
  14 => 'rentrer_ps',
  15 => 'rentrer_sec_eb9',
  );

// This foreach loop creates an array 'day' => 'terms for this day'

foreach($obj as $result) {

// grabs raw data
  $tid = $result->term_data_tid;
  $inizio = $result->calendar_fields->node_data_field_date_field_date_value;
  $fine = $result->calendar_fields->node_data_field_date_field_date_value;

// start & end day
  $from = substr($inizio,8,2);
  $till = substr($fine,8,2);

// start & end month
  $from_m = substr($inizio,5,2);
  $till_m = substr($fine,5,2);

// what month is this?
  $this_m = substr($rows[1][0]['id'], -5, 2);

// Takes care of events spanning multiple months
  if ($till_m != $from_m) {
    if ($this_m == $from_m) {
        $till += 31;
        }
    if ($this_m == $till_m) {
        $from = 1;   
        }
       
    if (($this_m != $from_m)&&($this_m != $till_m)) { // in case the event spans the whole month
        $from = 1; $till = 31;
        }
    }
// Populates the array
  for ($day = $from; $day <= $till; $day += 1) {
    $terms[$day] .= $classes[$tid].' ';
    }
  }

?>

<div class="calendar-calendar"><div class="month-view">
<table>
  <thead>
    <tr>
      <?php foreach ($day_names as $cell): ?>
        <th class="<?php print $cell['class']; ?>">
          <?php print $cell['data']; ?>
        </th>
      <?php endforeach; ?>
    </tr>
  </thead>
  <tbody>
    <?php foreach ((array) $rows as $row): ?>
      <tr>
        <?php foreach ($row as $cell): ?>
          <td id="<?php print $cell['id']; ?>" class="<?php print $cell['class']; ?>
    <?php
                    // prints all classes for today
                        foreach($terms as $day => $class) {
                            $today = substr($cell['id'],-2);
                            if ($day == $today) {print $class;}
                        }
                    ?>">
            <?php print $cell['data']; ?>
          </td>
        <?php endforeach; ?>
      </tr>
    <?php endforeach; ?>
  </tbody>
</table>
</div></div>

But it's still not working :(

Wassim Ghannoum’s picture

any news about this issue?

lucio.ferrari’s picture

I'm sorry, I think I don't have any...
Just my 2 cents:
I notice you use the same field for $inizio & $fine, while this should not cause problems,
check whether you have a begin and a end date field.
You can also check if your $terms array is populated by:
dpm($terms);
after the lines where it should be...

lucio.ferrari’s picture

I'm sorry, I think I don't have any...
Just my 2 cents:
I notice you use the same field for $inizio & $fine, while this should not cause problems,
check whether you have a begin and a end date field.
You can also check if your $terms array is populated by:
dpm($terms);
after the lines where it should be...

Neslee Canil Pinto’s picture

Issue summary: View changes
Status: Needs review » Closed (outdated)

The D6 branch is no longer supported so we're closing this issue. If you think this issue still exists in D7 you can open a new one.