tripal_pub_authors.tpl.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. $pub = $node->pub;
  3. // expand the pub to include the pubauthors.
  4. $options = [
  5. 'return_array' => 1,
  6. 'order_by' => ['rank' => 'ASC'],
  7. ];
  8. $pub = chado_expand_var($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 = [
  16. 'return_array' => 1,
  17. 'include_fk' => [
  18. 'contact_id' => [
  19. 'type_id' => 1,
  20. ],
  21. ],
  22. ];
  23. $author = chado_expand_var($author, 'table', 'pubauthor_contact', $options);
  24. if ($author->pubauthor_contact) {
  25. $has_contacts = TRUE;
  26. }
  27. }
  28. }
  29. if ($has_contacts) { ?>
  30. <div class="tripal_pub-data-block-desc tripal-data-block-desc">Additional
  31. information about authors:
  32. </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 = ['', '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 = [];
  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 = [
  47. 'return_array' => 1,
  48. 'include_fk' => [
  49. 'type_id' => 1,
  50. ],
  51. ];
  52. $contact = chado_expand_var($contact, 'table', 'contactprop', $options);
  53. $properties = $contact->contactprop;
  54. $options = ['order_by' => ['rank' => 'ASC']];
  55. $properties = chado_expand_var($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[] = [
  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 = [
  87. 'header' => $headers,
  88. 'rows' => $rows,
  89. 'attributes' => [
  90. 'id' => 'tripal_pub-table-contacts',
  91. 'class' => 'tripal-data-table',
  92. ],
  93. 'sticky' => FALSE,
  94. 'caption' => '',
  95. 'colgroups' => [],
  96. 'empty' => '',
  97. ];
  98. // once we have our table array structure defined, we call Drupal's theme_table()
  99. // function to generate the table.
  100. print theme_table($table);
  101. }