Skip to content

Commit

Permalink
Merge pull request #30 from hananils/integration
Browse files Browse the repository at this point in the history
Custom CSV Styles
  • Loading branch information
nitriques committed Oct 22, 2015
2 parents b36489f + c548c18 commit 8349240
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
2 changes: 1 addition & 1 deletion data-sources/datasource.remote.php
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ public function execute(array &$param_pool = null)
if (empty($this->_env)) {
$this->_env['env']['pool'] = array(
'root' => URL,
'workspace' => WORKSPACE
'workspace' => URL . '/workspace'
);
}

Expand Down
14 changes: 14 additions & 0 deletions extension.driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,18 @@ public function addCachingOpportunity($context)

$context['wrapper']->appendChild($label);
}

public function install()
{
Symphony::Configuration()->set('csv-delimiter', ',', 'remote_datasource');
Symphony::Configuration()->set('csv-enclosure', '"', 'remote_datasource');
Symphony::Configuration()->set('csv-escape', '\\', 'remote_datasource');
Symphony::Configuration()->write();
}

public function uninstall()
{
Symphony::Configuration()->remove('remote_datasource');
}

}
4 changes: 4 additions & 0 deletions extension.meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
</author>
</authors>
<releases>
<release version="2.2.0" date="2015-06-24" min="2.4" max="2.6.x">
- Make CSV style configurable.
- Fix `{$workspace}` path
</release>
<release version="2.1.3" date="2015-05-13" min="2.4" max="2.6.x">
- Fix a bug with late static binding on PHP 5.3.
</release>
Expand Down
12 changes: 10 additions & 2 deletions lib/class.csv.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ public static function convertToXML($data)
{
$headers = array();

// Get CSV settings
$settings = array(
'csv-delimiter' => ',',
'csv-enclosure' => '"',
'csv-escape' => '\\'
);
$settings = array_merge($settings, (array) Symphony::Configuration()->get('remote_datasource'));

// DOMDocument
$doc = new DOMDocument('1.0', 'utf-8');
$doc->formatOutput = true;
Expand All @@ -46,14 +54,14 @@ public static function convertToXML($data)
}

if ($i == 0) {
foreach (str_getcsv($row) as $i => $head) {
foreach (str_getcsv($row, $settings['csv-delimiter'], $settings['csv-enclosure'], $settings['csv-escape']) as $i => $head) {
if (class_exists('Lang')) {
$head = Lang::createHandle($head);
}
$headers[] = $head;
}
} else {
self::addRow($doc, $root, str_getcsv($row), $headers);
self::addRow($doc, $root, str_getcsv($row, $settings['csv-delimiter'], $settings['csv-enclosure'], $settings['csv-escape']), $headers);
}
}

Expand Down

0 comments on commit 8349240

Please sign in to comment.