@@ -3536,7 +3536,7 @@ public function export_responses($sSessionKey, $iSurveyID, $sDocumentType, $sLan
35363536 * @param string $sSessionKey Auth credentials
35373537 * @param int $iSurveyID ID of the Survey
35383538 * @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
35403540 * @param string $sLanguageCode The language to be used
35413541 * @param string $sCompletionStatus Optional 'complete','incomplete' or 'all' - defaults to 'all'
35423542 * @param string $sHeadingType 'code','full' or 'abbreviated' Optional defaults to 'code'
@@ -3545,11 +3545,10 @@ public function export_responses($sSessionKey, $iSurveyID, $sDocumentType, $sLan
35453545 * @return array|string On success: Requested file as base 64-encoded string. On failure array with error information
35463546 *
35473547 */
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 )
35493549 {
35503550 $ iSurveyID = (int ) $ iSurveyID ;
35513551 $ survey = Survey::model ()->findByPk ($ iSurveyID );
3552-
35533552 if (!$ this ->_checkSessionKey ($ sSessionKey )) {
35543553 return array ('status ' => self ::INVALID_SESSION_KEY );
35553554 }
@@ -3563,9 +3562,21 @@ public function export_responses_by_token($sSessionKey, $iSurveyID, $sDocumentTy
35633562 if (!empty ($ sLanguageCode ) && !in_array ($ sLanguageCode , $ survey ->getAllLanguages ())) {
35643563 return array ('status ' => 'Language code not found for this survey. ' );
35653564 }
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 " );
35693580 }
35703581 if (!Permission::model ()->hasSurveyPermission ($ iSurveyID , 'responses ' , 'export ' )) {
35713582 return array ('status ' => 'No permission ' );
@@ -3576,22 +3587,17 @@ public function export_responses_by_token($sSessionKey, $iSurveyID, $sDocumentTy
35763587 if (is_null ($ aFields )) {
35773588 $ aFields = array_keys (createFieldMap ($ survey , 'full ' , true , false , $ sLanguageCode ));
35783589 }
3579-
35803590 $ oFormattingOptions = new FormattingOptions ();
35813591 $ oFormattingOptions ->responseMinRecord = 1 ;
35823592 $ oFormattingOptions ->responseMaxRecord = $ maxId ;
3583-
35843593 $ oFormattingOptions ->selectedColumns = $ aFields ;
35853594 $ oFormattingOptions ->responseCompletionState = $ sCompletionStatus ;
35863595 $ oFormattingOptions ->headingFormat = $ sHeadingType ;
35873596 $ oFormattingOptions ->answerFormat = $ sResponseType ;
35883597 $ oFormattingOptions ->output = 'file ' ;
3589-
35903598 $ oExport = new ExportSurveyResultsService ();
3591-
35923599 $ 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 );
35953601 return new BigFile ($ sTempFile , true , 'base64 ' );
35963602 }
35973603
0 commit comments