tripal_example_references.tpl.php

1 theme call to tripal_example_references.tpl.php
tripal_example_node_view in tripal_example/includes/tripal_example.chado_node.inc
Implementation of hook_node_view().

File

tripal_example/theme/templates/tripal_example_references.tpl.php
View source
  1. <?php
  2. $example = $variables['node']->example;
  3. // expand the example object to include the records from the example_dbxref
  4. // table
  5. $options = array('return_array' => 1);
  6. $example = chado_expand_var($example, 'table', 'example_dbxref', $options);
  7. $example_dbxrefs = $example->example_dbxref;
  8. $references = array();
  9. if (count($example_dbxrefs) > 0 ) {
  10. foreach ($example_dbxrefs as $example_dbxref) {
  11. $references[] = $example_dbxref->dbxref_id;
  12. }
  13. }
  14. if(count($references) > 0){ ?>
  15. <div class="tripal_example-data-block-desc tripal-data-block-desc">This example is also available in the following databases:</div><?php
  16. // the $headers array is an array of fields to use as the colum headers.
  17. // additional documentation can be found here
  18. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  19. $headers = array('Database', 'Accession');
  20. // the $rows array contains an array of rows where each row is an array
  21. // of values for each column of the table in that row. Additional
  22. // documentation can be found here:
  23. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  24. $rows = array();
  25. foreach ($references as $dbxref){
  26. $database = $dbxref->db_id->name . ': ' . $dbxref->db_id->description;
  27. if ($dbxref->db_id->url) {
  28. $database = l($dbxref->db_id->name, $dbxref->db_id->url, array('attributes' => array('target' => '_blank'))) . ': ' . $dbxref->db_id->description;
  29. }
  30. $accession = $dbxref->db_id->name . ':' . $dbxref->accession;
  31. if ($dbxref->db_id->urlprefix) {
  32. $accession = l($accession, $dbxref->db_id->urlprefix . $dbxref->accession, array('attributes' => array('target' => '_blank')));
  33. }
  34. if (property_exists($dbxref, 'is_primary')) {
  35. $accession .= " <i>(primary cross-reference)</i>";
  36. }
  37. $rows[] = array(
  38. $database,
  39. $accession
  40. );
  41. }
  42. // the $table array contains the headers and rows array as well as other
  43. // options for controlling the display of the table. Additional documentation
  44. // can be found here:
  45. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  46. $table = array(
  47. 'header' => $headers,
  48. 'rows' => $rows,
  49. 'attributes' => array(
  50. 'id' => 'tripal_example-table-references',
  51. 'class' => 'tripal-data-table'
  52. ),
  53. 'sticky' => FALSE,
  54. 'caption' => '',
  55. 'colgroups' => array(),
  56. 'empty' => '',
  57. );
  58. // once we have our table array structure defined, we call Drupal's theme_table()
  59. // function to generate the table.
  60. print theme_table($table);
  61. }