Skip to content

Commit

Permalink
Fix #09790: Use conditions to get a subset of list_participants
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan-E committed Jul 28, 2015
1 parent d9cdf1f commit c21da9d
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions application/helpers/remotecontrol/remotecontrol_handle.php
Expand Up @@ -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))
{
Expand All @@ -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');
Expand Down

0 comments on commit c21da9d

Please sign in to comment.