Welcome Guest, Not a member yet? Register   Sign In
[Solved] Calendar - Event text within table cells

Hi all,
I'm currently building a script where members of a site can add events to a database which can then be looped out and be displayed within a Calendar. So far, I have events going in and looping out. I have it so in the cells, where the day is displayed, ie, 4 (4th of this month) is a link which goes to the event page.

To do this I am setting up an array and passing it to the calendar class. Example:

$temp = array('4' => 'http://www.mysite.com/events/2009/09/04');

What I am after is the ability to display text within the cell and not link the actual day number (4). So in the cell that displays the 4th day of the month, it will say 'My Birthday Party' and this will be the link to go to my event page.

So I am after this type of array:

$temp = array('4' => array('My Birthday Party', 'http://www.mysite.com/events/2009/09/04'));

How can this be achieved?

I hope what I am asking makes sense!


It makes sense, but is not a feature you can utilize with the default Calendar class. You could extend the class and edit the functions to include that feature if you wanted.

I was dreading this answer. I don't feel very confident in making this adjustment however I do like a challenge! So, I will have a look into this and post a solution if I get it to work.

If anyone else has any other idea's, it will be appreciated.


After a glans at your post it looks as if you're after the kind of array I'm making in a model I posted. If not it could probably give you some ideas. Right now I'm only tinkering with the fetched array. The aim is to alter the query so that I get the right array right away.
Method to get nifty array.

Wow uberfuzz, yes this would help too. It would eliminate me rebuilding the array to pass to the calendar class.

Let me know how you get on with it. Note: I don't want to override the result() function as I am using this for other queries which do not need an array built in this specific way.


OK peoples, I have successfully extended the Calendar class to output actual event names with a link instead of events being linked with the day number.

Your template has to change to reflect the changes.

The code is flexible, so if you pass a normal array like the one below it will still work with the default template only.

$temp = array('4' => 'http://www.mysite.com/events/2009/09/04');

However, if you wish to use an array like this one below, you will need to use the following template.

$temp = array('4' => array('My Birthday Party', 'http://www.mysite.com/events/2009/09/04'));

Adjusted Template

$prefs['template'] = '

   {table_open}<table class="cal" width="100%" border="0" cellpadding="0" cellspacing="0">{/table_open}

   {heading_row_start}<tr class="month">{/heading_row_start}

   {heading_previous_cell}<th align="center"><a href="{previous_url}">&lt;&lt;</a></th>{/heading_previous_cell}
   {heading_title_cell}<th height="30" align="center" colspan="{colspan}">{heading}</th>{/heading_title_cell}
   {heading_next_cell}<th align="center"><a href="{next_url}">&gt;&gt;</a></th>{/heading_next_cell}


   {week_day_cell}<td class="day" width="14%" height="20" align="center">{week_day}</td>{/week_day_cell}

   {cal_cell_start}<td class="date" height="45" valign="top">{/cal_cell_start}

   {cal_cell_content}{day}<br /><a href="{content}">{event}</a>{/cal_cell_content}
   {cal_cell_content_today}<div class="highlight">{day}</div><a href="{content}">{event}</a>{/cal_cell_content_today}

   {cal_cell_no_content_today}<div class="highlight">{day}</div>{/cal_cell_no_content_today}




Example working code

$eventDays = array();
if ( $events ) {
    foreach( $events->result() as $e ) {
        $eventDays["$e->raceday"] = array($e->event_name, $e->event_url);
    echo $this->calendar->generate($year, $month, $eventDays);
} else {
    echo $this->calendar->generate($year, $month);

MY_Calendar.php extension code
See attached file.



Theme © iAndrew 2016 - Forum software by © MyBB