You are here

function office_hours_field_settings in Office Hours 6

Same name and namespace in other branches
  1. 5 office_hours.module \office_hours_field_settings()
  2. 6.2 office_hours.module \office_hours_field_settings()

Implementation of hook_field_settings().

Handle the parameters for a field.

File

./office_hours.module, line 110
Creates a field and widget for inserting working or office hours per day

Code

function office_hours_field_settings($op, $field) {
  switch ($op) {
    case 'form':
      if (is_numeric($element['#default_hours'])) {
        list($defhr, $defmin, $ampm) = _office_hours_return_defaults($element['#default_hours'], $field['#hoursformat']);
      }
      $form = array();
      $form['hoursformat'] = array(
        '#type' => 'select',
        '#title' => t('Hours format'),
        '#options' => array(
          t('24 hrs.'),
          t('12 hrs'),
        ),
        '#default_value' => $field['hoursformat'] ? $field['hoursformat'] : 0,
        '#required' => FALSE,
        '#description' => t('Format of the clock. IMPORTANT NOTE: if you do not select "Multiple values", you can enter only one day.'),
      );
      $form['granularity'] = array(
        '#type' => 'select',
        '#title' => t('Granularity of time'),
        '#options' => array(
          '60' => t('hours'),
          '30' => t('half hours'),
          '15' => t('quarter hours'),
          '5' => t('5 minute intervals'),
          '1' => t('minutes'),
        ),
        '#default_value' => $field['granularity'] ? $field['granularity'] : 0,
        '#required' => FALSE,
        '#description' => t('Restrict the input to fixed fractions of an hour.'),
      );
      $form['limitstart'] = array(
        '#type' => 'select',
        '#title' => t('Limit widget hours - start from'),
        '#description' => t('Restrict the hours available - select options will start from this hour'),
        '#default_value' => !empty($field['limitstart']) ? $field['limitstart'] : '',
        '#options' => _office_hours_show_ampm(date_hours('H')),
      );
      $form['limitend'] = array(
        '#type' => 'select',
        '#title' => t('Limit widget hours - until'),
        '#description' => t('Restrict the hours available - select options will end at this hour'),
        '#default_value' => !empty($field['limitend']) ? $field['limitend'] : '',
        '#options' => _office_hours_show_ampm(date_hours('H')),
      );
      $form['valhrs'] = array(
        '#type' => 'checkbox',
        '#title' => t('Validate hours'),
        '#required' => FALSE,
        '#default_value' => isset($field['valhrs']) ? $field['valhrs'] : 0,
        '#description' => t('Please note that this will work as long as the opening hours are not through midnight.'),
      );
      $form['addhrs'] = array(
        '#type' => 'checkbox',
        '#title' => t('Display the "Add more hours" link'),
        '#required' => FALSE,
        '#default_value' => isset($field['addhrs']) ? $field['addhrs'] : 1,
        '#description' => t('Make it possible to use 2 hour block for each day instead of one'),
      );
      $form['showclosed'] = array(
        '#type' => 'checkbox',
        '#title' => t('Show empty days'),
        '#required' => FALSE,
        '#default_value' => isset($field['showclosed']) ? $field['showclosed'] : 0,
        '#description' => t('Show empty days on the node.'),
      );
      return $form;
    case 'validate':
      if ($field['limitend'] <= $field['limitstart'] && !empty($field['limitend']) && !empty($field['limitstart'])) {
        form_set_error('limitend', 'Limit ending hours are earlier than start hours');
      }
      break;
    case 'save':
      return array(
        'hoursformat',
        'granularity',
        'limitstart',
        'limitend',
        'valhrs',
        'addhrs',
        'showclosed',
      );
    case 'database columns':
      $columns = array(
        'day' => array(
          'type' => 'int',
          'not null' => FALSE,
          'sortable' => TRUE,
        ),
        'starthours' => array(
          'type' => 'int',
          'not null' => FALSE,
          'sortable' => TRUE,
        ),
        'endhours' => array(
          'type' => 'int',
          'not null' => FALSE,
          'sortable' => TRUE,
        ),
      );
      return $columns;
    case 'views data':
      $data = _office_hours_views_field_views_data($field);
      $db_info = content_database_info($field);
      $table_alias = content_views_tablename($field);

      // Swap the filter handler.
      $data[$table_alias][$field['field_name'] . '_day']['filter']['handler'] = 'office_hours_handler_filter_day';
      $data[$table_alias][$field['field_name'] . '_starthours']['filter']['handler'] = 'office_hours_handler_filter_hours';
      $data[$table_alias][$field['field_name'] . '_endhours']['filter']['handler'] = 'content_handler_handler_filter_hours';
      return $data;
  }
}