flag_handler_sort_flagged.inc 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * @file
  4. * Contains the flagged content sort handler.
  5. */
  6. /**
  7. * Handler to sort on whether objects are flagged or not.
  8. *
  9. * @ingroup views
  10. */
  11. class flag_handler_sort_flagged extends views_handler_sort {
  12. /**
  13. * Provide a list of options for the default sort form.
  14. *
  15. * Should be overridden by classes that don't override sort_form.
  16. */
  17. function sort_options() {
  18. return array(
  19. 'ASC' => t('Unflagged first'),
  20. 'DESC' => t('Flagged first'),
  21. );
  22. }
  23. /**
  24. * Display whether or not the sort order is ascending or descending
  25. */
  26. function admin_summary() {
  27. if (!empty($this->options['exposed'])) {
  28. return t('Exposed');
  29. }
  30. // Get the labels defined in sort_options().
  31. $sort_options = $this->sort_options();
  32. return $sort_options[strtoupper($this->options['order'])];
  33. }
  34. function query() {
  35. $this->ensure_my_table();
  36. // Add the ordering.
  37. // Using IS NOT NULL means that the ASC/DESC ordering work in the same
  38. // direction as sorting by flagging date: empty results come first.
  39. $this->query->add_orderby(NULL, "($this->table_alias.uid IS NOT NULL)", $this->options['order']);
  40. }
  41. }