Skip to content

Commit

Permalink
Fixed issue #13901: Prefilling single choice prefill other and comment
Browse files Browse the repository at this point in the history
New feature : allow to use EM code for subquestions in prefilling
Dev: Less for inside for, use LimeExpressionManager::getLEMqcode2sgqa
Dev: remove unneeded part in getLEMqcode2sgqa (no need to set in all in one mode)
  • Loading branch information
Shnoulle committed Jul 24, 2018
1 parent e86dc23 commit bb2be15
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
10 changes: 6 additions & 4 deletions application/helpers/expressions/em_manager_helper.php
Expand Up @@ -840,14 +840,16 @@ public static function RevertUpgradeConditionsToRelevance($surveyId=NULL, $qid=N
* Return array database name as key, LEM name as value
* @example (['gender'] => '38612X10X145')
* @param integer $iSurveyId
* @param boolean $initialize force initialisation of Survey
* @return array
**/
public static function getLEMqcode2sgqa($iSurveyId){
$LEM =& LimeExpressionManager::singleton();

$LEM->SetEMLanguage(Survey::model()->findByPk($iSurveyId)->language);
$LEM->SetSurveyId($iSurveyId);
$LEM->StartProcessingPage(true,true);
$LEM->SetSurveyId($iSurveyId); // This update session only if needed
if( !in_array(Yii::app()->session['LEMlang'],Survey::model()->findByPk($iSurveyId)->getAllLanguages()) ) {
$LEM->SetEMLanguage(Survey::model()->findByPk($iSurveyId)->language);// Reset language only if needed
}
$LEM->setVariableAndTokenMappingsForExpressionManager($iSurveyId);
return $LEM->qcode2sgqa;
}

Expand Down
30 changes: 18 additions & 12 deletions application/helpers/frontend_helper.php
Expand Up @@ -869,19 +869,25 @@ function prefillFromCommandLine($surveyid)
} else {
$startingValues = $_SESSION['survey_'.$surveyid]['startingValues'];
}

if (isset($_GET)) {

foreach ($_GET as $k=>$v) {

if (!in_array($k, $reservedGetValues) && isset($_SESSION['survey_'.$surveyid]['fieldmap'][$k])) {
$startingValues[$k] = $v;
} else {
// Search question codes to use those for prefilling.
foreach ($_SESSION['survey_'.$surveyid]['fieldmap'] as $sgqa => $details) {
if ($details['title'] == $k) {
$startingValues[$sgqa] = $v;
if (Yii::app()->getRequest()->getRequestType()=='GET') {
$getValues = array_diff_key($_GET,array_combine($reservedGetValues, $reservedGetValues));
if(!empty($getValues)) {
$qcode2sgqa = LimeExpressionManager::getLEMqcode2sgqa($surveyid);
foreach ($getValues as $k=>$v) {
if (isset($_SESSION['survey_'.$surveyid]['fieldmap'][$k])) {
// sXgXqa prefilling
$startingValues[$k] = $v;
} elseif( !empty($qcode2sgqa) && array_key_exists($k,$qcode2sgqa) ) {
// EM code prefilling
$startingValues[$qcode2sgqa[$k]] = $v;
/* Alternative
foreach ($_SESSION['survey_'.$surveyid]['fieldmap'] as $sgqa => $details) {
// Need Yii::import('application.helpers.viewHelper');
if (viewHelper::getFieldCode($details,array('LEMcompat'=>true)) == $k) {
$startingValues[$sgqa] = $v;
}
}
*/
}
}
}
Expand Down

6 comments on commit bb2be15

@maziminke
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Denis, can you give an example for "allow to use EM code for subquestions in prefilling"? Does that refer to the "default answers" feature or is it something different?

@Shnoulle
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@olleharstedt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! It might be better if you link to a mantis feature ticket when doing a new feature. The new feature introduced a bug, it seems (https://bugs.limesurvey.org/view.php?id=14008) - we want to fix it, but of course without breaking the new feature. But how can we test the new feature without a proper description of it, including test cases and test surveys?

@Shnoulle
Copy link
Collaborator Author

@Shnoulle Shnoulle commented on bb2be15 Aug 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@olleharstedt :

  1. see comment (and test link) on mantis 14008
  2. This commit was linked with https://bugs.limesurvey.org/view.php?id=13901
  3. The fix need to know _other and _comment, then the fix force new feature …

@olleharstedt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Shnoulle
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See 2a9d8c4 , not linked with this commit …

Please sign in to comment.