tripal_project_publications.tpl.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. $project = $variables['node']->project;
  3. // expand project to include pubs
  4. $options = array('return_array' => 1);
  5. $project = chado_expand_var($project, 'table', 'project_pub', $options);
  6. $project_pubs = $project->project_pub;
  7. if (count($project_pubs) > 0) { ?>
  8. <div class="tripal_project_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 ($project_pubs as $project_pub) {
  19. $pub = $project_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_project-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. }