taxonomy_check_vocabulary_hierarchy
modules/taxonomy/taxonomy.module, строка 269
- Версии
- 6
taxonomy_check_vocabulary_hierarchy($vocabulary, $changed_term)
Dynamicly check and update the hierarachy flag of a vocabulary.
Checks the current parents of all terms in a vocabulary and updates the vocabularies hierarchy setting to the lowest possible level. A hierarchy with no parents in any of its terms will be given a hierarchy of 0. If terms contain at most a single parent, the vocabulary will be given a hierarchy of 1. If any term contain multiple parents, the vocabulary will be given a hieararchy of 2.
Параметры
$vocabulary
An array of the vocabulary structure.
$changed_term
An array of the term structure that was updated.
Код
<?php
function taxonomy_check_vocabulary_hierarchy($vocabulary, $changed_term) {
$tree = taxonomy_get_tree($vocabulary['vid']);
$hierarchy = 0;
foreach ($tree as $term) {
// Update the changed term with the new parent value before comparision.
if ($term->tid == $changed_term['tid']) {
$term = (object)$changed_term;
$term->parents = $term->parent;
}
// Check this term's parent count.
if (count($term->parents) > 1) {
$hierarchy = 2;
break;
}
elseif (count($term->parents) == 1 && 0 !== array_shift($term->parents)) {
$hierarchy = 1;
}
}
if ($hierarchy != $vocabulary['hierarchy']) {
$vocabulary['hierarchy'] = $hierarchy;
taxonomy_save_vocabulary($vocabulary);
}
return $hierarchy;
}
?>
Войдите или зарегистрируйтесь, чтобы получить возможность отправлять комментарии