How should the response to a ranking question be sent via RC2?

More
8 months 1 week ago #163878 by mattellen
mattellen created the topic: How should the response to a ranking question be sent via RC2?
I am calling the "add_response" method of RemoteControl2. I'm trying to add an answer to a ranking question. All the other answers are being accepted, but I can't see any documentation on how to structure the ranking answer.

So far I have tried (where S is the survey ID, G is the group ID, and Q is the question ID)

SXGXQ = "A1,A2,A3,A4"
SXGXQ = ["A1", "A2", "A3", "A4"]
SXGXQ = {"A1":1, "A2":2, "A3":3, "A4":4}
SXGXQ_1 = "A1", SXGXQ_2 = "A2", SXGXQ_3 = "A3", SXGXQ_1 = "A3"
SXGXQA1 = 1, SXGXQA2 = 2, SXGXQA3 = 3, SXGXQA4 = 4

What is the correct structure for this?

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

More
8 months 6 days ago #163916 by tpartner
tpartner replied the topic: How should the response to a ranking question be sent via RC2?
Try this:

SXGXQ1 = 'A1', SXGXQ2 = 'A2', SXGXQ3 = 'A3', SXGXQ4 = 'A4'

Here is a working example using RPC:

<?php
 
	require_once 'jsonRPCClient.php';
 
	define( 'LS_BASEURL', 'http://pathTo/limesurvey/');  
	define( 'LS_USER', 'admin' );
	define( 'LS_PASSWORD', 'password' );
 
	$iSurveyID = 123456;
	$g1ID = 123;
	$q1ID = 1234;
	$q1SGQ = $iSurveyID.'X'.$g1ID.'X'.$q1ID;
 
 
	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
 
 
			// Set a new response
			$aResponseData = array($q1SGQ.'1'=>'A1', $q1SGQ.'2'=>'A2', $q1SGQ.'3'=>'A3', $q1SGQ.'4'=>'A4');
			$newResponse = $myJSONRPCClient->add_response($sSessionKey, $iSurveyID, $aResponseData);
		}
 
		// 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.
The following user(s) said Thank You: LouisGac, mattellen

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

More
8 months 5 days ago #163944 by mattellen
mattellen replied the topic: How should the response to a ranking question be sent via RC2?
Thanks! That worked.

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!