function _sna_blocks_resultset in Simple Node Archive Blocks 7.2
Same name and namespace in other branches
- 6 sna_blocks.module \_sna_blocks_resultset()
- 7 sna_blocks.module \_sna_blocks_resultset()
Format views results to add year, month and count.
Parameters
array $results: Array contain views result.
string $field_name: string contain field name.
Return value
array An associate arrry.
1 call to _sna_blocks_resultset()
- _sna_blocks_preprocess_sna_blocks in theme/
sna_blocks.theme.inc - @file The theme system, which controls the output of simple node archive.
File
- theme/
sna_blocks.theme.inc, line 71 - The theme system, which controls the output of simple node archive.
Code
function _sna_blocks_resultset($results, $field_name) {
$archive = array();
$field_query = 'node_created';
// Adding year and month field.
foreach ($results as $row) {
if ($field_name != 'node_created') {
$field_query = 'field_' . $field_name;
// Even if the field is multiple type it will accpet only first delta.
if (!empty($row->{$field_query}) && isset($row->{$field_query}[0]['raw']['value'])) {
// Check field is timestamp
// If not convert string date to unix timestamp.
$date_timestamp = $row->{$field_query}[0]['raw']['value'];
if (!(is_numeric($date_timestamp) && (int) $date_timestamp == $date_timestamp)) {
$date_timestamp = strtotime($row->{$field_query}[0]['raw']['value']);
}
}
else {
// If field is empty don't include.
continue;
}
}
else {
$date_timestamp = $row->{$field_query};
}
$archive[date('Y', $date_timestamp)][date('F', $date_timestamp)][$row->nid] = $row->node_title;
}
return $archive;
}