You are here

function rooms_preprocess_rooms_three_month_calendar in Rooms - Drupal Booking for Hotels, B&Bs and Vacation Rentals 7

Default implementation of hook_preprocess_rooms_three_month_calendar().

Here we setup the three-month calendar based on a specified year, month, and url.

File

./rooms.module, line 1268
Provides basic underlying functionality and configuration options used by all Rooms modules

Code

function rooms_preprocess_rooms_three_month_calendar(&$vars) {

  // Load FullCalendar.
  rooms_fullcalendar_loaded();

  // Add css styles for three-month-calendar.
  drupal_add_css(drupal_get_path('module', 'rooms_availability') . '/css/rooms_three_month_calendar.css');
  drupal_add_css(drupal_get_path('module', 'rooms_availability') . '/css/fullcalendar.theme.css');

  // If dates are not provided then use the current date.
  $year = empty($vars['year']) ? date('Y', time()) : check_plain($vars['year']);
  $month = empty($vars['month']) ? date('n', time()) : check_plain($vars['month']);

  // Inject settings in javascript that will be used to setup the three months
  // display.
  drupal_add_js(array(
    'roomsCalendar' => array(
      'currentMonth' => intval($month),
    ),
  ), 'setting');
  drupal_add_js(array(
    'roomsCalendar' => array(
      'currentYear' => intval($year),
    ),
  ), 'setting');
  drupal_add_js(array(
    'roomsCalendar' => array(
      'firstDay' => intval(variable_get('date_first_day', 0)),
    ),
  ), 'setting');

  // Calculate forward and back dates for the 3-month view calendar.
  $date1 = new DateTime("{$year}-{$month}-1");
  $date2 = new DateTime("{$year}-{$month}-1");
  $date_current = new DateTime("now");
  $forward = $date1
    ->add(new DateInterval('P3M'));
  $backward = $date2
    ->sub(new DateInterval('P3M'));

  // Create the links based off the url variable passed in.
  if (!isset($vars['url'])) {
    $vars['url'] = '';
  }
  $forward_path = $vars['url'] . '/' . $forward
    ->format('Y') . '/' . $forward
    ->format('n');
  $backward_path = $vars['url'] . '/' . $backward
    ->format('Y') . '/' . $backward
    ->format('n');
  $current_path = $vars['url'] . '/' . $date_current
    ->format('Y') . '/' . $date_current
    ->format('n');
  if (!is_array($vars['link_options']) || empty($vars['link_options'])) {
    $vars['link_options'] = array();
  }
  $vars['forward_link'] = l(t('Forward'), $forward_path, $vars['link_options']);
  $vars['backward_link'] = l(t('Back'), $backward_path, $vars['link_options']);
  $vars['current_link'] = l(t('Current'), $current_path, $vars['link_options']);
}