You are here

function taxonomy_manager_check_circular_hierarchy in Taxonomy Manager 6.2

Same name and namespace in other branches
  1. 7 taxonomy_manager.admin.inc \taxonomy_manager_check_circular_hierarchy()

checks for circles in the hierarchy, e.g. 1 -> 2 -> 3 -> 1 a term can't contain itself as a parent

returns TRUE if resulting hierarchy is valid, else FALSE

4 calls to taxonomy_manager_check_circular_hierarchy()
taxonomy_manager_double_tree_edit_move in ./taxonomy_manager.admin.inc
taxonomy_manager_form_merge_validate in ./taxonomy_manager.admin.inc
Validation handler for validating terms
taxonomy_manager_form_move_validate in ./taxonomy_manager.admin.inc
Validation handler for moving terms
taxonomy_manager_term_data_edit in ./taxonomy_manager.admin.inc
callback handler for updating term data

File

./taxonomy_manager.admin.inc, line 1327
Taxonomy Manager Admin

Code

function taxonomy_manager_check_circular_hierarchy($tids, $new_parents_tids) {
  if (is_array($tids) && is_array($new_parents_tids)) {

    //directly same term
    foreach ($tids as $tid) {
      if (in_array($tid, $new_parents_tids)) {
        return FALSE;
      }
    }

    //same term over more hierarchy levels
    $all_parents = array();
    foreach ($new_parents_tids as $parent_tid) {
      $parents = taxonomy_get_parents_all($parent_tid);
      foreach ($parents as $parent) {
        $all_parents[$parent->tid] = $parent->tid;
      }
    }
    foreach ($tids as $tid) {
      if (in_array($tid, $all_parents)) {
        return FALSE;
      }
    }
  }
  return TRUE;
}