Skip to content

Commit

Permalink
Fixed issue #18358: Statistics filter feature is not working properly (
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrieljenik committed Oct 24, 2022
1 parent eaa827c commit 9cd57df
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions application/helpers/admin/statistics_helper.php
Expand Up @@ -335,6 +335,8 @@ function buildSelects($allfields, $surveyid, $language)
$postvars[] = $key;
}

$responseModel = SurveyDynamic::model($surveyid);

/*
* Iterate through postvars to create "nice" data for SQL later.
*
Expand Down Expand Up @@ -381,7 +383,7 @@ function buildSelects($allfields, $surveyid, $language)

$db = Yii::app()->db;
foreach ($_POST[$pv] as $condition) {
$thisquestion .= "{$db->quoteValue($condition)}, ";
$thisquestion .= Yii::app()->db->quoteValue(getEncryptedCondition($responseModel, $pv, $condition)) . ", ";
}

$thisquestion = substr($thisquestion, 0, -2)
Expand All @@ -402,7 +404,8 @@ function buildSelects($allfields, $surveyid, $language)
foreach ($aresult as $arow) {
// only add condition if answer has been chosen
if (in_array($arow['title'], $_POST[$pv])) {
$mselects[] = Yii::app()->db->quoteColumnName(substr($pv, 1, strlen($pv)) . $arow['title']) . " = 'Y'";
$fieldname = substr($pv, 1, strlen($pv)) . $arow['title'];
$mselects[] = Yii::app()->db->quoteColumnName($fieldname) . " = " . Yii::app()->db->quoteValue(getEncryptedCondition($responseModel, $fieldname, 'Y'));
}
}
/* If there are mutliple conditions generated from this multiple choice question, join them using the boolean "OR" */
Expand Down Expand Up @@ -533,6 +536,13 @@ function square($number)
return $squarenumber;
}

function getEncryptedCondition($responseModel, $attribute, $value)
{
$attributes = [$attribute => $value];
$attributes = $responseModel->encryptAttributeValues($attributes);
return $attributes[$attribute] ?? $value;
}

class statistics_helper
{
/**
Expand Down

0 comments on commit 9cd57df

Please sign in to comment.