Skip to content

Commit

Permalink
Fixed issue #6441: Public statistics is missing result data and charts
Browse files Browse the repository at this point in the history
  • Loading branch information
c-schmitz committed Oct 9, 2012
1 parent 6424132 commit 807a137
Show file tree
Hide file tree
Showing 4 changed files with 345 additions and 24 deletions.
40 changes: 28 additions & 12 deletions application/controllers/Statistics_userController.php
Expand Up @@ -190,7 +190,8 @@ function actionAction($surveyid,$language)
* only show questions where question attribute "public_statistics" is set to "1"
*/

$query = "SELECT q.* , group_name, group_order FROM {{questions}} q, {{groups}} g, {{question_attributes}} qa WHERE 'g.gid' = 'q.gid' AND 'g.language' = :lang AND 'q.language' = :lang AND 'q.sid' = :surveyid AND 'q.qid' = 'qa.qid' AND 'q.parent_qid' = 0 AND 'qa.attribute' = 'public_statistics'";
$query = "SELECT q.* , group_name, group_order FROM {{questions}} q, {{groups}} g, {{question_attributes}} qa
WHERE g.gid = q.gid AND g.language = :lang AND q.language = :lang AND q.sid = :surveyid AND q.qid = qa.qid AND q.parent_qid = 0 AND qa.attribute = 'public_statistics'";
$databasetype = Yii::app()->db->getDriverName();
if ($databasetype=='mssql' || $databasetype=="sqlsrv")
{
Expand Down Expand Up @@ -277,7 +278,7 @@ function actionAction($surveyid,$language)
case "Q": // Multiple Short Text
//get answers
$query = "SELECT title as code, question as answer FROM {{questions}} WHERE parent_qid=:flt_0 AND language = :lang ORDER BY question_order";
$result = Yii::app()->db->createCommand($query)->bindParam(":flt_0", $flt[0], PDO::PARAM_INT)->bindParam(":flt_0", $language, PDO::PARAM_STR)->queryAll();
$result = Yii::app()->db->createCommand($query)->bindParam(":flt_0", $flt[0], PDO::PARAM_INT)->bindParam(":lang", $language, PDO::PARAM_STR)->queryAll();

//go through all the (multiple) answers
foreach($result as $row)
Expand All @@ -294,7 +295,7 @@ function actionAction($surveyid,$language)
case "H": // ARRAY (By Column)
//get answers
$query = "SELECT title as code, question as answer FROM {{questions}} WHERE parent_qid=:flt_0 AND language = :lang ORDER BY question_order";
$result = Yii::app()->db->createCommand($query)->bindParam(":flt_0", $flt[0], PDO::PARAM_INT)->bindParam(":flt_0", $language, PDO::PARAM_STR)->queryAll();
$result = Yii::app()->db->createCommand($query)->bindParam(":flt_0", $flt[0], PDO::PARAM_INT)->bindParam(":lang", $language, PDO::PARAM_STR)->queryAll();

//go through all the (multiple) answers
foreach($result as $row)
Expand All @@ -313,11 +314,11 @@ function actionAction($surveyid,$language)
case ";": //ARRAY (Multi Flex) (Text)
case ":": //ARRAY (Multi Flex) (Numbers)
$query = "SELECT title, question FROM {{questions}} WHERE parent_qid=:flt_0 AND language=:lang AND scale_id = 0 ORDER BY question_order";
$result = Yii::app()->db->createCommand($query)->bindParam(":flt_0", $flt[0], PDO::PARAM_INT)->bindParam(":flt_0", $language, PDO::PARAM_STR)->queryAll();
$result = Yii::app()->db->createCommand($query)->bindParam(":flt_0", $flt[0], PDO::PARAM_INT)->bindParam(":lang", $language, PDO::PARAM_STR)->queryAll();
foreach($result as $row)
{
$fquery = "SELECT * FROM {{questions}} WHERE parent_qid = :flt_0 AND language = :lang AND scale_id = 1 ORDER BY question_order, title";
$fresult = Yii::app()->db->createCommand($query)->bindParam(":flt_0", $flt[0], PDO::PARAM_INT)->bindParam(":flt_0", $language, PDO::PARAM_STR)->queryAll();
$fresult = Yii::app()->db->createCommand($query)->bindParam(":flt_0", $flt[0], PDO::PARAM_INT)->bindParam(":lang", $language, PDO::PARAM_STR)->queryAll();
foreach($fresult as $frow)
{
$myfield2 = $myfield . reset($row) . "_" . $frow['title'];
Expand All @@ -328,10 +329,10 @@ function actionAction($surveyid,$language)
case "R": //RANKING
//get some answers
$query = "SELECT code, answer FROM {{answers}} WHERE qid = :flt_0 AND language = :lang ORDER BY sortorder, answer";
$result = Yii::app()->db->createCommand($query)->bindParam(":flt_0", $flt[0], PDO::PARAM_INT)->bindParam(":flt_0", $language, PDO::PARAM_STR)->queryAll();
$result = Yii::app()->db->createCommand($query)->bindParam(":flt_0", $flt[0], PDO::PARAM_INT)->bindParam(":lang", $language, PDO::PARAM_STR)->queryAll();

//get number of answers
$count = $result->num_rows();
$count = count($result);

//loop through all answers. if there are 3 items to rate there will be 3 statistics
for ($i=1; $i<=$count; $i++)
Expand All @@ -346,16 +347,16 @@ function actionAction($surveyid,$language)
case "1": // MULTI SCALE
//get answers
$query = "SELECT title, question FROM {{questions}} WHERE parent_qid = :flt_0 AND language = :lang ORDER BY question_order";
$result = Yii::app()->db->createCommand($query)->bindParam(":flt_0", $flt[0], PDO::PARAM_INT)->bindParam(":flt_0", $language, PDO::PARAM_STR)->queryAll();
$result = Yii::app()->db->createCommand($query)->bindParam(":flt_0", $flt[0], PDO::PARAM_INT)->bindParam(":lang", $language, PDO::PARAM_STR)->queryAll();

//loop through answers
foreach($result as $row)
{
//----------------- LABEL 1 ---------------------
$myfield2 = $myfield . reset($row[0])."#0";
$myfield2 = $myfield . $row['title']."#0";
$allfields[]=$myfield2;
//----------------- LABEL 2 ---------------------
$myfield2 = $myfield . "$row[0]#1";
$myfield2 = $myfield . $row['title']."#1";
$allfields[]=$myfield2;
} //end WHILE -> loop through all answers
break;
Expand Down Expand Up @@ -440,11 +441,11 @@ function actionAction($surveyid,$language)

} // end foreach -> loop through all questions

$statisticsoutput .= generate_statistics($iSurveyID, $summary, $summary, $publicgraphs, 'html',null,$language,false);
$statisticsoutput .= generate_statistics($iSurveyID, $summary, $summary, $publicgraphs, 'html', null,$language,false);

} //end if -> show summary results


$data['statisticsoutput']=$statisticsoutput;
//done! set progress bar to 100%
if (isset($prb))
{
Expand All @@ -453,6 +454,21 @@ function actionAction($surveyid,$language)
$prb->hide();
}

// Get the survey inforamtion
$thissurvey = getSurveyInfo($surveyid,$language);

//SET THE TEMPLATE DIRECTORY
if (!isset($thissurvey['templatedir']) || !$thissurvey['templatedir'])
{
$data['sTemplatePath'] = validateTemplateDir("default");
}
else
{
$data['sTemplatePath'] = validateTemplateDir($thissurvey['templatedir']);
}


header_includes('statistics_user.js');
$this->render('/statistics_user_view',$data);

//output footer
Expand Down
8 changes: 5 additions & 3 deletions application/helpers/admin/statistics_helper.php
Expand Up @@ -835,8 +835,10 @@ function buildOutputList($rt, $language, $surveyid, $outputType, $sql, $oLanguag
$tmpqid=substr($qqid, 0, strlen($qqid)-1);

//did we get a valid ID?
while (!in_array ($tmpqid,$legitqids))
$tmpqid=substr($tmpqid, 0, strlen($tmpqid)-1);
while (!in_array ($tmpqid,$legitqids,true))
{
$tmpqid=(int)substr($tmpqid, 0, strlen($tmpqid)-1);
}

//check lenght of ID
$iQuestionIDlength=strlen($tmpqid);
Expand Down Expand Up @@ -3055,7 +3057,7 @@ function displayResults($outputs, $results, $rt, $outputType, $surveyid, $sql, $
."</div></td></tr>";

}
$statisticsoutput .= "</table><br /> \n";
$statisticsoutput .= "</td></tr></table><br /> \n";
}

return array("statisticsoutput"=>$statisticsoutput, "pdf"=>$pdf, "astatdata"=>$astatdata);
Expand Down
20 changes: 11 additions & 9 deletions application/views/statistics_user_view.php
@@ -1,16 +1,18 @@
<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang="<?php echo $surveylanguage; ?>" lang="<?php echo $surveylanguage; ?>" <?php if ($condition) { echo 'dir = "rtl"'; } ?> >
<head>
<title><?php echo $sitename; ?></title>
<meta http-equiv="content-type" content="text/html; charset=UTF-\" />
<link href="<?php echo $thisSurveyCssPath; ?>/template.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?php
doHeader();
echo templatereplace(file_get_contents(getTemplatePath(validateTemplateDir($sTemplatePath))."/startpage.pstpl"));
?>
<script type='text/javascript'>
var graphUrl="<?php echo Yii::app()->getController()->createUrl("admin/statistics/graph"); ?>";
</script>
<div id='statsContainer'>
<div id='statsHeader'>
<div class='statsSurveyTitle'><?php echo $thisSurveyTitle; ?></div>
<div class='statsNumRecords'><?php echo $clang->gT("Total records in survey")." : $totalrecords"; ?></div>
</div>
<?php if (isset($summary) && $summary) { echo $statisticsoutput; } ?><br />
<?php if (isset($statisticsoutput) && $statisticsoutput) { echo $statisticsoutput; } ?><br />
</div>
<?php
echo templatereplace(file_get_contents(getTemplatePath(validateTemplateDir($sTemplatePath))."/endpage.pstpl"));
?>

0 comments on commit 807a137

Please sign in to comment.