You are here

protected function availability_calendar_handler_filter_availability::value_form_duration_field in Availability Calendars 7.5

Returns a duration form field definition for the given operand

Parameters

string[] $operators: The names of the possible operators for this operand in the given context: (at, from_to, from_to1,) from_duration

string $operand: The name of the operand: (from, to, to1,) duration

string $dependency_source: The name of the dependency source

Return value

array A form field definition.

1 call to availability_calendar_handler_filter_availability::value_form_duration_field()
availability_calendar_handler_filter_availability::value_form in views/availability_calendar_handler_filter_availability.inc
Add validation and date popup(s) to the value form.

File

views/availability_calendar_handler_filter_availability.inc, line 232

Class

availability_calendar_handler_filter_availability
Views handler to filter on availability.

Code

protected function value_form_duration_field($operators, $operand, $dependency_source) {
  $operator = in_array($this->operator, $operators) ? $this->operator : reset($operators);
  $options = array(
    0 => t('- Select duration -'),
  );
  for ($i = 1; $i <= 28; $i++) {
    if ($i % 7 === 0) {
      $options[$i] = format_plural($i / 7, '1 week', '@count weeks');
    }
    else {
      if ($i <= 20) {
        if ($this->definition['allocation_type'] === AC_ALLOCATION_TYPE_FULLDAY) {
          $options[$i] = format_plural($i, '1 day', '@count days');
        }
        else {
          $options[$i] = format_plural($i, '1 night', '@count nights');
        }
      }
    }
  }
  $variable_name = "availability_calendar_views_op_{$operator}_{$operand}";
  $element = array(
    '#type' => 'select',
    '#title' => availability_calendar_get_customizable_text($variable_name),
    '#options' => $options,
    '#default_value' => $this->value[$operand],
  );
  if ($dependency_source !== NULL) {
    $element['#dependency'] = array(
      $dependency_source => $operators,
    );
  }
  return $element;
}