View source
<?php
function tagadelic_views_views_plugins() {
$plugins = array(
'style' => array(
'tagadelic' => array(
'title' => t('Tagadelic list'),
'help' => t('Displays terms as tagadelic.'),
'handler' => 'tagadelic_plugin_style',
'parent' => 'list',
'theme' => 'views_view_list',
'uses row plugin' => 'tagadelic_plugin_row_fields',
'uses options' => TRUE,
'type' => 'normal',
),
),
);
return $plugins;
}
function tagadelic_views_views_query_alter(&$view, &$query) {
if (get_class($view->style_plugin) != 'tagadelic_plugin_style') {
return;
}
$field_tid = 'tid';
$taxonomy_term_table_alias_default = 'taxonomy_term_data';
$taxonomy_term_table_alias = null;
if ($view->base_table == 'taxonomy_term_data') {
$taxonomy_term_table_alias = $taxonomy_term_table_alias_default;
$join = views_get_table_join('taxonomy_index', 'taxonomy_term_data');
$query
->add_relationship("taxonomy_index_taxonomy_term_data", $join, 'taxonomy_index', NULL);
}
else {
$taxonomy_term_table_alias = isset($query->tables['taxonomy_term_data']) ? 'taxonomy_term_data' : null;
if (is_null($taxonomy_term_table_alias)) {
foreach ($query->relationships as $alias => $relationship) {
if ($relationship['base'] == 'taxonomy_term_data') {
$taxonomy_term_table_alias = $alias;
break;
}
}
if (!$taxonomy_term_table_alias) {
$taxonomy_term_table_alias = 'tagadelic_taxonomy_term_data';
}
if (!is_null($taxonomy_term_table_alias)) {
if (!isset($query->table_queue['taxonomy_index'])) {
$query
->ensure_table('taxonomy_index');
}
$reference_table = $query->base_table;
$join = $query->table_queue['taxonomy_index']['join'];
$query
->add_relationship('tagadelic_taxonomy_index', $join, 'taxonomy_index', $reference_table);
$join = views_get_table_join('taxonomy_term_data', 'taxonomy_index');
$query
->add_relationship('tagadelic_taxonomy_term_data', $join, 'tagadelic_taxonomy_index');
$field_tid = $query
->add_field($taxonomy_term_table_alias, 'tid', 'taxonomy_term_data_tag_tid');
$query
->add_field($taxonomy_term_table_alias, 'vid', 'taxonomy_term_data_tag_vid');
}
else {
views_debug(t("Consider adding at least a relationship to a taxonomy term to get (better) results."));
}
}
}
$field_name_count = $query
->add_field($taxonomy_term_table_alias, 'name', $alias = 'taxonomy_term_data_tag_count', $params = array(
'function' => 'count',
));
$field_name = $query
->add_field($taxonomy_term_table_alias, 'name', $alias = 'taxonomy_term_data_tag_name');
$field_desc = $query
->add_field($taxonomy_term_table_alias, 'description', $alias = 'taxonomy_term_data_tag_description');
$query->distinct = TRUE;
$query->no_distinct = $field_tid;
$query
->add_groupby($field_tid);
$query
->add_having_expression(0, 'taxonomy_term_data_tag_count > 0');
}