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.

▾ 2 функции вызывают taxonomy_check_vocabulary_hierarchy()

taxonomy_form_term_submit in modules/taxonomy/taxonomy.admin.inc
Обработчик кнопки "Отправить", формы добавления или обновления термина. См. также taxonomy_form_term()
taxonomy_term_confirm_delete_submit in modules/taxonomy/taxonomy.admin.inc
Submit handler to delete a term after confirmation. See alsotaxonomy_term_confirm_delete()

Код

<?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;
}
?>
Войдите или зарегистрируйтесь, чтобы получить возможность отправлять комментарии

Вход в систему