Skip to content

Commit

Permalink
Fixed issue #05766: exclude_all_others_auto does not work
Browse files Browse the repository at this point in the history
Dev Was failing when the equations tried to reference variables that were not also declared elsewhere on the page.
  • Loading branch information
TMSWhite committed May 25, 2012
1 parent d7f26a2 commit 65a4334
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 14 deletions.
4 changes: 2 additions & 2 deletions classes/expressions/ExpressionManager.php
Expand Up @@ -1301,7 +1301,7 @@ public function GetJavaScriptEquivalentOfExpression()
$nonNAvarsUsed = array();
foreach ($this->GetVarsUsed() as $var) // this function wants to see the NAOK suffix
{
if (!preg_match("/^.*\.NAOK$/", $var))
if (!preg_match("/^.*\.(NAOK|relevanceStatus)$/", $var))
{
$nonNAvarsUsed[] = $var;
}
Expand Down Expand Up @@ -1756,7 +1756,7 @@ public function ProcessBooleanExpression($expr,$groupSeq=-1,$questionSeq=-1)
// Check whether any variables are irrelevant - making this comparable to JavaScript which uses LEManyNA(varlist) to do the same thing
foreach ($this->GetVarsUsed() as $var) // this function wants to see the NAOK suffix
{
if (!preg_match("/^.*\.NAOK$/", $var))
if (!preg_match("/^.*\.(NAOK|relevanceStatus)$/", $var))
{
if (!LimeExpressionManager::GetVarAttribute($var,'relevanceStatus',false,$groupSeq,$questionSeq))
{
Expand Down
55 changes: 43 additions & 12 deletions classes/expressions/LimeExpressionManager.php
Expand Up @@ -609,10 +609,10 @@ class LimeExpressionManager {
*/
private $qrootVarName2arrayFilter = array();
/**
* Array, keyed on qid, to JavaScript needed to implement exclude_all_others_auto
* Array, keyed on qid, to JavaScript and list of variables needed to implement exclude_all_others_auto
* @var type
*/
private $qid2exclusiveAutoJS = array();
private $qid2exclusiveAuto = array();


/**
Expand Down Expand Up @@ -1254,11 +1254,18 @@ public function _CreateSubQLevelRelevanceAndValidationEqns($onlyThisQseq=NULL)
}
}
if (count($sq_names) > 0) {
$relpart = "LEMsum(LEMval('" . implode(".relevanceStatus'), LEMval('", $sq_names) . ".relevanceStatus'))";
$checkedpart = "LEMcount(LEMval('" . implode("'), LEMval('", $sq_names) . "'))";
$eoRelevantAndUnchecked = "(LEMval('" . $eoVarName . ".relevanceStatus') && LEMval('" . $eoVarName . "')=='')";
$eosaJS = "if (" . $eoRelevantAndUnchecked . " && (" . $relpart . " == " . $checkedpart . ")) {\n";
$relpart = "sum(" . implode(".relevanceStatus, ", $sq_names) . ".relevanceStatus)";
$checkedpart = "count(" . implode(".NAOK, ", $sq_names) . ".NAOK)";
$eoRelevantAndUnchecked = "(" . $eoVarName . ".relevanceStatus && " . $eoVarName . "=='')";
$eoEqn = "(" . $eoRelevantAndUnchecked . " && (" . $relpart . " == " . $checkedpart . "))";

$this->em->ProcessBooleanExpression($eoEqn, $qinfo['gseq'], $qinfo['qseq']);

$relevanceVars = implode('|',$this->em->GetJSVarsUsed());
$relevanceJS = $this->em->GetJavaScriptEquivalentOfExpression();

// Unset all checkboxes and hidden values for this question (irregardless of whether they are array filtered)
$eosaJS = "if (" . $relevanceJS . ") {\n";
$eosaJS .=" $('#question" . $questionNum . " [type=checkbox]').attr('checked',false);\n";
$eosaJS .=" $('#java" . $qinfo['sgqa'] . "other').val('');\n";
$eosaJS .=" $('#answer" . $qinfo['sgqa'] . "other').val('');\n";
Expand All @@ -1269,7 +1276,11 @@ public function _CreateSubQLevelRelevanceAndValidationEqns($onlyThisQseq=NULL)
$eosaJS .=" relChange" . $questionNum ."=true;\n";
$eosaJS .="}\n";

$this->qid2exclusiveAutoJS[$questionNum] = $eosaJS;
$this->qid2exclusiveAuto[$questionNum] = array(
'js'=>$eosaJS,
'relevanceVars'=>$relevanceVars, // so that EM knows which variables to declare
'rowdivid'=>$eoVarName, // to ensure that EM creates a hidden relevanceSGQA input for the exclusive option
);
}
}
}
Expand Down Expand Up @@ -3494,7 +3505,7 @@ static function StartProcessingPage($allOnOnePage=false,$rooturl=NULL, $initiali
$LEM->surveyOptions['rooturl'] = $rooturl;
$LEM->surveyOptions['hyperlinkSyntaxHighlighting']=true; // this will be temporary - should be reset in running survey
}
$LEM->qid2exclusiveAutoJS=array();
$LEM->qid2exclusiveAuto=array();

// $LEM->runtimeTimings[] = array(__METHOD__,(microtime(true) - $now));

Expand Down Expand Up @@ -6036,13 +6047,23 @@ static function GetRelevanceAndTailoringJavaScript()
$qids = $gseq_qidList[$gr['gseq']];
foreach ($qids as $_qid=>$_val)
{
$qid2exclusiveAuto = (isset($LEM->qid2exclusiveAuto[$_qid]) ? $LEM->qid2exclusiveAuto[$_qid] : array());
if ($_val==1)
{
$jsParts[] = " LEMrel" . $_qid . "(sgqa);\n";
if (isset($LEM->qattr[$_qid]['exclude_all_others_auto']) && $LEM->qattr[$_qid]['exclude_all_others_auto'] == '1'
&& isset($LEM->qid2exclusiveAutoJS[$_qid]) && strlen($LEM->qid2exclusiveAutoJS[$_qid]) > 0)
&& isset($qid2exclusiveAuto['js']) && strlen($qid2exclusiveAuto['js']) > 0)
{
$jsParts[] = $LEM->qid2exclusiveAutoJS[$_qid];
$jsParts[] = $qid2exclusiveAuto['js'];
$vars = explode('|',$qid2exclusiveAuto['relevanceVars']);
if (is_array($vars))
{
$allJsVarsUsed = array_merge($allJsVarsUsed,$vars);
}
if (!isset($rowdividList[$qid2exclusiveAuto['rowdivid']]))
{
$rowdividList[$qid2exclusiveAuto['rowdivid']] = true;
}
}
if (isset($LEM->qattr[$_qid]['exclude_all_others']))
{
Expand All @@ -6066,13 +6087,23 @@ static function GetRelevanceAndTailoringJavaScript()
$qids = $gseq_qidList[$gr['gseq']];
foreach ($qids as $_qid=>$_val)
{
$qid2exclusiveAuto = (isset($LEM->qid2exclusiveAuto[$_qid]) ? $LEM->qid2exclusiveAuto[$_qid] : array());
if ($_val == 1)
{
$jsParts[] = " LEMrel" . $_qid . "(sgqa);\n";
if (isset($LEM->qattr[$_qid]['exclude_all_others_auto']) && $LEM->qattr[$_qid]['exclude_all_others_auto'] == '1'
&& isset($LEM->qid2exclusiveAutoJS[$_qid]) && strlen($LEM->qid2exclusiveAutoJS[$_qid]) > 0)
&& isset($qid2exclusiveAuto['js']) && strlen($qid2exclusiveAuto['js']) > 0)
{
$jsParts[] = $LEM->qid2exclusiveAutoJS[$_qid];
$jsParts[] = $qid2exclusiveAuto['js'];
$vars = explode('|',$qid2exclusiveAuto['relevanceVars']);
if (is_array($vars))
{
$allJsVarsUsed = array_merge($allJsVarsUsed,$vars);
}
if (!isset($rowdividList[$qid2exclusiveAuto['rowdivid']]))
{
$rowdividList[$qid2exclusiveAuto['rowdivid']] = true;
}
}
if (isset($LEM->qattr[$_qid]['exclude_all_others']))
{
Expand Down

0 comments on commit 65a4334

Please sign in to comment.