Skip to content

Commit

Permalink
Fixed issue #7286: Relevance Equation Problem with Ranking Question
Browse files Browse the repository at this point in the history
Dev: Ranking filter array filter the answer, not the SUBQ
Dev: Tested with: array filter for rankning and array filter by ranking with answer code to 1,2,3
Dev: when make modification, remove a warning " Invalid argument supplied for foreach()" in em_manager_helper.php(3835): Quick fix
  • Loading branch information
Shnoulle committed Feb 18, 2013
1 parent c3ac848 commit 7138d9c
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 41 deletions.
75 changes: 40 additions & 35 deletions application/helpers/expressions/em_manager_helper.php
Expand Up @@ -3831,53 +3831,55 @@ static function GetAllVarNamesForQ($qseq,$varname)
$sqpatt = implode('|',$sqpatts);
$nosqpatt = implode('|',$nosqpatts);
$vars = array();

foreach ($LEM->knownVars as $kv)
if(isset($LEM->knownVars))
{
if ($type == 'self')
{
if (!isset($kv['qseq']) || $kv['qseq'] != $qseq || trim($kv['sgqa']) == '')
{
continue;
}
}
else
foreach ($LEM->knownVars as $kv)
{
if (!isset($kv['rootVarName']) || $kv['rootVarName'] != $qroot)
if ($type == 'self')
{
continue;
if (!isset($kv['qseq']) || $kv['qseq'] != $qseq || trim($kv['sgqa']) == '')
{
continue;
}
}
}
if ($comments != '')
{
if ($comments == 'Y' && !preg_match('/comment$/',$kv['sgqa']))
else
{
continue;
if (!isset($kv['rootVarName']) || $kv['rootVarName'] != $qroot)
{
continue;
}
}
if ($comments == 'N' && preg_match('/comment$/',$kv['sgqa']))
if ($comments != '')
{
continue;
if ($comments == 'Y' && !preg_match('/comment$/',$kv['sgqa']))
{
continue;
}
if ($comments == 'N' && preg_match('/comment$/',$kv['sgqa']))
{
continue;
}
}
}
$sgq = $LEM->sid . 'X' . $kv['gid'] . 'X' . $kv['qid'];
$ext = substr($kv['sgqa'],strlen($sgq));
$sgq = $LEM->sid . 'X' . $kv['gid'] . 'X' . $kv['qid'];
$ext = substr($kv['sgqa'],strlen($sgq));

if ($sqpatt != '')
{
if (!preg_match('/'.$sqpatt.'/',$ext))
if ($sqpatt != '')
{
continue;
if (!preg_match('/'.$sqpatt.'/',$ext))
{
continue;
}
}
}
if ($nosqpatt != '')
{
if (preg_match('/'.$nosqpatt.'/',$ext))
if ($nosqpatt != '')
{
continue;
if (preg_match('/'.$nosqpatt.'/',$ext))
{
continue;
}
}
}

$vars[] = $kv['sgqa'] . $suffix;
$vars[] = $kv['sgqa'] . $suffix;
}
}
if (count($vars) > 0)
{
Expand Down Expand Up @@ -6219,8 +6221,10 @@ static function GetRelevanceAndTailoringJavaScript()
$relParts[] = " $('#javatbd" . $sq['rowdivid'] . "$inputSelector').removeAttr('disabled');\n";
$relParts[] = " }\n";
}
$test=var_export ($arg,true);
$relParts[] = " relChange" . $arg['qid'] . "=true;\n";
$relParts[] = " $('#relevance" . $sq['rowdivid'] . "').val('1');\n";
if($arg['type']!='R') // Ranking: rowdivid are subquestion, but array filter apply to answers and not SQ.
$relParts[] = " $('#relevance" . $sq['rowdivid'] . "').val('1');\n";
$relParts[] = " }\n else {\n";
if ($sq['isExclusiveJS'] != '')
{
Expand Down Expand Up @@ -6258,7 +6262,8 @@ static function GetRelevanceAndTailoringJavaScript()
}
}
$relParts[] = " relChange" . $arg['qid'] . "=true;\n";
$relParts[] = " $('#relevance" . $sq['rowdivid'] . "').val('');\n";
if($arg['type']!='R') // Ranking: rowdivid are subquestion, but array filter apply to answers and not SQ.
$relParts[] = " $('#relevance" . $sq['rowdivid'] . "').val('');\n";
switch ($sq['qtype'])
{
case 'L': //LIST drop-down/radio-button list
Expand Down
2 changes: 1 addition & 1 deletion application/helpers/qanda_helper.php
Expand Up @@ -2144,7 +2144,7 @@ function do_ranking($ia)
$answer .="</ul>"
. "<div style='display:none' id='ranking-{$ia[0]}-maxans'>{".$max_answers."}</div>"
. "<div style='display:none' id='ranking-{$ia[0]}-minans'>{".$min_answers."}</div>"
. "<div style='display:none' id='ranking-{$ia[0]}-name'>javatbd".$ia[1]."</div>"
. "<div style='display:none' id='ranking-{$ia[0]}-name'>".$ia[1]."</div>"
. "</div>";
// The list with HTML answres
$answer .="<div style=\"display:none\">";
Expand Down
21 changes: 16 additions & 5 deletions scripts/ranking.js
Expand Up @@ -4,7 +4,7 @@ function doDragDropRank(qID, showpopups, samechoiceheight, samelistheight) {
if (typeof samechoiceheight === 'undefined'){samechoiceheight=true;}
if (typeof samelistheight === 'undefined'){ samelistheight=true;}
var maxanswers= parseInt($("#ranking-"+qID+"-maxans").text(),10);
var rankingname= $("#ranking-"+qID+"-name").text();
var rankingname= "javatbd"+$("#ranking-"+qID+"-name").text();
var rankingnamewidth=rankingname.length;
//Add a class to the question
$('#question'+qID+'').addClass('dragDropRanking');
Expand Down Expand Up @@ -102,7 +102,8 @@ function doDragDropRank(qID, showpopups, samechoiceheight, samelistheight) {

function updateDragDropRank(qID){
var maxanswers= parseInt($("#ranking-"+qID+"-maxans").text(),10);
var rankingname= $("#ranking-"+qID+"-name").text();
var rankingname= "javatbd"+$("#ranking-"+qID+"-name").text();
var relevancename= "relevance"+$("#ranking-"+qID+"-name").text();
var rankingnamewidth=rankingname.length;
$('#question'+qID+' .select-item select').val('');
$('#sortable-rank-'+qID+' li').each(function(index) {
Expand All @@ -111,7 +112,11 @@ function updateDragDropRank(qID){
liValue = liID.substr(rankingnamewidth);
$('#question'+qID+' .select-item select').eq(index).val(liValue);
});
$('#question'+qID+' .select-item select').each(function(){
// Update #relevance and lauch checkconditions function
$("[id^=" + relevancename + "]").val('0');
$('#question'+qID+' .select-item select').each(function(index){
number=index+1;
if($(this).val()!=""){$("#"+relevancename+number).val("1");}
checkconditions($(this).val(),$(this).attr("name"),'select-one','onchange');
});
$('#sortable-rank-'+qID+' li').removeClass("error");
Expand All @@ -128,13 +133,19 @@ function sortableAlert (qID,showpopups)
}
function loadDragDropRank(qID){
var maxanswers= parseInt($("#ranking-"+qID+"-maxans").text(),10);
var rankingname= $("#ranking-"+qID+"-name").text();
var rankingname= "javatbd"+$("#ranking-"+qID+"-name").text();
var relevancename= "relevance"+$("#ranking-"+qID+"-name").text();
var rankingnamewidth=rankingname.length;
$('#question'+qID+' .select-item select').each(function(){
// Update #relevance
$("[id^=" + relevancename + "]").val('0');
$('#question'+qID+' .select-item select').each(function(index){
if($(this).val()!=''){
number=index+1;
$("#"+relevancename+number).val("1");
$('#sortable-choice-'+qID+' li#'+rankingname+$(this).val()).appendTo('#sortable-rank-'+qID);
}
});

$('#sortable-rank-'+qID+' li').removeClass("error");
$('#sortable-choice-'+qID+' li').removeClass("error");
$('#sortable-rank-'+qID+' li:gt('+(maxanswers*1-1)+')').addClass("error");
Expand Down

2 comments on commit 7138d9c

@c-schmitz
Copy link
Contributor

Choose a reason for hiding this comment

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

Great work!

@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.

Maybe, but again an EM exception. Hardly think is to find the problem.

Maybe need for Plugins a updateRelevance and an updateRelevanceSQ function.

Please sign in to comment.