Skip to content

Commit

Permalink
Export delimiter setting
Browse files Browse the repository at this point in the history
  • Loading branch information
Hubert Prein committed Dec 22, 2015
1 parent 40aa9eb commit 2b58118
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 5 deletions.
10 changes: 9 additions & 1 deletion AmFormsPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,15 @@ public function getName()
*/
public function getVersion()
{
return '1.2.10';
return '1.3.0';
}

/**
* @return string
*/
public function getSchemaVersion()
{
return '1.3.0';
}

/**
Expand Down
4 changes: 4 additions & 0 deletions config.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
),
),
'export' => array(
array(
'name' => 'Delimiter',
'value' => ';',
),
array(
'name' => 'Export rows per set',
'value' => 50,
Expand Down
25 changes: 25 additions & 0 deletions migrations/m151222_111300_amforms_addDelimiterSetting.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Craft;

/**
* The class name is the UTC timestamp in the format of mYYMMDD_HHMMSS_pluginHandle_migrationName.
*/
class m151222_111300_amforms_addDelimiterSetting extends BaseMigration
{
/**
* Any migration code in here is wrapped inside of a transaction.
*
* @return bool
*/
public function safeUp()
{
$settings = array(
array(
'name' => 'Delimiter',
'value' => ';',
),
);
return craft()->amForms_install->installSettings($settings, AmFormsModel::SettingExport);
}
}
14 changes: 10 additions & 4 deletions services/AmForms_ExportsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@
*/
class AmForms_ExportsService extends BaseApplicationComponent
{
private $_delimiter;
private $_exportFiles = array();
private $_exportFields = array();
private $_exportColumns = array();
private $_exportSpaceCounter = array();

public function __construct()
{
$this->_delimiter = craft()->amForms_settings->getSettingsValueByHandleAndType('delimiter', AmFormsModel::SettingExport, ';');
}

/**
* Get all exports.
*
Expand Down Expand Up @@ -360,7 +366,7 @@ public function runExport(AmForms_ExportModel $export, $limit = null, $offset =
$this->_exportFiles['manual'] = fopen('php://output', 'w');

// Create columns
fputcsv($this->_exportFiles['manual'], $this->_getExportColumns($export, $form), ';');
fputcsv($this->_exportFiles['manual'], $this->_getExportColumns($export, $form), $this->_delimiter);
}
else {
$this->_exportFiles[$export->id] = fopen($export->file, 'a');
Expand Down Expand Up @@ -540,7 +546,7 @@ private function _createExportFile(AmForms_ExportModel $export, AmForms_FormMode
if (! $export->submissions) {
// Add columns to export file
$exportFile = fopen($file, 'w');
fputcsv($exportFile, $this->_getExportColumns($export, $form), ';');
fputcsv($exportFile, $this->_getExportColumns($export, $form), $this->_delimiter);
fclose($exportFile);
}

Expand Down Expand Up @@ -805,7 +811,7 @@ private function _exportSubmission(AmForms_ExportModel $export, $submission, $re
if ($returnData) {
return $data;
}
fputcsv($this->_exportFiles[ ($export->startRightAway ? 'manual' : $export->id) ], $data, ';');
fputcsv($this->_exportFiles[ ($export->startRightAway ? 'manual' : $export->id) ], $data, $this->_delimiter);

// Add more rows?
if ($hasMoreRows) {
Expand All @@ -824,7 +830,7 @@ private function _exportSubmission(AmForms_ExportModel $export, $submission, $re
}

// Add row to CSV
fputcsv($this->_exportFiles[ ($export->startRightAway ? 'manual' : $export->id) ], $data, ';');
fputcsv($this->_exportFiles[ ($export->startRightAway ? 'manual' : $export->id) ], $data, $this->_delimiter);
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions templates/settings/exports.twig
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
{% set selectedTab = 'exports' %}

{% block fields %}
{{ forms.textField({
label: exports.delimiter.name|t,
id: exports.delimiter.handle,
name: exports.delimiter.handle,
value: exports.delimiter.value,
instructions: 'Which character should be used as delimiter?'|t
}) }}
{{ forms.textField({
label: exports.exportRowsPerSet.name|t,
id: exports.exportRowsPerSet.handle,
Expand Down
2 changes: 2 additions & 0 deletions translations/nl.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
'Date' => 'Datum',
'Date created' => 'Aanmaakdatum',
'Date updated' => 'Wijzigingsdatum',
'Delimiter' => 'Scheidingsteken',
'Design your form' => 'Stel uw formulier samen',
'Don’t include the field and block names in the column name.' => 'De naam van het veld en de blokken niet opnemen in de kolomnaam.',
'Don’t show' => 'Niet weergeven',
Expand Down Expand Up @@ -183,6 +184,7 @@
'Whether to silently log an error or throw an exception if a form does not exist. By default, it will throw an exception.' => 'Of er stil gefaald en de fout gelogd moet worden als het formulier niet bestaat, of de fout door middel van een exception wordt getoond. Standaard wordt de exception getoond.',
'Whether to email form submissions.' => 'Of formulier inzendingen via e-mail verstuurd moeten worden.',
'Whether to store form submissions.' => 'Of formulier inzendingen opgeslagen moeten worden.',
'Which character should be used as delimiter?' => 'Welk karakter moet worden gebruikt als scheidingsteken?',
'Which fields do you want to export?' => 'Welke velden wilt u exporteren?',
'Which form do you want to export?' => 'Welk formulier wilt u exporteren?',
'Which form do you want to see submissions from?' => 'Van welk formulier wilt u de laatste inzendingen zien?',
Expand Down

0 comments on commit 2b58118

Please sign in to comment.