aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/csv.php33
1 files changed, 25 insertions, 8 deletions
diff --git a/tests/csv.php b/tests/csv.php
index c48118b..c08b18f 100644
--- a/tests/csv.php
+++ b/tests/csv.php
@@ -31,6 +31,28 @@ function filter(&$field = NULL) {
$field = str_replace('>', '', $field);
}
+/**
+ * Merge fields in a single cel.
+ *
+ * @param $data
+ * Array with field data.
+ *
+ * @param $field
+ * Field name.
+ *
+ * @return
+ * Cel with merged fields.
+ */
+function merge_fields($data, $field) {
+ $cel = '';
+ $sep = (count($data) > 1) ? '; ': '';
+ foreach ($data as $subkey => $subvalue) {
+ $cel = $cel . $data[$subkey][$field] . $sep;
+ }
+
+ return $cel;
+}
+
// Import Cinisis Library.
require_once '../index.php';
@@ -44,12 +66,10 @@ if ($isis->db) {
$format = $isis->db->format;
// Prepare output.
- /*
header("Content-type: application/text/x-csv");
header("Content-Disposition: attachment; filename=export.csv");
header("Pragma: no-cache");
header("Expires: 0");
- */
// Format fields.
foreach ($format['fields'] as $field) {
@@ -65,7 +85,7 @@ if ($isis->db) {
echo "\n";
// Format output.
- for ($n=1; $n <= 30; $n++) {
+ for ($n=1; $n <= $rows; $n++) {
$result = $isis->db->read($n);
if ($result) {
@@ -81,12 +101,9 @@ if ($isis->db) {
}
if (is_array($field['subfields'])) {
foreach ($field['subfields'] as $key => $value) {
+ // Deals with subfield repetition.
if (isset($result[$field['name']][0][$value])) {
- $cel = '';
- foreach ($result[$field['name']] as $subkey => $subvalue) {
- $cel = $cel . $result[$field['name']][$subkey][$value] .'; ';
- }
- echo csv($cel);
+ echo csv(merge_fields($result[$field['name']], $value));
}
else {
echo csv($result[$field['name']][$value]);