diff --git a/flag.info b/flag.info index 6933238b0c39e9dcbb126e64494e9d701092ff62..b01a43c3818f45ef2743a560a24c695970d21d12 100644 --- a/flag.info +++ b/flag.info @@ -10,6 +10,7 @@ files[] = flag.rules.inc files[] = includes/flag_handler_argument_content_id.inc files[] = includes/flag_handler_field_ops.inc files[] = includes/flag_handler_filter_flagged.inc +files[] = includes/flag_handler_sort_flagged.inc files[] = includes/flag_handler_relationships.inc files[] = includes/flag_plugin_argument_validate_flaggability.inc files[] = tests/flag.test diff --git a/includes/flag.views.inc b/includes/flag.views.inc index 4f85ffd1779b03a2e805eb4102e79394b9f403e7..b149764235b61536906c201b4289ccd3e341e643 100644 --- a/includes/flag.views.inc +++ b/includes/flag.views.inc @@ -89,11 +89,16 @@ function flag_views_data() { // Specialized is null/is not null filter. $data['flag_content']['flagged'] = array( 'title' => t('Flagged'), - 'help' => t('Filter to ensure content has or has not been flagged.'), 'real field' => 'uid', 'filter' => array( 'handler' => 'flag_handler_filter_flagged', 'label' => t('Flagged'), + 'help' => t('Filter to ensure content has or has not been flagged.'), + ), + 'sort' => array( + 'handler' => 'flag_handler_sort_flagged', + 'label' => t('Flagged'), + 'help' => t('Sort by whether entities have or have not been flagged.'), ), ); diff --git a/includes/flag_handler_sort_flagged.inc b/includes/flag_handler_sort_flagged.inc new file mode 100644 index 0000000000000000000000000000000000000000..a510aab0e2235feb25d7cdd48f13b27b37bffce0 --- /dev/null +++ b/includes/flag_handler_sort_flagged.inc @@ -0,0 +1,46 @@ + t('Unflagged first'), + 'DESC' => t('Flagged first'), + ); + } + + /** + * Display whether or not the sort order is ascending or descending + */ + function admin_summary() { + if (!empty($this->options['exposed'])) { + return t('Exposed'); + } + + // Get the labels defined in sort_options(). + $sort_options = $this->sort_options(); + return $sort_options[strtoupper($this->options['order'])]; + } + + function query() { + $this->ensure_my_table(); + // Add the ordering. + // Using IS NOT NULL means that the ASC/DESC ordering work in the same + // direction as sorting by flagging date: empty results come first. + $this->query->add_orderby(NULL, "($this->table_alias.uid IS NOT NULL)", $this->options['order']); + } + +}