function sheetnode_handler_field_named_range::render in Sheetnode 6
Same name and namespace in other branches
- 7.2 views/sheetnode_handler_field_named_range.inc \sheetnode_handler_field_named_range::render()
- 7 views/sheetnode_handler_field_named_range.inc \sheetnode_handler_field_named_range::render()
File
- views/
sheetnode_handler_field_named_range.inc, line 33
Class
Code
function render($values) {
require_once drupal_get_path('module', 'sheetnode') . '/socialcalc.inc';
$sheet = $values->{$this->field_alias};
if (empty($sheet)) {
return NULL;
}
$sc = socialcalc_parse_sheet($sheet);
if (!empty($sc['names'])) {
foreach ($sc['names'] as $name => $info) {
if (strcasecmp($name, $this->options['named_range']) == 0) {
$reference = $info['definition'];
// Is it a literal value?
if (substr($reference, 0, 1) == '=') {
return substr($reference, 1);
}
else {
if (strpos($reference, ':') === FALSE) {
return isset($sc['cells'][$reference]) ? $sc['cells'][$reference]['datavalue'] : NULL;
}
else {
$range = preg_split('/:/', $reference, 2);
$start = socialcalc_coord_to_cr($range[0]);
$end = socialcalc_coord_to_cr(isset($range[1]) ? $range[1] : $range[0]);
if (empty($end[0])) {
$end[0] = $sc['attribs']['lastcol'];
}
if (empty($end[1])) {
$end[1] = $sc['attribs']['lastrow'];
}
// Build the range of values.
$range = array();
for ($r = $start[1]; $r <= $end[1]; $r++) {
for ($c = $start[0]; $c <= $end[0]; $c++) {
$coord = socialcalc_cr_to_coord($c, $r);
$range[$coord] = !empty($sc['cells'][$coord]['datavalue']) ? $sc['cells'][$coord]['datavalue'] : NULL;
}
}
return theme('sheetnode_range', $range, $this->options['labels']);
}
}
}
}
}
return '';
}