You are here

function visitors_expand_date in Visitors 7.2

Same name and namespace in other branches
  1. 8 forms/date_filter.inc \visitors_expand_date()
  2. 7 forms/date_filter.inc \visitors_expand_date()
  3. 7.0 forms/date_filter.inc \visitors_expand_date()

Roll out a single date element.

1 string reference to 'visitors_expand_date'
visitors_date_filter_form_block in forms/date_filter.inc
Date filter form block.

File

forms/date_filter.inc, line 65
Date filter form for the visitors module.

Code

function visitors_expand_date($element) {

  // Default to current date
  if (empty($element['#value'])) {
    $element['#value'] = array(
      'day' => format_date(time(), 'custom', 'j'),
      'month' => format_date(time(), 'custom', 'n'),
      'year' => format_date(time(), 'custom', 'Y'),
    );
  }
  $element['#tree'] = TRUE;

  // Determine the order of day, month, year in the site's chosen date format.
  $format = variable_get('date_format_short', 'm/d/Y - H:i');
  $sort = array();
  $sort['day'] = max(strpos($format, 'd'), strpos($format, 'j'));
  $sort['month'] = max(strpos($format, 'm'), strpos($format, 'M'));
  $sort['year'] = strpos($format, 'Y');
  asort($sort);
  $order = array_keys($sort);

  // Output multi-selector for date.
  foreach ($order as $type) {
    switch ($type) {
      case 'day':
        $options = drupal_map_assoc(range(1, 31));
        break;
      case 'month':
        $options = drupal_map_assoc(range(1, 12), 'map_month');
        break;
      case 'year':
        $options = drupal_map_assoc(visitors_get_years_range());
        break;
    }
    $parents = $element['#parents'];
    $parents[] = $type;
    $element[$type] = array(
      '#type' => 'select',
      '#value' => $element['#value'][$type],
      '#attributes' => $element['#attributes'],
      '#options' => $options,
    );
  }
  return $element;
}