You are here

function _better_statistics_get_views_handlers in Better Statistics 7

Returns a best guess on which Views handlers should be used based on a provided field schema.

Parameters

$schema: An array representing the field's schema.

Return value

An array of views handlers.

1 call to _better_statistics_get_views_handlers()
_better_statistics_get_custom_fields_by_module in ./better_statistics.admin.inc
Returns arrays of fields keyed by the module that declares them. In addition, this function will attempt to apply sensible views handlers. This should be the only function used to get declared fields.

File

./better_statistics.admin.inc, line 599
Admin and config code for the Better Statistics module.

Code

function _better_statistics_get_views_handlers($schema) {
  $handlers = array();

  // Define some straightforward string handlers.
  $string_handlers = array(
    'field' => array(
      'handler' => 'views_handler_field',
      'click sortable' => TRUE,
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_string',
      'allow empty' => TRUE,
    ),
    'argument' => array(
      'handler' => 'views_handler_argument_string',
    ),
  );

  // Define some straightforward numeric handlers.
  $numeric_handlers = array(
    'field' => array(
      'handler' => 'views_handler_field_numeric',
      'click sortable' => TRUE,
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_numeric',
      'allow empty' => TRUE,
    ),
    'argument' => array(
      'handler' => 'views_handler_argument_numeric',
    ),
  );
  switch ($schema['type']) {
    case 'serial':
    case 'int':
    case 'float':
    case 'numeric':
      $handlers = $numeric_handlers;
      break;
    case 'varchar':
    case 'text':
      $handlers = $string_handlers;
      break;
    case 'blob':
      $handlers = FALSE;
      break;
  }
  return $handlers;
}