tripal_stock_properties.tpl.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. $stock = $variables['node']->stock;
  3. $options = ['return_array' => 1];
  4. $stock = chado_expand_var($stock, 'table', 'stockprop', $options);
  5. $stockprops = $stock->stockprop;
  6. // the stock synonyms are stored in the stockprop table because we do not have
  7. // a stock_synonym table. Therefore, we don't want to synonyms in the properties
  8. // list as those get shown by the tripal_stock_synonyms.tpl.inc template.
  9. $properties = [];
  10. if ($stockprops) {
  11. foreach ($stockprops as $property) {
  12. // we want to keep all properties but the stock_description as that
  13. // property is shown on the base template page.
  14. if ($property->type_id->name != 'synonym' and $property->type_id->name != 'alias') {
  15. $property = chado_expand_var($property, 'field', 'stockprop.value');
  16. $properties[] = $property;
  17. }
  18. }
  19. }
  20. if (count($properties) > 0) {
  21. // the $headers array is an array of fields to use as the colum headers.
  22. // additional documentation can be found here
  23. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  24. $headers = ['Property Name', 'Value'];
  25. // the $rows array contains an array of rows where each row is an array
  26. // of values for each column of the table in that row. Additional documentation
  27. // can be found here:
  28. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  29. $rows = [];
  30. foreach ($properties as $property) {
  31. $property = chado_expand_var($property, 'field', 'stockprop.value');
  32. $rows[] = [
  33. [
  34. 'data' => ucfirst(preg_replace('/_/', ' ', $property->type_id->name)),
  35. 'width' => '20%',
  36. ],
  37. urldecode($property->value),
  38. ];
  39. }
  40. // the $table array contains the headers and rows array as well as other
  41. // options for controlling the display of the table. Additional
  42. // documentation can be found here:
  43. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  44. $table = [
  45. 'header' => $headers,
  46. 'rows' => $rows,
  47. 'attributes' => [
  48. 'id' => 'tripal_stock-table-properties',
  49. 'class' => 'tripal-data-table',
  50. ],
  51. 'sticky' => FALSE,
  52. 'caption' => '',
  53. 'colgroups' => [],
  54. 'empty' => '',
  55. ];
  56. // once we have our table array structure defined, we call Drupal's theme_table()
  57. // function to generate the table.
  58. print theme_table($table);
  59. }