tripal_project.theme.inc

  1. 2.x tripal_project/theme/tripal_project.theme.inc
  2. 3.x legacy/tripal_project/theme/tripal_project.theme.inc

File

tripal_project/theme/tripal_project.theme.inc
View source
  1. <?php
  2. /**
  3. *
  4. *
  5. * @ingroup tripal_project
  6. */
  7. function tripal_project_preprocess_tripal_project_relationships(&$variables) {
  8. $project = $variables['node']->project;
  9. // expand the project object to include the project relationships.
  10. $options = array(
  11. 'return_array' => 1,
  12. // we don't want to fully recurse we only need information about the
  13. // relationship type and the object and subject projects
  14. 'include_fk' => array(
  15. 'type_id' => 1,
  16. 'object_project_id' => 1,
  17. 'subject_project_id' => 1,
  18. ),
  19. );
  20. $project = chado_expand_var($project, 'table', 'project_relationship', $options);
  21. // get the subject relationships
  22. $srelationships = $project->project_relationship->subject_project_id;
  23. $orelationships = $project->project_relationship->object_project_id;
  24. // combine both object and subject relationshisp into a single array
  25. $relationships = array();
  26. $relationships['object'] = array();
  27. $relationships['subject'] = array();
  28. // iterate through the object relationships
  29. if ($orelationships) {
  30. foreach ($orelationships as $relationship) {
  31. $rel = new stdClass();
  32. $rel->record = $relationship;
  33. // get the relationship and child types
  34. $rel_type = t(preg_replace('/_/', " ", $relationship->type_id->name));
  35. // get the node id of the subject
  36. $sql = "SELECT nid FROM {chado_project} WHERE project_id = :project_id";
  37. $n = db_query($sql, array(':project_id' => $relationship->subject_project_id->project_id))->fetchObject();
  38. if ($n) {
  39. $rel->record->nid = $n->nid;
  40. }
  41. $relationships['object'][$rel_type][] = $rel;
  42. }
  43. }
  44. // now add in the subject relationships
  45. if ($srelationships) {
  46. foreach ($srelationships as $relationship) {
  47. $rel = new stdClass();
  48. $rel->record = $relationship;
  49. $rel_type = t(preg_replace('/_/', " ", $relationship->type_id->name));
  50. // get the node id of the subject
  51. $sql = "SELECT nid FROM {chado_project} WHERE project_id = :project_id";
  52. $n = db_query($sql, array(':project_id' => $relationship->object_project_id->project_id))->fetchObject();
  53. if ($n) {
  54. $rel->record->nid = $n->nid;
  55. }
  56. $relationships['subject'][$rel_type][] = $rel;
  57. }
  58. }
  59. $project->all_relationships = $relationships;
  60. }