Example #1
1
 /**
  * Simple procedure to test most RPC functions
  *
  */
 public function test()
 {
     $sFileToImport = dirname(Yii::app()->basePath) . DIRECTORY_SEPARATOR . 'docs' . DIRECTORY_SEPARATOR . 'demosurveys' . DIRECTORY_SEPARATOR . 'limesurvey2_sample_survey_english.lss';
     //        $sFileToImport=dirname(Yii::app()->basePath).DIRECTORY_SEPARATOR.'docs'.DIRECTORY_SEPARATOR.'demosurveys'.DIRECTORY_SEPARATOR.'survey_archive_example_feedback_survey.zip';
     Yii::app()->loadLibrary('jsonRPCClient');
     $myJSONRPCClient = new jsonRPCClient(Yii::app()->getBaseUrl(true) . '/' . dirname(Yii::app()->request->getPathInfo()));
     $sSessionKey = $myJSONRPCClient->get_session_key('admin', 'password');
     if (is_array($sSessionKey)) {
         echo $sSessionKey['status'];
         die;
     } else {
         echo 'Retrieved session key' . '<br>';
     }
     $sLSSData = base64_encode(file_get_contents($sFileToImport));
     $iSurveyID = $myJSONRPCClient->import_survey($sSessionKey, $sLSSData, 'zip', 'Test import by JSON_RPC', 1000);
     echo 'Created new survey SID:' . $iSurveyID . '<br>';
     /*
             Very simple example to export responses as Excel file
             $aResult=$myJSONRPCClient->export_reponses($sSessionKey,$iSurveyID,'xls');
             file_put_contents('d:\test.xls',base64_decode(chunk_split($aResult)));
     */
     $aResult = $myJSONRPCClient->activate_survey($sSessionKey, $iSurveyID);
     if ($aResult['status'] == 'OK') {
         echo 'Survey ' . $iSurveyID . ' successfully activated.<br>';
     }
     $aResult = $myJSONRPCClient->activate_participant_tokens($sSessionKey, $iSurveyID, array(1, 2));
     if ($aResult['status'] == 'OK') {
         echo 'Tokens for Survey ID ' . $iSurveyID . ' successfully activated.<br>';
     }
     $aResult = $myJSONRPCClient->set_survey_properties($sSessionKey, $iSurveyID, array('faxto' => '0800-LIMESURVEY'));
     if ($aResult['status'] == 'OK') {
         echo 'Modified survey settings for survey ' . $iSurveyID . '<br>';
     }
     $aResult = $myJSONRPCClient->add_survey_language($sSessionKey, $iSurveyID, 'ar');
     if ($aResult['status'] == 'OK') {
         echo 'Added Arabian as additional language' . '<br>';
     }
     $aResult = $myJSONRPCClient->set_survey_language_properties($sSessionKey, $iSurveyID, array('surveyls_welcometext' => 'An Arabian welcome text!'), 'ar');
     if ($aResult['status'] == 'OK') {
         echo 'Modified survey locale setting welcometext for Arabian in survey ID ' . $iSurveyID . '<br>';
     }
     $aResult = $myJSONRPCClient->delete_survey_language($sSessionKey, $iSurveyID, 'ar');
     if ($aResult['status'] == 'OK') {
         echo 'Removed Arabian as additional language' . '<br>';
     }
     die;
     $aResult = $myJSONRPCClient->delete_survey($sSessionKey, $iSurveyID);
     echo 'Deleted survey SID:' . $iSurveyID . '-' . $aResult['status'] . '<br>';
     // Release the session key - close the session
     $Result = $myJSONRPCClient->release_session_key($sSessionKey);
     echo 'Closed the session' . '<br>';
 }