tripal_library_publications.tpl.php

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

File

tripal_library/theme/templates/tripal_library_publications.tpl.php
View source
  1. <?php
  2. $library = $variables['node']->library;
  3. // expand library to include pubs
  4. $options = array('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 = array('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 = array();
  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 = array(
  24. 'pub_id' => $pub->pub_id,
  25. 'type_id' => array(
  26. 'name' => 'Citation',
  27. ),
  28. );
  29. $options = array('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 ,array('attributes' => array('target' => '_blank')));
  39. $patterns = array(
  40. '/(\()/', '/(\))/',
  41. '/(\])/', '/(\[)/',
  42. '/(\{)/', '/(\})/',
  43. '/(\+)/', '/(\.)/', '/(\?)/',
  44. );
  45. $fixed_title = preg_replace($patterns, "\\\\$1", $pub->title);
  46. $citation = preg_replace('/' . $fixed_title . '/', $link, $citation);
  47. }
  48. $rows[] = array(
  49. $pub->pyear,
  50. $citation,
  51. );
  52. }
  53. // the $table array contains the headers and rows array as well as other
  54. // options for controlling the display of the table. Additional
  55. // documentation can be found here:
  56. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  57. $table = array(
  58. 'header' => $headers,
  59. 'rows' => $rows,
  60. 'attributes' => array(
  61. 'id' => 'tripal_library-table-publications',
  62. 'class' => 'tripal-data-table'
  63. ),
  64. 'sticky' => FALSE,
  65. 'caption' => '',
  66. 'colgroups' => array(),
  67. 'empty' => '',
  68. );
  69. // once we have our table array structure defined, we call Drupal's theme_table()
  70. // function to generate the table.
  71. print theme_table($table);
  72. }