summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoachim Noreiko2013-02-17 09:41:09 (GMT)
committer Joachim Noreiko2013-02-17 09:41:09 (GMT)
commit32cac54ac36a52b65389052d2029221cad78093f (patch)
treee23898fe63893941037d7c06ba6cd42fe3f4949a
parentf882f36673ce71b5872487a3073f8efb1b3d8487 (diff)
Issue #1355864 by joachim, socketwench: Added a Views sort handler for flagged / unflagged.7.x-2.1
-rw-r--r--flag.info1
-rw-r--r--includes/flag.views.inc7
-rw-r--r--includes/flag_handler_sort_flagged.inc46
3 files changed, 53 insertions, 1 deletions
diff --git a/flag.info b/flag.info
index 6933238..b01a43c 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 4f85ffd..b149764 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 0000000..a510aab
--- /dev/null
+++ b/includes/flag_handler_sort_flagged.inc
@@ -0,0 +1,46 @@
+<?php
+/**
+ * @file
+ * Contains the flagged content sort handler.
+ */
+
+/**
+ * Handler to sort on whether objects are flagged or not.
+ *
+ * @ingroup views
+ */
+class flag_handler_sort_flagged extends views_handler_sort {
+
+ /**
+ * Provide a list of options for the default sort form.
+ * Should be overridden by classes that don't override sort_form
+ */
+ function sort_options() {
+ return array(
+ 'ASC' => 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']);
+ }
+
+}