tripal_pub_libraries.tpl.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 = $_SESSION['chado_pager'][$element]['total_records'];
  28. if(count($libraries) > 0){ ?>
  29. <div id="tripal_pub-libraries-box" class="tripal_pub-info-box tripal-info-box">
  30. <div class="tripal_pub-info-box-title tripal-info-box-title">Libraries</div>
  31. <div class="tripal_pub-info-box-desc tripal-info-box-desc">This publication contains information about <?php print number_format($total_records) ?> libraries:</div> <?php
  32. // the $headers array is an array of fields to use as the colum headers.
  33. // additional documentation can be found here
  34. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  35. $headers = array('Library Name', 'Unique Name', 'Organism');
  36. // the $rows array contains an array of rows where each row is an array
  37. // of values for each column of the table in that row. Additional documentation
  38. // can be found here:
  39. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  40. $rows = array();
  41. foreach ($libraries as $library){
  42. $library_name = $library->name;
  43. if (property_exists($library, 'nid')) {
  44. $library_name = l($library_name, 'node/' . $library->nid, array('attributes' => array('target' => '_blank')));
  45. }
  46. $organism = '<i>' . $library->organism_id->genus . ' ' . $library->organism_id->species . '</i>';
  47. if (property_exists($library->organism_id, 'nid')) {
  48. $organism = l($organism, 'node/' . $library->organism_id->nid, array('attributes' => array('target' => '_blank')));
  49. }
  50. $rows[] = array(
  51. $library_name,
  52. $library->uniquename,
  53. $organism,
  54. );
  55. }
  56. // the $table array contains the headers and rows array as well as other
  57. // options for controlling the display of the table. Additional
  58. // documentation can be found here:
  59. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  60. $table = array(
  61. 'header' => $headers,
  62. 'rows' => $rows,
  63. 'attributes' => array(
  64. 'id' => 'tripal_pub-table-libraries',
  65. ),
  66. 'sticky' => FALSE,
  67. 'caption' => '',
  68. 'colgroups' => array(),
  69. 'empty' => '',
  70. );
  71. // once we have our table array structure defined, we call Drupal's theme_table()
  72. // function to generate the table.
  73. print theme_table($table);
  74. // the $pager array values that control the behavior of the pager. For
  75. // documentation on the values allows in this array see:
  76. // https://api.drupal.org/api/drupal/includes!pager.inc/function/theme_pager/7
  77. // here we add the paramter 'block' => 'libraries'. This is because
  78. // the pager is not on the default block that appears. When the user clicks a
  79. // page number we want the browser to re-appear with the page is loaded.
  80. $pager = array(
  81. 'tags' => array(),
  82. 'element' => $element,
  83. 'parameters' => array(
  84. 'block' => 'libraries'
  85. ),
  86. 'quantity' => $num_per_page,
  87. );
  88. print theme_pager($pager); ?>
  89. </div><?php
  90. }?>