Skip to content

Commit

Permalink
Dev: Simple stats various fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisGac committed Jan 14, 2016
1 parent 8a09aaa commit 23465d8
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 74 deletions.
12 changes: 10 additions & 2 deletions application/controllers/admin/statistics.php
Expand Up @@ -654,7 +654,7 @@ function graph()
/**
* Render satistics for users
*/
public function publicStatistics($surveyid)
public function simpleStatistics($surveyid)
{
$iSurveyId = sanitize_int($surveyid);
$aData['surveyid'] = $iSurveyId;
Expand Down Expand Up @@ -682,7 +682,15 @@ public function publicStatistics($surveyid)
// $summary[]=$surveyid.'X'.$question->gid.'X'.$question->qid;
foreach($rows as $row)
{
$summary[] = $iSurveyId.'X'.$row['gid'].'X'.$row['qid'];
$type=$row['type'];
if($type=="M" || $type=="P" || $type=="T" || $type=="S" || $type=="Q" || $type=="R" || $type=="|" || $type=="" || $type=="N" || $type=="K" || $type=="D")
{
$summary[] = $type.$iSurveyId.'X'.$row['gid'].'X'.$row['qid'];
}
else // single question
{
$summary[] = $iSurveyId.'X'.$row['gid'].'X'.$row['qid'];
}
}


Expand Down
124 changes: 52 additions & 72 deletions application/helpers/admin/statistics_helper.php
Expand Up @@ -640,6 +640,7 @@ protected function buildOutputList($rt, $language, $surveyid, $outputType, $sql,
$qtype="";
$statlang = $oLanguage;
$firstletter = substr($rt, 0, 1);
var_dump($firstletter);
$fieldmap=createFieldMap($surveyid, "full", false, false, $language);
$sDatabaseType = Yii::app()->db->getDriverName();
$statisticsoutput="";
Expand Down Expand Up @@ -1236,7 +1237,11 @@ protected function buildOutputList($rt, $language, $surveyid, $outputType, $sql,
}

// NICE SIMPLE SINGLE OPTION ANSWERS
elseif(isset($fieldmap[$rt]))
elseif(!isset($fieldmap[$rt]))
{
//echo "problem, wrong question type for $rt ; $firstletter"; die();
}
else
{
//search for key
//var_dump($firstletter); die();
Expand Down Expand Up @@ -2369,88 +2374,64 @@ protected function displaySimpleResults($outputs, $results, $rt, $outputType, $s
$cachefilename = createChart($qqid, $qsid, $bShowPieChart, $lbl, $gdata, $grawdata, $MyCache, $sLanguage, $outputs['qtype']);
}

if($cachefilename || $outputType == 'html') // Add the image only if constructed
{
//introduce new counter
if (!isset($ci)) {$ci=0;}

//increase counter, start value -> 1
$ci++;
switch($outputType)
{
case 'xls':
/**
* No Image for Excel...
*/
}
}

break;
case 'pdf':

$this->pdf->AddPage('P','A4');
if(isset($aattr["statistics_graphtype"]))
{
$req_chart_type = $aattr["statistics_graphtype"];
}
else
{
$req_chart_type = 0;
}

$this->pdf->titleintopdf($pdfTitle,$titleDesc);
$this->pdf->Image($tempdir."/".$cachefilename, 0, 70, 180, 0, '', Yii::app()->getController()->createUrl("admin/survey/sa/view/surveyid/".$surveyid), 'B', true, 150,'C',false,false,0,true);
//// If user forced the chartype from statistics_view
if ( isset($_POST['charttype']) && $_POST['charttype'] != 'default' )
{
$req_chart_type = $_POST['charttype'];
}

break;
case 'html':
//// The value of the select box in the question advanced setting is numerical. So we need to translate it.
if(isset($req_chart_type))
{
switch ($req_chart_type) {
case '1':
$charttype = "Pie";
break;

if(isset($aattr["statistics_graphtype"]))
{
$req_chart_type = $aattr["statistics_graphtype"];
}
case '2':
$charttype = "Radar";
break;

//// If user forced the chartype from statistics_view
if ( isset($_POST['charttype']) && $_POST['charttype'] != 'default' )
{
$req_chart_type = $_POST['charttype'];
}
case '3':
$charttype = "Line";
break;

//// The value of the select box in the question advanced setting is numerical. So we need to translate it.
if(isset($req_chart_type))
{
switch ($req_chart_type) {
case '1':
$charttype = "Pie";
break;

case '2':
$charttype = "Radar";
break;

case '3':
$charttype = "Line";
break;

case '4':
$charttype = "PolarArea";
break;

case '5':
$charttype = "Doughnut";
break;

default:
$charttype = "Bar";
break;
}
}
case '4':
$charttype = "PolarArea";
break;

//// Here the 72 colors of the original limesurvey palette.
//// This could be change by some user palette coming from database.
$COLORS_FOR_SURVEY = array('20,130,200','232,95,51','34,205,33','210,211,28','134,179,129','201,171,131','251,231,221','23,169,161','167,187,213','211,151,213','147,145,246','147,39,90','250,250,201','201,250,250','94,0,94','250,125,127','0,96,201','201,202,250','0,0,127','250,0,250','250,250,0','0,250,250','127,0,127','127,0,0','0,125,127','0,0,250','0,202,250','201,250,250','201,250,201','250,250,151','151,202,250','251,149,201','201,149,250','250,202,151','45,96,250','45,202,201','151,202,0','250,202,0','250,149,0','250,96,0','184,230,115','102,128,64','220,230,207','134,191,48','184,92,161','128,64,112','230,207,224','191,48,155','230,138,115','128,77,64','230,211,207','191,77,48','80,161,126','64,128,100','207,230,220','48,191,130','25,25,179','18,18,125','200,200,255','145,145,255','255,178,0','179,125,0','255,236,191','255,217,128','255,255,0','179,179,0','255,255,191','255,255,128','102,0,153','71,0,107','234,191,255','213,128,255');
case '5':
$charttype = "Doughnut";
break;

//// $lbl is generated somewhere upthere by the original code. We translate it for chartjs.
$labels = array();
foreach($lbl as $name => $lb)
$labels[] = $name;
break;
default:
break;
}
}
default:
$charttype = "Bar";
break;
}
}

//// Here the 72 colors of the original limesurvey palette.
//// This could be change by some user palette coming from database.
$COLORS_FOR_SURVEY = array('20,130,200','232,95,51','34,205,33','210,211,28','134,179,129','201,171,131','251,231,221','23,169,161','167,187,213','211,151,213','147,145,246','147,39,90','250,250,201','201,250,250','94,0,94','250,125,127','0,96,201','201,202,250','0,0,127','250,0,250','250,250,0','0,250,250','127,0,127','127,0,0','0,125,127','0,0,250','0,202,250','201,250,250','201,250,201','250,250,151','151,202,250','251,149,201','201,149,250','250,202,151','45,96,250','45,202,201','151,202,0','250,202,0','250,149,0','250,96,0','184,230,115','102,128,64','220,230,207','134,191,48','184,92,161','128,64,112','230,207,224','191,48,155','230,138,115','128,77,64','230,211,207','191,77,48','80,161,126','64,128,100','207,230,220','48,191,130','25,25,179','18,18,125','200,200,255','145,145,255','255,178,0','179,125,0','255,236,191','255,217,128','255,255,0','179,179,0','255,255,191','255,255,128','102,0,153','71,0,107','234,191,255','213,128,255');

//// $lbl is generated somewhere upthere by the original code. We translate it for chartjs.
$labels = array();
foreach($lbl as $name => $lb)
$labels[] = $name;

//close table/output
if($outputType=='html') {
// show this block only when we show graphs and are not in the public statics controller
Expand Down Expand Up @@ -3734,7 +3715,6 @@ public function generate_simple_statistics($surveyid, $allfields, $q2show='all',
/**
* Start generating
*/
$selects=buildSelects($allfields, $surveyid, $language);

//count number of answers
$query = "SELECT count(*) FROM {{survey_$surveyid}}";
Expand Down

0 comments on commit 23465d8

Please sign in to comment.