From c21da9d5fbdf19fc82c2a37f95efe65879c0fb71 Mon Sep 17 00:00:00 2001 From: Jan-E Date: Tue, 28 Jul 2015 16:06:38 +0200 Subject: [PATCH] Fix #09790: Use conditions to get a subset of list_participants --- .../helpers/remotecontrol/remotecontrol_handle.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/application/helpers/remotecontrol/remotecontrol_handle.php b/application/helpers/remotecontrol/remotecontrol_handle.php index 1f0a786a201..64b03230821 100644 --- a/application/helpers/remotecontrol/remotecontrol_handle.php +++ b/application/helpers/remotecontrol/remotecontrol_handle.php @@ -1770,9 +1770,10 @@ public function list_groups($sSessionKey, $iSurveyID) * @param int $iLimit Number of participants to return * @param bool $bUnused If you want unused tokens, set true * @param bool|array $aAttributes The extented attributes that we want + * @param array $aConditions Optional conditions to limit the list, e.g. with array('email' => 'info@example.com') * @return array The list of tokens */ - public function list_participants($sSessionKey, $iSurveyID, $iStart=0, $iLimit=10, $bUnused=false,$aAttributes=false) + public function list_participants($sSessionKey, $iSurveyID, $iStart=0, $iLimit=10, $bUnused=false, $aAttributes=false, $aConditions=array() ) { if ($this->_checkSessionKey($sSessionKey)) { @@ -1785,10 +1786,16 @@ public function list_participants($sSessionKey, $iSurveyID, $iStart=0, $iLimit=1 if(!tableExists("{{tokens_$iSurveyID}}")) return array('status' => 'Error: No token table'); + $aAttributeValues = array(); + if (count($aConditions)) { + $aConditionFields = array_flip(Token::model($iSurveyID)->getMetaData()->tableSchema->columnNames); + $aAttributeValues = array_intersect_key($aConditions, $aConditionFields); + } + if($bUnused) - $oTokens = Token::model($iSurveyID)->incomplete()->findAll(array('limit' => $iLimit, 'offset' => $iStart)); + $oTokens = Token::model($iSurveyID)->incomplete()->findAllByAttributes($aAttributeValues, array('order' => 'tid', 'limit' => $iLimit, 'offset' => $iStart)); else - $oTokens = Token::model($iSurveyID)->findAll(array('limit' => $iLimit, 'offset' => $iStart)); + $oTokens = Token::model($iSurveyID)->findAllByAttributes($aAttributeValues, array('order' => 'tid', 'limit' => $iLimit, 'offset' => $iStart)); if(count($oTokens)==0) return array('status' => 'No Tokens found');