tripal_pub_libraries.tpl.php 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. $pub = $variables['node']->pub;
  3. $libraries = array();
  4. // get the libraries that are associated with this publication. But we only
  5. // want 25 and we want a pager to let the user cycle between pages of libraries.
  6. // so we, use the tripal_core_chado_select API function to get the results and
  7. // generate the pager. The function is smart enough to know which page the user is
  8. // on and retrieves the proper set of libraries
  9. $element = 3; // an index to specify the pager this must be unique amongst all pub templates
  10. $num_per_page = 25; // the number of libraries to show per page$num_results_per_page = 25;
  11. // get the libraries from the library_pub table
  12. $options = array(
  13. 'return_array' => 1,
  14. 'pager' => array(
  15. 'limit' => $num_per_page,
  16. 'element' => $element
  17. ),
  18. );
  19. $pub = tripal_core_expand_chado_vars($pub, 'table', 'library_pub', $options);
  20. $library_pubs = $pub->library_pub;
  21. if (count($library_pubs) > 0 ) {
  22. foreach ($library_pubs as $library_pub) {
  23. $libraries[] = $library_pub->library_id;
  24. }
  25. }
  26. // the total number of records for the paged query is stored in a session variable
  27. $total_records = chado_pager_get_count($element);
  28. if(count($libraries) > 0){ ?>
  29. <div class="tripal_pub-data-block-desc tripal-data-block-desc">This publication contains information about <?php print number_format($total_records) ?> libraries:</div> <?php
  30. // the $headers array is an array of fields to use as the colum headers.
  31. // additional documentation can be found here
  32. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  33. $headers = array('Library Name', 'Unique Name', 'Organism');
  34. // the $rows array contains an array of rows where each row is an array
  35. // of values for each column of the table in that row. Additional documentation
  36. // can be found here:
  37. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  38. $rows = array();
  39. foreach ($libraries as $library){
  40. $library_name = $library->name;
  41. if (property_exists($library, 'nid')) {
  42. $library_name = l($library_name, 'node/' . $library->nid, array('attributes' => array('target' => '_blank')));
  43. }
  44. $organism = '<i>' . $library->organism_id->genus . ' ' . $library->organism_id->species . '</i>';
  45. if (property_exists($library->organism_id, 'nid')) {
  46. $organism = l($organism, 'node/' . $library->organism_id->nid, array('attributes' => array('target' => '_blank')));
  47. }
  48. $rows[] = array(
  49. $library_name,
  50. $library->uniquename,
  51. $organism,
  52. );
  53. }
  54. // the $table array contains the headers and rows array as well as other
  55. // options for controlling the display of the table. Additional
  56. // documentation can be found here:
  57. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  58. $table = array(
  59. 'header' => $headers,
  60. 'rows' => $rows,
  61. 'attributes' => array(
  62. 'id' => 'tripal_pub-table-libraries',
  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. // the $pager array values that control the behavior of the pager. For
  73. // documentation on the values allows in this array see:
  74. // https://api.drupal.org/api/drupal/includes!pager.inc/function/theme_pager/7
  75. // here we add the paramter 'block' => 'libraries'. This is because
  76. // the pager is not on the default block that appears. When the user clicks a
  77. // page number we want the browser to re-appear with the page is loaded.
  78. $pager = array(
  79. 'tags' => array(),
  80. 'element' => $element,
  81. 'parameters' => array(
  82. 'block' => 'libraries'
  83. ),
  84. 'quantity' => $num_per_page,
  85. );
  86. print theme_pager($pager);
  87. }