tripal_example_properties.tpl.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 column 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
  19. // documentation 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 separate properties. We want to show them
  25. // only in a single field not as a bunch of individual properties, so when
  26. // we see one, save it in an array for later and don't add it yet to the
  27. // table yet.
  28. if ($property->type_id->name == 'Keywords') {
  29. $keywords[] = $property->value;
  30. continue;
  31. }
  32. $rows[] = array(
  33. $property->type_id->name,
  34. $property->value
  35. );
  36. }
  37. // now add in a single row for all keywords
  38. if (count($keywords) > 0) {
  39. $rows[] = array(
  40. 'Keywords',
  41. implode(', ', $keywords),
  42. );
  43. }
  44. // the $table array contains the headers and rows array as well as other
  45. // options for controlling the display of the table. Additional documentation
  46. // can be found here:
  47. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  48. $table = array(
  49. 'header' => $headers,
  50. 'rows' => $rows,
  51. 'attributes' => array(
  52. 'id' => 'tripal_example-table-properties',
  53. 'class' => 'tripal-data-table'
  54. ),
  55. 'sticky' => FALSE,
  56. 'caption' => '',
  57. 'colgroups' => array(),
  58. 'empty' => '',
  59. );
  60. // once we have our table array structure defined, we call Drupal's
  61. // theme_table() function to generate the table.
  62. print theme_table($table);
  63. }