function _chado_update_cvtermpath_loop

3.x tripal_chado.cv.api.inc _chado_update_cvtermpath_loop( $origin, $child_id, $cv_id, $type_id, $depth, $increment_of_depth, $tree_path, $possible_loop, $matched_rows, $possible_start_of_loop, $no_loop_skip_test)

Parameters

$origin: The root terms cvterm_id.

$child_id: The cvterm_id of the current child term. The child term is a descendent of the origin.

$cv_id: The controlled vocabulary ID from the cv table of Chado (i.e. cv.cv_id).

$type_id: The relationship type between the origin term and the child.

$depth: The depth of the recursion.

$increment_of_depth.: An integer tailing the number of children that have been walked down.

$tree_path.: The array of every term between the current child and the origin. Each element in the array is an associative array with the keys: -build_id: an string identifier for the child that combines the origin, child cvterm_id,cv_id, and the type_id. -depth: the depth that a child was inserted into the cvtermpath table.

$possible_loop: A boolean flag.

$matched_row: An array of rows that are currently in the cvtermpath table that match the build_id of the current term trying to be written to the table

$possible_start_of_ loop: The array of the possible loop item between the current child and the origin. Each element in the array is an associative array with the keys:

  • cvid : $cv_id
  • subject_id:
  • child_id : $child_id,
  • type_id : $type_id,
  • depth : $depth,

$no_loop_skip_test: A boolean used when the possible loop has been ruled out as a loop.

Related topics

2 calls to _chado_update_cvtermpath_loop()
_chado_update_cvtermpath_loop_increment in tripal_chado/api/modules/tripal_chado.cv.api.inc
_chado_update_cvtermpath_root_loop in tripal_chado/api/modules/tripal_chado.cv.api.inc
Duplicate of _fill_cvtermpath4root() stored procedure in Chado.

File

tripal_chado/api/modules/tripal_chado.cv.api.inc, line 514
Provides API functions specificially for managing controlled vocabulary records in Chado.

Code

function _chado_update_cvtermpath_loop(
$origin, 
$child_id, 
$cv_id, 
$type_id, 
$depth, 
$increment_of_depth, 
$tree_path, 
$possible_loop, 
$matched_rows, 
$possible_start_of_loop, 
$no_loop_skip_test) {

  // We have not detected a loop, so it's safe to insert the term.
  $new_match_rows =[];
  if (!empty($possible_start_of_loop)) {
    // Go through each matched_row.
    if (count($matched_rows) === 1) {
      // Get the cvtermpath_id and then increment down one row.
      $cvtermpath_id = (int) $matched_rows[0]->cvtermpath_id;
      $cvtermpath_id = $cvtermpath_id + 1;
      chado_set_active('chado');
      $next_row = db_query(
      'SELECT *
          FROM cvtermpath
          WHERE cvtermpath_id = :cvtermpath_id
        ', 
      [':cvtermpath_id' $cvtermpath_id]
      );
      $next_row = $next_row->fetchObject();

      // If the next row matches the values passed we can't rule out a loop.
      if (($next_row->type_id === $type_id) && 
        ($next_row->subject_id === $child_id) && 
        ($next_row->object_id === $origin) && 
        ($next_row->cv_id === $cv_id)) {
        $new_match_rows[] = $next_row;
      }
      elseif (($next_row->type_id === $possible_start_of_loop['type_id']) && 
        ($next_row->subject_id === $possible_start_of_loop['subject_id']) && 
        ($next_row->object_id === $possible_start_of_loop['object_id']) && 
        ($next_row->cv_id === $possible_start_of_loop['cv_id'])) {
        // The next_row is equal to start of loop, so we've reached the end
        // and confirmed that this is a loop.
        $possible_loop == FALSE;
        $matched_rows =[];
        _chado_update_cvtermpath_loop_increment($origin, $child_id, $cv_id, 
        $type_id, $depth + 1, $increment_of_depth, $tree_path, $possible_loop, 
        $new_match_rows, $possible_start_of_loop, $no_loop_skip_test);

      }
    }
    else {
      foreach ($matched_rows as $matched_row) {
        // Get the cvtermpath_id and then increment down one row.
        $cvtermpath_id = (int) $match_row->cvtermpath_id;
        // Get the cvtermpath_id and then increment down one row.
        $cvtermpath_id = $cvtermpath_id + 1;
        chado_set_active('chado');
        $next_row = db_query(
        'SELECT *
            FROM cvtermpath
            WHERE cvtermpath_id = :cvtermpath_id
          ', 
        [':cvtermpath_id' $cvtermpath_id]
        );
        $next_row = $next_row->fetchObject();

        // If the next row matches the values passed we can't rule out a loop.
        if (($next_row->type_id === $type_id) && 
          ($next_row->subject_id === $child_id) && 
          ($next_row->object_id === $origin) && 
          ($next_row->cv_id === $cv_id)) {
          $new_match_rows[] = $next_row;
        }
        elseif (($next_row->type_id === $possible_start_of_loop['type_id']) && 
          ($next_row->subject_id === $possible_start_of_loop['subject_id']) && 
          ($next_row->object_id === $possible_start_of_loop['object_id']) && 
          ($next_row->cv_id === $possible_start_of_loop['cv_id'])) {
          // The next_row is equal to start of loop, so we've reached the end
          // and confirmed that this is a loop.
          $possible_loop == FALSE;
          $matched_rows =[];
          _chado_update_cvtermpath_loop_increment($origin, $child_id, $cv_id, 
          $type_id, $depth + 1, $increment_of_depth, $tree_path, $possible_loop, 
          $new_match_rows, $possible_start_of_loop, $no_loop_skip_test);

        }
      }
    }
    // If $match_rows is empty there is no loop.
    if (empty($new_match_rows)) {
      $possible_loop == FALSE;
      $matched_rows =[];
      unset($new_match_rows);
      $no_loop_skip_test = TRUE;
      // There is not loop so pass it back the possible_start_of_loop info
      // and a flag telling it to skip the loop check.
      _chado_update_cvtermpath_loop_increment($possible_start_of_loop->subject_id, 
      $possible_start_of_loop->child_id, $possible_start_of_loop->cvid, 
      $possible_start_of_loop->type_id, $possible_start_of_loop->depth, 
      $increment_of_depth, $tree_path, $possible_loop, $matched_rows, 
      $possible_start_of_loop, $no_loop_skip_test);
    }
    // If $match_rows is not empty we need to keep trying rows.
    else {
      _chado_update_cvtermpath_loop_increment($origin, $child_id, $cv_id, 
      $type_id, $depth + 1, $increment_of_depth, $tree_path, $possible_loop, 
      $match_rows, $possible_start_of_loop, $no_loop_skip_test);
    }
  }
  elseif ($possible_loop === FALSE) {
    _chado_update_cvtermpath_loop_increment($origin, $child_id, $cv_id, 
    $type_id, $depth + 1, $increment_of_depth, $tree_path, $possible_loop, 
    $matched_rows, $possible_start_of_loop, $no_loop_skip_test);
  }
}