tripal_pub_authors.tpl.php

  1. 2.x tripal_pub/theme/templates/tripal_pub_authors.tpl.php
  2. 3.x legacy/tripal_pub/theme/templates/tripal_pub_authors.tpl.php
1 theme call to tripal_pub_authors.tpl.php
tripal_pub_node_view in legacy/tripal_pub/includes/tripal_pub.chado_node.inc
Implements hook_node_view(). Acts on all content types.

File

legacy/tripal_pub/theme/templates/tripal_pub_authors.tpl.php
View source
  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 = 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 = array(
  16. 'return_array' => 1,
  17. 'include_fk' => array(
  18. 'contact_id' => array(
  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 information about authors:</div> <?php
  31. // the $headers array is an array of fields to use as the colum headers.
  32. // additional documentation can be found here
  33. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  34. $headers = array('', 'Details');
  35. // the $rows array contains an array of rows where each row is an array
  36. // of values for each column of the table in that row. Additional documentation
  37. // can be found here:
  38. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  39. $rows = array();
  40. $rank = 1;
  41. foreach ($authors as $author) {
  42. // expand the author to include the contact information linked via the pubauthor_contact table
  43. $contact = $author->pubauthor_contact[0]->contact_id;
  44. $options = array(
  45. 'return_array' => 1,
  46. 'include_fk' => array(
  47. 'type_id' => 1,
  48. ),
  49. );
  50. $contact = chado_expand_var($contact, 'table', 'contactprop', $options);
  51. $properties = $contact->contactprop;
  52. $options = array('order_by' => array('rank' => 'ASC'));
  53. $properties = chado_expand_var($properties, 'field', 'contactprop.value', $options);
  54. // link the contact to it's node if one exists
  55. $contact_name = $author->givennames . " " . $author->surname;
  56. if (property_exists($contact, 'nid')) {
  57. $contact_name = l($contact_name, 'node/' . $contact->nid);
  58. }
  59. // Get some additional details about this contact if they exists.
  60. $details = '';
  61. if (is_array($properties)) {
  62. foreach ($properties as $property) {
  63. // skip the description and name properties
  64. if ($property->type_id->name == "contact_description" or
  65. $property->type_id->name == "Surname" or
  66. $property->type_id->name == "Given Name" or
  67. $property->type_id->name == "First Initials" or
  68. $property->type_id->name == "Suffix") {
  69. continue;
  70. }
  71. $details .= "<br>" . $property->type_id->name . " : " . $property->value;
  72. }
  73. }
  74. $rows[] = array(
  75. $rank,
  76. $contact_name . $details,
  77. );
  78. $rank++;
  79. }
  80. // the $table array contains the headers and rows array as well as other
  81. // options for controlling the display of the table. Additional
  82. // documentation can be found here:
  83. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  84. $table = array(
  85. 'header' => $headers,
  86. 'rows' => $rows,
  87. 'attributes' => array(
  88. 'id' => 'tripal_pub-table-contacts',
  89. 'class' => 'tripal-data-table'
  90. ),
  91. 'sticky' => FALSE,
  92. 'caption' => '',
  93. 'colgroups' => array(),
  94. 'empty' => '',
  95. );
  96. // once we have our table array structure defined, we call Drupal's theme_table()
  97. // function to generate the table.
  98. print theme_table($table);
  99. }