RemoteControl list_questions behavior

More
3 years 3 weeks ago #108116 by simogeo
simogeo created the topic: RemoteControl list_questions behavior
Hi,

I use the RemoteControl list_questions() method but I noticed the returned questions are not ordered as in survey.

Is that the normal behavior or a bug ? Is there an easy way to get it ordered?

Many thanks,

simo

Please Log in to join the conversation.

More
1 year 9 months ago #123063 by lacd
lacd replied the topic: RemoteControl list_questions behavior
Hello Simo,

I am facing a similar issue :( . In my case whenever I import a survey in LS, the order of question changes. When I use preview survey option, the questions are in correct order; however when I use RemoteControl API list_questions the order is changed. I queried lime_questions table and found that the questions are inserted in wrong order in DB :S .
Is there a work around for this? Did you figure out how to get the questions ordered?

Thanks in advance.
-LACD

Please Log in to join the conversation.

More
1 year 9 months ago #123071 by DenisChenu
DenisChenu replied the topic: RemoteControl list_questions behavior
Bug can be reported to mantis ...

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .

Please Log in to join the conversation.

More
1 year 9 months ago - 1 year 9 months ago #123085 by simogeo
simogeo replied the topic: RemoteControl list_questions behavior
Hi lacd,

I worked on that more than 1 year back so it is not that fresh ..... but I can tell you how I did :

I'm getting all groups by using :
// receive session key
$sessionKey= $myJSONRPCClient->get_session_key( LS_USER, LS_PASSWORD );
 
// receive all ids and info of groups belonging to a given survey
 
$groups = $myJSONRPCClient->list_groups( $sessionKey, $survey_id );
 
$order = array();
// we sort group on name (they use numbers as prefix)
foreach ($groups as $key => $row) {
	$order[$key]  = $row['group_name'];
}
@array_multisort($order, SORT_ASC, $groups);
 
// print_r($groups, null );

Then, I loop on groups to retrieve questions and use 'question_order' property to sort them !
 
$all = array();
 
 
foreach($groups as $group ) {
 
	$questions = $myJSONRPCClient->list_questions( $sessionKey, $survey_id, $group['id']['gid'] );
 
	$all[$group['id']['gid']] = $group;
 
	// print_r($questions, null );
 
	$data = array();
	$order = array();
 
	foreach($questions as $q ) {
 
		// print_r($q );
		// echo "<br></br>";
 
		// rgetting questions properties
		$qproperties = $myJSONRPCClient->get_question_properties($sessionKey, $q['id']['qid'], array('title', 'question', 'type', 'other', 'subquestions', 'question_order', 'answeroptions', 'other'));
 
		// we add 'id' field to questions
		$qproperties['qid'] =  $q['id']['qid'];
		$data[] = $qproperties;
 
	}
 
	// we sort questions	
	foreach ($data as $key => $row) {
	    $order[$key]  = $row['question_order'];
	}
 
	// Sort the data with question_order ascending
	// Add $data as the last parameter, to sort by the common key
 
	// Affiche un warning : "array_multisort(): Array sizes are inconsistent" car la taille des tableaux n'est pas égal
	// on supprime l'affichage.
	// Le tri fonctionne correctement
	@array_multisort($order, SORT_ASC, $data);
 
 
	// we add the questions array to the main array
	$all[$group['id']['gid']]['questions'][] = $data;
 
	// echo "<br><br>";
}
 
//print_r($all);
Last Edit: 1 year 9 months ago by simogeo.

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now