You are here

function event_calendar_month in Event 5

Same name and namespace in other branches
  1. 5.2 event.module \event_calendar_month()

Displays a monthly event calendar.

Return value

a themed monthly event calendar.

Related topics

2 calls to event_calendar_month()
event_block in ./event.module
Provides the blocks that this module is capable of displaying.
event_page in ./event.module
Displays a page containing event information. The page layout defaults to a graphical calendar.

File

./event.module, line 495

Code

function event_calendar_month($op, $stamp, $types = NULL, $terms = NULL) {
  $year = gmdate('Y', $stamp);
  $month = gmdate('m', $stamp);
  $day = gmdate('d', $stamp);
  switch ($op) {
    case 'page':

      // setup callback for data population
      $callback = 'event_render_day';
      $view = 'month';
      break;
    case 'block':

      // create caption and navigation links
      $caption = _event_nav($stamp, 'prev', 'block', $types, $terms) . ' ' . l(t(gmdate('F', $stamp)) . ' ' . $year, 'event/' . $year . '/' . $month . '/' . $day . '/month') . ' ' . _event_nav($stamp, 'next', 'block', $types, $terms);
      $callback = 'event_render_day_single';
      $view = 'block';
      break;
  }

  // get weekdays array and header information
  $weekdays = event_week_days();
  $thead = event_week_header();
  $tbody = array();

  // get GMT current date value
  $today = _event_user_date();

  // name of the month
  $month_name = t(gmdate('F', $stamp));
  $month_name_abbrev = t(gmdate('M', $stamp));

  // timestamp of first day of month
  $curstamp = gmmktime(0, 0, 0, $month, 01, $year);

  // timestamp of last day in month
  $lastday = gmmktime(0, 0, 0, $month, gmdate('t', $stamp), $year);

  // pad the first week row array to fill up days in the previous month we don't build
  $row = array_fill(0, 6, array(
    'class' => 'pad',
  ));

  // get the day of week offset value for the first day of the month
  $start = $offset = _event_day_of_week($curstamp);

  // render the month calendar
  while ($curstamp <= $lastday) {
    for ($x = $start; $x < 7; $x++) {
      $cur_day = $week * 7 + ($x + 1) - $offset;
      $row[$x] = array(
        'class' => strtolower($weekdays[$x]['day']) . " day-{$cur_day}" . ($curstamp == $today ? ' today' : '') . ($cur_day == $day ? ' selected' : ''),
        'data' => $callback($year, $month, $cur_day, $view, $types, $terms),
      );
      $curstamp += 86400;
      if ($curstamp > $lastday) {
        $x = 8;
      }
    }
    $week++;
    $start = 0;
    $tbody[] = array_pad($row, 7, array(
      'class' => 'pad',
    ));
    $row = array();
  }
  switch ($op) {
    case 'page':
      return array(
        $thead,
        $tbody,
      );
      break;
    case 'block':
      return theme('event_calendar_month', $op, $thead, $tbody, $attributes = array(
        'class' => 'event-block ' . strtolower($month_name),
      ), $caption);
      break;
  }
}