Page 1 of 1

Calendar module: can categories be colored?

Posted: Tue Jan 23, 2007 6:55 pm
by Jevos
hi,

been asked a long time ago by a different user, but no response unfortunately...

I have several categories in my calendar but qould very much like to emphasise one on a page. Is there a way to apply different stylings/color to different categories?

Thanks in advance.

Testsite at www.arcana.nl/cmsmadesimple

Jevos

Re: Calendar module: can categories be colored?

Posted: Sat Jan 27, 2007 5:04 pm
by Jevos
no active Calendar-users around that have either battled with this issue or know of an alternative (other module perhaps?)

Any thoughts appreciated!

Jevos

Re: Calendar module: can categories be colored?

Posted: Sat Jan 27, 2007 5:51 pm
by heatherfeuer
I've been working with the calendar templates and stylesheet for the last three days or so, but I haven't gotten as far as doing anything with the categories.  I do agree with you, though, that it would be a nice feature to be able to color code the categories.

I notice that at the beginning of each template there is a line of code to assign variables to the month.  I don't know much PHP (mostly just enough to get myself in trouble  :D), but someone with more knowledge might be able to write something that would assign colors to the categories.  Maybe some kind of "foreach" loop similar to the big calendar layout, but would loop through the categories.  Just a thought...

And if someone DID do that, I'd love to be able to use it too!

Re: Calendar module: can categories be colored?

Posted: Mon Jan 29, 2007 3:06 pm
by Jevos
Found a possible solution, working on it now... in the calendar-view (not the other views strangely enough) the categories are delivered to the event-set as an array [$categories]. Reading out this array and adding them in the HTML-code as style-classes seems to be the ticket... maybe sorting them before output to create more control.

If  i succeed: where do i leave this code for others to use? [STUPID!!! Read first, type later... found the sticky!]

Jevos

Re: Calendar module: can categories be colored?

Posted: Wed Jan 31, 2007 5:38 pm
by Jevos
I found a partial solution; in module-file function.displaycalendar.php there is additional code to supply category-name to the event-array. Calling it in the calendar-template with slight modifications:

  {foreach from=$day.events item=event}
    {$event.event_title}


gives you a containing span with whitespace-separated classnames in lower case.

Now for the trouble: i can't get the code to work in the yearlist/list/event-view... anyone know enough array and object programming to help me out?

Code in the module-file function.displaycalendar.php follows:

            // Added by Colin R. R. Johnson, crrj@candjsolutions.com on 2006-10-18
// Retreive the category IDs for the event into an array appended into the events array.
// This will allow for custom formatting of event summaries based on category in the
// Calendar display.
$categoryDb = $module->GetDb();

// Build the sql to retrieve the categories for the event.
$sql = "SELECT DISTINCT $categories_table_name.*
FROM $categories_table_name
INNER JOIN $events_to_categories_table_name
ON $events_to_categories_table_name.category_id = $categories_table_name.category_id
WHERE $events_to_categories_table_name.event_id = $event_id";

$crs = $categoryDb->Execute($sql); // Get the categories result set
$categories = array();
if ($crs) // make sure there are results and assign to the $categories array
{
$categories = $crs->GetArray();
}
$row['categories'] = $categories; // make sure that we actually provide a categories item to the row, even if empty.

// End category retreval.


Jevos

Re: Calendar module: can categories be colored?

Posted: Sat Feb 03, 2007 3:58 am
by c_head
I've just started digging into the Calendar module for a project and color-coding is something I'd like to do also.

The code you posted worked for me when I added it to function.displayupcominglist. The $event_id variable has to be assigned before the SQL query:

Code: Select all

$event_id = $row[event_id]; // Added this line right before SQL query
You can then access each event's 'categories' array from the associated Calendar template. I had to convert the {foreach} loop in the template to {section} loops to get to the data in the nested arrays. Here's a basic example that shows the syntax:

Code: Select all

{section name=event loop=$events}
	<h2>{$events[event].event_title}</h2>
	<p>
	{section name=cats loop=$events[event].categories}
		{$events[event].categories[cats].category_name}, 
	{/section}
	</p>
{/section}
The category names could easily be output in the template as classes for CSS styling. Since events can be in multiple categories, it could get messy quickly; I'm not sure how best to reconcile that. I'll be interested to see what you come up with.

Re: Calendar module: can categories be colored?

Posted: Sat Feb 03, 2007 8:00 am
by Jevos
ahaaaa, that first line did the trick!

now i have a class-listing of all associated categories using the code as show above. in the templates i placed this:

{$event.event_title}

exept for the event-page where it's this (as categories where  included there already  :o:

{$event.event_title}

and in calendar-view where it is:

{$event.event_title|wordwrap:50:"\n":true}


Next up: how to get order in the class chaos.

For me the categories are
  3 different series of events with a name: serie_a, serie_b and serie_c.
  different types of events in all 3 series: weekend, workshops and one_off.

since i don't have overlap (each event is one serie and one type) i've created CSS for putting a logo in front of the text for the associated serie and colored the text according to whicht type it is...

Sample CSS for one serie to place the logo:
/* calendar-view */

#big li.arcana, li.arcana {list-style-type: none; margin-left: -13px; padding-top: 32px; padding-left: 13px; background-image: url('arcana-templates/algemeen/images/logo-book-38px.gif'); background-repeat: no-repeat;
}

/* lists */

div.calendar-event .arcana {
  margin-left: -20px;
  padding-left: 40px; padding-top: 10px;
  height: 25px;
  background-image: url('arcana-templates/algemeen/images/logo-book-38px.gif');
  background-repeat: no-repeat;
}


Trouble really starts when an event is in two series... no clue yet, but not giving up!

Jevos

Re: Calendar module: can categories be colored?

Posted: Sat Feb 03, 2007 5:36 pm
by c_head
Good work! Since you don't have conflicting categories, that should work well.

To do icons for multiple categories, you could insert tags for icons directly in your template, and use the $class.category_name for the image filename. That would get around the limitation of a single background-image in CSS. It might actually be less maintenance work, as you'd only have to upload images when your categories change instead of uploading images and editing CSS too.

My current set of categories do overlap, so I'll have to do some thinking about solutions when I get to that stage. Small icons are probably going to be my best bet.

One other enhancement I added to my monthly calendar is displaying the summary description on mouseover, using the TITLE attribute in the link:

{$event.event_title|wordwrap:50:"\n":true}[/color] title='{$event.event_summary|truncate:80:"..."}'>

When the calendar has a lot of items, it's nice to get a preview of details without navigating away from the page.

Re: Calendar module: can categories be colored?

Posted: Sat Feb 03, 2007 6:54 pm
by mel
Hi,
It seems to be interesting (scuse, i dont understand coding...)
Do you think it will be add to the module if its work fine?
And a question : is it difficult to add this ? The possibility to filter categories on front-end (as already possible on the back end)?

With more export fonctionnality, it will become a very more complete module!

Thanks !
Mel

Re: Calendar module: can categories be colored?

Posted: Wed Feb 07, 2007 11:07 pm
by chead
Looks like the query to return categories needs to be a bit different for the upcoming list.

There are some values not being passed through the SQL queries and that's why it's not working. I gave it a try, but don't have the SQL experience on INNER JOINs to solve it.

It's going to take someone who understands more about the coding to solve this one. I've added a development feature request for the module to provide all event parameters (categories, etc.) to each calendar template.

Re: Calendar module: can categories be colored?

Posted: Mon Mar 26, 2007 3:00 pm
by codepoet
Nice one. Is there a plan to get this feature added to the "official" module? I would like to use this feature, but have a rule that I only allow myself to use stuff "off the shelf" to make it easier to had over to another admin.

Cheers

phill

Re: Calendar module: can categories be colored?

Posted: Tue Jan 29, 2008 9:58 pm
by streever
his code has been removed, and there is nothing in calendar module :(

calendar module is the sad child of CMSMS, no categories, no updates :(!

Can someone reply if this code is still somewhere? If there is someway, documented, to display the category, and to use it in template? I'm working on writing it in myself, but would rather not reproduce all this work which is missing!

Re: Calendar module: can categories be colored?

Posted: Tue Jan 29, 2008 10:34 pm
by calguy1000
well, the category name could be used in a css class name in the template.... and the class name could assign a foreground or background color.

Re: Calendar module: can categories be colored?

Posted: Wed Jan 30, 2008 12:51 pm
by streever
Hey calguy,

I think the problem is that I can't call the category: I tried all the category calls they had, and inserted the code they'd written into the module itself, but it's not working. I think I need the file that they had posted which was deleted.

Do you know what I mean? I used {get_template_vars} but I can't seem to find any valid call to the category.

In my case, I just need a line inside the template, that says, "If it's x category than do this". I don't even need something as complicated as what they want, but I do need to reference the category....