diff --git a/application/helpers/admin/export/CsvWriter.php b/application/helpers/admin/export/CsvWriter.php index 2fe102d3604..3a53ac47afa 100644 --- a/application/helpers/admin/export/CsvWriter.php +++ b/application/helpers/admin/export/CsvWriter.php @@ -59,12 +59,15 @@ protected function outputRecord($headers, $values, FormattingOptions $oOptions) $this->output .= $sRecord; fwrite($this->file, $this->output); $this->output=''; - } + } } public function close() { + // Output white line at the end, better for R import + echo "\n"; if (!is_null($this->file)) { + fwrite($this->file, "\n"); fclose($this->file); } } diff --git a/application/helpers/admin/export/HtmlWriter.php b/application/helpers/admin/export/HtmlWriter.php index 17e6517218c..321f3b7e9bb 100644 --- a/application/helpers/admin/export/HtmlWriter.php +++ b/application/helpers/admin/export/HtmlWriter.php @@ -90,8 +90,10 @@ protected function outputRecord($headers, $values, FormattingOptions $oOptions) )); foreach ($questions as $question) { - $this->renderQuestion($question, $values[$question['index']], $headers[$question['index']]); - + if (isset($values[$question['index']]) && isset($headers[$question['index']])) + { + $this->renderQuestion($question, $values[$question['index']], $headers[$question['index']]); + } } $this->closeTag(); } diff --git a/application/helpers/admin/export/SurveyDao.php b/application/helpers/admin/export/SurveyDao.php index 5a035b71104..3b80cd565d4 100644 --- a/application/helpers/admin/export/SurveyDao.php +++ b/application/helpers/admin/export/SurveyDao.php @@ -116,14 +116,4 @@ public function loadSurveyResults(SurveyObj $survey, $iMinimum, $iMaximum, $sFil $iOffset = $iMinimum - 1; $survey->responses=$oRecordSet->select($aSelectFields)->order('{{survey_' . $survey->id . '}}.id')->limit($iMaximum - $iOffset, $iOffset)->query(); } - - /** - * Close the resultset - */ - public function close() - { - if ($survey->responses instanceof CDbDataReader) { - $survey->responses->close(); - } - } } \ No newline at end of file diff --git a/application/helpers/admin/export/Translator.php b/application/helpers/admin/export/Translator.php index 3a368d22d49..d81cb8f5dd3 100644 --- a/application/helpers/admin/export/Translator.php +++ b/application/helpers/admin/export/Translator.php @@ -4,59 +4,11 @@ class Translator //An associative array: key = language code, value = translation library private $translations = array(); - //The following array stores field names that require pulling a value from the - //internationalization layer. => - private $headerTranslationKeys = array( - 'id' => 'id', - 'lastname' => 'Last name', - 'firstname' => 'First name', - 'email' => 'Email address', - 'token' => 'Token', - 'datestamp' => 'Date last action', - 'startdate' => 'Date started', - 'submitdate' => 'Completed', - 'ipaddr' => 'IP address', - 'refurl' => 'Referring URL', - 'lastpage' => 'Last page', - 'startlanguage' => 'Start language' - ); - public function translate($key, $sLanguageCode) { return $this->getTranslationLibrary($sLanguageCode)->gT($key); } - /** - * Accepts a fieldName from a survey fieldMap and returns the translated value - * for the fieldName in the survey's base language (if one exists). - * If no translation exists for the provided column/fieldName then - * false is returned. - * - * To add any columns/fieldNames to be processed by this function, simply add the - * column/fieldName to the $headerTranslationKeys associative array. - * - * This provides a mechanism for determining of a column in a survey's data table - * needs to be translated through the translation mechanism, or if its an actual - * survey data column. - * - * @param string $column - * @param string $sLanguageCode - * @return string - */ - public function translateHeading($column, $sLanguageCode) - { - $key = $this->getHeaderTranslationKey($column); - //echo "Column: $column, Key: $key".PHP_EOL; - if ($key) - { - return $this->translate($key, $sLanguageCode); - } - else - { - return false; - } - } - protected function getTranslationLibrary($sLanguageCode) { $library = null; diff --git a/application/helpers/admin/export/Writer.php b/application/helpers/admin/export/Writer.php index 412ac549900..77a2d9ed3da 100644 --- a/application/helpers/admin/export/Writer.php +++ b/application/helpers/admin/export/Writer.php @@ -17,12 +17,6 @@ protected function translate($key, $sLanguageCode) return $this->translator->translate($key, $sLanguageCode); } - protected function translateHeading($column, $sLanguageCode) - { - if (substr($column,0,10)=='attribute_') return $column; - return $this->translator->translateHeading($column, $sLanguageCode); - } - /** * An initialization method that implementing classes can override to gain access * to any information about the survey, language, or formatting options they @@ -405,29 +399,19 @@ final public function write(SurveyObj $survey, $sLanguageCode, FormattingOptions foreach ($oOptions->selectedColumns as $column) { - //Output the header. - $value = $this->translateHeading($column, $sLanguageCode); - if($value===false) + //Survey question field, $column value is a field name from the getFieldMap function. + switch ($oOptions->headingFormat) { - //This branch may be reached erroneously if columns are added to the LimeSurvey product - //but are not updated in the Writer->headerTranslationKeys array. We should trap for this - //condition and do a safeDie. - //FIXME fix the above condition - - //Survey question field, $column value is a field name from the getFieldMap function. - switch ($oOptions->headingFormat) - { - case 'abbreviated': - $value = $this->getAbbreviatedHeading($survey, $column); - break; - case 'full': - $value = $this->getFullHeading($survey, $oOptions, $column); - break; - default: - case 'code': - $value = $this->getCodeHeading($survey, $oOptions, $column); - break; - } + case 'abbreviated': + $value = $this->getAbbreviatedHeading($survey, $column); + break; + case 'full': + $value = $this->getFullHeading($survey, $oOptions, $column); + break; + default: + case 'code': + $value = viewHelper::getFieldCode($survey->fieldMap[$column]); + break; } if ($oOptions->headerSpacesToUnderscores) { diff --git a/application/helpers/admin/exportresults_helper.php b/application/helpers/admin/exportresults_helper.php index aa46f9fdf32..3d3da6b1108 100644 --- a/application/helpers/admin/exportresults_helper.php +++ b/application/helpers/admin/exportresults_helper.php @@ -133,7 +133,11 @@ function exportSurvey($iSurveyId, $sLanguageCode, $sExportPlugin, FormattingOpti $writer->write($survey, $sLanguageCode, $oOptions,true); $result = $writer->close(); - $surveyDao->close(); + + // Close resultset if needed + if ($survey->responses instanceof CDbDataReader) { + $survey->responses->close(); + } if ($oOptions->output=='file') {