Skip to content

Commit

Permalink
Fixed issue #14899: Incorrect behavior with Question of type R (Ranking)
Browse files Browse the repository at this point in the history
Dev: get the min between answer count and columns count
  • Loading branch information
Shnoulle committed May 16, 2019
1 parent 20cff4d commit 8cdcaae
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
1 change: 1 addition & 0 deletions application/helpers/common_helper.php
Expand Up @@ -1775,6 +1775,7 @@ function createFieldMap($survey, $style = 'short', $force_refresh = false, $ques
$answersCount = intval(Answer::model()->countByAttributes(array('qid' => $arow['qid'], 'language' => $sLanguage)));
$maxDbAnswer = QuestionAttribute::model()->find("qid = :qid AND attribute = 'max_subquestions'", array(':qid' => $arow['qid']));
$columnsCount = (!$maxDbAnswer || intval($maxDbAnswer->value) < 1) ? $answersCount : intval($maxDbAnswer->value);
$columnsCount = min($columnsCount,$answersCount); // Can not be upper than current answers #14899
for ($i = 1; $i <= $columnsCount; $i++) {
$fieldname = "{$arow['sid']}X{$arow['gid']}X{$arow['qid']}$i";
if (isset($fieldmap[$fieldname])) {
Expand Down
18 changes: 8 additions & 10 deletions application/helpers/expressions/em_manager_helper.php
Expand Up @@ -2171,17 +2171,15 @@ public function _CreateSubQLevelRelevanceAndValidationEqns($onlyThisQseq=NULL)
{
$max_subquestions=intval($qattr['max_subquestions']);
// We don't have another answer count in EM ?
$answerCount=Answer::model()->count("qid=:qid and language=:language",array(":qid"=>$questionNum,'language'=>$_SESSION['LEMlang']));
if($max_subquestions < $answerCount)
$answerCount = Answer::model()->count("qid=:qid and language=:language",array(":qid"=>$questionNum,'language'=>$_SESSION['LEMlang']));
$max_subquestions = min($max_subquestions,$answerCount); // Can not be upper than current answers #14899
if($max_answers!='')
{
if($max_answers!='')
{
$max_answers='min('.$max_answers.','.$max_subquestions.')';
}
else
{
$max_answers=intval($qattr['max_subquestions']);
}
$max_answers='min('.$max_answers.','.$max_subquestions.')';
}
else
{
$max_answers= $max_subquestions;
}
}
// Fix min_num_value_n and max_num_value_n for multinumeric with slider: see bug #7798
Expand Down
7 changes: 2 additions & 5 deletions application/helpers/qanda_helper.php
Expand Up @@ -1815,12 +1815,9 @@ function do_ranking($ia)
$ansresult = Yii::app()->db->createCommand($ansquery)->query()->readAll();
$anscount = count($ansresult);
$max_subquestions = intval($aQuestionAttributes['max_subquestions']) > 0 ? intval($aQuestionAttributes['max_subquestions']) : $anscount;
$max_subquestions = min($max_subquestions,$anscount); // Can not be upper than current answers #14899
if (trim($aQuestionAttributes["max_answers"]) != '') {
if ($max_subquestions < $anscount) {
$max_answers = "min(".trim($aQuestionAttributes["max_answers"]).",".$max_subquestions.")";
} else {
$max_answers = trim($aQuestionAttributes["max_answers"]);
}
$max_answers = "min(".trim($aQuestionAttributes["max_answers"]).",".$max_subquestions.")";
} else {
$max_answers = $max_subquestions;
}
Expand Down
Expand Up @@ -681,6 +681,7 @@
$answersCount = count($result[$key1]);
$maxDbAnswer=QuestionAttribute::model()->find("qid = :qid AND attribute = 'max_subquestions'",array(':qid' => $flt[0]));
$columnsCount=(!$maxDbAnswer || intval($maxDbAnswer->value)<1) ? $answersCount : intval($maxDbAnswer->value); // If max_subquestions is not set or is invalid : get the answer count
$columnsCount = min($columnsCount,$answersCount); // Can not be upper than current answers #14899
//lets put the answer code and text into the answers array
foreach($result[$key1] as $row)
{
Expand Down

0 comments on commit 8cdcaae

Please sign in to comment.