Skip to content

Commit

Permalink
dev: Map response in pluginapi to question code instead of sidXgidXqid
Browse files Browse the repository at this point in the history
  • Loading branch information
mennodekker committed Mar 20, 2013
1 parent fd2c43e commit e177db8
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion application/libraries/PluginManager/LimesurveyApi.php
Expand Up @@ -32,12 +32,42 @@ public function EMevaluateExpression($expression)

/**
* Gets a response from the database.
*
* @param int $surveyId
* @param int $responseId
*/
public function getResponse($surveyId, $responseId)
{
return Survey_dynamic::model($surveyId)->findByPk($responseId)->attributes;
$response = Survey_dynamic::model($surveyId)->findByPk($responseId)->attributes;

// Now map the response to the question codes if possible, duplicate question codes will result in the
// old sidXgidXqid code for the second time the code is found
$fieldmap = createFieldMap($surveyId, 'full',null, false, $response['startlanguage']);
$output = array();
foreach($response as $key => $value)
{
$newKey = $key;
if (array_key_exists($key, $fieldmap)) {
if (array_key_exists('title', $fieldmap[$key]))
{
$code = $fieldmap[$key]['title'];
// Add subquestion code if needed
if (array_key_exists('aid', $fieldmap[$key]) && !empty($fieldmap[$key]['aid'])) {
$code .= '_' . $fieldmap[$key]['aid'];
}
// Only add if the code does not exist yet and is not empty
if (!empty($code) && !array_key_exists($code, $output)) {
$newKey = $code;
}
}
}
$output[$newKey] = $value;
}

// And return the mapped response, to further enhance we could add a method to the api that provides a
// simple sort of fieldmap that returns qcode index array with group, question, subquestion,
// possible answers, maybe even combined with relevance info so a plugin can handle display of the response
return $output;
}


Expand Down

0 comments on commit e177db8

Please sign in to comment.