aboutsummaryrefslogtreecommitdiff
path: root/apps/csv.php
blob: e1553e68255f7515e2a3fa6ee8038daa96948cd2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
/**
 * Cinisis - Isis db reading tool.
 */

// Import Cinisis Library.
require_once '../index.php';

// Get a db instance.
$isis    = new IsisConnector();
$display = new CinisisDisplayHelper(NULL);

// Test connection.
if ($isis) {
  // Setup format, response header and CSV title.
  $format = $isis->format;
  $display->httpHeader('application/text/x-csv', 'export.csv');
  $display->csvTitles($format);
  $display->csvRow();

  // Format output.
  foreach(new IsisEntryIterator($isis) as $entry => $result) {
    // Filter results.
    array_walk_recursive($result, array($isis, 'removeBracketsCallback'));

    foreach ($format['fields'] as $field) {
      $display->mergeCsvItems($isis->getMainItems($field));

      if (isset($field['subfields']) && is_array($field['subfields'])) {
        foreach ($field['subfields'] as $subfield) {
          $display->mergeCsvItems($isis->getSubfields($field, $subfield));
        }
      }
    }

    $display->csvRow();
  }
}