tripal_stock_collections.tpl.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. $stock = $variables['node']->stock;
  3. // expand the stock object to include the stockcollections associated with this stock
  4. $options = ['return_array' => 1];
  5. $stock = chado_expand_var($stock, 'table', 'stockcollection_stock', $options);
  6. $collections = $stock->stockcollection_stock;
  7. if (count($collections) > 0) { ?>
  8. <div class="tripal_stock-data-block-desc tripal-data-block-desc">This stock
  9. is found in the following collections.
  10. </div> <?php
  11. // the $headers array is an array of fields to use as the colum headers.
  12. // additional documentation can be found here
  13. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  14. // This table for the analysis has a vertical header (down the first column)
  15. // so we do not provide headers here, but specify them in the $rows array below.
  16. $headers = ['Collection Name', 'Type', 'Contact'];
  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 = [];
  22. foreach ($collections as $collection_stock) {
  23. // get the stock collection details
  24. $collection = $collection_stock->stockcollection_id;
  25. $contact = $collection->contact_id;
  26. $cname = $collection->name;
  27. if (property_exists($collection, 'nid')) {
  28. $cname = l($collection->name, "node/" . $collection->nid, ['attributes' => ['target' => '_blank']]);
  29. }
  30. $rows[] = [
  31. $cname,
  32. ucwords(preg_replace('/_/', ' ', $collection->type_id->name)),
  33. $contact->name,
  34. ];
  35. }
  36. // the $table array contains the headers and rows array as well as other
  37. // options for controlling the display of the table. Additional
  38. // documentation can be found here:
  39. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  40. $table = [
  41. 'header' => $headers,
  42. 'rows' => $rows,
  43. 'attributes' => [
  44. 'id' => 'tripal_stock-table-synonyms',
  45. 'class' => 'tripal-data-table',
  46. ],
  47. 'sticky' => FALSE,
  48. 'caption' => '',
  49. 'colgroups' => [],
  50. 'empty' => '',
  51. ];
  52. // once we have our table array structure defined, we call Drupal's theme_table()
  53. // function to generate the table.
  54. print theme_table($table);
  55. }