// Add all the tables to the query via joins. We assume all LEFT joins.
foreach ($this->tableQueue
as $table) { if (is_object($table['join'
])) { $table['join'
]->
buildJoin($query,
$table,
$this);
} } // Assemble the groupby clause, if any.
$this->hasAggregate = FALSE;
$non_aggregates =
$this->
getNonAggregates();
if (count($this->having
)) { $this->hasAggregate = TRUE;
} elseif (!
$this->hasAggregate
) { // Allow 'GROUP BY' even no aggregation function has been set.
$this->hasAggregate =
$this->view->display_handler->
getOption('group_by'
);
} $groupby =
[];
if ($this->hasAggregate
&& (!
empty($this->groupby
) || !
empty($non_aggregates))) { $groupby =
array_unique(array_merge($this->groupby,
$non_aggregates));
}