Welcome, Guest
Username: Password: Remember me

TOPIC: RemoteControl list_questions behavior

RemoteControl list_questions behavior 1 year 3 months ago #108116

  • simogeo
  • simogeo's Avatar
  • Offline
  • Junior Lime
  • Posts: 20
  • Karma: 0
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
The administrator has disabled public write access.

RemoteControl list_questions behavior 4 days 14 hours ago #123063

  • lacd
  • lacd's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 2
  • Karma: 1
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
The administrator has disabled public write access.

RemoteControl list_questions behavior 4 days 10 hours ago #123071

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • Moderator Lime
  • Posts: 7478
  • Thank you received: 1019
  • Karma: 295
Bug can be reported to mantis ...
The administrator has disabled public write access.

RemoteControl list_questions behavior 4 days 8 hours ago #123085

  • simogeo
  • simogeo's Avatar
  • Offline
  • Junior Lime
  • Posts: 20
  • Karma: 0
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: 4 days 8 hours ago by simogeo.
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.136 seconds