Skip to content

Commit

Permalink
Dev Changed export_responses_by_token to use export_responses.
Browse files Browse the repository at this point in the history
  • Loading branch information
SamMousa committed Jun 23, 2013
1 parent 4fcd825 commit 6ae5075
Showing 1 changed file with 4 additions and 28 deletions.
32 changes: 4 additions & 28 deletions application/controllers/admin/remotecontrol.php
Expand Up @@ -2420,37 +2420,13 @@ public function export_responses($sSessionKey, $iSurveyID, $sDocumentType, $sLan
public function export_responses_by_token($sSessionKey, $iSurveyID, $sDocumentType, $sToken, $sLanguageCode=null, $sCompletionStatus='all', $sHeadingType='full', $sResponseType='short', $aFields=null)
{
if (!$this->_checkSessionKey($sSessionKey)) return array('status' => 'Invalid session key');

Yii::app()->loadHelper('admin/exportresults');
if (!Permission::model()->hasSurveyPermission($iSurveyID, 'responses', 'export')) return array('status' => 'No permission');
if (!tableExists('{{survey_' . $iSurveyID . '}}')) return array('status' => 'No Data');
if(!$oResult = Survey_dynamic::model($iSurveyID)->findByAttributes(array('token' => $sToken))) return array('status' => 'No Response found for Token');
if ($oResult['id'])
if(!$oResult = SurveyDynamic::model($iSurveyID)->findByAttributes(array('token' => $sToken))) return array('status' => 'No Response found for Token');
if ($oResult['id'])
{
$sFilter="{{survey_{$iSurveyID}}}.id=".(int)$oResult['id'];
}
if (!hasSurveyPermission($iSurveyID, 'responses', 'export')) return array('status' => 'No permission');
if (empty($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);
return $this->export_responses($sSessionKey, $iSurveyID, $sDocumentType, $sLanguageCode, $sCompletionStatus, $sHeadingType, $sResponseType, $oResult['id'], $oResult['id'], $aFields);
}

$oFomattingOptions=new FormattingOptions();

$oFomattingOptions->selectedColumns=$aFields;
$oFomattingOptions->responseCompletionState=$sCompletionStatus;
$oFomattingOptions->headingFormat=$sHeadingType;
$oFomattingOptions->answerFormat=$sResponseType;
$oFomattingOptions->output='file';
$oExport=new ExportSurveyResultsService();

$sTempFile=$oExport->exportSurvey($iSurveyID,$sLanguageCode, $sDocumentType,$oFomattingOptions, $sFilter);
$sFileData = file_get_contents($sTempFile);
unlink($sTempFile);

return base64_encode($sFileData);
}


Expand Down

0 comments on commit 6ae5075

Please sign in to comment.