Skip to content

Commit

Permalink
Fixed issue #06238: array filtering does not work for Ranking questions
Browse files Browse the repository at this point in the history
  • Loading branch information
TMSWhite committed Jun 19, 2012
1 parent e976d61 commit f9a3589
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
35 changes: 23 additions & 12 deletions classes/expressions/LimeExpressionManager.php
Expand Up @@ -1059,6 +1059,17 @@ public function _CreateSubQLevelRelevanceAndValidationEqns($onlyThisQseq=NULL)
$cascadedAFE = array_reverse($cascadedAFE);

$subqs = $qinfo['subqs'];
if ($type == 'R') {
$subqs = array();
foreach ($this->qans[$qinfo['qid']] as $k=>$v)
{
$_code = explode('~',$k);
$subqs[] = array(
'rowdivid'=>$qinfo['sgqa'] . $_code[1],
'sqsuffix'=>'_' . $_code[1],
);
}
}
$last_rowdivid = '--';
foreach ($subqs as $sq) {
if ($sq['rowdivid'] == $last_rowdivid)
Expand All @@ -1083,6 +1094,7 @@ public function _CreateSubQLevelRelevanceAndValidationEqns($onlyThisQseq=NULL)
case 'P': //Multiple choice with comments checkbox + text
case 'K': //MULTIPLE NUMERICAL QUESTION
case 'Q': //MULTIPLE SHORT TEXT
case 'R': //Ranking
// if ($this->sgqaNaming)
// {
foreach ($cascadedAF as $_caf)
Expand Down Expand Up @@ -1481,7 +1493,7 @@ public function _CreateSubQLevelRelevanceAndValidationEqns($onlyThisQseq=NULL)
'qtype' => $type,
'type' => 'min_answers',
'class' => 'num_answers',
'eqn' => '(count(' . implode(', ', $sq_names) . ') >= (' . $min_answers . '))',
'eqn' => 'if(is_empty('.$min_answers.'),1,(count(' . implode(', ', $sq_names) . ') >= (' . $min_answers . ')))',
'qid' => $questionNum,
);
}
Expand Down Expand Up @@ -1567,7 +1579,7 @@ public function _CreateSubQLevelRelevanceAndValidationEqns($onlyThisQseq=NULL)
'qtype' => $type,
'type' => 'max_answers',
'class' => 'num_answers',
'eqn' => '(count(' . implode(', ', $sq_names) . ') <= (' . $max_answers . '))',
'eqn' => '(if(is_empty('.$max_answers.'),1,count(' . implode(', ', $sq_names) . ') <= (' . $max_answers . ')))',
'qid' => $questionNum,
);
}
Expand Down Expand Up @@ -6006,6 +6018,7 @@ static function GetRelevanceAndTailoringJavaScript()
* $afHide - if true, then use jQuery.show(). If false, then disable/enable the row
*/
$afHide = (isset($LEM->qattr[$arg['qid']]['array_filter_style']) ? ($LEM->qattr[$arg['qid']]['array_filter_style'] == '0') : true);
$inputSelector = (($arg['type'] == 'R') ? '' : ' :input:not(:hidden)');
foreach ($subqParts as $sq)
{
$rowdividList[$sq['rowdivid']] = $sq['result'];
Expand All @@ -6017,15 +6030,15 @@ static function GetRelevanceAndTailoringJavaScript()
}
else
{
$relParts[] = " $('#javatbd" . $sq['rowdivid'] . " :input:not(:hidden)').removeAttr('disabled');\n";
$relParts[] = " $('#javatbd" . $sq['rowdivid'] . "$inputSelector').removeAttr('disabled');\n";
}
if ($sq['isExclusiveJS'] != '')
{
$relParts[] = " if ( " . $sq['isExclusiveJS'] . " ) {\n";
$relParts[] = " $('#javatbd" . $sq['rowdivid'] . " :input:not(:hidden)').attr('disabled','disabled');\n";
$relParts[] = " $('#javatbd" . $sq['rowdivid'] . "$inputSelector').attr('disabled','disabled');\n";
$relParts[] = " }\n";
$relParts[] = " else {\n";
$relParts[] = " $('#javatbd" . $sq['rowdivid'] . " :input:not(:hidden)').removeAttr('disabled');\n";
$relParts[] = " $('#javatbd" . $sq['rowdivid'] . "$inputSelector').removeAttr('disabled');\n";
$relParts[] = " }\n";
}
$relParts[] = " relChange" . $arg['qid'] . "=true;\n";
Expand All @@ -6036,23 +6049,23 @@ static function GetRelevanceAndTailoringJavaScript()
if ($sq['irrelevantAndExclusiveJS'] != '')
{
$relParts[] = " if ( " . $sq['irrelevantAndExclusiveJS'] . " ) {\n";
$relParts[] = " $('#javatbd" . $sq['rowdivid'] . " :input:not(:hidden)').attr('disabled','disabled');\n";
$relParts[] = " $('#javatbd" . $sq['rowdivid'] . "$inputSelector').attr('disabled','disabled');\n";
$relParts[] = " }\n";
$relParts[] = " else {\n";
$relParts[] = " $('#javatbd" . $sq['rowdivid'] . " :input:not(:hidden)').removeAttr('disabled');\n";
$relParts[] = " $('#javatbd" . $sq['rowdivid'] . "$inputSelector').removeAttr('disabled');\n";
if ($afHide)
{
$relParts[] = " $('#javatbd" . $sq['rowdivid'] . "').hide();\n";
}
else
{
$relParts[] = " $('#javatbd" . $sq['rowdivid'] . " :input:not(:hidden)').attr('disabled','disabled');\n";
$relParts[] = " $('#javatbd" . $sq['rowdivid'] . "$inputSelector').attr('disabled','disabled');\n";
}
$relParts[] = " }\n";
}
else
{
$relParts[] = " $('#javatbd" . $sq['rowdivid'] . " :input:not(:hidden)').attr('disabled','disabled');\n";
$relParts[] = " $('#javatbd" . $sq['rowdivid'] . "$inputSelector').attr('disabled','disabled');\n";
}
}
else
Expand All @@ -6063,7 +6076,7 @@ static function GetRelevanceAndTailoringJavaScript()
}
else
{
$relParts[] = " $('#javatbd" . $sq['rowdivid'] . " :input:not(:hidden)').attr('disabled','disabled');\n";
$relParts[] = " $('#javatbd" . $sq['rowdivid'] . "$inputSelector').attr('disabled','disabled');\n";
}
}
$relParts[] = " relChange" . $arg['qid'] . "=true;\n";
Expand Down Expand Up @@ -8026,8 +8039,6 @@ static public function ShowSurveyLogicFile($sid, $gid=NULL, $qid=NULL,$LEMdebugL
$sgqa_len = strlen($sid . 'X'. $gid . 'X' . $qid);
$varName = $rootVarName . '_' . substr($_rowdivid,$sgqa_len);
}
case 'L':
// TODO - need to show array filters applied to lists
break;
}
if (is_null($rowdivid)) {
Expand Down
6 changes: 3 additions & 3 deletions common_functions.php
Expand Up @@ -3215,23 +3215,23 @@ function questionAttributes($returnByName=false)
"caption"=>$clang->gT('Answer width'));

$qattributes["array_filter"]=array(
"types"=>"1ABCEF:;MPLKQ",
"types"=>"1ABCEF:;MPLKQR",
'category'=>$clang->gT('Logic'),
'sortorder'=>100,
'inputtype'=>'text',
"help"=>$clang->gT("Enter the code(s) of Multiple choice question(s) (separated by semicolons) to only show the matching answer options in this question."),
"caption"=>$clang->gT('Array filter'));

$qattributes["array_filter_exclude"]=array(
"types"=>"1ABCEF:;MPLKQ",
"types"=>"1ABCEF:;MPLKQR",
'category'=>$clang->gT('Logic'),
'sortorder'=>100,
'inputtype'=>'text',
"help"=>$clang->gT("Enter the code(s) of Multiple choice question(s) (separated by semicolons) to exclude the matching answer options in this question."),
"caption"=>$clang->gT('Array filter exclusion'));

$qattributes["array_filter_style"]=array(
"types"=>"1ABCEF:;MPLKQ",
"types"=>"1ABCEF:;MPLKQR",
'category'=>$clang->gT('Logic'),
'sortorder'=>100,
'inputtype'=>'singleselect',
Expand Down

0 comments on commit f9a3589

Please sign in to comment.