- Posts: 9
- Thank you received: 1
Ask the community, share ideas, and connect with other LimeSurvey users!
<?php require_once 'jsonRPCClient.php'; define( 'LS_BASEURL', 'https://pathTo/limeSurvey'); define( 'LS_USER', 'admin' ); define( 'LS_PASSWORD', 'password' ); $iSurveyID = 123456; 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 // Filter by token value $aConditions = array('token'=>'123456789'); // Get the filtered participants $participants = $myJSONRPCClient->list_participants($sSessionKey, $iSurveyID, 0, 10, false, false, $aConditions); // Print the results echo '<ul>'; foreach($participants as $key => $value) { echo '<li>'; print_r($value); echo '</li>'; } echo '</ul>'; } // Release the session key $myJSONRPCClient->release_session_key( $sSessionKey ); } else { // Invalid SID format die( 'Invalid format!' ); } ?>
<?php require_once 'jsonRPCClient.php'; define( 'LS_BASEURL', 'https://pathTo/limeSurvey'); define( 'LS_USER', 'admin' ); define( 'LS_PASSWORD', 'password' ); $iSurveyID = 123456; $token = 123456789; 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 // Filter by token value $aConditions = array('token'=>$token); // Get the filtered participants $participants = $myJSONRPCClient->list_participants($sSessionKey, $iSurveyID, 0, 10, false, false, $aConditions); // Now, delete the first returned participant $aTokenIDs = array($participants[0]['tid']); $deleteParticipants = $myJSONRPCClient->delete_participants($sSessionKey, $iSurveyID, $aTokenIDs); } // Release the session key $myJSONRPCClient->release_session_key( $sSessionKey ); } else { // Invalid SID format die( 'Invalid format!' ); } ?>
[strike]Yes, since tokens are unique, the "token" condition can only match one result.[/strike]I suppose the filter by token value allow you to only get one participant?
Not sure I understand this. With filtering on the API call, you will only get one participantI suppose I need to get all the participants from Lime Survey then filter it on the application side, right?
foreach ($aConditions as $columnName => $valueOrTuple) { if (is_array($valueOrTuple)) { /** @var string[] List of operators allowed in query. */ $allowedOperators = ['<', '>', '>=', '<=', '=', '<>', 'LIKE']; /** @var string */ $operator = $valueOrTuple[0]; if (!in_array($operator, $allowedOperators)) { return array('status' => 'Illegal operator: ' . $operator); } elseif ($operator === 'LIKE') { /** @var mixed */ $value = $valueOrTuple[1]; $oCriteria->addSearchCondition($columnName, $value); } else { /** @var mixed */ $value = $valueOrTuple[1]; $oCriteria->compare($columnName, $operator . $value); } } elseif (is_string($valueOrTuple)) { if (in_array($columnName, $aConditionFields)) { $aAttributeValues[$columnName] = $valueOrTuple; } } else { // Silent ignore? } }
<?php require_once 'jsonRPCClient.php'; define( 'LS_BASEURL', 'https://pathTo/limeSurvey'); define( 'LS_USER', 'admin' ); define( 'LS_PASSWORD', 'password' ); $iSurveyID = 429116; 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 $aAttributes = array('attribute_1', 'attribute_2'); $tokens = array('1111', '2'); $aConditions = array('token'=>$tokens); $participants = $myJSONRPCClient->list_participants($sSessionKey, $iSurveyID, 0, 10, false, $aAttributes, $aConditions); // Print the results echo '<ul>'; foreach($participants as $key => $value) { echo '<li>'; print_r($value); echo '</li>'; } echo '</ul>'; echo '<br /><br />'; } // Release the session key $myJSONRPCClient->release_session_key( $sSessionKey ); } else { // Invalid SID format die( 'Invalid format!' ); } ?>
This appears to be the case. I consider this to be a serious regression. Please file a bug report and give a link here.I suppose the multiple tokens it's not supported anymore by list_participants()