';
$voc_count = 0;
-
- $terms = db_query('SELECT name, tid FROM {term_data} WHERE vid=%d ORDER BY weight, name', $voc['vid']);
- while ($term = db_fetch_object($terms)) {
- $sql = _indexpage_check_status("SELECT COUNT(n.nid) FROM {node} n LEFT JOIN {term_node} t on n.nid=t.nid WHERE type='%s' AND t.tid=%d");
- $how_many = db_result(db_query($sql, $type, $term->tid));
- if ($how_many) {
- $term_list[] = l($term->name, "indexpage/$type/$term->tid") . ($show_count ? ' ('. $how_many .')' : NULL);
- $voc_count += $how_many;
- }
- else {
- if (!$suppress_unused) {
- $term_list[] = check_plain($term->name);
- }
- }
- }
- if ($term_list) {
- $stuff = implode(' | ', $term_list);
- }
- else {
- $stuff = t('None found');
+
+ // 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']);
+ if ( $child_content === '' )
+ $li_type = "";
+ else
+ $li_type = "class='expandable '";
+
+ $stuff .= "
\n".pre_li();
+ $stuff .= " "
+ . l("$avoc->name", "taxonomy/term/$avoc->tid/all") . " ("
+ . taxonomy_term_count_nodes($avoc->tid).")"
+ . $child_content
+ . post_li()
+ . "\n";
+ }
+ $stuff = ($stuff != "") ? "
\n" : t('None found');
+ } else {
+ $output .= '
';
+ $terms = db_query('SELECT name, tid FROM {term_data} WHERE vid=%d ORDER BY weight, name', $voc['vid']);
+ while ($term = db_fetch_object($terms)) {
+ $sql = _indexpage_check_status("SELECT COUNT(n.nid) FROM {node} n LEFT JOIN {term_node} t on n.nid=t.nid WHERE type='%s' AND t.tid=%d");
+ $how_many = db_result(db_query($sql, $type, $term->tid));
+ if ($how_many) {
+ $term_list[] = l($term->name, "indexpage/$type/$term->tid") . ($show_count ? ' ('. $how_many .')' : NULL);
+ $voc_count += $how_many;
+ }
+ else {
+ if (!$suppress_unused) {
+ $term_list[] = check_plain($term->name);
+ }
+ }
+ }
+ if ($term_list) {
+ $stuff = implode(' | ', $term_list);
+ }
+ else {
+ $stuff = t('None found');
+ }
}
$fieldset = array(
'#title' => t('List by !s terms', array('!s' => $voc['name'])) . ($show_count ? ' ('. $voc_count .')' : NULL),
@@ -577,3 +646,48 @@
$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";;
+ }
+
+ function get_child_terms($parent, $vid) {
+ $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);
+ if ( $child_content === '' )
+ $li_type = "";
+ else
+ $li_type = "class='expandable '";
+
+ $output .= "
\n".pre_li();
+ $output .= " "
+ . l("$aterm->name", "taxonomy/term/$aterm->tid/all") . " ("
+ . taxonomy_term_count_nodes($aterm->tid).")"
+ . $child_content
+ . post_li()
+ . "\n";
+
+ }
+ return ($output != "") ? "
\n" : "";
+ }
\ No newline at end of file