chado_wrapper_functions.inc 2.5 KB

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