tripal_library_publications.tpl.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. $library = $variables['node']->library;
  3. // expand library to include pubs
  4. $options = ['return_array' => 1];
  5. $library = chado_expand_var($library, 'table', 'library_pub', $options);
  6. $library_pubs = $library->library_pub;
  7. if (count($library_pubs) > 0) { ?>
  8. <div class="tripal_library_pub-data-block-desc tripal-data-block-desc"></div> <?php
  9. // the $headers array is an array of fields to use as the colum headers.
  10. // additional documentation can be found here
  11. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  12. $headers = ['Year', 'Publication'];
  13. // the $rows array contains an array of rows where each row is an array
  14. // of values for each column of the table in that row. Additional documentation
  15. // can be found here:
  16. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  17. $rows = [];
  18. foreach ($library_pubs as $library_pub) {
  19. $pub = $library_pub->pub_id;
  20. $pub = chado_expand_var($pub, 'field', 'pub.title');
  21. $citation = $pub->title; // use the title as the default citation
  22. // get the citation for this pub if it exists
  23. $values = [
  24. 'pub_id' => $pub->pub_id,
  25. 'type_id' => [
  26. 'name' => 'Citation',
  27. ],
  28. ];
  29. $options = ['return_array' => 1];
  30. $citation_prop = chado_generate_var('pubprop', $values, $options);
  31. if (count($citation_prop) == 1) {
  32. $citation_prop = chado_expand_var($citation_prop, 'field', 'pubprop.value');
  33. $citation = $citation_prop[0]->value;
  34. }
  35. // if the publication is synced then link to it
  36. if ($pub->nid) {
  37. // replace the title with a link
  38. $link = l($pub->title, 'node/' . $pub->nid, ['attributes' => ['target' => '_blank']]);
  39. $patterns = [
  40. '/(\()/',
  41. '/(\))/',
  42. '/(\])/',
  43. '/(\[)/',
  44. '/(\{)/',
  45. '/(\})/',
  46. '/(\+)/',
  47. '/(\.)/',
  48. '/(\?)/',
  49. ];
  50. $fixed_title = preg_replace($patterns, "\\\\$1", $pub->title);
  51. $citation = preg_replace('/' . $fixed_title . '/', $link, $citation);
  52. }
  53. $rows[] = [
  54. $pub->pyear,
  55. $citation,
  56. ];
  57. }
  58. // the $table array contains the headers and rows array as well as other
  59. // options for controlling the display of the table. Additional
  60. // documentation can be found here:
  61. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  62. $table = [
  63. 'header' => $headers,
  64. 'rows' => $rows,
  65. 'attributes' => [
  66. 'id' => 'tripal_library-table-publications',
  67. 'class' => 'tripal-data-table',
  68. ],
  69. 'sticky' => FALSE,
  70. 'caption' => '',
  71. 'colgroups' => [],
  72. 'empty' => '',
  73. ];
  74. // once we have our table array structure defined, we call Drupal's theme_table()
  75. // function to generate the table.
  76. print theme_table($table);
  77. }