tripal_contact.theme.inc

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

File

legacy/tripal_contact/theme/tripal_contact.theme.inc
View source
  1. <?php
  2. /**
  3. *
  4. *
  5. * @ingroup tripal_legacy_contact
  6. */
  7. function tripal_contact_preprocess_tripal_contact_relationships(&$variables) {
  8. $contact = $variables['node']->contact;
  9. // expand the contact object to include the contact 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 contacts (including contact type)
  14. 'include_fk' => array(
  15. 'type_id' => 1,
  16. 'object_id' => array(
  17. 'type_id' => 1,
  18. ),
  19. 'subject_id' => array(
  20. 'type_id' => 1,
  21. ),
  22. ),
  23. );
  24. $contact = chado_expand_var($contact, 'table', 'contact_relationship', $options);
  25. // get the subject relationships
  26. $srelationships = $contact->contact_relationship->subject_id;
  27. $orelationships = $contact->contact_relationship->object_id;
  28. // combine both object and subject relationshisp into a single array
  29. $relationships = array();
  30. $relationships['object'] = array();
  31. $relationships['subject'] = array();
  32. // iterate through the object relationships
  33. if ($orelationships) {
  34. foreach ($orelationships as $relationship) {
  35. $rel = new stdClass();
  36. $rel->record = $relationship;
  37. // get the relationship and child types
  38. $rel_type = t(preg_replace('/_/', " ", $relationship->type_id->name));
  39. $child_type = $relationship->subject_id->type_id->name;
  40. // get the node id of the subject
  41. $sql = "SELECT nid FROM {chado_contact} WHERE contact_id = :contact_id";
  42. $n = db_query($sql, array(':contact_id' => $relationship->subject_id->contact_id))->fetchObject();
  43. if ($n) {
  44. $rel->record->nid = $n->nid;
  45. }
  46. if (!array_key_exists($rel_type, $relationships['object'])) {
  47. $relationships['object'][$rel_type] = array();
  48. }
  49. if (!array_key_exists($child_type, $relationships['object'][$rel_type])) {
  50. $relationships['object'][$rel_type][$child_type] = array();
  51. }
  52. $relationships['object'][$rel_type][$child_type][] = $rel;
  53. }
  54. }
  55. // now add in the subject relationships
  56. if ($srelationships) {
  57. foreach ($srelationships as $relationship) {
  58. $rel = new stdClass();
  59. $rel->record = $relationship;
  60. $rel_type = t(preg_replace('/_/', " ", $relationship->type_id->name));
  61. $parent_type = $relationship->object_id->type_id->name;
  62. // get the node id of the subject
  63. $sql = "SELECT nid FROM {chado_contact} WHERE contact_id = :contact_id";
  64. $n = db_query($sql, array(':contact_id' => $relationship->object_id->contact_id))->fetchObject();
  65. if ($n) {
  66. $rel->record->nid = $n->nid;
  67. }
  68. if (!array_key_exists($rel_type, $relationships['subject'])) {
  69. $relationships['subject'][$rel_type] = array();
  70. }
  71. if (!array_key_exists($parent_type, $relationships['subject'][$rel_type])) {
  72. $relationships['subject'][$rel_type][$parent_type] = array();
  73. }
  74. $relationships['subject'][$rel_type][$parent_type][] = $rel;
  75. }
  76. }
  77. $contact->all_relationships = $relationships;
  78. }