tripal_fields_layout_generic.tpl.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. drupal_add_js('misc/form.js');
  3. drupal_add_js('misc/collapse.js');
  4. drupal_add_js(drupal_get_path('module','tripal_fields_layout') . '/theme/js/tripal_fields_layout.js');
  5. $panels = $variables['element']['#panels'];
  6. $fields = $variables['element']['#fields'];
  7. // TODO, the horz_table variable needs to be set in a variable and checked here.
  8. $horz_table = TRUE;
  9. // Group fields into panels
  10. $content = '';
  11. $toc = '';
  12. $has_base_panel_only = TRUE;
  13. foreach ($panels AS $panel_id => $panel) {
  14. if ($panel->name != 'te_base') {
  15. $has_base_panel_only = FALSE;
  16. }
  17. $panel_settings = unserialize($panel->settings);
  18. $hz_table_group = key_exists('hz_table', $panel_settings) ? $panel_settings['hz_table'] : array();
  19. $vt_table_group = key_exists('vt_table', $panel_settings) ? $panel_settings['vt_table'] : array();
  20. $panel_fields = $fields[$panel_id];
  21. // Rearrange fields into groups for each panel
  22. $hz_table = array();
  23. $vt_table = array();
  24. $no_group = array();
  25. // Keyed by field's '#weight' and '#field_name so we can ksort() by weight
  26. foreach ($panel_fields AS $field) {
  27. if (in_array($field['#field_name'], $hz_table_group)) {
  28. $hz_table [$field['#weight'] . $field['#field_name']] = $field;
  29. }
  30. else if (in_array($field['#field_name'], $vt_table_group)) {
  31. $vt_table [$field['#weight'] . $field['#field_name']] = $field;
  32. }
  33. else {
  34. $no_group [$field['#weight'] . $field['#field_name']] = $field;
  35. }
  36. }
  37. // Render horizontal table
  38. $horz_table = '';
  39. if (count($hz_table) != 0) {
  40. ksort($hz_table, SORT_NUMERIC);
  41. $rows = array();
  42. foreach ($hz_table as $field) {
  43. $rows[] = array(
  44. array(
  45. 'data' => $field['#title'],
  46. 'header' => TRUE,
  47. 'width' => '20%',
  48. 'nowrap' => 'nowrap'
  49. ),
  50. $field[0]['#markup']
  51. );
  52. }
  53. $horz_table = theme_table(array(
  54. 'header' => array(),
  55. 'rows' => $rows,
  56. 'attributes' => array(
  57. 'id' => '', // TODO: need to add an ID
  58. 'class' => 'tripal-data-horz-table'
  59. ),
  60. 'sticky' => FALSE,
  61. 'caption' => '',
  62. 'colgroups' => array(),
  63. 'empty' => '',
  64. ));
  65. }
  66. // Render horizontal table
  67. $vert_table = '';
  68. if (count($vt_table) != 0) {
  69. ksort($vt_table, SORT_NUMERIC);
  70. $value = array();
  71. $headers = array();
  72. foreach ($vt_table as $field) {
  73. $headers [] = $field['#title'];
  74. array_push($value, $field[0]['#markup']);
  75. }
  76. $vert_table = theme_table(array(
  77. 'header' => $headers,
  78. 'rows' => array($value),
  79. 'attributes' => array(
  80. 'id' => '', // TODO: need to add an ID
  81. 'class' => 'tripal-data-vert-table'
  82. ),
  83. 'sticky' => FALSE,
  84. 'caption' => '',
  85. 'colgroups' => array(),
  86. 'empty' => '',
  87. ));
  88. }
  89. // Render field not in a group
  90. $ungrouped = '';
  91. if (count($no_group) != 0) {
  92. ksort($no_group, SORT_NUMERIC);
  93. foreach ($no_group as $field) {
  94. $ungrouped .= render($field);
  95. }
  96. }
  97. $output = $horz_table . $vert_table . $ungrouped ;
  98. // If this is a base content, do not organize the content in a fieldset
  99. if ($panel->name == 'te_base') {
  100. $content .= '<div class="tripal_base_panel">' . $output . '</div>';
  101. } else {
  102. $collapsible_item = array('element' => array());
  103. $collapsible_item['element']['#description'] = $output;
  104. $collapsible_item['element']['#title'] = $panel->label;
  105. $collapsible_item['element']['#children'] = '';
  106. $collapsible_item['element']['#attributes']['id'] = 'tripal_panel_fieldset-' . $panel->name;
  107. $collapsible_item['element']['#attributes']['class'][] = 'tripal_panel_fieldset';
  108. $collapsible_item['element']['#attributes']['class'][] = 'collapsible';
  109. $collapsible_item['element']['#attributes']['class'][] = 'collapsed';
  110. $toc_item_id = $panel_id;
  111. $toc .= "<div class=\"tripal_toc_list_item\"><a id=\"" . $panel->name . "\" class=\"tripal_toc_list_item_link\" href=\"?pane=" . $panel->name . "\">" . $panel->label . "</a></div>";
  112. $content .= theme('fieldset', $collapsible_item);
  113. }
  114. }
  115. $bundle_type = ''; // TODO: need to add the bundle type
  116. if ($has_base_panel_only) { ?>
  117. <div id ="tripal-<?php print $bundle_type?>-contents-box"> <?php
  118. // print the rendered content
  119. print $content; ?>
  120. </div> <?php
  121. } else { ?>
  122. <table id ="tripal-<?php print $bundle_type?>-contents-table" class="tripal-contents-table">
  123. <tr class="tripal-contents-table-tr"> <?php
  124. ?>
  125. <td nowrap class="tripal-contents-table-td tripal-contents-table-td-toc" align="left"><?php
  126. print $toc; ?>
  127. </td>
  128. <td class="tripal-contents-table-td-data" align="left" width="100%"> <?php
  129. // print the rendered content
  130. print $content; ?>
  131. </td>
  132. </tr>
  133. </table> <?php
  134. } ?>