views_handler_sort.inc

  1. 3.x handlers/views_handler_sort.inc
  2. 2.x handlers/views_handler_sort.inc

File

handlers/views_handler_sort.inc
View source
  1. <?php
  2. /**
  3. * @defgroup views_sort_handlers Views' sort handlers
  4. * @{
  5. * Handlers to tell Views how to sort queries
  6. */
  7. /**
  8. * Base sort handler that has no options and performs a simple sort
  9. */
  10. class views_handler_sort extends views_handler {
  11. /**
  12. * Called to add the sort to a query.
  13. */
  14. function query() {
  15. $this->ensure_my_table();
  16. // Add the field.
  17. $this->query->add_orderby($this->table_alias, $this->real_field, $this->options['order']);
  18. }
  19. function option_definition() {
  20. $options = parent::option_definition();
  21. $options['order'] = array('default' => 'ASC');
  22. return $options;
  23. }
  24. /**
  25. * Display whether or not the sort order is ascending or descending
  26. */
  27. function admin_summary() {
  28. switch ($this->options['order']) {
  29. case 'ASC':
  30. case 'asc':
  31. default:
  32. $type = t('asc');
  33. break;
  34. case 'DESC';
  35. case 'desc';
  36. $type = t('desc');
  37. break;
  38. }
  39. return '<span class="views-ascending"><span>' . $type . '</span></span>';
  40. }
  41. /**
  42. * Basic options for all sort criteria
  43. */
  44. function options_form(&$form, &$form_state) {
  45. $form['order'] = array(
  46. '#type' => 'radios',
  47. '#title' => t('Sort order'),
  48. '#options' => array('ASC' => t('Ascending'), 'DESC' => t('Descending')),
  49. '#default_value' => $this->options['order'],
  50. );
  51. }
  52. }
  53. /**
  54. * A special handler to take the place of missing or broken handlers.
  55. */
  56. class views_handler_sort_broken extends views_handler_sort {
  57. function ui_name($short = FALSE) {
  58. return t('Broken/missing handler');
  59. }
  60. function ensure_my_table() { /* No table to ensure! */ }
  61. function query() { /* No query to run */ }
  62. function options_form(&$form, &$form_state) {
  63. $form['markup'] = array(
  64. '#prefix' => '<div class="form-item description">',
  65. '#value' => t('The handler for this item is broken or missing and cannot be used. If a module provided the handler and was disabled, re-enabling the module may restore it. Otherwise, you should probably delete this item.'),
  66. );
  67. }
  68. /**
  69. * Determine if the handler is considered 'broken'
  70. */
  71. function broken() { return TRUE; }
  72. }
  73. /**
  74. * @}
  75. */