• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Solved] Calendar - Event text within table cells

#1
[eluser]LifeSteala[/eluser]
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:

Code:
$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:

Code:
$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!

Thanks!

#2
[eluser]Aken[/eluser]
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.

#3
[eluser]LifeSteala[/eluser]
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.

Thanks!

#4
[eluser]überfuzz[/eluser]
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.

#5
[eluser]LifeSteala[/eluser]
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.

Thanks!

#6
[eluser]LifeSteala[/eluser]
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.

Code:
$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.

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

Adjusted Template

Code:
$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}

   {heading_row_end}</tr>{/heading_row_end}

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

   {cal_row_start}<tr>{/cal_row_start}
   {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}{day}{/cal_cell_no_content}
   {cal_cell_no_content_today}<div class="highlight">{day}</div>{/cal_cell_no_content_today}

   {cal_cell_blank}&nbsp;{/cal_cell_blank}

   {cal_cell_end}</td>{/cal_cell_end}
   {cal_row_end}</tr>{/cal_row_end}

   {table_close}</table>{/table_close}
';

Example working code

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.

Enjoy!

Thanks!


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.