public function views_aggregator_plugin_style_table::pre_render in Views Aggregator Plus 7
Overrides pre_render().
Note that this class being a views_plugin, rather than a views_handler, it does not have a post_execute() function.
This function applies to the currently visible page only. If paging is enabled for this display view->result may only contain part of the entire result set.
Parameters
array $results: The results returned from the database query.
Overrides views_plugin_style::pre_render
File
Class
- views_aggregator_plugin_style_table
- Style plugin to render each item as a row in a table.
Code
public function pre_render($results) {
if (isset($this->view->is_temp_views_aggregator)) {
return;
}
parent::pre_render($results);
if (empty($this->view->result)) {
return;
}
$functions = $this
->collect_aggregation_functions();
$show_global_totals_with_pager = empty($this->options['column_aggregation']['totals_per_page']) && !empty($this->view->total_rows);
if ($show_global_totals_with_pager) {
$view_without_pager = $this
->execute_view_without_pager($this->view, $this->view->current_display);
// First apply the row filters (if any), then aggregate the columns.
$view_without_pager->style_plugin
->apply_row_filters();
// Only interested in column aggregation, so only 'column' group needed.
$column_group = array(
'column' => array(),
);
foreach ($view_without_pager->result as $num => $row) {
$column_group['column'][$num] = $row;
}
$totals = $view_without_pager->style_plugin
->execute_aggregation_functions($column_group, $functions);
$this->view->totals = $this
->set_totals_row($totals);
}
// Because we are going to need the View results AFTER token replacement,
// we render the result set here. This is NOT duplication of CPU time,
// because render_fields(), if called for a second time, will do nothing
// when $this->rendered_fields has been populated already.
// render_fields() will puts currency signs in front of moneys, embeds node
// and taxonomy term references in hyperlinks etc.
$this
->render_fields($results);
// Apply the row filters first, then aggregate the groups.
$this
->apply_row_filters();
$groups = $this
->aggregate_groups();
$values = $this
->execute_aggregation_functions($groups, $functions);
unset($groups['column']);
// Write group aggregation results into the View results.
$this
->set_aggregated_group_values($groups, $values);
if (empty($this->view->totals)) {
// If not already set above, write the column aggregation result row on
// the View object. This row will be rendered via
// template_preprocess_views_aggregator_results_table().
$this->view->totals = $this
->set_totals_row($values);
}
// With the aggregation functions now complete, destroy rows not part of the
// aggregation.
$this
->compress_grouped_results($groups);
// Sort the table based on the selected sort column, i.e. $this->active.
if (isset($this->active)) {
// To aid in sorting, add the row's index to each row object.
foreach ($this->view->result as $num => $row) {
$this->view->result[$num]->num = $num;
}
uasort($this->view->result, array(
$this,
'compare_result_rows',
));
}
}