function content_handler_field_multiple::pre_render in Content Construction Kit (CCK) 6.3
Same name and namespace in other branches
- 6.2 includes/views/handlers/content_handler_field_multiple.inc \content_handler_field_multiple::pre_render()
File
- includes/
views/ handlers/ content_handler_field_multiple.inc, line 129 - An extended subclass for field handling that adds multiple field grouping.
Class
- content_handler_field_multiple
- @file An extended subclass for field handling that adds multiple field grouping.
Code
function pre_render($values) {
// If there are no values to render (displaying a summary, or query returned no results),
// or if this is not a grouped field, do nothing specific.
if (isset($this->view->build_info['summary']) || empty($values) || !$this->defer_query) {
return parent::pre_render($values);
}
$field = $this->content_field;
$db_info = content_database_info($field);
$options = $this->options;
// Build the list of vids to retrieve.
// TODO: try fetching from cache_content first ??
$vids = array();
$this->field_values = array();
foreach ($values as $result) {
if (isset($result->{$this->field_alias})) {
$vids[] = $result->{$this->field_alias};
}
}
// It may happend that the multiple values field is related to a non
// required relation for which no node data related to the field being
// processed here is available.
if (empty($vids)) {
return parent::pre_render($values);
}
// List columns to retrieve.
$alias = content_views_tablename($field);
// Prefix aliases with '_' to avoid clashing with field columns names.
$query_columns = array(
'vid AS _vid',
"delta as _delta",
// nid is needed to generate the links for 'link to node' option.
'nid AS _nid',
);
// The actual field columns.
foreach ($db_info['columns'] as $column => $attributes) {
$query_columns[] = "{$attributes['column']} AS {$column}";
}
$query = 'SELECT ' . implode(', ', $query_columns) . ' FROM {' . $db_info['table'] . "}" . " WHERE vid IN (" . implode(',', $vids) . ')' . " ORDER BY _nid ASC, _delta " . ($options['multiple']['multiple_reversed'] ? 'DESC' : 'ASC');
$result = db_query($query);
while ($item = db_fetch_array($result)) {
// Clean up the $item from vid and delta. We keep nid for now.
$vid = $item['_vid'];
unset($item['_vid']);
$delta = !empty($item['_delta']) ? $item['_delta'] : 0;
$item['#delta'] = $item['_delta'];
unset($item['_delta']);
$this->field_values[$vid][$delta] = $item;
}
}