From 90810b8f7266259135e0374c1c2c12363cdcc975 Mon Sep 17 00:00:00 2001 From: GabrielJenik Date: Fri, 14 Aug 2020 15:32:04 -0300 Subject: [PATCH] Fixed issue #15980: No results shown for selected date questions at statistics - Date/Time responses are treated as "Answer" when the value is not null, and "No answer" when it's null. - Equation questions are handled as text. It seems they always have a value, so "Not displayed" may always be 0. - Condition had to be updated as to work with dates. It may have an impact on some DB engine (not sure). --- .../helpers/admin/statistics_helper.php | 73 ++++++++++++++++--- .../export/statistics_subviews/_question.php | 3 +- 2 files changed, 64 insertions(+), 12 deletions(-) diff --git a/application/helpers/admin/statistics_helper.php b/application/helpers/admin/statistics_helper.php index 99206e9b390..20762fc124e 100644 --- a/application/helpers/admin/statistics_helper.php +++ b/application/helpers/admin/statistics_helper.php @@ -444,6 +444,7 @@ function buildSelects($allfields, $surveyid, $language) //T - Long Free Text //Q - Multiple Short Text + //Equations are also included here (firstletter = T) elseif (($firstletter == "T" || $firstletter == "Q") && $_POST[$pv] != "") { $selectSubs = array(); //We intepret and * and % as wildcard matches, and use ' OR ' and , as the separators @@ -1122,17 +1123,32 @@ protected function buildOutputList($rt, $language, $surveyid, $outputType, $sql, } //end else-if -> multiple numerical types - //is there some "id", "datestamp" or "D" within the type? - elseif (substr($rt, 0, 2) == "id" || substr($rt, 0, 9) == "datestamp" || ($firstletter == "D")) { + //is there some "id" or "datestamp" within the type? + elseif (substr($rt, 0, 2) == "id" || substr($rt, 0, 9) == "datestamp") { /* - * DON'T show anything for date questions - * because there aren't any statistics implemented yet! - * - * See bug report #2539 and - * feature request #2620 + * DON'T show anything */ } + //D - Date/Time + elseif ($firstletter == "D") { + //search for key + $fld = substr($rt, 1, strlen($rt)); + $fielddata = $fieldmap[$fld]; + + //get question data + $nresult = Question::model()->find('language=:language AND parent_qid=0 AND qid=:qid', array(':language'=>$language, ':qid'=>$fielddata['qid'])); + $qtitle = $nresult->title; + $qtype = $nresult->type; + $qquestion = flattenText($nresult->question); + + $mfield = substr($rt, 1, strlen($rt)); + + //Date/time questions are handled the same way as text questions. + $alist[] = array("Answer", gT("Answer"), $mfield); + $alist[] = array("NoAnswer", gT("No answer"), $mfield); + } + // NICE SIMPLE SINGLE OPTION ANSWERS /* TO DEBUG QUESTION TYPES FIRSTLETTER, UNCOMMENT THOSE LINES @@ -2261,11 +2277,46 @@ protected function displayResults($outputs, $results, $rt, $outputType, $surveyi $query = "SELECT count(*) FROM {{survey_$surveyid}} WHERE ( "; $query .= ($sDatabaseType == "mysql") ? Yii::app()->db->quoteColumnName($al[2])." = '')" : " (".Yii::app()->db->quoteColumnName($al[2])." LIKE ''))"; } + } + /* + * Date/Time question + */ + elseif ($outputs['qtype'] == "D") { + $sDatabaseType = Yii::app()->db->getDriverName(); + + // Date answers + if ($al[0] == "Answer") { + $query = "SELECT count(*) FROM {{survey_$surveyid}} WHERE "; + $query .= Yii::app()->db->quoteColumnName($al[2])." IS NOT NULL"; + } + //"no answer" handling + elseif ($al[0] == "NoAnswer") { + $query = "SELECT count(*) FROM {{survey_$surveyid}} WHERE "; + $query .= Yii::app()->db->quoteColumnName($al[2])." IS NULL"; + } } elseif ($outputs['qtype'] == "O") { $query = "SELECT count(*) FROM {{survey_$surveyid}} WHERE ( "; $query .= ($sDatabaseType == "mysql") ? Yii::app()->db->quoteColumnName($al[2])." <> '')" : " (".Yii::app()->db->quoteColumnName($al[2])." NOT LIKE ''))"; - // all other question types - } else { + } + /* + * Equation + */ + elseif ($outputs['qtype'] == "*") { + $sDatabaseType = Yii::app()->db->getDriverName(); + + // Equation with non empty result + if ($al[0] == "Answer") { + $query = "SELECT count(*) FROM {{survey_$surveyid}} WHERE "; + $query .= ($sDatabaseType == "mysql") ? Yii::app()->db->quoteColumnName($al[2])." != ''" : "NOT (".Yii::app()->db->quoteColumnName($al[2])." LIKE '')"; + } + //"no answer" handling + elseif ($al[0] == "NoAnswer") { + $query = "SELECT count(*) FROM {{survey_$surveyid}} WHERE ( "; + $query .= ($sDatabaseType == "mysql") ? Yii::app()->db->quoteColumnName($al[2])." = '')" : " (".Yii::app()->db->quoteColumnName($al[2])." LIKE ''))"; + } + } + // all other question types + else { $query = "SELECT count(*) FROM {{survey_$surveyid}} WHERE ".Yii::app()->db->quoteColumnName($al[2])." ="; @@ -4241,10 +4292,10 @@ protected function getQuartile($quartile, $fieldname, $surveyid, $sql, $excludez */ function _listcolumn($surveyid, $column, $sortby = "", $sortmethod = "", $sorttype = "") { - $search['condition'] = Yii::app()->db->quoteColumnName($column)." != ''"; + $search['condition'] = "COALESCE(CAST(".Yii::app()->db->quoteColumnName($column)." as char), '') != ''"; $sDBDriverName = Yii::app()->db->getDriverName(); if ($sDBDriverName == 'sqlsrv' || $sDBDriverName == 'mssql' || $sDBDriverName == 'dblib') { - $search['condition'] = "CAST(".Yii::app()->db->quoteColumnName($column)." as varchar) != ''"; + $search['condition'] = "COALESCE(CAST(".Yii::app()->db->quoteColumnName($column)." as varchar), '') != ''"; } //filter incomplete answers if set diff --git a/application/views/admin/export/statistics_subviews/_question.php b/application/views/admin/export/statistics_subviews/_question.php index 9f3ff0aa6ad..116f2f32e96 100644 --- a/application/views/admin/export/statistics_subviews/_question.php +++ b/application/views/admin/export/statistics_subviews/_question.php @@ -135,9 +135,11 @@ /* * all "free text" types (T, U, S) get the same prefix ("T") + * Equations are treated the same way */ case "T": // Long free text case "U": // Huge free text + case '*': // Equation echo '
'; $myfield2="T$myfield"; echo "\t no analysis needed case "X": //This is a boilerplate question and it has no business in this script - case '*': // EQUATION echo '

'.$oStatisticsHelper::_showSpeaker($niceqtext).'


'; eT("This question type can't be selected."); break;