- Posts: 40
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
11111X222X333SQ001
<?php require_once 'jsonRPCClient.php'; define( 'LS_BASEURL', 'https://pathTo/limeSurvey/'); define( 'LS_USER', 'username' ); define( 'LS_PASSWORD', 'password' ); $iSurveyID = 11111; $group1ID = 222; $question1ID = 333; $question1SGQ = $iSurveyID.'X'.$group1ID.'X'.$question1ID; $token = 'asdf'; if(ctype_alnum($iSurveyID) && (strlen($iSurveyID) == 5 || strlen($iSurveyID) == 6)) { // Valid SID format // Instantiate a new RPC client $myJSONRPCClient = new jsonRPCClient( LS_BASEURL.'/index.php/admin/remotecontrol' ); // Get a session key $sSessionKey= $myJSONRPCClient->get_session_key( LS_USER, LS_PASSWORD ); if(is_array($sSessionKey)) { // Invalid session echo $sSessionKey['status']; } else if($sSessionKey) { // Valid session // Get token properties (to check if already used) $aTokenQueryProperties = array('token'=>$token); $aTokenProperties = array('email', 'firstname', 'lastname', 'token', 'tid', 'completed'); $participantProperties = $myJSONRPCClient->get_participant_properties( $sSessionKey, $iSurveyID, $aTokenQueryProperties, $aTokenProperties); if($participantProperties['completed'] != 'N') { // Token already used echo 'This token has already been used!'; } else { // Token not used // Set a new response $aResponseData = array('token'=>$token, $question1SGQ.'SQ001'=>2, $question1SGQ.'SQ002'=>5, $question1SGQ.'SQ003'=>3); $newResponse = $myJSONRPCClient->add_response($sSessionKey, $iSurveyID, $aResponseData); // Set the token as "used" $aTokenData = array('completed'=>date('Y-m-d h:m'), 'usesleft'=>0); $newTokenProperties = $myJSONRPCClient->set_participant_properties($sSessionKey, $iSurveyID, $aTokenQueryProperties, $aTokenData); } } // Release the session key $myJSONRPCClient->release_session_key( $sSessionKey ); } else { // Invalid SID format die( 'Invalid format!' ); } ?>
function setSeed($surveyid) { if (isset($_SESSION['survey_'.$surveyid]['srid'])) { $oResponse = \Response::model($surveyid)->findByPk($_SESSION['survey_'.$surveyid]['srid']); $seed = $oResponse->seed; } else { $seed = mt_rand(); $_SESSION['survey_'.$surveyid]['startingValues']['seed'] = $seed; } return($seed); } $aResponseData = array("seed" => setSeed(123456), ...
Are you aware of a explanation of the exact purpose in LS3?Joffm wrote: "seed" is the "initial value of randomization".
New feature: Store random seed with each response, making it possible to render the exact same order of questions and groups when respondent loads survey.
$aResponseData = array("123456X5X61" => "an answer","123456X5X62SQ002" => "Y","123456X5X63other" => "sorry no idea");