Skip to content

Instantly share code, notes, and snippets.

@frederikprijck
Created June 15, 2016 15:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frederikprijck/fe7580909eb6fb54ceecd857b609ca08 to your computer and use it in GitHub Desktop.
Save frederikprijck/fe7580909eb6fb54ceecd857b609ca08 to your computer and use it in GitHub Desktop.
Extend LS RPC with get_participant_properties_by_token
/**
* RPC Routine to return settings of a token/participant of a survey .
*
* @access public
* @param string $sSessionKey Auth credentials
* @param int $iSurveyID Id of the Survey to get token properties
* @param int $sToken Token of the participant to check
* @param array $aTokenProperties The properties to get
* @return array The requested values
*/
public function get_participant_properties_by_token($sSessionKey, $iSurveyID, $sToken, $aTokenProperties)
{
if ($this->_checkSessionKey($sSessionKey))
{
$surveyidExists = Survey::model()->findByPk($iSurveyID);
if (!isset($surveyidExists))
return array('status' => 'Error: Invalid survey ID');
if (Permission::model()->hasSurveyPermission($iSurveyID, 'tokens', 'read'))
{
if(!tableExists("{{tokens_$iSurveyID}}"))
return array('status' => 'Error: No token table');
$token = Token::model($iSurveyID)->findByAttributes(array('token' => $sToken));
if (!isset($token))
return array('status' => 'Error: Invalid tokenid');
$result = array_intersect_key($token->attributes, array_flip($aTokenProperties));
if (empty($result))
{
return array('status' => 'No valid Data');
}
else
{
return $result;
}
}
else
return array('status' => 'No permission');
}
else
return array('status' => 'Invalid Session Key');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment