You are here

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

Handles display for per person pricing.

_state

_keys

Parameters

$form:

$tmp_unit:

$units:

$c:

$type:

$price:

Return value

mixed

1 call to _rooms_booking_manager_handle_per_person_pricing()
book_units_per_type_form in modules/rooms_booking_manager/rooms_booking_manager.module
Book units per type booking form callback.

File

modules/rooms_booking_manager/rooms_booking_manager.units_per_type_form.inc, line 282
Helper functions to clear up the units per type form and make the logic easier to follow.

Code

function _rooms_booking_manager_handle_per_person_pricing($form, &$form_state, $tmp_unit, $units, $units_keys, $c, $type, $price) {

  // Show Guests and Children selectors if price calculation is set
  // to 'Price per person per night'.
  $form[$type][$price]['fieldset'][$c]['persons'] = array(
    '#type' => 'select',
    '#field_suffix' => t('Guests'),
    '#options' => array_combine(range($tmp_unit->min_sleeps, $tmp_unit->max_sleeps), range($tmp_unit->min_sleeps, $tmp_unit->max_sleeps)),
    '#default_value' => $tmp_unit->max_sleeps,
    '#ajax' => array(
      'callback' => 'rooms_booking_manager_quantity_change_callback',
      'wrapper' => $type . '_' . $price . '_container',
    ),
    '#title' => t('How many people in this unit (including adults and children)?'),
    '#prefix' => '<div class="rooms-search-result__select-guests">',
    '#suffix' => '</div>',
  );
  $max_children = $tmp_unit->max_children;
  if (isset($form_state['values'][$type][$price]['fieldset'][$c]['persons'])) {
    $persons = $form_state['values'][$type][$price]['fieldset'][$c]['persons'];
    if ($persons < $tmp_unit->max_children) {
      $max_children = $persons;
    }
  }
  if (variable_get('rooms_display_children', ROOMS_DISPLAY_CHILDREN_NO) == ROOMS_DISPLAY_CHILDREN) {
    if ($tmp_unit->max_children > 0) {
      $form[$type][$price]['fieldset'][$c]['children'] = array(
        '#type' => 'select',
        '#title' => t('How many of the guests are children?'),
        '#field_suffix' => t('Children'),
        '#options' => array_combine(range($tmp_unit->min_children, $max_children), range($tmp_unit->min_children, $max_children)),
        '#default_value' => 0,
        '#ajax' => array(
          'callback' => 'rooms_booking_manager_children_change_callback',
          'wrapper' => $type . '_' . $price . '_' . $c . '_childrensage',
        ),
        '#prefix' => '<div class="rooms-search-result__select-children">',
        '#suffix' => '</div>',
      );
    }
    $form[$type][$price]['fieldset'][$c]['childrens_age'] = array(
      '#prefix' => '<div class="rooms-search-result__select-childrenage" id="' . $type . '_' . $price . '_' . $c . '_childrensage">',
      '#suffix' => '</div>',
    );
    $children_number = 0;
    if (isset($form_state['values'][$type][$price]['fieldset'][$c]['children'])) {
      if ($form_state['values'][$type][$price]['fieldset'][$c]['children'] > 0) {
        $children_number = $form_state['values'][$type][$price]['fieldset'][$c]['children'];
      }
    }
    else {
      $children_number = $tmp_unit->min_children;
    }
    for ($t = 1; $t <= $children_number; $t++) {
      $form[$type][$price]['fieldset'][$c]['childrens_age'][$t] = array(
        '#type' => 'select',
        '#field_prefix' => t('Age of child @num', array(
          '@num' => $t,
        )),
        '#options' => range(0, 18),
        '#ajax' => array(
          'callback' => 'rooms_booking_manager_options_change_callback',
          'wrapper' => $type . '_' . $price . '_' . $c . '_price',
        ),
        '#attributes' => array(
          'class' => array(
            'rooms-search-result__childrens-age',
          ),
        ),
      );
    }
  }
  return $form;
}