summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorilyin.eugenegmail.com2013-01-18 12:53:20 (GMT)
committer Andrei Mateescu2013-01-18 12:53:42 (GMT)
commit6dc82fa1ee00cc74f4454ba15a8c10024076b239 (patch)
treedd93097ef9dfb35167d1267cca395b63f0e6b519
parent70c0602854643f3f488a20e8f9a88942b07d14fe (diff)
Issue #1881956 by eugene.ilyin: Added a Views sort handler which allows combining the nodequeue position with another (random) parameter.
-rw-r--r--includes/views/nodequeue.views.inc21
-rw-r--r--includes/views/nodequeue_handler_sort_by_position_and_other.inc33
-rw-r--r--nodequeue.info1
3 files changed, 55 insertions, 0 deletions
diff --git a/includes/views/nodequeue.views.inc b/includes/views/nodequeue.views.inc
index 14d9043..0b32f6b 100644
--- a/includes/views/nodequeue.views.inc
+++ b/includes/views/nodequeue.views.inc
@@ -47,6 +47,27 @@ function nodequeue_views_data() {
),
);
+ // Nodequeue position and other.
+ $data['nodequeue_nodes']['position_and_other'] = array(
+ 'title' => t('Position in nodequeue and other parameter'),
+ 'help' => t("Allows combining the nodequeue position with another (random)
+ parameter (created date for example). This handler is useful only if the
+ nodequeue relationship is NOT required."),
+ 'field' => array(
+ 'handler' => 'views_handler_field_numeric',
+ 'click sortable' => TRUE,
+ ),
+ 'sort' => array(
+ 'handler' => 'nodequeue_handler_sort_by_position_and_other',
+ ),
+ 'filter' => array(
+ 'handler' => 'views_handler_filter_numeric',
+ ),
+ 'argument' => array(
+ 'handler' => 'views_handler_argument_numeric',
+ ),
+ );
+
// timestamp
$data['nodequeue_nodes']['timestamp'] = array(
'title' => t('Added date'),
diff --git a/includes/views/nodequeue_handler_sort_by_position_and_other.inc b/includes/views/nodequeue_handler_sort_by_position_and_other.inc
new file mode 100644
index 0000000..68ad6aa
--- /dev/null
+++ b/includes/views/nodequeue_handler_sort_by_position_and_other.inc
@@ -0,0 +1,33 @@
+<?php
+
+/**
+ * @file
+ * Views handler for sorting nodes by position in nodequeue and some other
+ * parameter.
+ */
+
+/**
+ * Allows combining the nodequeue position with another (random) parameter
+ * (created date for example). This handler is useful only if the nodequeue
+ * relationship is NOT required.
+ */
+class nodequeue_handler_sort_by_position_and_other extends views_handler_sort {
+
+ function query() {
+ $table = $this->ensure_my_table();
+
+ $field = 'position';
+ $as = $table . '_' . $field;
+
+ if ($field) {
+ $this->query->add_field($table, $field, $as);
+ }
+
+ // If we sort ASC items with NULL should be last, so set 99999999,
+ // if DESC set 0.
+ $order = strtoupper($this->options['order']);
+ $stub = ($order == 'DESC') ? '0' : '999999999';
+
+ $this->query->orderby[] = array('field' => "IFNULL($as, $stub) ", 'direction' => $order);
+ }
+}
diff --git a/nodequeue.info b/nodequeue.info
index 16da04c..c2599ce 100644
--- a/nodequeue.info
+++ b/nodequeue.info
@@ -16,3 +16,4 @@ files[] = includes/views/nodequeue_handler_field_links.inc
files[] = includes/views/nodequeue_handler_field_queue_tab.inc
files[] = includes/views/nodequeue_handler_filter_in_queue.inc
files[] = includes/views/nodequeue_handler_relationship_nodequeue.inc
+files[] = includes/views/nodequeue_handler_sort_by_position_and_other.inc