- Modified patch #20505 by Morbus: fixed scalability issues with terms, tried to create a better distinction between vocabularies and terms, fixed problem with term pager (temporary fix).

4.7.x
Dries Buytaert 2005-07-19 17:00:26 +00:00
parent 4da128a416
commit 1d9c0cd65f
2 changed files with 38 additions and 72 deletions

View File

@ -34,11 +34,9 @@ function taxonomy_link($type, $node = NULL) {
} }
} }
else { else {
$links = array();
foreach (taxonomy_node_get_terms($node->nid) as $term) { foreach (taxonomy_node_get_terms($node->nid) as $term) {
$links[] = l($term->name, 'taxonomy/term/'. $term->tid); $links[] = l($term->name, 'taxonomy/term/'. $term->tid);
} }
} }
return $links; return $links;
} }
@ -359,13 +357,11 @@ function _taxonomy_confirm_del_term($tid) {
* Generate a tabular listing of administrative functions for vocabularies. * Generate a tabular listing of administrative functions for vocabularies.
*/ */
function taxonomy_overview() { function taxonomy_overview() {
$vid = arg(2); $vid = arg(2);
// Show all vocabularies and their terms. if vocabulary is "Free tagging", // Show all vocabularies, and a "view terms" link to the pagers.
// don't show terms here, but instruct user to "view terms" instead.
if (!$vid) { if (!$vid) {
$header = array(t('Name'), t('Type'), array('data' => t('Operations'), 'colspan' => '3')); $header = array(t('Name'), t('Type'), array('data' => t('Operations'), 'colspan' => '2'));
$vocabularies = taxonomy_get_vocabularies(); $vocabularies = taxonomy_get_vocabularies();
foreach ($vocabularies as $vocabulary) { foreach ($vocabularies as $vocabulary) {
$types = array(); $types = array();
@ -373,38 +369,23 @@ function taxonomy_overview() {
$node_type = node_invoke($type, 'node_name'); $node_type = node_invoke($type, 'node_name');
$types[] = $node_type ? $node_type : $type; $types[] = $node_type ? $node_type : $type;
} }
$rows[] = array('<strong>'. check_plain($vocabulary->name) .'</strong>', implode(', ', $types), l(t('edit vocabulary'), "admin/taxonomy/edit/vocabulary/$vocabulary->vid"), l(t('add term'), "admin/taxonomy/add/term/$vocabulary->vid"), l(t('view terms'), "admin/taxonomy/$vocabulary->vid")); $rows[] = array('<strong>'. check_plain($vocabulary->name) .'</strong>', implode(', ', $types), l(t('edit vocabulary'), "admin/taxonomy/edit/vocabulary/$vocabulary->vid"), l(t('edit terms'), "admin/taxonomy/$vocabulary->vid"));
// Show terms if non-free.
if (!$vocabulary->tags) {
$tree = taxonomy_get_tree($vocabulary->vid);
if ($tree) {
foreach ($tree as $term) {
$rows[] = array(array('data' => _taxonomy_depth($term->depth) . ' ' . l($term->name, "taxonomy/term/$term->tid"), 'class' => 'term'), NULL, NULL, NULL, l(t('edit term'), "admin/taxonomy/edit/term/$term->tid"));
}
}
else {
$rows[] = array(array('data' => t('No terms available.'), 'colspan' => '5', 'class' => 'message'));
}
}
elseif ($vocabulary->tags) {
$rows[] = array(array('data' => t('This is a free tagging vocabulary:') . ' ' . l(t('view terms'), "admin/taxonomy/$vocabulary->vid") . '.', 'colspan' => '5', 'class' => 'message'));
}
} }
if (!$rows) { if (!$rows) {
$rows[] = array(array('data' => t('No categories available.'), 'colspan' => '5', 'class' => 'message')); $rows[] = array(array('data' => t('No categories available.'), 'colspan' => '4', 'class' => 'message'));
} }
} }
// Free tagging vocabularies get their own terms pager // Show the vocabulary's terms with a pager.
// since there is a greater chance of 1000+ terms.
else { else {
$header = array(t('Name'), array('data' => t('Operations'), 'width' => '60')); $destination = drupal_get_destination();
$header = array(t('Name'), t('Operations'));
$vocabulary = taxonomy_get_vocabulary($vid); $vocabulary = taxonomy_get_vocabulary($vid);
if ($vocabulary->module == 'taxonomy') {
drupal_set_title(check_plain($vocabulary->name)); drupal_set_title(check_plain($vocabulary->name));
$start_from = $_GET['from'] ? $_GET['from'] : 0; $start_from = $_GET['page'] ? $_GET['page'] : 0;
$total_entries = 0; // total count for pager $total_entries = 0; // total count for pager
$page_increment = 25; // number of tids per page $page_increment = 25; // number of tids per page
$displayed_count = 0; // number of tids shown $displayed_count = 0; // number of tids shown
@ -412,20 +393,22 @@ function taxonomy_overview() {
$tree = taxonomy_get_tree($vocabulary->vid); $tree = taxonomy_get_tree($vocabulary->vid);
foreach ($tree as $term) { foreach ($tree as $term) {
$total_entries++; // we're counting all-totals, not displayed $total_entries++; // we're counting all-totals, not displayed
if (($start_from && $start_from > $total_entries) || ($displayed_count == $page_increment)) { continue; } if (($start_from && ($start_from * $page_increment) >= $total_entries) || ($displayed_count == $page_increment)) { continue; }
$rows[] = array(_taxonomy_depth($term->depth) . ' ' . check_plain($term->name), l(t('edit term'), "admin/taxonomy/edit/term/$term->tid")); $rows[] = array(_taxonomy_depth($term->depth) . ' ' . check_plain($term->name), l(t('edit'), "admin/taxonomy/edit/term/$term->tid", array(), $destination));
$displayed_count++; // we're counting tids displayed $displayed_count++; // we're counting tids displayed
}
if (!$rows) { if (!$rows) {
$rows[] = array(array('data' => t('No terms available.'), 'colspan' => '2')); $rows[] = array(array('data' => t('No terms available.'), 'colspan' => '2'));
} }
$GLOBALS['pager_from_array'][] = $start_from; $GLOBALS['pager_page_array'][] = $start_from; // FIXME
$GLOBALS['pager_total'][] = $total_entries; $GLOBALS['pager_total'][] = intval($total_entries / $page_increment) + 1; // FIXME
if ($total_entries >= $page_increment) {
$rows[] = array(array('data' => theme('pager', NULL, $page_increment), 'colspan' => '2')); $rows[] = array(array('data' => theme('pager', NULL, $page_increment), 'colspan' => '2'));
} }
} }
}
return theme('table', $header, $rows, array('id' => 'taxonomy')); return theme('table', $header, $rows, array('id' => 'taxonomy'));
} }
@ -707,7 +690,7 @@ function taxonomy_get_children($tid, $vid = 0, $key = 'tid') {
$result = db_query('SELECT t.* FROM {term_hierarchy} h, {term_data} t WHERE t.vid = %d AND h.tid = t.tid AND h.parent = %d ORDER BY weight, name', $vid, $tid); $result = db_query('SELECT t.* FROM {term_hierarchy} h, {term_data} t WHERE t.vid = %d AND h.tid = t.tid AND h.parent = %d ORDER BY weight, name', $vid, $tid);
} }
else { else {
$result = db_query('SELECT t.* FROM {term_hierarchy} h, {term_data} t WHERE h.tid = t.tid AND parent = %d ORDER BY weight', $tid); $result = db_query('SELECT t.* FROM {term_hierarchy} h, {term_data} t WHERE h.tid = t.tid AND parent = %d ORDER BY weight, name', $tid);
} }
$children = array(); $children = array();
while ($term = db_fetch_object($result)) { while ($term = db_fetch_object($result)) {

View File

@ -34,11 +34,9 @@ function taxonomy_link($type, $node = NULL) {
} }
} }
else { else {
$links = array();
foreach (taxonomy_node_get_terms($node->nid) as $term) { foreach (taxonomy_node_get_terms($node->nid) as $term) {
$links[] = l($term->name, 'taxonomy/term/'. $term->tid); $links[] = l($term->name, 'taxonomy/term/'. $term->tid);
} }
} }
return $links; return $links;
} }
@ -359,13 +357,11 @@ function _taxonomy_confirm_del_term($tid) {
* Generate a tabular listing of administrative functions for vocabularies. * Generate a tabular listing of administrative functions for vocabularies.
*/ */
function taxonomy_overview() { function taxonomy_overview() {
$vid = arg(2); $vid = arg(2);
// Show all vocabularies and their terms. if vocabulary is "Free tagging", // Show all vocabularies, and a "view terms" link to the pagers.
// don't show terms here, but instruct user to "view terms" instead.
if (!$vid) { if (!$vid) {
$header = array(t('Name'), t('Type'), array('data' => t('Operations'), 'colspan' => '3')); $header = array(t('Name'), t('Type'), array('data' => t('Operations'), 'colspan' => '2'));
$vocabularies = taxonomy_get_vocabularies(); $vocabularies = taxonomy_get_vocabularies();
foreach ($vocabularies as $vocabulary) { foreach ($vocabularies as $vocabulary) {
$types = array(); $types = array();
@ -373,38 +369,23 @@ function taxonomy_overview() {
$node_type = node_invoke($type, 'node_name'); $node_type = node_invoke($type, 'node_name');
$types[] = $node_type ? $node_type : $type; $types[] = $node_type ? $node_type : $type;
} }
$rows[] = array('<strong>'. check_plain($vocabulary->name) .'</strong>', implode(', ', $types), l(t('edit vocabulary'), "admin/taxonomy/edit/vocabulary/$vocabulary->vid"), l(t('add term'), "admin/taxonomy/add/term/$vocabulary->vid"), l(t('view terms'), "admin/taxonomy/$vocabulary->vid")); $rows[] = array('<strong>'. check_plain($vocabulary->name) .'</strong>', implode(', ', $types), l(t('edit vocabulary'), "admin/taxonomy/edit/vocabulary/$vocabulary->vid"), l(t('edit terms'), "admin/taxonomy/$vocabulary->vid"));
// Show terms if non-free.
if (!$vocabulary->tags) {
$tree = taxonomy_get_tree($vocabulary->vid);
if ($tree) {
foreach ($tree as $term) {
$rows[] = array(array('data' => _taxonomy_depth($term->depth) . ' ' . l($term->name, "taxonomy/term/$term->tid"), 'class' => 'term'), NULL, NULL, NULL, l(t('edit term'), "admin/taxonomy/edit/term/$term->tid"));
}
}
else {
$rows[] = array(array('data' => t('No terms available.'), 'colspan' => '5', 'class' => 'message'));
}
}
elseif ($vocabulary->tags) {
$rows[] = array(array('data' => t('This is a free tagging vocabulary:') . ' ' . l(t('view terms'), "admin/taxonomy/$vocabulary->vid") . '.', 'colspan' => '5', 'class' => 'message'));
}
} }
if (!$rows) { if (!$rows) {
$rows[] = array(array('data' => t('No categories available.'), 'colspan' => '5', 'class' => 'message')); $rows[] = array(array('data' => t('No categories available.'), 'colspan' => '4', 'class' => 'message'));
} }
} }
// Free tagging vocabularies get their own terms pager // Show the vocabulary's terms with a pager.
// since there is a greater chance of 1000+ terms.
else { else {
$header = array(t('Name'), array('data' => t('Operations'), 'width' => '60')); $destination = drupal_get_destination();
$header = array(t('Name'), t('Operations'));
$vocabulary = taxonomy_get_vocabulary($vid); $vocabulary = taxonomy_get_vocabulary($vid);
if ($vocabulary->module == 'taxonomy') {
drupal_set_title(check_plain($vocabulary->name)); drupal_set_title(check_plain($vocabulary->name));
$start_from = $_GET['from'] ? $_GET['from'] : 0; $start_from = $_GET['page'] ? $_GET['page'] : 0;
$total_entries = 0; // total count for pager $total_entries = 0; // total count for pager
$page_increment = 25; // number of tids per page $page_increment = 25; // number of tids per page
$displayed_count = 0; // number of tids shown $displayed_count = 0; // number of tids shown
@ -412,20 +393,22 @@ function taxonomy_overview() {
$tree = taxonomy_get_tree($vocabulary->vid); $tree = taxonomy_get_tree($vocabulary->vid);
foreach ($tree as $term) { foreach ($tree as $term) {
$total_entries++; // we're counting all-totals, not displayed $total_entries++; // we're counting all-totals, not displayed
if (($start_from && $start_from > $total_entries) || ($displayed_count == $page_increment)) { continue; } if (($start_from && ($start_from * $page_increment) >= $total_entries) || ($displayed_count == $page_increment)) { continue; }
$rows[] = array(_taxonomy_depth($term->depth) . ' ' . check_plain($term->name), l(t('edit term'), "admin/taxonomy/edit/term/$term->tid")); $rows[] = array(_taxonomy_depth($term->depth) . ' ' . check_plain($term->name), l(t('edit'), "admin/taxonomy/edit/term/$term->tid", array(), $destination));
$displayed_count++; // we're counting tids displayed $displayed_count++; // we're counting tids displayed
}
if (!$rows) { if (!$rows) {
$rows[] = array(array('data' => t('No terms available.'), 'colspan' => '2')); $rows[] = array(array('data' => t('No terms available.'), 'colspan' => '2'));
} }
$GLOBALS['pager_from_array'][] = $start_from; $GLOBALS['pager_page_array'][] = $start_from; // FIXME
$GLOBALS['pager_total'][] = $total_entries; $GLOBALS['pager_total'][] = intval($total_entries / $page_increment) + 1; // FIXME
if ($total_entries >= $page_increment) {
$rows[] = array(array('data' => theme('pager', NULL, $page_increment), 'colspan' => '2')); $rows[] = array(array('data' => theme('pager', NULL, $page_increment), 'colspan' => '2'));
} }
} }
}
return theme('table', $header, $rows, array('id' => 'taxonomy')); return theme('table', $header, $rows, array('id' => 'taxonomy'));
} }
@ -707,7 +690,7 @@ function taxonomy_get_children($tid, $vid = 0, $key = 'tid') {
$result = db_query('SELECT t.* FROM {term_hierarchy} h, {term_data} t WHERE t.vid = %d AND h.tid = t.tid AND h.parent = %d ORDER BY weight, name', $vid, $tid); $result = db_query('SELECT t.* FROM {term_hierarchy} h, {term_data} t WHERE t.vid = %d AND h.tid = t.tid AND h.parent = %d ORDER BY weight, name', $vid, $tid);
} }
else { else {
$result = db_query('SELECT t.* FROM {term_hierarchy} h, {term_data} t WHERE h.tid = t.tid AND parent = %d ORDER BY weight', $tid); $result = db_query('SELECT t.* FROM {term_hierarchy} h, {term_data} t WHERE h.tid = t.tid AND parent = %d ORDER BY weight, name', $tid);
} }
$children = array(); $children = array();
while ($term = db_fetch_object($result)) { while ($term = db_fetch_object($result)) {