View Issue Details

IDProjectCategoryView StatusLast Update
09209Bug reportsOther issuespublic2014-09-15 22:57
Reportermderoucy Assigned Toc_schmitz  
PrioritynormalSeverityminor 
Status closedResolutionfixed 
Fixed in Version2.05+ 
Summary09209: 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
  • create a survey with 2 questions
  • reply the survey "incompletely", several time
  • reply one time completely
  • activate the JSON-RPC API
  • use the export_responses_by_token in a test to get 'incomplete' answers
    → only one answer is reported
  • use the export_responses_by_token in a test to get the 'complete' answer
    → no answer is reported
TagsNo tags attached.
Complete LimeSurvey version number (& build)726d755847660f2d7768fe7e1a41
I will donate to the project if issue is resolved
Browser
Database & DB-Version
Server OS (if known)
Webserver software & version (if known)
PHP Version

Relationships

related to 09208 closedc_schmitz function export_responses_by_token sometimes returns no data (empty Response) instead of completed surveyresponse 

Activities

mderoucy

mderoucy

2014-09-03 14:37

reporter  

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
c_schmitz

c_schmitz

2014-09-11 13:39

administrator   ~30572

Fix committed to master branch: http://bugs.limesurvey.org/plugin.php?page=Source/view&id=14481

c_schmitz

c_schmitz

2014-09-11 13:39

administrator   ~30573

Thank you very much. Please use a pull request on GitHub next time.

c_schmitz

c_schmitz

2014-09-15 22:57

administrator   ~30648

2.05+ Build 140915 released

Related Changesets

LimeSurvey: master bb06f6b6

2014-09-11 11:39:24

c_schmitz

Details Diff
Fixed issue 09209: RemoteControl export_responses_by_token does not return all responses Affected Issues
09209
mod - application/helpers/remotecontrol/remotecontrol_handle.php Diff File

Issue History

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 User patches => 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