- Posts: 16
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
h0rr0rOrg wrote: I am stalled right at the beginning. I don't see any indication of how to connect to my Limesurvey other than this:
How to use LSRC2
The basic LSRC2 URL is: https://<your_domain>/<your_limesurvey_dir>/index.php/admin/remotecontrol
But what is my domain? What is my Limesurvey dir? Where do I find that information? Is this for the cloud or just for an installation?
Thanks!
Angel...
In your website … you can't include a file on another server …h0rr0rOrg wrote: Is this RPC on my website server or on the Limesurvey cloud?
To include JSON-RPC in your application, you can write an application using the light-weight jsonRPCClient from the jsonrpcphp Github repository.
<?php require_once 'jsonrpcphp/JsonRPCClient.php'; define( 'LS_BASEURL', 'https://www.limesurvey.de/survey'); // adjust this one to your actual LimeSurvey URL define( 'LS_USER', 'user' ); define( 'LS_PASSWORD', 'pass' ); // the survey to process $survey_id=557357; // instantiate a new client $myJSONRPCClient = new \org\jsonrpcphp\JsonRPCClient( LS_BASEURL.'/index.php/admin/remotecontrol' ); // receive session key $sessionKey= $myJSONRPCClient->get_session_key( LS_USER, LS_PASSWORD ); print_r($sessionKey ); if(is_array($sessionKey)) { header("Content-type: application/json"); echo json_encode($sessionKey); die(); } /* Get the responses */ $response = $myJSONRPCClient->export_responses( $sessionKey, $survey_id, 'json', // Document type : pdf,csv,xls,doc,json null, // Language code : null : default from survey 'all', // Stautus complete|incomplete|all null, // Heading : code|full|abbreviated : question text, default code null // answer : short|long , default : long ); // See https://api.limesurvey.org/classes/remotecontrol_handle.html#method_export_responses or https://github.com/LimeSurvey/LimeSurvey/blob/master/application/helpers/remotecontrol/remotecontrol_handle.php#L2382 or
echo '<table border=1 cellpadding=5>'; $i = 0; foreach ($responseArr as $value) { $row2 = reset($responseArr['responses'][$i]); $title = $row2['title']; echo '<tr><td>'; echo $title . '</td><td><br>' . $i . '</td></tr>'; ++$i; } echo '</table>';
<?php require_once 'jsonRPCClient.php'; define( 'LS_BASEURL', 'https://pathTo/limeSurvey'); define( 'LS_USER', 'admin' ); define( 'LS_PASSWORD', 'password' ); $iSurveyID = 123456; // 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 $surveyResponses = $myJSONRPCClient->export_responses($sSessionKey, $iSurveyID, 'json', null, 'completed', 'code', 'short', null, null, null); if(is_array($surveyResponses)) { // Oops, print any errors print_r($surveyResponses); } else { // Decode the retuned base-64 string and convert to an array $decodedString = base64_decode($surveyResponses); $aResponses = json_decode($decodedString, True); // Find the first response ID $aFirstResponse = reset($aResponses['responses'][0]); echo '<table style="border-collapse: collapse; text-align: left;">'; echo '<tr>'; // Insert column headers foreach($aFirstResponse as $key => $value) { echo '<th style="border: 1px solid #CCC; padding: 2px 7px;">'.$key .'</th>'; } echo '</tr>'; foreach($aResponses['responses'] as $key => $row) { echo '<tr>'; // Insert the data foreach(reset($row) as $key => $item) { echo '<td style="border: 1px solid #CCC; padding: 2px 7px;">'.$item .'</td>'; } echo '</tr>'; } echo '</table>'; } } // Release the session key $myJSONRPCClient->release_session_key( $sSessionKey ); ?>
Is "poetry" in a well defined column or somewhere in the dataset?I want to display only the rows where one of the data points is "poetry".
$rawResponses = $myJSONRPCClient->export_responses( $sessionKey, $survey_id, 'json', // Document type : pdf,csv,xls,doc,json null, // Language code : null : default from survey 'complete', // Stautus complete|incomplete|all 'code', // Heading : code|full|abbreviated : question text, default code 'short', // answer : short|long , default : long null, null, null ); if(is_array($rawResponses)) { // Oops, print any errors print_r($rawResponses); } else { // There is a valid response... // Decode the retuned base-64 string and convert to an array $decodedString = base64_decode($rawResponses); // The decodedString variable turns the data into an array and contains the entire array of data for the survey in English $responseArr = json_decode($decodedString, True); // Creates the json-decoded array of data for use in PHP. echo '<table border=1 text-align="left">'; echo '<tr>'; // Insert column headers_list foreach($responseArr as $key => $value) // $responseArr is the entire array, $key returns the name of the data set 'responses'; $value returns an array of the jSon data pairs with => between { foreach($responseArr['responses'] as $rownumber => $row) // $rownumber is a numeric value, not an array; $row is an array of all data in each submission. { echo '<tr>'; // Inserts the data foreach(reset($row) as $headinng => $item) // $heading returns the heading name (of which 'category' is one), $item returns the data, one item at a time { // THE FOLLOWING line is where I need to echo only specified $item data, and if I can nest those criteria, all the better. I need to filter first by $item (APPROVED), then filter by multiple other $items (AUTHOR and TITLE) to choose which to show. echo '<td style="border: 1px solid #CCC; padding: 2px 7px;">' . $item . '</td>'; } } }
$response = $myJSONRPCClient->export_responses( $sessionKey, $survey_id, 'json', // Document type : pdf,csv,xls,doc,json null, // Language code : null : default from survey 'complete', // Stautus complete|incomplete|all NULL, // Heading : code|full|abbreviated : question text, default code NULL, // answer : short|long , default : long 1, 3, ['id','token','submitdate','lastpage'] );
['submitdate','lastpage','id','title','author','publisher','category']
echo '<td style="border: 1px solid #CCC; padding: 2px 7px;">A: ' . $item . '</td>';