View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
09209 | Bug reports | Other | public | 2014-09-03 14:37 | 2014-09-15 22:57 |
Reporter | mderoucy | Assigned To | c_schmitz | ||
Priority | normal | Severity | minor | ||
Status | closed | Resolution | fixed | ||
Fixed in Version | 2.05+ | ||||
Summary | 09209: JSON-RPC API : export_responses_by_token | ||||
Description | Hello, Here is a patch to make export_responses_by_token behave as expected : return all the responses belonging to one token.The current implementation only export the first response found in the database. I just copy/paste export_responses in export_responses_by_token and adapt the implementation to filter the data. Please tel me if there is any problem with this patch. Thank you in advance. Regards Maxime de Roucy | ||||
Steps To Reproduce |
| ||||
Tags | No tags attached. | ||||
Attached Files | export_responses_by_token.patch (3,199 bytes)
diff --git a/application/helpers/remotecontrol/remotecontrol_handle.php b/application/helpers/remotecontrol/remotecontrol_handle.php index ee0e50e..0d2beba 100644 --- a/application/helpers/remotecontrol/remotecontrol_handle.php +++ b/application/helpers/remotecontrol/remotecontrol_handle.php @@ -2378,15 +2378,44 @@ class remotecontrol_handle public function export_responses_by_token($sSessionKey, $iSurveyID, $sDocumentType, $sToken, $sLanguageCode=null, $sCompletionStatus='all', $sHeadingType='code', $sResponseType='short', $aFields=null) { if (!$this->_checkSessionKey($sSessionKey)) return array('status' => 'Invalid session key'); + Yii::app()->loadHelper('admin/exportresults'); + if (!tableExists('{{survey_' . $iSurveyID . '}}')) return array('status' => 'No Data, survey table does not exist.'); + if(!$maxId = SurveyDynamic::model($iSurveyID)->getMaxId()) return array('status' => 'No Data, could not get max id.'); + + if (!SurveyDynamic::model($iSurveyID)->findByAttributes(array('token' => $sToken))) return array('status' => 'No Response found for Token'); if (!Permission::model()->hasSurveyPermission($iSurveyID, 'responses', 'export')) return array('status' => 'No permission'); - if (!tableExists('{{survey_' . $iSurveyID . '}}')) return array('status' => 'No Data'); - if(!$oResult = SurveyDynamic::model($iSurveyID)->findByAttributes(array('token' => $sToken))) return array('status' => 'No Response found for Token'); - if ($oResult['id']) - { - return $this->export_responses($sSessionKey, $iSurveyID, $sDocumentType, $sLanguageCode, $sCompletionStatus, $sHeadingType, $sResponseType, $oResult['id'], $oResult['id'], $aFields); + if (is_null($sLanguageCode)) $sLanguageCode=getBaseLanguageFromSurveyID($iSurveyID); + if (is_null($aFields)) $aFields=array_keys(createFieldMap($iSurveyID,'full',true,false,$sLanguageCode)); + if($sDocumentType=='xls'){ + // Cut down to the first 255 fields + $aFields=array_slice($aFields,0,255); } - } + $oFomattingOptions=new FormattingOptions(); + if($iFromResponseID !=null) + $oFomattingOptions->responseMinRecord=$iFromResponseID; + else + $oFomattingOptions->responseMinRecord=1; + + if($iToResponseID !=null) + $oFomattingOptions->responseMaxRecord=$iToResponseID; + else + $oFomattingOptions->responseMaxRecord = $maxId; + + $oFomattingOptions->selectedColumns=$aFields; + $oFomattingOptions->responseCompletionState=$sCompletionStatus; + $oFomattingOptions->headingFormat=$sHeadingType; + $oFomattingOptions->answerFormat=$sResponseType; + $oFomattingOptions->output='file'; + + $oExport=new ExportSurveyResultsService(); + + $sTableName = Yii::app()->db->tablePrefix.'survey_'.$iSurveyID; + + $sTempFile=$oExport->exportSurvey($iSurveyID,$sLanguageCode, $sDocumentType,$oFomattingOptions, "$sTableName.token='$sToken'"); + return new BigFile($sTempFile, true, 'base64'); + + } /** * Tries to login with username and password | ||||
Bug heat | 2 | ||||
Complete LimeSurvey version number (& build) | 726d755847660f2d7768fe7e1a41 | ||||
I will donate to the project if issue is resolved | |||||
Browser | |||||
Database type & version | |||||
Server OS (if known) | |||||
Webserver software & version (if known) | |||||
PHP Version | |||||
Fix committed to master branch: http://bugs.limesurvey.org/plugin.php?page=Source/view&id=14481 |
|
Thank you very much. Please use a pull request on GitHub next time. |
|
2.05+ Build 140915 released |
|
Date Modified | Username | Field | Change |
---|---|---|---|
2014-09-03 14:37 | mderoucy | New Issue | |
2014-09-03 14:37 | mderoucy | File Added: export_responses_by_token.patch | |
2014-09-08 10:50 | DenisChenu | Project | @2@ => Bug reports |
2014-09-08 10:50 | DenisChenu | Category | Import / Export => Other issues |
2014-09-08 10:51 | DenisChenu | Relationship added | related to 09208 |
2014-09-11 13:39 | c_schmitz | Assigned To | => c_schmitz |
2014-09-11 13:39 | c_schmitz | Status | new => assigned |
2014-09-11 13:39 | c_schmitz | Changeset attached | => LimeSurvey master bb06f6b6 |
2014-09-11 13:39 | c_schmitz | Note Added: 30572 | |
2014-09-11 13:39 | c_schmitz | Resolution | open => fixed |
2014-09-11 13:39 | c_schmitz | Note Added: 30573 | |
2014-09-11 13:39 | c_schmitz | Status | assigned => resolved |
2014-09-11 13:39 | c_schmitz | Fixed in Version | => 2.05+ |
2014-09-15 22:57 | c_schmitz | Note Added: 30648 | |
2014-09-15 22:57 | c_schmitz | Status | resolved => closed |