chado_views_handler_sort.inc

  1. 3.x tripal_chado/views_handlers/chado_views_handler_sort.inc
  2. 1.x tripal_views/views/handlers/chado_views_handler_sort.inc

A chado wrapper for the views_handler_sort.

Handles fields which may be aggregated during the chado join process. Sorting of aggregated fields required PostgreSQL 9.0 due to postgresql limitations. Sorting of non-aggregated fields works for all PostgreSQL versions.

File

tripal_views/views/handlers/chado_views_handler_sort.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * A chado wrapper for the views_handler_sort.
  5. *
  6. * Handles fields which may be aggregated during the chado join process. Sorting of
  7. * aggregated fields required PostgreSQL 9.0 due to postgresql limitations. Sorting of
  8. * non-aggregated fields works for all PostgreSQL versions.
  9. */
  10. class chado_views_handler_sort extends views_handler_sort {
  11. /**
  12. * Defines the options form (form available to admin when they add a field to a view)
  13. */
  14. function options_form(&$form, &$form_state) {
  15. $form['msg'] = array(
  16. '#type' => 'item',
  17. '#value' => '<b>Sorting of aggregated fields only works for PostgreSQL 9.0+. This is due to lack of support at the database level. With lower postgreSQL versions, no sorting is applied.</b>'
  18. );
  19. parent::options_form($form, $form_state);
  20. }
  21. /**
  22. * Adds the sort to the query only if the field isn't aggregated
  23. * If the field is aggregated then the sort has to be applied at the join handler level
  24. */
  25. function query() {
  26. // Determine if the current field is part of an aggregated table
  27. $table = $this->query->get_table_info($this->table);
  28. if (preg_match('/aggregator/', $table['join']->definition['handler'])) {
  29. $this->aggregated = TRUE;
  30. }
  31. else {
  32. $this->aggregated = FALSE;
  33. }
  34. // One day when the aggregated sort will work (ie: Postgresql 9.0+)
  35. // it will need to be applied in join handler
  36. // thus tell join handler about the sort
  37. $table['join']->sort[] = array(
  38. 'table' => $table['alias'],
  39. 'field' => $this->options['field'],
  40. 'order' => $this->options['order']
  41. );
  42. // if not then add the sort
  43. if (!$this->aggregated) {
  44. parent::query();
  45. }
  46. }
  47. }