chado_wrapper_functions.inc 2.5 KB

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