tripal_project.publications.tpl.php 3.2 KB

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