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
Comment #1
milos.kroulik CreditAttribution: milos.kroulik commentedUnfortunately, 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?
Comment #2
As If CreditAttribution: As If commentedEverything 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!
Comment #3
milos.kroulik CreditAttribution: milos.kroulik commentedOK, 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):
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).
Comment #4
lucio.ferrari CreditAttribution: lucio.ferrari commentedI 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:
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.
Comment #5
luffy48 CreditAttribution: luffy48 commentedHi !
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
Comment #6
lucio.ferrari CreditAttribution: lucio.ferrari commentedHi, 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 :-)
Comment #7
Wassim Ghannoum CreditAttribution: Wassim Ghannoum commentedHow to do it for the calendar page and not mini calendar, what is the code?
N.b: for drupal 6
Comment #8
lucio.ferrari CreditAttribution: lucio.ferrari commentedCheck this out:
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.
Comment #9
Wassim Ghannoum CreditAttribution: Wassim Ghannoum commentedthank 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:
- then i cleared the cache but it's not working
Comment #10
lucio.ferrari CreditAttribution: lucio.ferrari commentedAre 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.
Comment #11
Wassim Ghannoum CreditAttribution: Wassim Ghannoum commentedThanks 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:
But it's still not working :(
Comment #12
Wassim Ghannoum CreditAttribution: Wassim Ghannoum commentedany news about this issue?
Comment #13
lucio.ferrari CreditAttribution: lucio.ferrari commentedI'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...
Comment #14
lucio.ferrari CreditAttribution: lucio.ferrari commentedI'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...
Comment #15
Neslee Canil PintoThe 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.