Skip to content

Commit

Permalink
Fixed issue #06173: users can skip min_sum_value and equals_sum_value…
Browse files Browse the repository at this point in the history
… questions

Dev added 'value_range_allows_missing' attribute to let authors decide whether users must answer questions with min_sum_value and/or equals_sum_value
  • Loading branch information
TMSWhite committed Jun 6, 2012
1 parent 9e48667 commit f8ea028
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
15 changes: 15 additions & 0 deletions application/helpers/common_helper.php
Expand Up @@ -4110,6 +4110,21 @@ function questionAttributes($returnByName=false)
"help"=>$clang->gT("Place questions into a specified randomization group, all questions included in the specified group will appear in a random order"),
"caption"=>$clang->gT("Randomization group name"));

// This is added to support historical behavior. Early versions of 1.92 used a value of "No", so if there was a min_sum_value or equals_sum_value, the question was not valid
// unless those criteria were met. In later releases of 1.92, the default was changed so that missing values were allowed even if those attributes were set
// This attribute lets authors control whether missing values should be allowed in those cases without needing to set min_answers
// Existing surveys will use the old behavior, but if the author edits the question, the default will be the new behavior.
$qattributes["value_range_allows_missing"]=array(
"types"=>"K",
'category'=>$clang->gT('Input'),
'sortorder'=>100,
"inputtype"=>"singleselect",
'options'=>array(0=>$clang->gT('No'),
1=>$clang->gT('Yes')),
'default'=>1,
"help"=>$clang->gT("Is no answer (missing) allowed when either 'Equals sum value' or 'Minimum sum value' are set?"),
"caption"=>$clang->gT("Value range allows missing"));

//This builds a more useful array (don't modify)
if ($returnByName==false)
{
Expand Down
35 changes: 32 additions & 3 deletions application/helpers/expressions/em_manager_helper.php
Expand Up @@ -473,6 +473,7 @@ class LimeExpressionManager {
* 'type' => 'M' // the one-letter question type
* 'fieldname' => '26626X34X702sq1' // the fieldname (used as JavaScript variable name, and also as database column name
* 'rootVarName' => 'afDS' // the root variable name
* 'preg' => '/[A-Z]+/' // regular expression validation equation, if any
* 'subqs' => array() of sub-questions, where each contains:
* 'rowdivid' => '26626X34X702sq1' // the javascript id identifying the question row (so array_filter can hide rows)
* 'varName' => 'afSrcFilter_sq1' // the full variable name for the sub-question
Expand Down Expand Up @@ -1017,6 +1018,15 @@ public function _CreateSubQLevelRelevanceAndValidationEqns($onlyThisQseq=NULL)
$input_boxes='';
}

if (isset($qattr['value_range_allows_missing']) && $qattr['value_range_allows_missing'] == '1')
{
$value_range_allows_missing = true;
}
else
{
$value_range_allows_missing = false;
}

// array_filter
// If want to filter question Q2 on Q1, where each have subquestions SQ1-SQ3, this is equivalent to relevance equations of:
// relevance for Q2_SQ1 is Q1_SQ1!=''
Expand Down Expand Up @@ -1205,11 +1215,18 @@ public function _CreateSubQLevelRelevanceAndValidationEqns($onlyThisQseq=NULL)
$sumRemainingEqn = 'round(' . $sumRemainingEqn . ', ' . $precision . ')';
$mainEqn = 'round(' . $mainEqn . ', ' . $precision . ')';
}

$noanswer_option = '';
if ($value_range_allows_missing)
{
$noanswer_option = ' || count(' . implode(', ', $sq_names) . ') == 0';
}

$validationEqn[$questionNum][] = array(
'qtype' => $type,
'type' => 'equals_num_value',
'class' => 'sum_range',
'eqn' => ($qinfo['mandatory']=='Y')?'(' . $mainEqn . ' == (' . $equals_num_value . '))':'(' . $mainEqn . ' == (' . $equals_num_value . ') || count(' . implode(', ', $sq_names) . ') == 0)',
'eqn' => ($qinfo['mandatory']=='Y')?'(' . $mainEqn . ' == (' . $equals_num_value . '))':'(' . $mainEqn . ' == (' . $equals_num_value . ')' . $noanswer_option . ')',
'qid' => $questionNum,
'sumEqn' => $sumEqn,
'sumRemainingEqn' => $sumRemainingEqn,
Expand Down Expand Up @@ -1718,11 +1735,17 @@ public function _CreateSubQLevelRelevanceAndValidationEqns($onlyThisQseq=NULL)
$sumEqn = 'round(' . $sumEqn . ', ' . $precision . ')';
}

$noanswer_option = '';
if ($value_range_allows_missing)
{
$noanswer_option = ' || count(' . implode(', ', $sq_names) . ') == 0';
}

$validationEqn[$questionNum][] = array(
'qtype' => $type,
'type' => 'min_num_value',
'class' => 'sum_range',
'eqn' => '(sum(' . implode(', ', $sq_names) . ') >= (' . $min_num_value . ') || count(' . implode(', ', $sq_names) . ') == 0)',
'eqn' => '(sum(' . implode(', ', $sq_names) . ') >= (' . $min_num_value . ')' . $noanswer_option . ')',
'qid' => $questionNum,
'sumEqn' => $sumEqn,
);
Expand Down Expand Up @@ -1776,11 +1799,17 @@ public function _CreateSubQLevelRelevanceAndValidationEqns($onlyThisQseq=NULL)
$sumEqn = 'round(' . $sumEqn . ', ' . $precision . ')';
}

$noanswer_option = '';
if ($value_range_allows_missing)
{
$noanswer_option = ' || count(' . implode(', ', $sq_names) . ') == 0';
}

$validationEqn[$questionNum][] = array(
'qtype' => $type,
'type' => 'max_num_value',
'class' => 'sum_range',
'eqn' => '(sum(' . implode(', ', $sq_names) . ') <= (' . $max_num_value . ') || count(' . implode(', ', $sq_names) . ') == 0)',
'eqn' => '(sum(' . implode(', ', $sq_names) . ') <= (' . $max_num_value . ')' . $noanswer_option . ')',
'qid' => $questionNum,
'sumEqn' => $sumEqn,
);
Expand Down

0 comments on commit f8ea028

Please sign in to comment.