You are here

function availability_calendar_preprocess_availability_calendar_months in Availability Calendars 7.3

Same name and namespace in other branches
  1. 7.4 availability_calendar.theme.inc \availability_calendar_preprocess_availability_calendar_months()

Implements hook_preprocess_HOOK for theme availability_calendar @link http://api.drupal.org/api/drupal/modules--system--theme.api.php/function...

This preprocess function adds

  • year (if not set)
  • month (if not set)
  • availability for all months to show

File

./availability_calendar.theme.inc, line 100

Code

function availability_calendar_preprocess_availability_calendar_months(&$variables) {
  if (empty($variables['year'])) {
    $variables['year'] = (int) date('Y');
  }
  if (empty($variables['month'])) {
    $variables['month'] = (int) date('n');
  }
  if (empty($variables['availability'])) {
    $months_to_render = $variables['settings']['show_number_of_months'];
    $from = new DateTime();
    $from
      ->setDate($variables['year'], $variables['month'], 1);
    $to = clone $from;
    $to
      ->modify("+{$months_to_render} months");
    $to
      ->modify('-1 day');
    if ($variables['settings']['allocation_type'] === ALLOCATION_TYPE_OVERNIGHT && $variables['settings']['show_split_day']) {

      // We may want to show the state of the first morning of the first month.
      // And we need the state from the last day of the previous month for that.
      $from
        ->modify('-1 day');
    }

    // Convert new cid's to 0.
    $cid = (int) $variables['cid'];
    $variables['availability'] = availability_calendar_get_availability($cid, $from, $to, $variables['settings']['default_state']);
  }
}