You are here

function bat_event_ui_calendar_page in Booking and Availability Management Tools for Drupal 7

Callback for admin/bat/calendar.

1 string reference to 'bat_event_ui_calendar_page'
bat_event_ui_menu in modules/bat_event_ui/bat_event_ui.module
Implements hook_menu().

File

modules/bat_event_ui/bat_event_ui.module, line 32
Manages events for Units and displaying dates on the jquery FullCalendar plugin.

Code

function bat_event_ui_calendar_page($unit_type, $event_type) {
  module_load_include('inc', 'composer_manager', 'composer_manager.admin');
  $composer_manager_installed_packages = composer_manager_installed_packages();
  if (!isset($composer_manager_installed_packages['roomify/bat'])) {
    drupal_set_message(t('Please install the BAT PHP Library. For instructions click <a target="_blank" href="@link">here</a>.', array(
      '@link' => 'http://docs.roomify.us/bat/drupal/installation.html#install-bat-php-library',
    )), 'error');
    return '';
  }
  $ev_type = bat_event_type_load($event_type);

  // Check if current type support this event type.
  if ($type = bat_type_load($unit_type)) {
    $type_bundle = bat_type_bundle_load($type->type);
    if (is_array($type_bundle->default_event_value_field_ids)) {
      if (!(isset($type_bundle->default_event_value_field_ids[$event_type]) && !empty($type_bundle->default_event_value_field_ids[$event_type]))) {
        return drupal_not_found();
      }
    }
    else {
      return drupal_not_found();
    }
  }
  elseif ($unit_type != 'all') {
    return drupal_not_found();
  }

  // Check if user has permission to view calendar data for this event type.
  if (!user_access('view calendar data for any ' . $ev_type->type . ' event')) {
    return drupal_access_denied();
  }

  // Set the page title.
  drupal_set_title(t('View Event Data'));

  // Pick what modal style to use.
  $calendar_settings['modal_style'] = 'default';
  if ($type = bat_event_type_load($event_type)) {
    $event_granularity = $type->event_granularity;
  }
  else {
    $event_granularity = 'both';
  }

  // All Drupal JS settings inside the batCalendar object.
  $fc_user_settings = array(
    'batCalendar' => array(
      array(
        'unitType' => $unit_type,
        'eventType' => $event_type,
        'eventGranularity' => $event_granularity,
      ),
    ),
  );
  $calendar_settings['user_settings'] = $fc_user_settings;
  $calendar_settings['calendar_id'] = 'fullcalendar-scheduler';
  if ($ev_type->fixed_event_states) {
    $calendar_settings['class'] = array(
      'fixed_event_states',
    );
  }
  else {
    $calendar_settings['class'] = array(
      'open_event_states',
    );
  }
  drupal_add_css(drupal_get_path('module', 'bat_event_ui') . '/css/bat_event_ui.css');
  $render_array = array(
    'event_type_form' => drupal_get_form('bat_event_ui_event_type_form', $unit_type, $event_type),
    'bulk_update_form' => array(),
    'calendar' => array(
      '#theme' => 'bat_fullcalendar',
      '#calendar_settings' => $calendar_settings,
    ),
  );
  if ($ev_type->fixed_event_states) {
    $render_array['bulk_update_form'] = drupal_get_form('bat_event_ui_bulk_update_form', $unit_type, $event_type);
  }
  $jquery_version = variable_get('jquery_update_jquery_version', '1.10');
  $admin_theme = variable_get('admin_theme', FALSE);
  if (theme_get_setting('jquery_update_jquery_version', $admin_theme) != '') {
    $jquery_version = theme_get_setting('jquery_update_jquery_version', $admin_theme);
  }
  if (function_exists('jquery_update_get_versions')) {
    $jquery_versions = array_keys(jquery_update_get_versions());
  }
  else {
    $jquery_versions = array(
      '1.5',
      '1.6',
      '1.7',
      '1.8',
      '1.9',
      '1.10',
    );
  }
  if ($jquery_version == 'default' || array_search($jquery_version, $jquery_versions) < array_search('1.8', $jquery_versions)) {
    drupal_set_message(t('Please ensure that you are using version 1.8 or greater of the jQuery library (<a href="@link">configure</a>)', array(
      '@link' => url('admin/config/development/jquery_update'),
    )), 'error');
  }
  return $render_array;
}