Created
June 15, 2016 15:37
-
-
Save frederikprijck/fe7580909eb6fb54ceecd857b609ca08 to your computer and use it in GitHub Desktop.
Extend LS RPC with get_participant_properties_by_token
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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