Skip to content

Commit

Permalink
Fixed issue #7762: Incorrect graph for List(Radio) with Comment
Browse files Browse the repository at this point in the history
  • Loading branch information
c-schmitz committed May 10, 2013
1 parent 84093ba commit 235143e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
9 changes: 5 additions & 4 deletions application/controllers/admin/statistics.php
Expand Up @@ -530,7 +530,8 @@ function graph()
// Strip first char when not numeric (probably T or D)
$qsid=substr($qsid,1);
}
$qtype = substr($_POST['id'], 0, 1);
$oQuestion=Questions::model()->findByAttributes(array('qid'=>$qqid,'language'=>$sStatisticsLanguage));
$qtype = $oQuestion->type;
$aattr = getQuestionAttributeValues($qqid);
$field = substr($_POST['id'], 1);

Expand Down Expand Up @@ -570,7 +571,7 @@ function graph()
$bChartType = $qtype != "M" && $qtype != "P" && $aattr["statistics_graphtype"] == "1";

$adata = Yii::app()->session['stats'][$_POST['id']];
$aData['chartdata'] = createChart($qqid, $qsid, $bChartType, $adata['lbl'], $adata['gdata'], $adata['grawdata'], $MyCache, $oStatisticsLanguage);
$aData['chartdata'] = createChart($qqid, $qsid, $bChartType, $adata['lbl'], $adata['gdata'], $adata['grawdata'], $MyCache, $oStatisticsLanguage, $qtype);


QuestionAttribute::model()->setAttribute($qqid, 'statistics_showgraph', 1);
Expand All @@ -587,7 +588,7 @@ function graph()
QuestionAttribute::model()->setAttribute($qqid, 'statistics_graphtype', 0);

$adata = Yii::app()->session['stats'][$_POST['id']];
$aData['chartdata'] = createChart($qqid, $qsid, 0, $adata['lbl'], $adata['gdata'], $adata['grawdata'], $MyCache, $oStatisticsLanguage);
$aData['chartdata'] = createChart($qqid, $qsid, 0, $adata['lbl'], $adata['gdata'], $adata['grawdata'], $MyCache, $oStatisticsLanguage, $qtype);

break;
case 'showpie':
Expand All @@ -600,7 +601,7 @@ function graph()
QuestionAttribute::model()->setAttribute($qqid, 'statistics_graphtype', 1);

$adata = Yii::app()->session['stats'][$_POST['id']];
$aData['chartdata'] = createChart($qqid, $qsid, 1, $adata['lbl'], $adata['gdata'], $adata['grawdata'], $MyCache, $oStatisticsLanguage);
$aData['chartdata'] = createChart($qqid, $qsid, 1, $adata['lbl'], $adata['gdata'], $adata['grawdata'], $MyCache, $oStatisticsLanguage, $qtype);


break;
Expand Down
9 changes: 5 additions & 4 deletions application/helpers/admin/statistics_helper.php
Expand Up @@ -22,9 +22,10 @@
* @param mixed $gdata An array containing the percentages for the chart items
* @param mixed $grawdata An array containing the raw count for the chart items
* @param mixed $cache An object containing [Hashkey] and [CacheFolder]
* @param string $sQuestionType The question type
* @return Name
*/
function createChart($iQuestionID, $iSurveyID, $type=null, $lbl, $gdata, $grawdata, $cache, $oLanguage)
function createChart($iQuestionID, $iSurveyID, $type=null, $lbl, $gdata, $grawdata, $cache, $oLanguage, $sQuestionType)
{
/* This is a lazy solution to bug #6389. A better solution would be to find out how
the "T" gets passed to this function from the statistics.js file in the first place! */
Expand Down Expand Up @@ -207,10 +208,10 @@ function createChart($iQuestionID, $iSurveyID, $type=null, $lbl, $gdata, $grawda
// this block is to remove the items with value == 0
// and an inelegant way to remove comments from List with Comments questions
$i = 0;
$aHelperArray=array_keys($lbl);
while (isset ($gdata[$i]))
{
if ($gdata[$i] == 0 || ($type == "O" && substr($aHelperArray[$i],0,strlen($oLanguage->gT("Comments")))==$oLanguage->gT("Comments")))
$aHelperArray=array_keys($lbl);
if ($gdata[$i] == 0 || ($sQuestionType == "O" && substr($aHelperArray[$i],0,strlen($oLanguage->gT("Comments")))==$oLanguage->gT("Comments")))
{
array_splice ($gdata, $i, 1);
array_splice ($lbl, $i, 1);
Expand Down Expand Up @@ -2963,7 +2964,7 @@ protected function displayResults($outputs, $results, $rt, $outputType, $surveyi

if (array_sum($gdata)>0 && $bShowGraph == true)
{
$cachefilename = createChart($qqid, $qsid, $bShowPieChart, $lbl, $gdata, $grawdata, $MyCache, $statlang);
$cachefilename = createChart($qqid, $qsid, $bShowPieChart, $lbl, $gdata, $grawdata, $MyCache, $statlang, $outputs['qtype']);
//introduce new counter
if (!isset($ci)) {$ci=0;}

Expand Down

0 comments on commit 235143e

Please sign in to comment.