function tripal_project_preprocess_tripal_project_relationships

2.x tripal_project.theme.inc tripal_project_preprocess_tripal_project_relationships(&$variables)
3.x tripal_project.theme.inc tripal_project_preprocess_tripal_project_relationships(&$variables)
1.x tripal_project.module tripal_project_preprocess_tripal_project_relationships(&$variables)

Related topics

File

tripal_project/tripal_project.module, line 490
This file contains the basic functions needed for this drupal module. The drupal tripal_project module maps directly to the chado general module.

Code

function tripal_project_preprocess_tripal_project_relationships(&$variables) {
  // we want to provide a new variable that contains the matched projects.
  $project = $variables['node']->project;

  // normally we would use tripal_core_expand_chado_vars to expand our
  // organism object and add in the relationships, however whan a large
  // number of relationships are present this significantly slows the
  // query, therefore we will manually perform the query
  $sql = "
    SELECT P.name, P.project_id, CP.nid, CVT.name as rel_type
    FROM project_relationship PR
      INNER JOIN {project} P            ON PR.object_project_id = P.project_id
      INNER JOIN {cvterm} CVT           ON PR.type_id           = CVT.cvterm_id
      LEFT JOIN public.chado_project CP ON P.project_id         = CP.project_id
    WHERE PR.subject_project_id = %d
  ";
  $as_subject = chado_query($sql, $project->project_id);
  $sql = "
    SELECT P.name, P.project_id, CP.nid, CVT.name as rel_type
    FROM project_relationship PR
      INNER JOIN {project} P            ON PR.subject_project_id = P.project_id
      INNER JOIN {cvterm} CVT           ON PR.type_id            = CVT.cvterm_id
      LEFT JOIN public.chado_project CP ON P.project_id          = CP.project_id
    WHERE PR.object_project_id = %d
  ";
  $as_object = chado_query($sql, $project->project_id);

  // combine both object and subject relationshisp into a single array
  $relationships = array();
  $relationships['object'] = array();
  $relationships['subject'] = array();

  // iterate through the object relationships
  while ($relationship = db_fetch_object($as_object)) {

    // get the relationship and child types
    $rel_type = t(preg_replace('/_/', " ", $relationship->rel_type));
    $sub_type = t(preg_replace('/_/', " ", $relationship->sub_type));

    if (!array_key_exists($rel_type, $relationships['object'])) {
      $relationships['object'][$rel_type] = array();
    }
    if (!array_key_exists($sub_type, $relationships['object'][$rel_type])) {
      $relationships['object'][$rel_type][$sub_type] = array();
    }
    $relationships['object'][$rel_type][$sub_type][] = $relationship;
  }

  // now add in the subject relationships
  while ($relationship = db_fetch_object($as_subject)) {

    // get the relationship and child types
    $rel_type = t(preg_replace('/_/', " ", $relationship->rel_type));
    $obj_type = t(preg_replace('/_/', " ", $relationship->obj_type));

    if (!array_key_exists($rel_type, $relationships['subject'])) {
      $relationships['subject'][$rel_type] = array();
    }
    if (!array_key_exists($obj_type, $relationships['subject'][$rel_type])) {
      $relationships['subject'][$rel_type][$obj_type] = array();
    }
    $relationships['subject'][$rel_type][$obj_type][] = $relationship;
  }


  $project->all_relationships = $relationships;

}