tripal_pub_projects.tpl.php

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

File

tripal_pub/theme/templates/tripal_pub_projects.tpl.php
View source
  1. <?php
  2. $pub = $variables['node']->pub;
  3. $projects = array();
  4. // get the features 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 features.
  6. // so we, use the chado_select_record 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 features
  9. $element = 4; // an index to specify the pager this must be unique amongst all pub templates
  10. $num_per_page = 25; // the number of projects to show per page$num_results_per_page = 25;
  11. // get the projects from the project_pub table
  12. $options = array(
  13. 'return_array' => 1,
  14. 'pager' => array(
  15. 'limit' => $num_per_page,
  16. 'element' => $element
  17. ),
  18. );
  19. $pub = chado_expand_var($pub, 'table', 'project_pub', $options);
  20. $project_pubs = $pub->project_pub;
  21. if (count($project_pubs) > 0 ) {
  22. foreach ($project_pubs as $project_pub) {
  23. $projects[] = $project_pub->project_id;
  24. }
  25. }
  26. // get the total number of records
  27. $total_records = chado_pager_get_count($element);
  28. if(count($projects) > 0){ ?>
  29. <div class="tripal_pub-data-block-desc tripal-data-block-desc">This publication contains information about <?php print number_format($total_records) ?> projects:</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('Project Name', 'Description');
  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 ($projects as $project){
  40. $project_name = $project->name;
  41. if (property_exists($project, 'nid')) {
  42. $project_name = l($project_name, 'node/' . $project->nid, array('attributes' => array('target' => '_blank')));
  43. }
  44. $description = substr($project->description, 0, 200);
  45. if (strlen($project->description) > 200) {
  46. $description .= "... " . l("[more]", 'node/' . $project->nid, array('attributes' => array('target' => '_blank')));
  47. }
  48. $rows[] = array(
  49. $project_name,
  50. $description
  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_pub-table-projects',
  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. // 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' => 'projects'. 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. // We remove the 'pane' parameter from the original query parameters because
  79. // Drupal won't reset the parameter if it already exists.
  80. $get = $_GET;
  81. unset($_GET['pane']);
  82. $pager = array(
  83. 'tags' => array(),
  84. 'element' => $element,
  85. 'parameters' => array(
  86. 'pane' => 'projects'
  87. ),
  88. 'quantity' => $num_per_page,
  89. );
  90. print theme_pager($pager);
  91. $_GET = $get;
  92. }