';
@@ -347,41 +403,114 @@
// Index by taxonomy terms block.
$voc_list = array();
+ $first = TRUE;
+ $suppress_unused = variable_get('indexpage_suppress_unused', FALSE);
if (variable_get('indexpage_'. $type .'_vocfilter', 1)) {
$vocs = db_query("SELECT v.name, v.vid FROM {vocabulary} v LEFT JOIN {vocabulary_node_types} t ON t.vid=v.vid WHERE t.type='%s'", $type);
while ($voc = db_fetch_array($vocs)) {
+ if ($first) {
+ $first = FALSE;
+ $output .= '
';
+ }
$term_list = array();
$voc_list[$voc['vid']] = check_plain($voc['name']);
- $output .= '
';
+
$voc_count = 0;
- $terms = taxonomy_get_tree($voc['vid']);
- foreach ($terms as $term) {
- $sql = _indexpage_check_status("SELECT COUNT(n.nid) FROM {node} n LEFT JOIN {term_node} t on t.nid=n.nid AND t.vid=n.vid WHERE type='%s' AND t.tid=%d");
- $term->node_count = $how_many = db_result(db_query($sql, $type, $term->tid));
- $voc_count += $how_many;
- if ($how_many || !$suppress_unused) {
- $term_list[] = theme('indexpage_term', $term, $type);
- }
- }
-
- if ($term_list) {
- if ($list_format == 'list') {
- $stuff = theme('item_list', $term_list, NULL, 'ul', array('class' => 'indexpage_term_list'));
- }
- else {
- $header = array();
- if ($show_description) {
- $header = array(
- t('Category'),
- t('Description'),
- );
+ // Check if Tree View checkbox is checked
+ if (variable_get('indexpage_'. $type .'_treeview', 1)) {
+ // Include css and js needed to manage the treeview
+ $path_tax_man = drupal_get_path('module', 'taxonomy_manager');
+ drupal_add_css($path_tax_man.'/css/taxonomy_manager.css');
+ drupal_add_js($path_tax_man.'/js/tree.js');
+ drupal_add_js(array('taxonomy_manager' => array('modulePath' => (url($module_path) == $module_path) ? $module_path : (base_path() . $module_path))), 'setting');
+ drupal_add_js(array('taxonomytree' => array('id' => 'IndexPage-TreeView', 'vid' => $voc['vid'])), 'setting');
+
+ $output .= '
';
+
+ // Query with Hierarchy structure
+ $sql = "SELECT td.tid, td.vid, td.name"
+ . " FROM {term_data} td"
+ . " JOIN {term_hierarchy} th on th.tid = td.tid"
+ . " WHERE th.parent = %d"
+ . " AND td.vid = %d"
+ . " ORDER BY td.weight, td.name";
+ $terms = db_query($sql, 0, $voc['vid']);
+
+ $stuff = "";
+ while ($avoc = db_fetch_object($terms)) {
+ $child_content = get_child_terms($avoc->tid, $voc['vid'],$type, 2 );
+ if ( $child_content === '' )
+ $li_type = "";
+ else {
+ if ($hierarchal_deep_ex >= 1 )
+ $li_type = "class='collapsable '";
+ else
+ $li_type = "class='expandable '";
+ }
+
+ $todos = indexpage_term_count_nodes($avoc->tid, $type, "all");
+ $solo = indexpage_term_count_nodes($avoc->tid, $type, "alone");
+ $voc_count += $solo;
+ if ($todos > 0 ){
+ $stodos = "
$todos";
+ } else {
+ $stodos = "0";
+ }
+ if ($solo > 0 ){
+ $ssolo = "
$solo";
+ } else {
+ $ssolo = "0";
+ }
+
+ $enlace ="";
+ if ($solo == 0 ){
+ $enlace = "$avoc->name";
+ } else {
+ $enlace = l("$avoc->name", "taxonomy/term/$avoc->tid/".$hierarchal_deep."/".$type);
+ }
+
+ $stuff .= "
\n".pre_li();
+ $stuff .= " "
+ . $enlace . " ("
+ . $ssolo."/".$stodos.")"
+ . $child_content
+ . post_li()
+ . "\n";
+ }
+ $stuff = ($stuff != "") ? "
\n" : t('None found');
+ } else {
+ $output .= '
';
+ $terms = taxonomy_get_tree($voc['vid']);
+ foreach ($terms as $term) {
+ $sql = _indexpage_check_status("SELECT COUNT(n.nid) FROM {node} n LEFT JOIN {term_node} t on t.nid=n.nid AND t.vid=n.vid WHERE type='%s' AND t.tid=%d");
+ $term->node_count = $how_many = db_result(db_query($sql, $type, $term->tid));
+ $voc_count += $how_many;
+ if ($how_many || !$suppress_unused) {
+ $term_list[] = theme('indexpage_term', $term, $type);
+ }
}
- $stuff = theme('table', $header, $term_list, array('class' => 'indexpage_term_list'));
- }
- }
- else {
- $stuff = '
'. t('None found') .'
';
+
+ if ($term_list) {
+ if ($list_format == 'list') {
+ $stuff = theme('item_list', $term_list, NULL, 'ul', array('class' => 'indexpage_term_list'));
+ }
+ else {
+ $header = array();
+ if ($show_description) {
+ $header = array(
+ t('Category'),
+ t('Description'),
+ );
+ }
+ $stuff = theme('table', $header, $term_list, array('class' => 'indexpage_term_list'));
+ }
+ }
+ else {
+ $stuff = '
'. t('None found') .'
';
+ }
+
}
$fieldset = array(
'#title' => t('List by !s Categories', array('!s' => $voc['name'])) . ($show_count ? ' ('. $voc_count .')' : NULL),
@@ -390,7 +519,7 @@
'#collapsed' => (count($term_list) > variable_get('indexpage_maxresults', 10)),
'#value' => $stuff,
'#attributes' => array('class' => 'indexpage_category indexpage_category_'. $voc['vid']),
- );
+ );
$output .= theme('fieldset', $fieldset) .'
';
}
@@ -648,3 +777,100 @@
$output .= theme('table', $header, $rows) . theme('pager', NULL, $max_results, 0);
return $output .'
';
}
+
+
+/*
+ * New functions to support Tree View
+ * Based on code :
+ * http://drupal.org/node/53085
+ */
+
+function pre_li(){
+ return "
\n"
+ . "
\n";
+}
+
+function post_li(){
+ return "
\n"
+ . "
\n";;
+}
+
+/*
+ * Esta función de vuelve en base a la info del módulo Taxonomy todos (all) los nodos debajo de un término
+ * ó solo (alone) los que pertenecen a ese termino.
+ */
+
+function indexpage_term_count_nodes($tid, $type = 0,$value = 'all'){
+ $result = 0;
+
+ switch ($value) {
+ case 'all':
+ $result = taxonomy_term_count_nodes($tid, $type);
+ break;
+ case 'alone':
+ $result = taxonomy_term_count_nodes($tid, $type);
+ foreach (_taxonomy_term_children($tid) as $c) {
+ $result -= taxonomy_term_count_nodes($c, $type);
+ }
+ break;
+ }
+ return $result;
+}
+
+function get_child_terms($parent, $vid, $type, $actual_deep ) {
+ // RSC, profundidad a la hora de incluir los nodos en el árbol de jerarquia
+ $hierarchal_deep = variable_get('indexpage_'. $type.'_deep_tree', 'all');
+ $hierarchal_deep_ex = variable_get('indexpage_'. $type.'_deep_tree_expanded', '0');
+
+ $sql = "SELECT td.tid, td.vid, td.name"
+ . " FROM {term_data} td"
+ . " JOIN {term_hierarchy} th on th.tid = td.tid"
+ . " WHERE th.parent = %d"
+ . " AND td.vid = %d"
+ . " ORDER BY td.weight, td.name";
+ $terms = db_query($sql, $parent, $vid);
+ $output = "";
+ while ($aterm = db_fetch_object($terms)) {
+ $child_content = get_child_terms($aterm->tid, $vid, $type, $actual_deep + 1 );
+ if ( $child_content === '' )
+ $li_type = "";
+ else {
+ if ($hierarchal_deep_ex >= $actual_deep )
+ $li_type = "class='collapsable '";
+ else
+ $li_type = "class='expandable '";
+ }
+
+ $todos = indexpage_term_count_nodes($aterm->tid, $type, "all");
+ $solo = indexpage_term_count_nodes($aterm->tid, $type, "alone");
+
+ if ($todos > 0 ){
+ $stodos = "
$todos";
+ } else {
+ $stodos = "0";
+ }
+
+ if ($solo > 0 ){
+ $ssolo = "
$solo";
+ } else {
+ $ssolo = "0";
+ }
+
+ $enlace ="";
+ if ($solo == 0 ){
+ $enlace = "$aterm->name";
+ } else {
+ $enlace = l("$aterm->name", "taxonomy/term/$aterm->tid/".$hierarchal_deep."/".$type);
+ }
+
+ $output .= "
\n".pre_li();
+ $output .= " "
+ . $enlace . " ("
+ . $ssolo."/".$stodos.")"
+ . $child_content
+ . post_li()
+ . "\n";
+
+ }
+ return ($output != "") ? "
\n" : "";
+}
\ No newline at end of file