chado_wrapper_functions.inc 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. if (preg_match('/^{(.*)}$/', $v->{$handler->field_alias}, $matches)) {
  19. $values[$k]->{$handler->field_alias} = str_getcsv($matches[1]);
  20. }
  21. else {
  22. $values[$k]->{$handler->field_alias} = array();
  23. }
  24. }
  25. }
  26. return $values;
  27. }
  28. /**
  29. * Determines if the current field is generated via the aggregated join handler
  30. *
  31. * @param $handler
  32. * pass in $this from handler::query()
  33. *
  34. * @return
  35. * TRUE/FALSE if or if not the field has the aggregated join handler
  36. */
  37. function chado_wrapper_is_aggregated_by_join($handler) {
  38. $aggregated = FALSE;
  39. $table = $handler->query->get_table_info($handler->table);
  40. if (preg_match('/aggregator/', $table['join']->definition['handler'])) {
  41. $aggregated = TRUE;
  42. }
  43. return $aggregated;
  44. }
  45. /**
  46. * Determines if the current field is generated via the result returned
  47. *
  48. * @param $handler
  49. * pass in $this from handler::pre_render()
  50. * @param $values
  51. * pass in $values from handler::pre_render()
  52. *
  53. * @return
  54. * TRUE/FALSE if or if not the field is aggregated
  55. */
  56. function chado_wrapper_is_aggregated_by_result($handler, $values) {
  57. $aggregated = FALSE;
  58. $i = 0;
  59. while (empty($values[$i]->{$handler->field_alias}) AND $i <= sizeof($values)) {
  60. $i++;
  61. }
  62. if (preg_match('/^{.*}$/', $values[$i]->{$handler->field_alias})) {
  63. $aggregated = TRUE;
  64. }
  65. return $aggregated;
  66. }
  67. function chado_wrapper_render_items($handler, $values) {
  68. // If it's aggregated (an array), then render each part
  69. // using the parent render functionality
  70. if ($handler->aggregated) {
  71. $items = array();
  72. $parts = $values->{$handler->field_alias};
  73. foreach ($parts as $p) {
  74. $v[ $handler->field_alias ] = $p;
  75. $val = (object) $v;
  76. $items[] = $handler->parent_render($val);
  77. unset($v, $val);
  78. }
  79. if ($handler->options['type'] == 'separator') {
  80. return implode(check_plain($handler->options['separator']), $items);
  81. }
  82. else {
  83. return theme('item_list', $items, NULL, $handler->options['type']);
  84. }
  85. // Otherwise it is not aggragated
  86. // Just render like the default handler would
  87. }
  88. else {
  89. return $handler->parent_render($values);
  90. }
  91. }