tripal_example_properties.tpl.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. $example = $node->example;
  3. // expand the example to include the properties.
  4. $options = array(
  5. 'return_array' => 1,
  6. 'order_by' => array('rank' => 'ASC'),
  7. );
  8. $example = chado_expand_var($example,'table', 'exampleprop', $options);
  9. $exampleprops = $example->exampleprop;
  10. $properties = array();
  11. if (count($properties)) { ?>
  12. <div class="tripal_example-data-block-desc tripal-data-block-desc">Additional details for this example include:</div> <?php
  13. // the $headers array is an array of fields to use as the colum headers.
  14. // additional documentation can be found here
  15. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  16. $headers = array('Property Name', 'Value');
  17. // the $rows array contains an array of rows where each row is an array
  18. // of values for each column of the table in that row. Additional documentation
  19. // can be found here:
  20. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  21. $rows = array();
  22. $keywords = array();
  23. foreach ($properties as $property) {
  24. // each keyword is stored as a seperate properties. We want to show them
  25. // only in a single field not as a bunc of individual properties, so when we see one,
  26. // save it in an array for later and down't add it yet to the table yet.
  27. if ($property->type_id->name == 'Keywords') {
  28. $keywords[] = $property->value;
  29. continue;
  30. }
  31. $rows[] = array(
  32. $property->type_id->name,
  33. $property->value
  34. );
  35. }
  36. // now add in a single row for all keywords
  37. if (count($keywords) > 0) {
  38. $rows[] = array(
  39. 'Keywords',
  40. implode(', ', $keywords),
  41. );
  42. }
  43. // the $table array contains the headers and rows array as well as other
  44. // options for controlling the display of the table. Additional
  45. // documentation can be found here:
  46. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  47. $table = array(
  48. 'header' => $headers,
  49. 'rows' => $rows,
  50. 'attributes' => array(
  51. 'id' => 'tripal_example-table-properties',
  52. 'class' => 'tripal-data-table'
  53. ),
  54. 'sticky' => FALSE,
  55. 'caption' => '',
  56. 'colgroups' => array(),
  57. 'empty' => '',
  58. );
  59. // once we have our table array structure defined, we call Drupal's theme_table()
  60. // function to generate the table.
  61. print theme_table($table);
  62. }