Skip to content

Commit

Permalink
Fixed issue ##08308: questions that nothing depends upon trigger the …
Browse files Browse the repository at this point in the history
…reevaluation of every conditionnal expression in the survey

Dev: using Expression Manager to get the list of questions with dependencies
  • Loading branch information
LouisGac committed Aug 25, 2016
1 parent f5283c6 commit f481515
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
7 changes: 4 additions & 3 deletions application/helpers/SurveyRuntimeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1417,13 +1417,14 @@ public function setJavascriptVar($iSurveyId)
$aRadix=getRadixPointData($aSurveyinfo['surveyls_numberformat']);
$aLSJavascriptVar['sLEMradix']=$aRadix['separator'];


$aCfieldnameWithDependences = (array)Condition::model()->getAllCfieldnameWithDependenciesForOneSurvey($iSurveyId);
/*
$aCfieldnameWithDependences = Condition::model()->getAllCfieldnameWithDependenciesForOneSurvey($iSurveyId);
foreach($aCfieldnameWithDependences as $sCfieldname)
{
$aLSJavascriptVar['aFieldWithDependencies'][] = $sCfieldname;
}

*/

$sLSJavascriptVar="LSvar=".json_encode($aLSJavascriptVar) . ';';
App()->clientScript->registerScript('sLSJavascriptVar',$sLSJavascriptVar,CClientScript::POS_HEAD);
}
Expand Down
21 changes: 21 additions & 0 deletions application/helpers/expressions/em_manager_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -7049,6 +7049,7 @@ static function FinishProcessingPage()
*/
static function GetRelevanceAndTailoringJavaScript()
{
$aQuestionsWithDependencies = array();
$now = microtime(true);
$LEM =& LimeExpressionManager::singleton();

Expand Down Expand Up @@ -7547,6 +7548,7 @@ static function GetRelevanceAndTailoringJavaScript()
$qrelgseqs[] = 'relChangeG' . $knownVar['gseq'];
}
}

$qrelgseqs[] = 'relChangeG' . $arg['gseq']; // so if current group changes visibility, re-tailor it.
$qrelQIDs = array_unique($qrelQIDs);
$qrelgseqs = array_unique($qrelgseqs);
Expand All @@ -7556,6 +7558,22 @@ static function GetRelevanceAndTailoringJavaScript()
$qrelgseqs=array();
}

/**
* https://bugs.limesurvey.org/view.php?id=8308#c26972
* Thomas White explained: "LEMrelXX functions were specifically designed to only be called for questions that have some dependency upon others "
* So $qrelQIDs contains those questions.
*/
foreach($qrelQIDs as $qrelQID)
{
$sQid = str_replace("relChange","",$qrelQID);
if(!in_array($sQid, $aQuestionsWithDependencies) )
{
$aQuestionsWithDependencies[]=$sQid;
}

}


$qrelJS = "function LEMrel" . $arg['qid'] . "(sgqa){\n";
$qrelJS .= " var UsesVars = ' " . implode(' ', $relJsVarsUsed) . " ';\n";
if (count($qrelQIDs) > 0)
Expand Down Expand Up @@ -7852,6 +7870,9 @@ static function GetRelevanceAndTailoringJavaScript()
}
$LEM->runtimeTimings[] = array(__METHOD__,(microtime(true) - $now));


$jsParts[]="<input type='hidden' id='aQuestionsWithDependencies' data-qids='".json_encode($aQuestionsWithDependencies)."' />";

return implode('',$jsParts);
}

Expand Down
11 changes: 10 additions & 1 deletion scripts/survey_runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,16 @@ function checkconditions(value, name, type, evt_type)
$('#java'+name).val(value);
}

$isRelevant = $.inArray(name, LSvar.aFieldWithDependencies);
aFieldWithDependencies = $('#aQuestionsWithDependencies').data('qids');

var result;
if(typeof name !== 'undefined')
{
result = name.split('X');
result = result[2]
}

$isRelevant = $.inArray(result, aFieldWithDependencies);

if($.isFunction(window.ExprMgr_process_relevance_and_tailoring ) && $isRelevant!=-1)
ExprMgr_process_relevance_and_tailoring(evt_type,name,type);
Expand Down

0 comments on commit f481515

Please sign in to comment.