Skip to content

Commit

Permalink
Fixed issue #19277: When export to CSV - multiple PHP error with debu…
Browse files Browse the repository at this point in the history
…g and php8.1 (#3651)
  • Loading branch information
Shnoulle committed Dec 11, 2023
1 parent 264e4cd commit 2a7d425
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
5 changes: 4 additions & 1 deletion application/helpers/admin/export/CsvWriter.php
Expand Up @@ -96,11 +96,14 @@ public function close()
/**
* Returns the value with all necessary escaping needed to place it into a CSV string.
*
* @param string $value
* @param string|null $value
* @return string
*/
protected function csvEscape($value)
{
if (is_null($value)) {
return '';
}
$sString = preg_replace(array('~\R~u'), array("\n"), $value);
return '"' . str_replace('"', '""', $sString) . '"';
}
Expand Down
16 changes: 10 additions & 6 deletions application/helpers/admin/export/SurveyObj.php
Expand Up @@ -77,18 +77,19 @@ class SurveyObj
* but could also be a comment entered by a participant.
*
* @param string $fieldName
* @param string $answerCode
* @param string|null $answerCode
* @param Translator $translator
* @param string $sLanguageCode
* @return string (or false)
* @return string
*/
public function getFullAnswer($fieldName, $answerCode, Translator $translator, $sLanguageCode)
{
$fullAnswer = null;
$fullAnswer = '';
$fieldType = $this->fieldMap[$fieldName]['type'];
$question = $this->fieldMap[$fieldName];
$questionId = $question['qid'];
$answer = null;
$answer = '';
$answerCode = strval($answerCode);
if ($questionId) {
$answers = $this->getAnswers($questionId);
if (isset($answers[$answerCode])) {
Expand Down Expand Up @@ -129,7 +130,7 @@ public function getFullAnswer($fieldName, $answerCode, Translator $translator, $
if (array_key_exists($answerCode, $answers)) {
$fullAnswer = $answers[$answerCode];
} else {
$fullAnswer = null;
$fullAnswer = '';
}
break;

Expand Down Expand Up @@ -252,11 +253,14 @@ public function getFullAnswer($fieldName, $answerCode, Translator $translator, $
* Returns the short answer for the question.
*
* @param string $sFieldName
* @param string $sValue
* @param string|null $sValue
* @return string
*/
public function getShortAnswer($sFieldName, $sValue)
{
if (is_null($sValue)) {
return "";
}
$aQuestion = $this->fieldMap[$sFieldName];
$sFieldType = $aQuestion['type'];

Expand Down
2 changes: 1 addition & 1 deletion application/helpers/admin/exportresults_helper.php
Expand Up @@ -105,7 +105,7 @@ function exportResponses($iSurveyId, $sLanguageCode, $sExportPlugin, FormattingO
$writer->init($survey, $sLanguageCode, $oOptions);

$countResponsesCommand = $surveyDao->loadSurveyResults($survey, $oOptions->responseMinRecord, $oOptions->responseMaxRecord, $sFilter, $oOptions->responseCompletionState, $oOptions->selectedColumns, $oOptions->aResponses);
$countResponsesCommand->order = null;
$countResponsesCommand->order = false;
$countResponsesCommand->select('count(*)');
$responseCount = $countResponsesCommand->queryScalar();
$maxRows = 100;
Expand Down

0 comments on commit 2a7d425

Please sign in to comment.