function tripal_feature_load_relationships

2.x tripal_feature.theme.inc tripal_feature_load_relationships($feature_id, $side = 'as_subject')
3.x tripal_feature.theme.inc tripal_feature_load_relationships($feature_id, $side = 'as_subject')
1.x tripal_feature.module tripal_feature_load_relationships($feature_id, $side = 'as_subject')

Related topics

2 calls to tripal_feature_load_relationships()
tripal_feature_edit_ALL_relationships_form in tripal_feature/includes/tripal_feature-relationships.inc
Implements Hook_form() Handles adding of Properties & Synonyms to Stocks
tripal_feature_get_aggregate_relationships in tripal_feature/tripal_feature.module

File

tripal_feature/tripal_feature.module, line 1148
@todo Add file header description

Code

function tripal_feature_load_relationships($feature_id, $side = 'as_subject') {
  // get the relationships for this feature.  The query below is used for both
  // querying the object and subject relationships
  $sql = "SELECT
           FS.name as subject_name,
           FS.uniquename as subject_uniquename,
           CVTS.name as subject_type,
           CVTS.cvterm_id as subject_type_id,
           FR.subject_id,
           FR.type_id as relationship_type_id,
           CVT.name as rel_type,
           FO.name as object_name,
           FO.uniquename as object_uniquename,
           CVTO.name as object_type,
           CVTO.cvterm_id as object_type_id,
           FR.object_id,
           FR.rank
         FROM {feature_relationship} FR
           INNER JOIN {cvterm} CVT ON FR.type_id = CVT.cvterm_id
           INNER JOIN {feature} FS ON FS.feature_id = FR.subject_id
           INNER JOIN {feature} FO ON FO.feature_id = FR.object_id
           INNER JOIN {cvterm} CVTO ON FO.type_id = CVTO.cvterm_id
           INNER JOIN {cvterm} CVTS ON FS.type_id = CVTS.cvterm_id
  ";
  if (strcmp($side, 'as_object') == 0) {
    $sql .= " WHERE FR.object_id = %d";
  }
  if (strcmp($side, 'as_subject') == 0) {
    $sql .= " WHERE FR.subject_id = %d";
  }
  $sql .= " ORDER BY FR.rank";

  // get the relationships
  $results = chado_query($sql, $feature_id);


  // iterate through the relationships, put these in an array and add
  // in the Drupal node id if one exists
  $i = 0;
  $nodesql = "SELECT nid FROM {chado_feature} WHERE feature_id = %d";
  $relationships = array();
  while ($rel = db_fetch_object($results)) {
    $node = db_fetch_object(db_query($nodesql, $rel->subject_id));
    if ($node) {
      $rel->subject_nid = $node->nid;
    }
    $node = db_fetch_object(db_query($nodesql, $rel->object_id));
    if ($node) {
      $rel->object_nid = $node->nid;
    }
    $relationships[$i++] = $rel;
  }
  return $relationships;
}