Commit 9645668a authored by merlinofchaos's avatar merlinofchaos
Browse files

#119742: Improved handling of DISTINCT; allow DISTINCT to not kill summaries.

parent b19859a3
......@@ -130,6 +130,7 @@ Views --dev
o #102716: Reduced the number of JOINs for taxonomy hierarchy queries
o #103649: Documentation fix fix for date granularity
o #115519: Restrict width of select items in UI.
o #119742: Improved handling of DISTINCT; allow DISTINCT to not kill summaries.
New features:
o #105620: (Attempt 2) allow modules to alter views tables + arguments
......
......@@ -264,6 +264,7 @@ function _views_build_summary(&$query, $argtype, $option, $self_sort) {
$query->add_field("count($primary_field)", '', 'num_nodes');
$query->add_groupby($fieldinfo['field']);
$query->set_count_field("DISTINCT($fieldinfo[field])");
if ($self_sort) {
$arginfo[$argtype]['handler']('sort', $query, $self_sort);
}
......@@ -331,13 +332,12 @@ class _views_query {
/*
* Set the base field to be distinct.
*/
function set_distinct() {
if (count($this->fields) && substr($this->fields[0], 0, 8) != 'DISTINCT') {
$field = $this->fields[0];
$this->fields[0] = "DISTINCT($field)";
$this->count_field = "DISTINCT($field)";
function set_distinct($value = TRUE) {
if (!($this->no_distinct && $value)) {
$this->distinct = $value;
}
}
/*
* Remove all fields that may've been added; primarily used for summary
* mode where we're changing the query because we didn't get data we needed.
......@@ -561,6 +561,15 @@ class _views_query {
function query($getcount = false) {
$table_data = _views_get_tables();
// Set distinct
if (!$this->no_distinct && $this->distinct && count($this->fields)) {
$field = $this->fields[0];
$this->fields[0] = "DISTINCT($field)";
$this->count_field = "DISTINCT($this->count_field)";
//this is only needed once
$this->no_distinct = TRUE;
}
// Add all the tables to the query via joins. We assume all LEFT joins.
foreach ($this->tablequeue as $tinfo) {
$table = $tinfo['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