tripal_pub_authors.tpl.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. $pub = $node->pub;
  3. // expand the pub to include the pubauthors.
  4. $options = array(
  5. 'return_array' => 1,
  6. 'order_by' => array('rank' => 'ASC'),
  7. );
  8. $pub = tripal_core_expand_chado_vars($pub, 'table', 'pubauthor', $options);
  9. // see if we have authors as contacts if so then we'll add this resource
  10. $authors = $pub->pubauthor;
  11. $has_contacts = FALSE;
  12. if (count($authors) > 0) {
  13. foreach ($authors as $author) {
  14. // expand the author to include the pubauthor_contact table records
  15. $options = array(
  16. 'return_array' => 1,
  17. 'include_fk' => array(
  18. 'contact_id' => array(
  19. 'type_id' => 1,
  20. ),
  21. ),
  22. );
  23. $author = tripal_core_expand_chado_vars($author, 'table', 'pubauthor_contact', $options);
  24. if ($author->pubauthor_contact) {
  25. $has_contacts = TRUE;
  26. }
  27. }
  28. }
  29. if ($has_contacts) { ?>
  30. <div id="tripal_pub-pubauthors-box" class="tripal_pub-info-box tripal-info-box">
  31. <div class="tripal_pub-info-box-title tripal-info-box-title">Author Details</div>
  32. <div class="tripal_pub-info-box-desc tripal-info-box-desc">Additional information about authors:</div> <?php
  33. // the $headers array is an array of fields to use as the colum headers.
  34. // additional documentation can be found here
  35. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  36. $headers = array('', 'Details');
  37. // the $rows array contains an array of rows where each row is an array
  38. // of values for each column of the table in that row. Additional documentation
  39. // can be found here:
  40. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  41. $rows = array();
  42. $rank = 1;
  43. foreach ($authors as $author) {
  44. // expand the author to include the contact information linked via the pubauthor_contact table
  45. $contact = $author->pubauthor_contact[0]->contact_id;
  46. $options = array(
  47. 'return_array' => 1,
  48. 'include_fk' => array(
  49. 'type_id' => 1,
  50. ),
  51. );
  52. $contact = tripal_core_expand_chado_vars($contact, 'table', 'contactprop', $options);
  53. $properties = $contact->contactprop;
  54. $options = array('order_by' => array('rank' => 'ASC'));
  55. $properties = tripal_core_expand_chado_vars($properties, 'field', 'contactprop.value', $options);
  56. // link the contact to it's node if one exists
  57. $contact_name = $author->givennames . " " . $author->surname;
  58. if (property_exists($contact, 'nid')) {
  59. $contact_name = l($contact_name, 'node/' . $contact->nid);
  60. }
  61. // Get some additional details about this contact if they exists.
  62. $details = '';
  63. if (is_array($properties)) {
  64. foreach ($properties as $property) {
  65. // skip the description and name properties
  66. if ($property->type_id->name == "contact_description" or
  67. $property->type_id->name == "Surname" or
  68. $property->type_id->name == "Given Name" or
  69. $property->type_id->name == "First Initials" or
  70. $property->type_id->name == "Suffix") {
  71. continue;
  72. }
  73. $details .= "<br>" . $property->type_id->name . " : " . $property->value;
  74. }
  75. }
  76. $rows[] = array(
  77. $rank,
  78. $contact_name . $details,
  79. );
  80. $rank++;
  81. }
  82. // the $table array contains the headers and rows array as well as other
  83. // options for controlling the display of the table. Additional
  84. // documentation can be found here:
  85. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  86. $table = array(
  87. 'header' => $headers,
  88. 'rows' => $rows,
  89. 'attributes' => array(
  90. 'id' => 'tripal_pub-table-contacts',
  91. ),
  92. 'sticky' => FALSE,
  93. 'caption' => '',
  94. 'colgroups' => array(),
  95. 'empty' => '',
  96. );
  97. // once we have our table array structure defined, we call Drupal's theme_table()
  98. // function to generate the table.
  99. print theme_table($table); ?>
  100. </div><?php
  101. }