tripal_stock_relationships.tpl.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. // Copyright 2010 University of Saskatchewan (Lacey-Anne Sanderson)
  3. //
  4. // Purpose: Provides layout and content for Stock Relationships where
  5. // the current stock is the Subject of the relationships. This includes all
  6. // fields in the stock_relationship table.
  7. //
  8. // Note: This template controls the layout/content for the default stock node
  9. // template (node-chado_stock.tpl.php) and the Stock Object Relationships Block
  10. //
  11. // Variables Available:
  12. // - $node: a standard object which contains all the fields associated with
  13. // nodes including nid, type, title, taxonomy. It also includes stock
  14. // specific fields such as stock_name, uniquename, stock_type, synonyms,
  15. // properties, db_references, object_relationships, subject_relationships,
  16. // organism, etc.
  17. // - $node->object_relationships: an array of stock relaionship objects
  18. // where each object has the following fields: stock_relationship_id,
  19. // subject_id (current stock_id), type_id, type, value, rank, object
  20. // - $node->object_relationships->object: a stock object describing the
  21. // object stock with the fields: stock_id, stock_name, uniquename,
  22. // description, stock_type_id, organism(object), man_db_reference(object),
  23. // nid (if sync'd with Drupal)
  24. // NOTE: For a full listing of fields available in the node object the
  25. // print_r $node line below or install the Drupal Devel module which
  26. // provides an extra tab at the top of the node page labelled Devel
  27. ?>
  28. <?php
  29. // expand the stock object to include the stock relationships.
  30. // since there two foreign keys (object_id and subject_id) in the
  31. // stock_relationship table, we will access each one separately
  32. $node = tripal_core_expand_chado_vars($node,
  33. 'table','stock_relationship', array('order_by'=>array('rank' => 'ASC')));
  34. //uncomment this line to see a full listing of the fields avail. to $node
  35. //print '<pre>'.print_r($node,TRUE).'</pre>';
  36. ?>
  37. <div id="tripal_stock-relationships-box" class="tripal_stock-info-box tripal-info-box">
  38. <div class="tripal_stock-info-box-title tripal-info-box-title">Relationships</div>
  39. <?php
  40. /////////////////////////////////////////////////
  41. // Subject Relationships
  42. /////////////////////////////////////////////////
  43. $relationships = $node->stock->stock_relationship->subject_id;
  44. if (!$relationships) {
  45. $relationships = array();
  46. } elseif (!is_array($relationships)) {
  47. $relationships = array($relationships);
  48. }
  49. ?>
  50. <div class="tripal_stock-info-box-desc tripal-info-box-desc">Subject relationships</div>
  51. <?php if(count($relationships) > 0){ ?>
  52. <table class="tripal_stock-table tripal-table tripal-table-horz">
  53. <tr>
  54. <th>Current Stock (Subject)</th>
  55. <th>Type</th>
  56. <th>Object</th>
  57. </tr>
  58. <?php
  59. $i = 0;
  60. foreach ($relationships as $result){
  61. $class = 'tripal_stock-table-odd-row tripal-table-odd-row';
  62. if($i % 2 == 0 ){
  63. $class = 'tripal_stock-table-odd-row tripal-table-even-row';
  64. } ?>
  65. <tr class="<?php print $class ?>">
  66. <td><?php print $node->stock->name; ?></td>
  67. <td><?php print $result->type_id->name; ?></td>
  68. <?php $object = $result->object_id;
  69. if ($object->nid) {?>
  70. <td><?php print l($object->name.' ('.$object->uniquename.')', 'node/'.$object->nid); ?></td>
  71. <?php } else { ?>
  72. <td><?php print $object->name.' ('.$object->uniquename.')'; ?></td>
  73. <?php } ?>
  74. </tr>
  75. <?php } //end of foreach?>
  76. </table>
  77. <?php } else {
  78. print '<div class="tripal-no-results">There are no relationships where the current stock is the subject</div>';
  79. } //end of if there are object relationships ?>
  80. <?php
  81. /////////////////////////////////////////////////
  82. // Object Relationships
  83. /////////////////////////////////////////////////
  84. $relationships = $node->stock->stock_relationship->object_id;
  85. if (!$relationships) {
  86. $relationships = array();
  87. } elseif (!is_array($relationships)) {
  88. $relationships = array($relationships);
  89. }
  90. ?>
  91. <br><br><div class="tripal_stock-info-box-desc tripal-info-box-desc">Object relationships</div>
  92. <?php if(count($relationships) > 0){ ?>
  93. <table class="tripal_stock-table tripal-table tripal-table-horz">
  94. <tr>
  95. <th>Subject</th>
  96. <th>Type</th>
  97. <th>Current Stock (Object)</th>
  98. </tr>
  99. <?php
  100. $i = 0;
  101. foreach ($relationships as $result){
  102. $class = 'tripal_stock-table-odd-row tripal-table-odd-row';
  103. if($i % 2 == 0 ){
  104. $class = 'tripal_stock-table-odd-row tripal-table-even-row';
  105. } ?>
  106. <tr class="<?php print $class ?>">
  107. <?php $subject = $result->subject_id;
  108. if ($subject->nid) {?>
  109. <td><?php print l($subject->name.' ('.$subject->uniquename.')', 'node/'.$subject->nid); ?></td>
  110. <?php } else { ?>
  111. <td><?php print $subject->name.' ('.$subject->uniquename.')'; ?></td>
  112. <?php } ?>
  113. <td><?php print $result->type_id->name; ?></td>
  114. <td><?php print $node->stock->name; ?></td>
  115. </tr>
  116. <?php } //end of foreach?>
  117. </table>
  118. <?php } else {
  119. print '<div class="tripal-no-results">There are no relationships where the current stock is the object.</div>';
  120. } //end of if there are subject relationships ?>
  121. </div>