You are here

function content_taxonomy_views_views_tables in Content Taxonomy 5

File

./content_taxonomy_views.module, line 19
Views Support for content_taxonomy

Code

function content_taxonomy_views_views_tables() {
  $tables = array();
  $fields = content_fields();
  $info = _content_type_info();
  foreach ($fields as $field) {
    if ($field['type'] == 'content_taxonomy') {

      //get out parent for opt groups
      foreach ($info['content types'] as $content_type) {
        foreach ($content_type['fields'] as $field_name => $field_info) {
          if ($field_name == $field['field_name']) {
            if (isset($field_info['widget']['group_tid'])) {
              $group_tid = $field_info['widget']['group_tid'];
            }
          }
        }
      }
      if ($field['save'] != 'tag') {
        $db_info = content_database_info($field);
        $tablename = $db_info['table'];
        $fieldname = $field['field_name'] . '_value';
        $table['name'] = $db_info['table'];
        $table['join'] = array(
          'left' => array(
            'table' => 'node',
            'field' => 'vid',
          ),
          'right' => array(
            'field' => 'vid',
          ),
        );
      }
      else {
        $tablename = 'content_taxonomy_' . $field['field_name'];
        $table['name'] = 'term_node';
        $fieldname = "tid";
        $table['join'] = array(
          'left' => array(
            'table' => 'node',
            'field' => 'nid',
          ),
          'right' => array(
            'field' => 'nid',
          ),
        );
      }
      $tables[$tablename] = array();
      $tables[$tablename] = $table;
      $tables[$tablename] += array(
        'provider' => 'internal',
        'fields' => array(
          $fieldname => array(
            'name' => 'Content Taxonomy Field: ' . $field['field_name'],
            'sortable' => TRUE,
            'parent' => $field['tid'],
            'voc_id' => $field['vid'],
            'content_field' => $field,
            'content_db_info' => $db_info,
          ),
        ),
        'filters' => array(
          $fieldname => array(
            'name' => 'Content Taxonomy Field: ' . $field['field_name'],
            'list' => 'views_handler_filter_terms_by_parent',
            'list-type' => isset($field['multiple']) ? 'list' : 'select',
            'value-type' => 'array',
            'option' => 'string',
            'operator' => 'views_handler_operator_andor',
            'parent' => $field['tid'],
            'voc_id' => $field['vid'],
            'group' => $group_tid,
          ),
        ),
      );
      if ($field['save'] == 'tag') {
        $tables[$tablename]['filters'][$fieldname]['handler'] = "views_handler_filter_tid_custom";
        $tables[$tablename]['fields'][$fieldname]['handler'] = array(
          'content_taxonomy_views_field_terms_by_parent' => t('Show value'),
        );
        $tables[$tablename]['fields'][$fieldname]['notafield'] = TRUE;
      }
      else {
        $tables[$tablename]['fields'][$fieldname]['handler'] = array(
          'content_taxonomy_views_field_handler_group' => t('Group multiple values'),
          'content_taxonomy_views_field_handler_ungroup' => t('Do not group multiple values'),
        );
      }
    }
  }
  return $tables;
}