Hey guys, still working on the event calendar class. There is this function that prints a week and time for each day from 6am-10pm. I just finished writing that part, but I’m going to keep on staring at the code to find ways to simplify the code even more.
If you have some suggestions on how to simplify it please let me know.
Here is the code that prints the cells for the time:
// >>>>>>>>>>>>>>>>>> TIME <<<<<<<<<<<<<<
// this time array is used for printing rows, one row for 00 and 15 minutes, and another row for 30 and 45 minutes
$time=array();
for($i=6; $i <= 22; $i++){
$time[] = strtotime('+'.$i.' hour 12AM');
$time[] = strtotime('+'.$i.' hour 30 minutes 12AM');
}
// loop hours
// for($i=6; $i <= 22; $i++){
foreach($time as $key => $fifteen_increments){
$hour = date('H', $fifteen_increments);
$hour_minutes = date('H:i', $fifteen_increments);
$fifteen_increments = ($hour_minutes != '12:00') ? date('g:i A', $fifteen_increments) : 'Noon';
// a row, every half-hour
if(date('i', strtotime($fifteen_increments))=='00'){
$complete .= '<tr><th scope="row">'.$fifteen_increments.'</th>';
}
// a row, every half-hour
if(date('i', strtotime($fifteen_increments))=='30'){
$complete .= '<tr><th scope="row"></th>';
}
$running_day='';
$running_day_15='';
$running_day_30='';
$running_day_45='';
// loop days
for($j=0; $j<7;$j++){
$insert_content = '';
if(substr($hour_minutes, -2)==00)
{
$running_day = date('Y-m-d', strtotime('+'.$j.' day '.$sunday_legible)).' '.$hour_minutes.':00';
$running_day_15 = date('Y-m-d', strtotime('+'.$j.' day '.$sunday_legible)).' '.$hour.':15:00';
}
if(substr($hour_minutes, -2)==30)
{
$running_day_30 = date('Y-m-d', strtotime('+'.$j.' day '.$sunday_legible)).' '.$hour.':30:00';
$running_day_45 = date('Y-m-d', strtotime('+'.$j.' day '.$sunday_legible)).' '.$hour.':45:00';
}
foreach($events as $key => $value){
if(substr($hour_minutes, -2)==00){
if($running_day==date('Y-m-d H:i:s', strtotime($value[0])) or $running_day_15==date('Y-m-d H:i:s', strtotime($value[0])) ){
$insert_content .= '<span class="event">'.date('g:i A', strtotime($value[0])).'<br />'.$value[1].'</span>';
}
}
if(substr($hour_minutes, -2)==30){
if($running_day_30==date('Y-m-d H:i:s', strtotime($value[0])) or $running_day_45==date('Y-m-d H:i:s', strtotime($value[0])) ){
$insert_content .= '<span class="event">'.date('g:i A', strtotime($value[0])).'<br />'.$value[1].'</span>';
}
}
}
$running_day='';
$running_day_15='';
$running_day_30='';
$running_day_45='';
$complete .= '<td>'.$insert_content.'</td>';
}
$complete .= '</tr>';
}
$label .= '</tr>';
$content .= '</tr>';