Help with remote control add response

More
2 months 4 weeks ago #162807 by jsibley
jsibley created the topic: Help with remote control add response
Hi,

I have some questions about using add_response.

First, is SGQA still the only or best way to identify questions when using remote control and, specifically, add_response?

Second, is the subquestion code, what shows as qid, with the question code as the parent_qid? In the example given at manual.limesurvey.org/SGQA_identifier/en...Array_question_types , the subquestion code is "ber1", while my "qid" is a number.

Third, if I am using an array with answer options that are on a scale of 1 to 5, is the actual response simply the number from 1 to 5?

Many thanks!

Please Log in or Create an account to join the conversation.

More
2 months 4 weeks ago #162808 by jsibley
jsibley replied the topic: Help with remote control add response
I forgot to add to my questions:

If it is a token-based survey, where does the token information go in the add_response request? I haven't seen that documented (and sorry if I missed that).

Please Log in or Create an account to join the conversation.

More
2 months 4 weeks ago - 2 months 4 weeks ago #162815 by tpartner
tpartner replied the topic: Help with remote control add response
1) You must use the SGQ, not the question code to identify the questions. It is the column name in the database.

2) Sub-questions are identified by their code (also in the column name). So, a sub-question identifier might look like:
11111X222X333SQ001

3) Answers are identified by their codes. So, if your codes are simple numerics, yes, otherwise they would be something like "A1".

4) The token can be included in the $aResponseData array as seen below.

Here is a quick example using JSON-RPC that will set 3 rows of an array to 2, 5 and 3 respectively and then update the token as "Completed":

<?php
 
	require_once 'jsonRPCClient.php';
 
	define( 'LS_BASEURL', 'http://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!' );
	}
 
?>

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last Edit: 2 months 4 weeks ago by tpartner.
The following user(s) said Thank You: LouisGac, jsibley

Please Log in or Create an account to join the conversation.

More
2 months 3 weeks ago #162934 by jsibley
jsibley replied the topic: Help with remote control add response
That is incredibly helpful. Thank you!

Please Log in or Create an account to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!