Commit 9a57c71f authored by generalredneck's avatar generalredneck

Issue #2176035 by generalredneck: Exposed Natural Sorts Don't Work

parent db966898
<?php
class views_natural_sort_handler_sort extends views_handler_sort {
function init(&$view, &$options) {
parent::init($view, $options);
$this->natural_sort = substr($this->options['order'],0,1) == 'N';
}
/**
* Provide a list of options for the default sort form.
* Should be overridden by classes that don't override sort_form
......@@ -12,20 +18,35 @@ class views_natural_sort_handler_sort extends views_handler_sort {
'NDESC' => t('Sort descending naturally'),
);
}
function query() {
switch ($this->options['order']) {
case 'NASC':
case 'NDESC':
// TODO: figure out the values on the same row feature for this case.
$this->ensure_my_table();
$order = substr($this->options['order'], 1);
$vns_alias = $this->query->add_relationship('vns_' . $this->table_alias, $this->natural_sort_join(), $this->table, $this->relationship);
$this->query->add_orderby($vns_alias, 'content', $order);
break;
default:
// If this field isn't being used as a Natural Sort Field, move along
// nothing to see here.
if (!$this->natural_sort) {
parent::query();
return;
}
// If someone has submitted the exposed form, lets grab it here
if ($this->options['exposed'] && $this->view->exposed_data['sort_order']) {
$temporder = $this->view->exposed_data['sort_order'];
}
// If we are using this like a normal sort, our info will be here.
else {
$temporder = &$this->options['order'];
}
// Add the Views Natural Sort table for this field.
$vns_alias = 'vns_' . $this->table_alias;
if (empty($this->query->relationships[$vns_alias])) {
$this->ensure_my_table();
$vns_alias = $this->query->add_relationship('vns_' . $this->table_alias, $this->natural_sort_join(), $this->table, $this->relationship);
}
// Sometimes we get the appended N from the sort options. Filter it out here.
$order = substr($temporder, 0, 1) == 'N' ? substr($temporder, 1) : $temporder;
$this->query->add_orderby($vns_alias, 'content', $order);
}
function natural_sort_join() {
$join = new views_join();
$table_data = views_fetch_data($this->table);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment