Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Help with remote control add response

  • jsibley
  • jsibley's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
6 years 2 months ago #162807 by jsibley
Help with remote control add response was created by jsibley
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!
The topic has been locked.
  • jsibley
  • jsibley's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
6 years 2 months ago #162808 by jsibley
Replied by jsibley on 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).
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 2 months ago - 6 years 2 months ago #162815 by tpartner
Replied by tpartner on 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:
Code:
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":

Code:
<?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) &amp;&amp; (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: 6 years 2 months ago by tpartner.
The following user(s) said Thank You: jsibley
The topic has been locked.
  • jsibley
  • jsibley's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
6 years 2 months ago #162934 by jsibley
Replied by jsibley on topic Help with remote control add response
That is incredibly helpful. Thank you!
The topic has been locked.
More
5 years 7 months ago - 5 years 7 months ago #173494 by afocal
Replied by afocal on topic Help with remote control add response
Thank you so much. Could you explain too: what is 'seed', and how can we generate it or get it, in order to set it in the add_response request? Because when using remote control api, 'seed' is not set with your example...

Should we use this code?
Code:
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), ...
 
Last edit: 5 years 7 months ago by afocal.
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 7 months ago #173501 by Joffm
Replied by Joffm on topic Help with remote control add response
Hi,
"seed" is the "initial value of randomization".

Because you do not run the survey, but enter the response data, this value is irrelevant.
Nice to see, but more or less useless.
Not necessary to generate or enter in the answer table.

Something to read about it:
en.wikipedia.org/wiki/Random_seed

stackoverflow.com/questions/14914595/wha...ting-a-random-number

Best regards
Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: tpartner
The topic has been locked.
More
5 years 7 months ago - 5 years 7 months ago #173523 by afocal
Replied by afocal on topic Help with remote control add response
Thank you. We use Limesurvey in order to record and analyse data from some html / php survey which don't use the Limesurvey Interface / ergonomy. For us, that is easier / faster than study an umpteenth templates / themes system... We don't need to identify users (anonym surveys). So, thousands users will participate to our surveys (thus we 'run the survey'), and we are going to use 'tokens' in order to prevent from duplicated answers. Therefore, do you confirm me that 'seeds' are not relevant for us? Is it only a technical data for developpers of Limesurevey's team?
Last edit: 5 years 7 months ago by afocal.
The topic has been locked.
More
5 years 7 months ago #173563 by jelo
Replied by jelo on topic Help with remote control add response

Joffm wrote: "seed" is the "initial value of randomization".

Are you aware of a explanation of the exact purpose in LS3?

I only found this in the release notes:

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.


The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
The following user(s) said Thank You: DenisChenu
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 7 months ago #173568 by tpartner
Replied by tpartner on topic Help with remote control add response
@afocal, to answer your question: yes, if you are loading data via the API, you can ignore the seed.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
5 years 7 months ago #173572 by afocal
Replied by afocal on topic Help with remote control add response
Thank you!
The topic has been locked.
More
5 years 5 months ago #176094 by afocal
Replied by afocal on topic Help with remote control add response
Hi, I'm coming back here because I didn't found how to add response for the "other" question?

This code doesn't work if I use "123456X5X63other":
Code:
$aResponseData = array("123456X5X61" => "an answer","123456X5X62SQ002" => "Y","123456X5X63other" => "sorry no idea");
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 5 months ago #176097 by tpartner
Replied by tpartner on topic Help with remote control add response
What question type is 123456X5X63?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose