You are here

function content_views_argument_handler in Content Construction Kit (CCK) 5

Perform filtering by an argument for field data stored via content.module.

1 string reference to 'content_views_argument_handler'
content_views_field_arguments in ./content_views.inc

File

./content_views.inc, line 244
Interface between content.module and views.module.

Code

function content_views_argument_handler($op, &$query, $argtype, $arg = '') {
  if ($op == 'filter') {
    $field_name = substr($argtype['type'], 9);
  }
  else {
    $field_name = substr($argtype, 9);
  }
  $field = content_fields($field_name);
  $db_info = content_database_info($field);
  $main_column = reset($db_info['columns']);

  // The table name used here is the Views alias for the table, not the actual
  // table name.
  $table = 'node_data_' . $field['field_name'];
  switch ($op) {
    case 'summary':
      $query
        ->ensure_table($table);
      $query
        ->add_field($main_column['column'], $table);
      return array(
        'field' => $table . '.' . $main_column['column'],
      );
      break;
    case 'sort':
      break;
    case 'filter':
      $query
        ->ensure_table($table);
      switch ($main_column['type']) {
        case 'int':
        case 'mediumint':
        case 'tinyint':
        case 'bigint':
          $column_placeholder = '%d';
          break;
        case 'float':
          $column_placeholder = '%f';
          break;
        default:
          $column_placeholder = "'%s'";
      }
      $query
        ->add_where($table . '.' . $main_column['column'] . ' = ' . $column_placeholder, $arg);
      break;
    case 'link':
      $item = array();
      foreach ($db_info['columns'] as $column => $attributes) {
        $view_column_name = $attributes['column'];
        $item[$column] = $query->{$view_column_name};
      }
      return l(content_format($field, $item, 'plain'), $arg . '/' . $query->{$main_column}['column'], array(), NULL, NULL, FALSE, TRUE);
    case 'title':
      $item = array(
        key($db_info['columns']) => $query,
      );
      return content_format($field, $item, 'plain');
  }
}