tripal_stock.theme.inc

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

Contains functions related to theme-ing including preprocess hooks

File

tripal_stock/theme/tripal_stock.theme.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Contains functions related to theme-ing including preprocess hooks
  5. */
  6. /**
  7. * Implements hook_preprocess_tripal_stock_relationships() which is the preprocess
  8. * hook for the tripal_stock_relationships template
  9. *
  10. * @ingroup tripal_stock
  11. */
  12. function tripal_stock_preprocess_tripal_stock_relationships(&$variables) {
  13. // we want to provide a new variable that contains the matched stocks.
  14. $stock = $variables['node']->stock;
  15. // expand the stock object to include the stock relationships.
  16. $options = array(
  17. 'return_array' => 1,
  18. 'order_by' => array('rank' => 'ASC'),
  19. // we don't want to fully recurse we only need information about the
  20. // relationship type and the object and subject stocks (including stock type
  21. // and organism)
  22. 'include_fk' => array(
  23. 'type_id' => 1,
  24. 'object_id' => array(
  25. 'type_id' => 1,
  26. 'organism_id' => 1
  27. ),
  28. 'subject_id' => array(
  29. 'type_id' => 1,
  30. 'organism_id' => 1
  31. ),
  32. ),
  33. );
  34. $stock = chado_expand_var($stock, 'table', 'stock_relationship', $options);
  35. // get the subject relationships
  36. $srelationships = $stock->stock_relationship->subject_id;
  37. $orelationships = $stock->stock_relationship->object_id;
  38. // combine both object and subject relationshisp into a single array
  39. $relationships = array();
  40. $relationships['object'] = array();
  41. $relationships['subject'] = array();
  42. // iterate through the object relationships
  43. if ($orelationships) {
  44. foreach ($orelationships as $relationship) {
  45. $rel = new stdClass();
  46. $rel->record = $relationship;
  47. // get the relationship and child types
  48. $rel_type = t(preg_replace('/_/', " ", $relationship->type_id->name));
  49. $child_type = $relationship->subject_id->type_id->name;
  50. // get the node id of the subject
  51. $sql = "SELECT nid FROM {chado_stock} WHERE stock_id = :stock_id";
  52. $n = db_query($sql, array(':stock_id' => $relationship->subject_id->stock_id))->fetchObject();
  53. if ($n) {
  54. $rel->record->nid = $n->nid;
  55. }
  56. if (!array_key_exists($rel_type, $relationships['object'])) {
  57. $relationships['object'][$rel_type] = array();
  58. }
  59. if (!array_key_exists($child_type, $relationships['object'][$rel_type])) {
  60. $relationships['object'][$rel_type][$child_type] = array();
  61. }
  62. $relationships['object'][$rel_type][$child_type][] = $rel;
  63. }
  64. }
  65. // now add in the subject relationships
  66. if ($srelationships) {
  67. foreach ($srelationships as $relationship) {
  68. $rel = new stdClass();
  69. $rel->record = $relationship;
  70. $rel_type = t(preg_replace('/_/', " ", $relationship->type_id->name));
  71. $parent_type = $relationship->object_id->type_id->name;
  72. // get the node id of the subject
  73. $sql = "SELECT nid FROM {chado_stock} WHERE stock_id = :stock_id";
  74. $n = db_query($sql, array(':stock_id' => $relationship->object_id->stock_id))->fetchObject();
  75. if ($n) {
  76. $rel->record->nid = $n->nid;
  77. }
  78. if (!array_key_exists($rel_type, $relationships['subject'])) {
  79. $relationships['subject'][$rel_type] = array();
  80. }
  81. if (!array_key_exists($parent_type, $relationships['subject'][$rel_type])) {
  82. $relationships['subject'][$rel_type][$parent_type] = array();
  83. }
  84. $relationships['subject'][$rel_type][$parent_type][] = $rel;
  85. }
  86. }
  87. $stock->all_relationships = $relationships;
  88. }