tripal_stock_synonyms.tpl.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. // there is no stock_synonym table, analogous to the stock_synonym table.
  3. // Therefore, synonyms have been stored in the stockprop table with a type
  4. // of 'synonym' or 'alias'.
  5. $stock = $node->stock;
  6. $synonyms = [];
  7. // expand the stock object to include the stockprop records
  8. $options = ['return_array' => 1];
  9. $stock = chado_expand_var($stock, 'table', 'stockprop', $options);
  10. $stockprops = $stock->stockprop;
  11. // iterate through all of the properties and pull out only the synonyms
  12. if ($stockprops) {
  13. foreach ($stockprops as $stockprop) {
  14. if ($stockprop->type_id->name == 'synonym' or $stockprop->type_id->name == 'alias') {
  15. $synonyms[] = $stockprop;
  16. }
  17. }
  18. }
  19. if (count($synonyms) > 0) { ?>
  20. <div class="tripal_stock-data-block-desc tripal-data-block-desc">The stock
  21. '<?php print $stock->name ?>' has the following synonyms
  22. </div> <?php
  23. // the $headers array is an array of fields to use as the colum headers.
  24. // additional documentation can be found here
  25. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  26. // This table for the analysis has a vertical header (down the first column)
  27. // so we do not provide headers here, but specify them in the $rows array below.
  28. $headers = ['Synonym'];
  29. // the $rows array contains an array of rows where each row is an array
  30. // of values for each column of the table in that row. Additional documentation
  31. // can be found here:
  32. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  33. $rows = [];
  34. foreach ($synonyms as $property) {
  35. $rows[] = [
  36. $property->value,
  37. ];
  38. }
  39. // the $table array contains the headers and rows array as well as other
  40. // options for controlling the display of the table. Additional
  41. // documentation can be found here:
  42. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  43. $table = [
  44. 'header' => $headers,
  45. 'rows' => $rows,
  46. 'attributes' => [
  47. 'id' => 'tripal_stock-table-synonyms',
  48. 'class' => 'tripal-data-table',
  49. ],
  50. 'sticky' => FALSE,
  51. 'caption' => '',
  52. 'colgroups' => [],
  53. 'empty' => '',
  54. ];
  55. // once we have our table array structure defined, we call Drupal's theme_table()
  56. // function to generate the table.
  57. print theme_table($table);
  58. }