[eluser]Leon Stafford[/eluser]
For my needs, this is currently working:
Code:
<?php
//get this month and next month's details. ie 17th February, 2009
$days_in_month = date('t'); //ie 28
$todays_date = date('d'); //17
$this_month = date('n'); //2
$next_month = date('n', strtotime('next month')); //3
$this_months_year = date('Y'); //2009
$next_months_year = date('Y', strtotime('next month')); //2009 (if this month is Dec, this will be 2010)
$events_in_database = array( //example of data as stored in events db
0 => array(
'id' => '0',
'year' => '2009',
'month' => '2',
'day' => '26',
'event_name' => 'Leons Birthday',
),
1 => array(
'id' => '1',
'year' => '2009',
'month' => '3',
'day' => '1',
'event_name' => 'Someone elses Birthday',
),
2 => array(
'id' => '2',
'year' => '2009',
'month' => '2',
'day' => '27',
'event_name' => 'Grand Opening',
),
3 => array( // creating another array with same date is OK for this project
'id' => '3',
'year' => '2009',
'month' => '2',
'day' => '27',
'event_name' => 'Different Event',
),
);
$this_month_events = array();
$next_month_events = array();
foreach ($events_in_database as $value) { //create this month's calendar data from db
if ($value['year'] == $this_months_year && $value['month'] == $this_month)
{
$this_month_events[$value['day']] = 'view/event/'.$value['year'].'/'.$value['month'].'/'.$value['day'];
} else if ( $value['year'] == $next_months_year && $value['month'] == $next_month)
{
$next_month_events[$value['day']] = 'view/event/'.$value['year'].'/'.$value['month'].'/'.$value['day'];
}
}
$bimonthly_events = array(0=>$this_month_events,1=>$next_month_events);
echo '<pre>';
echo print_r($bimonthly_events);
echo '</pre>';
echo $this->calendar->generate($this_months_year,$this_month,$this_month_events);
if ($days_in_month/2 < $todays_date){
//show next month's date if past the first half of this month
echo $this->calendar->generate($next_months_year,$next_month,$next_month_events);
//if adding a next month button, conditionally add it here
}
?>