function matrix_export in Matrix field 6.2
Menu callback for the export link on matrix fields
Parameters
string $nid the Node ID:
string $field_name the name of the field on the node:
Return value
csv file with download headers
1 string reference to 'matrix_export'
- matrix_menu in ./
matrix.module - Implementation of hook_menu().
File
- ./
matrix.module, line 1210 - Defines simple matrix field types.
Code
function matrix_export($nid, $field_name) {
if (is_numeric($nid)) {
$node = node_load($nid);
$field = $node->{$field_name};
foreach ($field['cols_header'] as $index => $value) {
$field['cols_header'][$index] = trim($value);
}
array_unshift($field['cols_header'], '');
$output .= '"' . implode('", "', $field['cols_header']) . "\"\n";
$i = 0;
foreach ($field['data'] as $row) {
$output .= '"' . trim($field['rows_header'][$i]) . '", "' . implode('", "', $row) . "\"\n";
$i++;
}
header('Content-type: text/csv');
header('Content-Disposition: attachment; filename="' . $nid . '-' . $field_name . '.csv"');
echo $output;
die;
}
}