Welcome Guest, Not a member yet? Register   Sign In
Horizontal Calendar
#1

[eluser]Unknown[/eluser]
I'm just starting with Codeigniter and would like to have a horizontal calendar. I have used a template to display each day of the month in a single row but I am having trouble with repeating the days of the week in a header. so far I have something like this....

Su Mo Tu We Th Fr Sa
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 ......... 31

using this template....

$prefs['template'] = '

{table_open}<table border="0" cellpadding="5" cellspacing="0">{/table_open}
{heading_row_start}<tr>{/heading_row_start}
{heading_previous_cell}<th><a href="{previous_url}">&lt;&lt;</a>th>{/heading_previous_cell}
{heading_title_cell}<th colspan="{colspan}">{heading}</th>{/heading_title_cell}
{heading_next_cell}<th><a href="{next_url}">&gt;&gt;</a></th>{/heading_next_cell}
{heading_row_end}</tr>{/heading_row_end}
{week_row_start}<tr class="weekrow">{/week_row_start}
{week_day_cell}<td class="weekday">{week_day}</td>{/week_day_cell}
{week_row_end}</tr>{/week_row_end}
{cal_row_start}{/cal_row_start}
{cal_cell_start}<td>{/cal_cell_start}
{cal_cell_content}<a href="{content}">{day}</a>{/cal_cell_content}
{cal_cell_content_today}<div class="highlight"><a href="{content}">{day}</a></div>{/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}{/cal_row_end}
{table_close}</table>{/table_close}

Any recommendations?
#2

[eluser]roguemonk[/eluser]
[quote author="cnother" date="1229877521"]I'm just starting with Codeigniter and would like to have a horizontal calendar. I have used a template to display each day of the month in a single row but I am having trouble with repeating the days of the week in a header. so far I have something like this....

Su Mo Tu We Th Fr Sa
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 ......... 31

using this template....

$prefs['template'] = '

{table_open}<table border="0" cellpadding="5" cellspacing="0">{/table_open}
{heading_row_start}<tr>{/heading_row_start}
{heading_previous_cell}<th><a href="{previous_url}">&lt;&lt;</a>th>{/heading_previous_cell}
{heading_title_cell}<th colspan="{colspan}">{heading}</th>{/heading_title_cell}
{heading_next_cell}<th><a href="{next_url}">&gt;&gt;</a></th>{/heading_next_cell}
{heading_row_end}</tr>{/heading_row_end}
{week_row_start}<tr class="weekrow">{/week_row_start}
{week_day_cell}<td class="weekday">{week_day}</td>{/week_day_cell}
{week_row_end}</tr>{/week_row_end}
{cal_row_start}{/cal_row_start}
{cal_cell_start}<td>{/cal_cell_start}
{cal_cell_content}<a href="{content}">{day}</a>{/cal_cell_content}
{cal_cell_content_today}<div class="highlight"><a href="{content}">{day}</a></div>{/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}{/cal_row_end}
{table_close}</table>{/table_close}

Any recommendations?[/quote]

I realize this is a really old post, but since no-one's documented a solution, here's mine:

Code:
// Somewhere before your calendar prefs, get the first day of the month
$first_day = mktime(0, 0, 0, date('m'), 1, date('Y'));

// Use the first day of the month to remove empty cells from the start of calendar
// For brevity, I've only included the start_day pref. Feel free to add more.
$prefs = array (
      'start_day'    => strtolower(date('l', $first_day)),
      );

// in prefs['template'], add a tag for your weekdays in all cell_content lines. I made mine {week_day}
// again, for brevity, I've only included the lines we're concerned with.
{cal_cell_content}{week_day} <a href="{content}">{day}</a> {/cal_cell_content}
{cal_cell_content_today}{week_day} <b><a href="{content}">{day}</a></b>{/cal_cell_content_today}
{cal_cell_no_content}{week_day} {day}{/cal_cell_no_content}
{cal_cell_no_content_today}{week_day} <b>{day}</b>{/cal_cell_no_content_today}

// generate the calendar. I'm using some quick defaults for testing.
$mycal = $this->calendar->generate(date('Y'), date('m'), $data);
    
// since we have the calendar class loaded, get the day names that way.
$weekdays = $this->calendar->get_day_names();

// remove empty cells from the end.
$mycal = preg_replace('/<td>&nbsp;<\/td>/', '', $mycal);

// set $i to the first day of the month. 'w' param gets weekday in 0-6 format (0=Sunday, 1=Monday, etc)
$i=date('w', $first_day);

// while our placeholder exists, switch it for the right day of the week.
while (preg_match('/{week_day}/', $mycal)) {
  # code...
  $mycal = preg_replace('/{week_day}/', $weekdays[$i], $mycal, 1);
  $i++;
  if ($i==7) {
    # code...
    $i=0;
  }
}

// do something with the calendar        
echo $mycal;

You could get fancier with the replacement. I've only just started playing with this. Let me know if it's unclear.

--Dave




Theme © iAndrew 2016 - Forum software by © MyBB