You are here

function availability_calendar_process_availability_calendar_months in Availability Calendars 7.5

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

This process function adds:

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

Parameters

array $variables:

Throws

\Exception

File

./availability_calendar.theme.inc, line 147

Code

function availability_calendar_process_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
      ->add(new DateInterval("P{$months_to_render}M"));
    $to
      ->sub(new DateInterval('P1D'));
    if ($variables['settings']['allocation_type'] === AC_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
        ->sub(new DateInterval('P1D'));
    }

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