@@ -3536,7 +3536,7 @@ public function export_responses($sSessionKey, $iSurveyID, $sDocumentType, $sLan
3536
3536
* @param string $sSessionKey Auth credentials
3537
3537
* @param int $iSurveyID ID of the Survey
3538
3538
* @param string $sDocumentType pdf, csv, xls, doc, json
3539
- * @param string $sToken The token for which responses needed
3539
+ * @param array| string $aTokens The tokens (or single token) for which responses needed
3540
3540
* @param string $sLanguageCode The language to be used
3541
3541
* @param string $sCompletionStatus Optional 'complete','incomplete' or 'all' - defaults to 'all'
3542
3542
* @param string $sHeadingType 'code','full' or 'abbreviated' Optional defaults to 'code'
@@ -3545,11 +3545,10 @@ public function export_responses($sSessionKey, $iSurveyID, $sDocumentType, $sLan
3545
3545
* @return array|string On success: Requested file as base 64-encoded string. On failure array with error information
3546
3546
*
3547
3547
*/
3548
- public function export_responses_by_token ($ sSessionKey , $ iSurveyID , $ sDocumentType , $ sToken , $ sLanguageCode = null , $ sCompletionStatus = 'all ' , $ sHeadingType = 'code ' , $ sResponseType = 'short ' , $ aFields = null )
3548
+ public function export_responses_by_token ($ sSessionKey , $ iSurveyID , $ sDocumentType , $ aTokens , $ sLanguageCode = null , $ sCompletionStatus = 'all ' , $ sHeadingType = 'code ' , $ sResponseType = 'short ' , $ aFields = null )
3549
3549
{
3550
3550
$ iSurveyID = (int ) $ iSurveyID ;
3551
3551
$ survey = Survey::model ()->findByPk ($ iSurveyID );
3552
-
3553
3552
if (!$ this ->_checkSessionKey ($ sSessionKey )) {
3554
3553
return array ('status ' => self ::INVALID_SESSION_KEY );
3555
3554
}
@@ -3563,9 +3562,21 @@ public function export_responses_by_token($sSessionKey, $iSurveyID, $sDocumentTy
3563
3562
if (!empty ($ sLanguageCode ) && !in_array ($ sLanguageCode , $ survey ->getAllLanguages ())) {
3564
3563
return array ('status ' => 'Language code not found for this survey. ' );
3565
3564
}
3566
-
3567
- if (!SurveyDynamic::model ($ iSurveyID )->findByAttributes (array ('token ' => $ sToken ))) {
3568
- return array ('status ' => 'No Response found for Token ' );
3565
+ if (is_array ($ aTokens )) {
3566
+ if (count ($ aTokens ) == 0 ) {
3567
+ return array ('status ' => 'No Data, empty tokens array parameter ' );
3568
+ } else {
3569
+ $ aTokensQuoted = Array ();
3570
+ foreach ($ aTokens as $ token ) {
3571
+ array_push ($ aTokensQuoted , App ()->db ->quoteValue ("$ token " ));
3572
+ }
3573
+ $ tokenFilter = " IN ( " . implode (", " , $ aTokensQuoted ) . ") " ;
3574
+ }
3575
+ } else {
3576
+ if (!SurveyDynamic::model ($ iSurveyID )->findByAttributes (array ('token ' => $ sToken ))) {
3577
+ return array ('status ' => 'No Response found for Token ' );
3578
+ }
3579
+ $ tokenFilter = "= " . App ()->db ->quoteValue ("$ aTokens " );
3569
3580
}
3570
3581
if (!Permission::model ()->hasSurveyPermission ($ iSurveyID , 'responses ' , 'export ' )) {
3571
3582
return array ('status ' => 'No permission ' );
@@ -3576,22 +3587,17 @@ public function export_responses_by_token($sSessionKey, $iSurveyID, $sDocumentTy
3576
3587
if (is_null ($ aFields )) {
3577
3588
$ aFields = array_keys (createFieldMap ($ survey , 'full ' , true , false , $ sLanguageCode ));
3578
3589
}
3579
-
3580
3590
$ oFormattingOptions = new FormattingOptions ();
3581
3591
$ oFormattingOptions ->responseMinRecord = 1 ;
3582
3592
$ oFormattingOptions ->responseMaxRecord = $ maxId ;
3583
-
3584
3593
$ oFormattingOptions ->selectedColumns = $ aFields ;
3585
3594
$ oFormattingOptions ->responseCompletionState = $ sCompletionStatus ;
3586
3595
$ oFormattingOptions ->headingFormat = $ sHeadingType ;
3587
3596
$ oFormattingOptions ->answerFormat = $ sResponseType ;
3588
3597
$ oFormattingOptions ->output = 'file ' ;
3589
-
3590
3598
$ oExport = new ExportSurveyResultsService ();
3591
-
3592
3599
$ sTableName = Yii::app ()->db ->tablePrefix . 'survey_ ' . $ iSurveyID ;
3593
-
3594
- $ sTempFile = $ oExport ->exportResponses ($ iSurveyID , $ sLanguageCode , $ sDocumentType , $ oFormattingOptions , "{$ sTableName }.token= " . App ()->db ->quoteValue ("$ sToken " ));
3600
+ $ sTempFile = $ oExport ->exportResponses ($ iSurveyID , $ sLanguageCode , $ sDocumentType , $ oFormattingOptions , "{$ sTableName }.token " . $ tokenFilter );
3595
3601
return new BigFile ($ sTempFile , true , 'base64 ' );
3596
3602
}
3597
3603
0 commit comments