コード例 #1
0
 /**
  * A function to generate day view of a set of events
  * @param array $day day to show
  * @param integer $month month to show
  * @param integer $year year to show
  * @param array $weekdaynames
  * @return object with `count` attribute containing the number of associated events with the item
  */
 public static function day_calendar($day, $month, $year)
 {
     global $langEvents, $langActions, $langCalendar, $langDateNow, $is_editor, $dateFormatLong, $langNoEvents, $langDay, $langWeek, $langMonth, $langView;
     $calendar_content = "";
     if (is_null($day)) {
         $day = 1;
     }
     $nextdaydate = new DateTime("{$year}-{$month}-{$day}");
     $nextdaydate->add(new DateInterval('P1D'));
     $previousdaydate = new DateTime("{$year}-{$month}-{$day}");
     $previousdaydate->sub(new DateInterval('P1D'));
     $thisday = new DateTime("{$year}-{$month}-{$day}");
     $daydescription = ucfirst(claro_format_locale_date($dateFormatLong, $thisday->getTimestamp()));
     $backward = array('day' => $previousdaydate->format('d'), 'month' => $previousdaydate->format('m'), 'year' => $previousdaydate->format('Y'));
     $foreward = array('day' => $nextdaydate->format('d'), 'month' => $nextdaydate->format('m'), 'year' => $nextdaydate->format('Y'));
     $calendar_content .= '<div class="right" style="width:100%">' . $langView . ':&nbsp;' . '<a href="#" onclick="show_day(selectedday, selectedmonth, selectedyear);return false;">' . $langDay . '</a>&nbsp;|&nbsp;' . '<a href="#" onclick="show_week(selectedday, selectedmonth, selectedyear);return false;">' . $langWeek . '</a>&nbsp;|&nbsp;' . '<a href="#" onclick="show_month(selectedday, selectedmonth, selectedyear);return false;">' . $langMonth . '</a></div>';
     $calendar_content .= "<table class='table-default'>";
     $calendar_content .= "<tr>";
     $calendar_content .= '<td width="25"><a href="#" onclick="show_day(' . $backward['day'] . ',' . $backward['month'] . ',' . $backward['year'] . '); return false;">&laquo;</a></td>';
     $calendar_content .= "<td class='center'><b>{$daydescription}</b></td>";
     $calendar_content .= '<td width="25" class="right"><a href="#" onclick="show_day(' . $foreward['day'] . ',' . $foreward['month'] . ',' . $foreward['year'] . '); return false;">&raquo;</a></td>';
     $calendar_content .= "</tr>";
     $calendar_content .= "</table>";
     $eventlist = Calendar_Events::get_calendar_events("day", "{$year}-{$month}-{$day}");
     $calendar_content .= "<table width='100%' class='tbl_alt'>";
     $curhour = 0;
     $now = getdate();
     $today = new DateTime($now['year'] . '-' . $now['mon'] . '-' . $now['mday'] . ' ' . $now['hours'] . ':' . $now['minutes']);
     if ($now['year'] . '-' . $now['mon'] . '-' . $now['mday'] == "{$year}-{$month}-{$day}") {
         $thisdayistoday = true;
     } else {
         $thisdayistoday = false;
     }
     $thishour = new DateTime($today->format('Y-m-d H:00'));
     $cursorhour = new DateTime("{$year}-{$month}-{$day} 00:00");
     $curstarthour = "";
     foreach ($eventlist as $thisevent) {
         $thiseventstart = new DateTime($thisevent->start);
         $thiseventhour = new DateTime($thiseventstart->format('Y-m-d H:00'));
         if ($curstarthour != $thiseventhour) {
             //event date changed
             while ($cursorhour < $thiseventhour) {
                 if ($thisdayistoday && $thishour >= $cursorhour && intval($cursorhour->diff($thishour, true)->format('%h')) < 6) {
                     $class = 'today';
                 } else {
                     $class = 'monthLabel';
                 }
                 $calendar_content .= "<tr><td colspan='3' class='{$class}'>" . "&nbsp;<b>" . ucfirst($cursorhour->format('H:i')) . "</b></td></tr>";
                 if (intval($cursorhour->diff($thiseventhour, true)->format('%h')) > 6) {
                     $calendar_content .= "<tr><td colspan='3'>{$langNoEvents}</td></tr>";
                 }
                 $cursorhour->add(new DateInterval('PT6H'));
                 $curhour += 6;
             }
             if ($thisdayistoday && $thishour >= $cursorhour && intval($cursorhour->diff($thishour, true)->format('%h')) < 6) {
                 $class = 'today';
             } else {
                 $class = 'monthLabel';
             }
             //No hour tr for the event
             //$calendar_content .= "<tr><td colspan='3' class='$class'>" . "&nbsp;<b>" . ucfirst($thiseventhour->format('H:i')) . "</b></td></tr>";
             if ($cursorhour <= $thiseventhour) {
                 $cursorhour->add(new DateInterval('PT6H'));
                 $curhour += 6;
             }
         }
         $calendar_content .= Calendar_Events::day_calendar_item($thisevent, 'even');
         $curstarthour = $thiseventhour;
         //$numLine++;
     }
     /* Fill with empty days*/
     for ($i = $curhour; $i < 24; $i += 6) {
         if ($thisdayistoday && $thishour >= $cursorhour && intval($cursorhour->diff($thishour, true)->format('%h')) < 6) {
             $class = 'today';
         } else {
             $class = 'monthLabel';
         }
         $calendar_content .= "<tr><td colspan='3' class='{$class}'>" . "&nbsp;<b>" . ucfirst($cursorhour->format('H:i')) . "</b></td></tr>";
         $calendar_content .= "<tr><td colspan='3'>{$langNoEvents}</td></tr>";
         $cursorhour->add(new DateInterval('PT6H'));
     }
     $calendar_content .= "</table>";
     /* Legend */
     $calendar_content .= Calendar_Events::calendar_legend();
     return $calendar_content;
 }