Commit e6368a2a authored by generalredneck's avatar generalredneck

[#1614234] Added field sort handler. Removed predefined joins and added on the fly joins.

parent b45d832f
......@@ -16,13 +16,59 @@ class views_natural_sort_handler_sort extends views_handler_sort {
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->ensure_table('views_natural_sort');
$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:
parent::query();
}
}
function natural_sort_join() {
$join = new views_join();
$table_data = views_fetch_data($this->table);
$join->definition = array(
'table' => 'views_natural_sort',
'field' => 'eid',
'left_field' => $table_data['table']['base']['field'],
'left_table' => $this->table,
'extra' => array(
array(
'field' => 'entity_type',
'value' => $table_data['table']['entity type'],
),
array(
'field' => 'field',
'value' => $this->real_field,
),
)
);
$join->construct();
$join->adjusted = TRUE;
return $join;
}
function admin_summary() {
if (!empty($this->options['exposed'])) {
return t('Exposed');
}
switch ($this->options['order']) {
case 'ASC':
case 'asc':
default:
return t('asc');
break;
case 'DESC':
case 'desc':
return t('desc');
break;
case 'NASC':
return t('natural asc');
break;
case 'NDESC':
return t('natural asc');
break;
}
}
}
<?php
class views_natural_sort_handler_sort_text_field extends views_natural_sort_handler_sort {
function natural_sort_join() {
$join = new views_join();
$other_join = $this->get_join();
$table_data = views_fetch_data($other_join->definition['left_table']);
$join->definition = array(
'table' => 'views_natural_sort',
'field' => 'eid',
'left_field' => 'entity_id',
'left_table' => $this->table_alias,
'extra' => array(
array(
'field' => 'entity_type',
'value' => $table_data['table']['entity type'],
),
array(
'field' => 'field',
'value' => $this->real_field,
),
)
);
$join->construct();
$join->adjusted = TRUE;
return $join;
}
}
......@@ -6,3 +6,4 @@ core = 7.x
; Views handlers
files[] = handlers/views_natural_sort_handler_sort.inc
files[] = handlers/views_natural_sort_handler_sort_text_field.inc
......@@ -7,26 +7,6 @@
* is most of the code.
*/
/**
* Implementation of hook_views_data().
*/
function views_natural_sort_views_data() {
$data['views_natural_sort']['table']['join'] = array(
'node' => array(
'left_field' => 'nid',
'field' => 'eid',
'extra' => array(
array(
'field' => 'entity_type',
'value' => 'node',
)
)
),
);
return $data;
}
function views_natural_sort_views_data_alter(&$data) {
// TODO: Add a field and argument handler to support grouping.
$data['node']['title']['sort']['handler'] = 'views_natural_sort_handler_sort';
......@@ -52,21 +32,7 @@ function views_natural_sort_field_views_data_alter(&$data, $field, $module) {
$current_view_field_column = $field['field_name'] . '_' . $column_name;
$view_fields[] = $current_view_field_column;
$data[$field_table][$current_view_field_column]['sort']['handler'] = 'views_natural_sort_handler_sort';
$data[$field_table][$current_view_field_column]['sort']['handler'] = 'views_natural_sort_handler_sort_text_field';
}
$data['views_natural_sort']['table']['join'][$field_table] = array(
'left_field' => 'entity_id',
'field' => 'eid',
'extra' => array(
array(
'field' => 'entity_type',
'value' => $entity_type,
),
array(
'field' => 'field',
'value' => $view_fields,
),
),
);
}
}
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