chado_wrapper_functions.inc 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. /**
  3. * @file
  4. * TODO: add documentation
  5. */
  6. /**
  7. * Splits an SQL array of results in a single field
  8. * into a php array
  9. *
  10. * @param $field
  11. * An SQL array (ie: {"",^(.*)$,646,tripal_analysis_blast} )
  12. * @return
  13. * A PHP version of the SQL array (ie: array('','^(.*)$','646','tripal_analysis_blast') )
  14. */
  15. function chado_wrapper_split_array_agg_results($handler, &$values) {
  16. if ($handler->aggregated) {
  17. foreach ($values as $k => $v) {
  18. // Some custom handlers re-use the same field
  19. // This ensures that an already split value doesn't get re-split
  20. if (!is_array($v->{$handler->field_alias})) {
  21. if (preg_match('/^{(.*)}$/', $v->{$handler->field_alias}, $matches)) {
  22. $values[$k]->{$handler->field_alias} = str_getcsv($matches[1]);
  23. }
  24. else {
  25. $values[$k]->{$handler->field_alias} = array();
  26. }
  27. }
  28. }
  29. }
  30. return $values;
  31. }
  32. /**
  33. * Determines if the current field is generated via the aggregated join handler
  34. *
  35. * @param $handler
  36. * pass in $this from handler::query()
  37. *
  38. * @return
  39. * TRUE/FALSE if or if not the field has the aggregated join handler
  40. */
  41. function chado_wrapper_is_aggregated_by_join($handler) {
  42. $aggregated = FALSE;
  43. $table = $handler->query->get_table_info($handler->table);
  44. if (preg_match('/aggregator/', $table['join']->definition['handler'])) {
  45. $aggregated = TRUE;
  46. }
  47. return $aggregated;
  48. }
  49. /**
  50. * Determines if the current field is generated via the result returned
  51. *
  52. * @param $handler
  53. * pass in $this from handler::pre_render()
  54. * @param $values
  55. * pass in $values from handler::pre_render()
  56. *
  57. * @return
  58. * TRUE/FALSE if or if not the field is aggregated
  59. */
  60. function chado_wrapper_is_aggregated_by_result($handler, $values) {
  61. $aggregated = FALSE;
  62. $i = 0;
  63. while (empty($values[$i]->{$handler->field_alias}) AND $i <= sizeof($values)) {
  64. $i++;
  65. }
  66. if (is_array($values[$i]->{$handler->field_alias})) {
  67. $aggregated = TRUE;
  68. }
  69. elseif (preg_match('/^{.*}$/', $values[$i]->{$handler->field_alias})) {
  70. $aggregated = TRUE;
  71. }
  72. return $aggregated;
  73. }
  74. function chado_wrapper_render_items($handler, $values) {
  75. // If it's aggregated (an array), then render each part
  76. // using the parent render functionality
  77. if ($handler->aggregated) {
  78. $items = array();
  79. $parts = $values->{$handler->field_alias};
  80. foreach ($parts as $p) {
  81. $v[ $handler->field_alias ] = $p;
  82. $val = (object) $v;
  83. $items[] = $handler->parent_render($val);
  84. unset($v, $val);
  85. }
  86. if ($handler->options['type'] == 'separator') {
  87. return implode(check_plain($handler->options['separator']), $items);
  88. }
  89. else {
  90. return theme('item_list', $items, NULL, $handler->options['type']);
  91. }
  92. // Otherwise it is not aggragated
  93. // Just render like the default handler would
  94. }
  95. else {
  96. return $handler->parent_render($values);
  97. }
  98. }