function content_taxonomy_views_argument_handler_taxid in Content Taxonomy 5
Perform filtering by an argument (as term id) for field data stored via content taxonomy
1 string reference to 'content_taxonomy_views_argument_handler_taxid'
- content_taxonomy_views_views_arguments in ./
content_taxonomy_views.module - Implementation of hook_views_arguments()
File
- ./
content_taxonomy_views.module, line 150 - Views Support for content_taxonomy
Code
function content_taxonomy_views_argument_handler_taxid($op, &$query, $argtype, $arg = '') {
if ($op == 'filter') {
$field_name = substr($argtype['type'], 6);
}
else {
$field_name = substr($argtype, 6);
}
$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);
$column_placeholder = '%d';
if ($argtype['options'] == '-1') {
$th_num = $query
->add_table('term_hierarchy', false, 1, array(
'left' => array(
'table' => $table,
'field' => $main_column['column'],
),
'right' => array(
'field' => 'parent',
),
));
$th_table = $query
->get_table_name('term_hierarchy', $th_num);
$query
->add_where($th_table . '.tid = %d', $arg);
}
else {
if ($argtype['options'] == '1') {
$th_num = $query
->add_table('term_hierarchy', false, 1, array(
'left' => array(
'table' => $table,
'field' => $main_column['column'],
),
'right' => array(
'field' => 'tid',
),
));
$th_table = $query
->get_table_name('term_hierarchy', $th_num);
$query
->add_where($th_table . '.parent = %d', $arg);
}
else {
$query
->add_where($table . '.' . $main_column['column'] . ' = ' . $column_placeholder, $arg);
}
}
break;
case 'link':
break;
case 'title':
$item = array(
key($db_info['columns']) => $query,
);
return content_format($field, $item, 'plain');
}
}