function views_plugin_query_default::compile_fields
Same name in other branches
- 7.x-3.x plugins/views_plugin_query_default.inc \views_plugin_query_default::compile_fields()
1 call to views_plugin_query_default::compile_fields()
- views_plugin_query_default::query in plugins/
views_plugin_query_default.inc - Generate a query and a countquery from all of the information supplied to the object.
File
-
plugins/
views_plugin_query_default.inc, line 958
Class
- views_plugin_query_default
- Object used to create a SELECT query.
Code
function compile_fields($fields_array) {
$fields = $distinct = array();
$non_aggregates = array();
foreach ($fields_array as $field) {
$string = '';
if (!empty($field['table'])) {
$string .= $field['table'] . '.';
}
$string .= $field['field'];
// store for use with non-aggregates below
$fieldname = !empty($field['alias']) ? $field['alias'] : $string;
if (!empty($field['distinct'])) {
$string = "DISTINCT({$string})";
}
if (!empty($field['count'])) {
// Retained for compatibility
$field['function'] = 'count';
}
if (!empty($field['function'])) {
$info = $this->get_aggregation_info();
if (!empty($info[$field['function']]['method']) && function_exists($info[$field['function']]['method'])) {
$string = $info[$field['function']]['method']($field['function'], $string);
}
$this->has_aggregate = TRUE;
}
elseif ($this->distinct && !in_array($fieldname, $this->groupby)) {
$string = $GLOBALS['db_type'] == 'pgsql' ? "FIRST({$string})" : $string;
}
elseif (empty($field['aggregate'])) {
$non_aggregates[] = $fieldname;
}
if ($field['alias']) {
$string .= " AS {$field['alias']}";
}
if (!empty($field['distinct']) && empty($field['function'])) {
$distinct[] = $string;
}
else {
$fields[] = $string;
}
if (!empty($get_count_optimized)) {
// We only want the first field in this case.
break;
}
}
return array(
$distinct,
$fields,
$non_aggregates,
);
}