Skip to content

Commit

Permalink
Fixed issue #06171: variable < X is true even if variable isn't answered
Browse files Browse the repository at this point in the history
Dev This now works automatically for authors who use the conditions editor
Dev To bulk-convert the entire database, call http://localhost/limesurvey/index.php/admin/expressions/upgrade_conditions2relevance
Dev Authors who manually enter relevance equations must pay more attention to the upgrade hints - http://docs.limesurvey.org/Upgrade+hints+for+version+1.92#Mathematical_comparisons_against_empty_no_responses
  • Loading branch information
TMSWhite committed Jun 5, 2012
1 parent 462912a commit 9a329a9
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 8 deletions.
22 changes: 22 additions & 0 deletions application/helpers/expressions/em_core_helper.php
Expand Up @@ -2569,6 +2569,17 @@ static function UnitTestEvaluator()
1~!0
0~(empty and 0)
0~(empty or 0)
<B>Empty_Var Vs. Zero</B>~"<B>Empty_Var Vs. Zero</B>"
0~empty == zero
1~empty != zero
0~empty > zero
0~empty >= zero
0~empty < zero
0~empty <= zero
1~!empty
1~!zero
0~(empty and zero)
0~(empty or zero)
<B>Empty_Var Vs. Constant</B>~"<B>Empty_Var Vs. Constant</B>"
0~empty == 3
1~empty != 3
Expand All @@ -2590,6 +2601,16 @@ static function UnitTestEvaluator()
0~!is_empty(empty) && (empty <= 0)
0~!is_empty(empty) && ((empty and 0))
0~!is_empty(empty) && ((empty or 0))
<B>Solution: Empty_Var Vs. Zero</B>~"<B>Solution: Empty_Var Vs. Zero</B>"
0~!is_empty(empty) && (empty == zero)
0~!is_empty(five) && (five == zero)
1~!is_empty(zero) && (zero == zero)
0~!is_empty(empty) && (empty > zero)
0~!is_empty(empty) && (empty >= zero)
0~!is_empty(empty) && (empty < zero)
0~!is_empty(empty) && (empty <= zero)
0~!is_empty(empty) && ((empty and zero))
0~!is_empty(empty) && ((empty or zero))
<B>Solution: Empty_Var Vs. Constant</B>~"<B>Solution: Empty_Var Vs. Constant</B>"
0~!is_empty(empty) && (empty < 3)
0~!is_empty(empty) && (empty <= 3)
Expand All @@ -2600,6 +2621,7 @@ static function UnitTestEvaluator()
1~(empty != 0)
1~!is_empty(empty) && (empty != 0)
1~is_empty(empty) || (empty != 0)
1~is_empty(empty) || (empty != zero)
0~is_empty(zero) || (zero != 0)
1~is_empty(five) || (five != 0)
<b>SETUP</b>~'<b>SETUP</b>'
Expand Down
51 changes: 43 additions & 8 deletions application/helpers/expressions/em_manager_helper.php
Expand Up @@ -791,6 +791,7 @@ public static function ConvertConditionsToRelevance($surveyId=NULL, $qid=NULL)
$relOrList = array();
foreach($query->readAll() as $row)
{
$row['method']=trim($row['method']); //For Postgres
if ($row['qid'] != $_qid)
{
// output the values for prior question is there was one
Expand Down Expand Up @@ -884,18 +885,52 @@ public static function ConvertConditionsToRelevance($surveyId=NULL, $qid=NULL)
{
// Conditions uses ' ' to mean not answered, but internally it is really stored as ''. Fix this
if ($value === '" "') {
if ($row['method'] == '==') {
if ($row['method'] == '==')
{
$relOrList[] = "is_empty(" . $fieldname . ")";
}
else if ($row['method'] == '!=') {
$relOrList[] = "!is_empty(" . $fieldname . ")";
}
else {
$relOrList[] = $fieldname . " " . $row['method'] . " " . $value;
else if ($row['method'] == '!=')
{
$relOrList[] = "!is_empty(" . $fieldname . ")";
}
else
{
$relOrList[] = $fieldname . " " . $row['method'] . " " . $value;
}
}
else {
$relOrList[] = $fieldname . " " . $row['method'] . " " . $value;
else
{
if ($value == '"0"' || !preg_match('/^".+"$/',$value))
{
switch ($row['method'])
{
case '==':
case '<':
case '<=':
case '>=':
$relOrList[] = '(!is_empty(' . $fieldname . ') && (' . $fieldname . " " . $row['method'] . " " . $value . '))';
break;
case '!=':
$relOrList[] = '(is_empty(' . $fieldname . ') || (' . $fieldname . " != " . $value . '))';
break;
default:
$relOrList[] = $fieldname . " " . $row['method'] . " " . $value;
break;
}
}
else
{
switch ($row['method'])
{
case '<':
case '<=':
$relOrList[] = '(!is_empty(' . $fieldname . ') && (' . $fieldname . " " . $row['method'] . " " . $value . '))';
break;
default:
$relOrList[] = $fieldname . " " . $row['method'] . " " . $value;
break;
}
}
}
}

Expand Down

0 comments on commit 9a329a9

Please sign in to comment.