tripal_pub_properties.tpl.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. $pub = $node->pub;
  3. // expand the pub to include the properties.
  4. $options = [
  5. 'return_array' => 1,
  6. 'order_by' => ['rank' => 'ASC'],
  7. ];
  8. $pub = chado_expand_var($pub, 'table', 'pubprop', $options);
  9. $pubprops = $pub->pubprop;
  10. $properties = [];
  11. if (is_array($pubprops)) {
  12. foreach ($pubprops as $property) {
  13. // skip the following properties as those are already on other templates
  14. if ($property->type_id->name == 'Abstract' or
  15. $property->type_id->name == 'Citation' or
  16. $property->type_id->name == 'Publication Dbxref' or
  17. $property->type_id->name == 'Authors' or
  18. $property->type_id->name == 'Structured Abstract Part') {
  19. continue;
  20. }
  21. $property = chado_expand_var($property, 'field', 'pubprop.value');
  22. $properties[] = $property;
  23. }
  24. }
  25. // we'll keep track of the keywords so we can lump them into a single row
  26. $keywords = [];
  27. if (count($properties)) { ?>
  28. <div class="tripal_pub-data-block-desc tripal-data-block-desc">Additional
  29. details for this publication include:
  30. </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 = ['Property Name', 'Value'];
  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 = [];
  40. $keywords = [];
  41. foreach ($properties as $property) {
  42. // each keyword is stored as a seperate properties. We want to show them
  43. // only in a single field not as a bunc of individual properties, so when we see one,
  44. // save it in an array for later and down't add it yet to the table yet.
  45. if ($property->type_id->name == 'Keywords') {
  46. $keywords[] = $property->value;
  47. continue;
  48. }
  49. $rows[] = [
  50. $property->type_id->name,
  51. $property->value,
  52. ];
  53. }
  54. // now add in a single row for all keywords
  55. if (count($keywords) > 0) {
  56. $rows[] = [
  57. 'Keywords',
  58. implode(', ', $keywords),
  59. ];
  60. }
  61. // the $table array contains the headers and rows array as well as other
  62. // options for controlling the display of the table. Additional
  63. // documentation can be found here:
  64. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  65. $table = [
  66. 'header' => $headers,
  67. 'rows' => $rows,
  68. 'attributes' => [
  69. 'id' => 'tripal_pub-table-properties',
  70. 'class' => 'tripal-data-table',
  71. ],
  72. 'sticky' => FALSE,
  73. 'caption' => '',
  74. 'colgroups' => [],
  75. 'empty' => '',
  76. ];
  77. // once we have our table array structure defined, we call Drupal's theme_table()
  78. // function to generate the table.
  79. print theme_table($table);
  80. }