Exemple #1
0
 /**
  * getSmallCalendar
  * 
  * Gets the data for the small calendar based on the month, day and year.
  *
  * NOTE: Dates are assumed already fixed for timezone and dst.
  * 
  * @param int $month 
  * @param int $year 
  * @param int $day 
  * 
  * @return array
  */
 function getSmallCalendar($month, $year, $day)
 {
     $month = (int) $month;
     $month = str_pad($month, 2, 0, STR_PAD_LEFT);
     $year = (int) $year;
     $day = (int) $day;
     $day = str_pad($day, 2, 0, STR_PAD_LEFT);
     $weekDays = getDayInitials();
     $categories = $this->getCategories();
     $eventDays = $this->getEventDays($month, $year);
     // First day of the month starts on which day?
     $first = mktime(0, 0, 0, $month, 1, $year);
     $offset = date('w', $first);
     // Fix offset - if day of week changed
     if ($this->weekStartOffset > 0) {
         $offset = $offset + (7 - $this->weekStartOffset);
         if ($offset >= 7) {
             $offset = $offset - 7;
         }
     }
     $daysInMonth = date('t', $first);
     // Previous month links
     $prevTS = strtotime("{$year}-{$month}-01 -1 month");
     // Make sure previous day is less than the total num of days in prev month
     $pDay = $day > date('t', $prevTS) ? date('t', $prevTS) : $day;
     list($pYear, $pMonth) = explode('-', date('Y-m', $prevTS));
     // Today links
     $tYear = fixDate('Y', $this->fcmsUser->tzOffset, gmdate('Y-m-d H:i:s'));
     $tMonth = fixDate('m', $this->fcmsUser->tzOffset, gmdate('Y-m-d H:i:s'));
     $tDay = fixDate('d', $this->fcmsUser->tzOffset, gmdate('Y-m-d H:i:s'));
     // Next month links
     $nextTS = strtotime("{$year}-{$month}-01 +1 month");
     // Make sure next day is less than the total num of days in next month
     $nDay = $day > date('t', $nextTS) ? date('t', $nextTS) : $day;
     list($nYear, $nMonth) = explode('-', date('Y-m', $nextTS));
     $formatDate = formatDate('F Y', "{$year}-{$month}-{$day}");
     $calendarData = array('thisMonthUrl' => 'calendar.php?year=' . $year . '&month=' . $month . '&day=' . $day, 'thisMonth' => $formatDate);
     // Weekday names
     $weekDayData = array();
     for ($w = 0; $w <= 6; $w++) {
         $weekDayData[] = $weekDays[($w + $this->weekStartOffset) % 7];
     }
     $calendarData['weekDays'] = $weekDayData;
     // Days in the month, fill with events
     $monthData = array();
     $i = 0;
     for ($d = 1 - $offset; $d <= $daysInMonth; $d++) {
         if ($i % 7 == 0) {
             // start new week
             $weekData = array();
         }
         if ($d < 1) {
             $weekData[] = array('class' => 'nonMonthDay', 'data' => '&nbsp;');
         } else {
             $class = 'monthDay';
             if ($d == $day) {
                 $class = 'monthToday';
             }
             $data = $d;
             if (in_array($d, $eventDays)) {
                 $data = '<a href="calendar.php?year=' . $year . '&amp;month=' . $month . '&amp;day=' . $d . '&amp;view=day">' . $d . '</a>';
             }
             $weekData[] = array('class' => $class, 'data' => $data);
         }
         $i++;
         // if we have 7 <td> for the current week close the <tr>
         if ($i % 7 == 0) {
             $monthData[] = $weekData;
         }
     }
     if ($i % 7 != 0) {
         // finish any incomplete weeks/rows
         for ($j = 0; $j < 7 - $i % 7; $j++) {
             $weekData[] = array('class' => 'nonMonthDay', 'data' => '&nbsp;');
         }
         $monthData[] = $weekData;
     }
     $calendarData['days'] = $monthData;
     return $calendarData;
 }
Exemple #2
0
/**
 * getDayInitial 
 * 
 * Given a number of the weekday 0-6, returns the translated initial for that day.
 * 
 * @param int $d
 * 
 * @return string
 */
function getDayInitial($w)
{
    $day_initial = getDayInitials();
    return $day_initial[$w];
}