You are here

function bat_facets_availability in Booking and Availability Management Tools for Drupal 7

Callback for facet availability form.

1 string reference to 'bat_facets_availability'
BatStateWidget::execute in modules/bat_facets/src/BatStateWidget.php
Execution callback.

File

modules/bat_facets/bat_facets.module, line 39

Code

function bat_facets_availability($form, &$form_state, $elements) {
  $params = drupal_get_query_parameters();
  $now = date_create();

  // Year defaults to current year, although we are not filtering yet.
  $default_year = $now
    ->format('Y');

  // Month doesn't have a default selection.
  $default_month = '';
  $form['container'] = array(
    '#type' => 'container',
    '#attributes' => array(
      'class' => array(
        'container-inline',
      ),
    ),
  );
  if (isset($params['bat_start_date']) && !empty($params['bat_start_date'])) {
    $start_date = new DateTime($params['bat_start_date']);
    $arrival = $start_date
      ->format('Y-m-d H:i');
  }
  if (isset($params['bat_end_date']) && !empty($params['bat_end_date'])) {
    $end_date = new DateTime($params['bat_end_date']);
    $departure = $end_date
      ->format('Y-m-d H:i');
  }

  // Create unique ids and selectors for each picker.
  $start_date_id = drupal_html_id('datepicker-start-date');
  $start_date_selector = '#' . $start_date_id . ' .form-text';
  $end_date_id = drupal_html_id('datepicker-end-date');
  $end_date_selector = '#' . $start_date_id . ' .form-text';

  // Specify the default datepicker parameters (see date_popup_element_info())
  $datepicker_options = array(
    // Limit bookings to X days in advance, depending on the
    // chosen configuration in your BAT installation, defaults
    // to the current day.
    'minDate' => '+' . variable_get('bat_event_start_date', 0) . 'd',
  );
  $form['container']['arrival'] = array(
    '#type' => 'date_popup',
    '#description' => '',
    '#date_format' => variable_get('bat_date_format', 'Y-m-d H:i'),
    '#default_value' => isset($arrival) ? $arrival : '',
    '#datepicker_options' => array_merge($datepicker_options, array(
      'endDateSelector' => $end_date_selector,
    )),
    '#required' => TRUE,
  );
  $form['container']['departure'] = array(
    '#type' => 'date_popup',
    '#description' => '',
    '#date_format' => variable_get('bat_date_format', 'Y-m-d H:i'),
    '#default_value' => isset($departure) ? $departure : '',
    '#datepicker_options' => array_merge($datepicker_options, array(
      'startDateSelector' => $start_date_selector,
    )),
    '#required' => TRUE,
    '#attached' => array(
      'js' => array(
        drupal_get_path('module', 'bat') . '/js/bat_date_popup.js',
        array(
          'data' => array(
            'bat' => array(
              'batBookingStartDay' => variable_get('bat_event_start_date', 0),
              'batDateFormat' => 'dd/mm/yy',
              // Here we create a listing of all datepickers registered on the
              // current page. This is available for use in your own custom
              // jQuery scripts as Drupal.settings.bat.datepickers.
              'datepickers' => array(
                $start_date_selector => array(
                  'endDateSelector' => $end_date_selector,
                ),
              ),
            ),
          ),
          'type' => 'setting',
        ),
      ),
    ),
  );
  $form['container']['submit'] = array(
    '#type' => 'submit',
    '#value' => 'Search',
  );
  return $form;
}