tripal_project_contact.tpl.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. $project = $variables['node']->project;
  3. // expand the project object to include the contacts from the project_contact
  4. // table in chado.
  5. $project = chado_expand_var($project, 'table', 'project_contact', ['return_array' => 1]);
  6. $project_contacts = $project->project_contact;
  7. if (count($project_contacts) > 0) { ?>
  8. <div class="tripal_project-data-block-desc tripal-data-block-desc">The
  9. following indivuals or groups have particpated in development or
  10. execution of this project
  11. </div><?php
  12. // the $headers array is an array of fields to use as the colum headers.
  13. // additional documentation can be found here
  14. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  15. $headers = ['', 'Details'];
  16. // the $rows array contains an array of rows where each row is an array
  17. // of values for each column of the table in that row. Additional documentation
  18. // can be found here:
  19. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  20. $rows = [];
  21. $i = 1;
  22. foreach ($project_contacts as $project_contact) {
  23. $contact = $project_contact->contact_id;
  24. $contact_name = $contact->name;
  25. if (property_exists($contact, 'nid')) {
  26. $contact_name = l($contact_name, 'node/' . $contact->nid, ['attributes' => ['target' => '_blank']]);
  27. }
  28. // Get some additional details about this contact if they exists.
  29. $details = '';
  30. $options = ['return_array' => 1];
  31. $contact = chado_expand_var($contact, 'table', 'contactprop', $options);
  32. $properties = $contact->contactprop;
  33. $options = ['order_by' => ['rank' => 'ASC']];
  34. $properties = chado_expand_var($properties, 'field', 'contactprop.value', $options);
  35. if (is_array($properties)) {
  36. foreach ($properties as $property) {
  37. // skip the description and name properties
  38. if ($property->type_id->name == "contact_description" or
  39. $property->type_id->name == "Surname" or
  40. $property->type_id->name == "Given Name" or
  41. $property->type_id->name == "First Initials" or
  42. $property->type_id->name == "Suffix") {
  43. continue;
  44. }
  45. $details .= "<br>" . $property->type_id->name . " : " . $property->value;
  46. }
  47. }
  48. $rows[] = [
  49. $i,
  50. $contact_name . $details,
  51. ];
  52. $i++;
  53. }
  54. // the $table array contains the headers and rows array as well as other
  55. // options for controlling the display of the table. Additional
  56. // documentation can be found here:
  57. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  58. $table = [
  59. 'header' => $headers,
  60. 'rows' => $rows,
  61. 'attributes' => [
  62. 'id' => 'tripal_pub-table-contacts',
  63. 'class' => 'tripal-data-table',
  64. ],
  65. 'sticky' => FALSE,
  66. 'caption' => '',
  67. 'colgroups' => [],
  68. 'empty' => '',
  69. ];
  70. // once we have our table array structure defined, we call Drupal's theme_table()
  71. // function to generate the table.
  72. print theme_table($table);
  73. }