Skip to content

Commit

Permalink
New feature: copy survey from remotecontroll (#688)
Browse files Browse the repository at this point in the history
Dev: Adds the option to copy surveys with the remote control.
  • Loading branch information
evently-nl authored and LouisGac committed Oct 9, 2017
1 parent 8090eb0 commit 839ee9a
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions application/helpers/remotecontrol/remotecontrol_handle.php
Expand Up @@ -244,6 +244,73 @@ public function import_survey($sSessionKey, $sImportData, $sImportDataType, $sNe
}

/**
* RPC Routine to copy a survey.
*
* @access public
* @param string $sSessionKey Auth credentials
* @param int $iSurveyID_org Id of the source survey
* @param string $sNewname name of the new survey
* @return On success: new $iSurveyID in array['newsid']. On failure array with error information
* */
public function copy_survey($sSessionKey, $iSurveyID_org, $sNewname )
{
$iSurveyID = (int) $iSurveyID_org;
if (!$this->_checkSessionKey($sSessionKey)) return array('status' => 'Invalid session key');
$aData['bFailed'] = false; // Put a var for continue
if (!$iSurveyID)
{
$aData['sErrorMessage'] = "No survey ID has been provided. Cannot copy survey";
$aData['bFailed'] = true;
}
elseif(!Survey::model()->findByPk($iSurveyID))
{
$aData['sErrorMessage'] = "Invalid survey ID";
$aData['bFailed'] = true;
}
elseif (!Permission::model()->hasSurveyPermission($iSurveyID, 'surveycontent', 'export') && !Permission::model()->hasSurveyPermission($iSurveyID, 'surveycontent', 'export'))
{
$aData['sErrorMessage'] = "You don't have sufficient permissions.";
$aData['bFailed'] = true;
}
else
{
$aExcludes = array();
$sNewSurveyName = $sNewname;
$aExcludes['dates'] = true;
$btranslinksfields=true;
Yii::app()->loadHelper('export');
$copysurveydata = surveyGetXMLData($iSurveyID, $aExcludes);
if($copysurveydata)
{
Yii::app()->loadHelper('admin/import');
$aImportResults = XMLImportSurvey('', $copysurveydata, $sNewSurveyName,NULL,$btranslinksfields);
if (isset($aExcludes['conditions']))
{
Question::model()->updateAll(array('relevance'=>'1'),'sid='.$aImportResults['newsid']);
QuestionGroup::model()->updateAll(array('grelevance'=>'1'),'sid='.$aImportResults['newsid']);
}
if (!isset($aExcludes['permissions']))
{
Permission::model()->copySurveyPermissions($iSurveyID,$aImportResults['newsid']);
}
}
else
{
$aData['bFailed']=true;
}
}
if($aData['bFailed'])
{
return array('status' => 'Copy failed','error'=> $aData['sErrorMessage']);
}
else
{
return array('status' => 'OK','newsid'=>$aImportResults['newsid']);
}
}

/**
* RPC Routine to get survey properties.
* Get properties of a survey
*
* All internal properties of a survey are available.
Expand Down

0 comments on commit 839ee9a

Please sign in to comment.