Skip to content

Commit

Permalink
Dev: added views for statistic rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisGac committed Dec 18, 2015
1 parent 24740cd commit 30b1e77
Show file tree
Hide file tree
Showing 4 changed files with 203 additions and 47 deletions.
94 changes: 50 additions & 44 deletions application/helpers/admin/statistics_helper.php
Expand Up @@ -659,6 +659,7 @@ protected function buildOutputList($rt, $language, $surveyid, $outputType, $sql,
break;
}

////
//M - Multiple choice, therefore multiple fields - one for each answer
if ($firstletter == "M" || $firstletter == "P")
{
Expand Down Expand Up @@ -887,16 +888,13 @@ protected function buildOutputList($rt, $language, $surveyid, $outputType, $sql,
$headPDF = array();
$tablePDF = array();
$footPDF = array();

$pdfTitle = sprintf(gT("Field summary for %s"),html_entity_decode($qtitle,ENT_QUOTES,'UTF-8'));
$titleDesc = html_entity_decode($qquestion,ENT_QUOTES,'UTF-8');

$headPDF[] = array(gT("Calculation"),gT("Result"));

break;

case 'html':
$statisticsoutput .= "\n<table class='statisticstable table table-bordered >\n"
$statisticsoutput .= "\n<table class='statisticstable table table-bordered >\n"
."\t<thead><tr class='success'><th style='text-align: center; '><strong>".sprintf(gT("Field summary for %s"),$qtitle).":</strong>"
."</th></tr>\n"
."\t<tr><th colspan='2' align='center'><strong>$qquestion</strong></th></tr>\n"
Expand Down Expand Up @@ -1606,7 +1604,8 @@ protected function buildOutputList($rt, $language, $surveyid, $outputType, $sql,
*
*
*/
protected function displayResults($outputs, $results, $rt, $outputType, $surveyid, $sql, $usegraph, $browse, $sLanguage) {
protected function displayResults($outputs, $results, $rt, $outputType, $surveyid, $sql, $usegraph, $browse, $sLanguage)
{

/* Set up required variables */
$TotalCompleted = 0; //Count of actually completed answers
Expand Down Expand Up @@ -1657,18 +1656,7 @@ protected function displayResults($outputs, $results, $rt, $outputType, $surveyi

break;
case 'html':
//output
$statisticsoutput .= "<table class='statisticstable table table-bordered'>\n"
."\t<thead><tr class='success'><th colspan='4' align='center' style='text-align: center; '><strong>"

//headline
.sprintf(gT("Field summary for %s"),$outputs['qtitle'])."</strong>"
."</th></tr>\n"
."\t<tr><th colspan='4' align='center' style='text-align: center; '><strong>"

//question title
.$outputs['qquestion']."</strong></th></tr>\n"
."\t<tr>\n\t\t<th width='50%' align='center' >";
//output now generated in subview _statisticsoutuput_header
break;
default:

Expand Down Expand Up @@ -1880,12 +1868,8 @@ protected function displayResults($outputs, $results, $rt, $outputType, $surveyi
$fname= "$al[1]";
}

$statisticsoutput .= "</th>\n"
."\t\t<th width='25%' align='center' >"
."<strong>".gT("Count")."</strong></th>\n"
."\t\t<th width='25%' align='center' >"
."<strong>".gT("Percentage")."</strong></th>\n"
."\t</tr></thead>\n";
$bAnswer = false; // For view
$bSum = false;

if ($browse===true && isset($_POST['showtextinline']) && $outputType=='pdf') {
$headPDF2 = array();
Expand Down Expand Up @@ -1926,14 +1910,8 @@ protected function displayResults($outputs, $results, $rt, $outputType, $surveyi
break;
case 'html':
//four columns
$statisticsoutput .= "<strong>".gT("Answer")."</strong></th>\n"
."\t\t<th width='15%' align='center' >"
."<strong>".gT("Count")."</strong></th>\n"
."\t\t<th width='20%' align='center' >"
."<strong>".gT("Percentage")."</strong></th>\n"
."\t\t<th width='15%' align='center' >"
."<strong>".gT("Sum")."</strong></th>\n"
."\t</tr></thead>\n";
$bAnswer = true;
$bSum = true;
break;
default:

Expand Down Expand Up @@ -1962,12 +1940,9 @@ protected function displayResults($outputs, $results, $rt, $outputType, $surveyi
break;
case 'html':
//three columns
$statisticsoutput .= "<strong>".gT("Answer")."</strong></td>\n"
."\t\t<th width='25%' align='center' >"
."<strong>".gT("Count")."</strong></th>\n"
."\t\t<th width='25%' align='center' >"
."<strong>".gT("Percentage")."</strong></th>\n"
."\t</tr></thead>\n";
$bAnswer = true; // For view
$bSum = false;

break;
default:

Expand Down Expand Up @@ -2006,12 +1981,8 @@ protected function displayResults($outputs, $results, $rt, $outputType, $surveyi
break;
case 'html':
//three columns
$statisticsoutput .= "<strong>".gT("Answer")."</strong></th>\n"
."\t\t<th width='25%' align='center' >"
."<strong>".gT("Count")."</strong></th>\n"
."\t\t<th width='25%' align='center' >"
."<strong>".gT("Percentage")."</strong></th>\n"
."\t</tr></thead>\n";
$bAnswer = true; // For view
$bSum = false;
break;
default:

Expand Down Expand Up @@ -2220,9 +2191,17 @@ protected function displayResults($outputs, $results, $rt, $outputType, $surveyi
//we need to know which item we are editing
$itemcounter = 1;

$aData['outputs'] = $outputs;
$aData['bSum'] = $bSum;
$aData['bAnswer'] = $bAnswer;
$statisticsoutput = Yii::app()->getController()->renderPartial('/admin/export/generatestats/_statisticsoutput_header', $aData, true);

//loop through all available answers
while (isset($gdata[$i]))
{
$aData['i']=$i;
///// We'll render at the end of this loop statisticsoutput_answer

//repeat header (answer, count, ...) for each new question
unset($showheadline);

Expand All @@ -2234,8 +2213,10 @@ protected function displayResults($outputs, $results, $rt, $outputType, $surveyi
* 2 (25%) = count (absolute)
* 3 (25%) = percentage
*/
/*
$statisticsoutput .= "\t<tr>\n\t\t<td align='center' >" . $label[$i] ."\n"
."\t\t</td>\n";
*/
/*
* If there is a "browse" button in this label, let's make sure there's an extra row afterwards
* to store the columnlist
Expand All @@ -2247,16 +2228,19 @@ protected function displayResults($outputs, $results, $rt, $outputType, $surveyi
if ($outputs['qtype']=='P')
{
$extraline.="<div class='statisticsbrowsecolumn' id='columnlist_{$ColumnName_RM[$i]}'></div></td></tr>\n";
$sColumnNameForView = $ColumnName_RM[$i];
}
else
{
$extraline.="<div class='statisticsbrowsecolumn' id='columnlist_{$sColumnName}'></div></td></tr>\n";
$sColumnNameForView = $sColumnName;
}
}

//output absolute number of records
/*
$statisticsoutput .= "\t\t<td align='center' >" . $grawdata[$i] . "\n</td>";

*/

//no data
if ($gdata[$i] === "N/A")
Expand All @@ -2278,6 +2262,7 @@ protected function displayResults($outputs, $results, $rt, $outputType, $surveyi
break;
case 'html':
//output when having no data
/*
$statisticsoutput .= "\t\t<td align='center' >";
//percentage = 0
Expand All @@ -2295,6 +2280,7 @@ protected function displayResults($outputs, $results, $rt, $outputType, $surveyi
}
$statisticsoutput .= "</tr>\n"; //Close the row
if(isset($extraline)) {$statisticsoutput .= $extraline;}
*/
break;
default:

Expand Down Expand Up @@ -2379,6 +2365,7 @@ protected function displayResults($outputs, $results, $rt, $outputType, $surveyi

case 'html':
//output percentage
/*
$statisticsoutput .= "\t\t<td align='center' >";
$statisticsoutput .= sprintf("%01.2f", $percentage) . "%</td>";
Expand All @@ -2389,6 +2376,7 @@ protected function displayResults($outputs, $results, $rt, $outputType, $surveyi
$statisticsoutput .= '&nbsp;';
}
$statisticsoutput .= "</td>\t\t";
*/
break;

default:
Expand Down Expand Up @@ -2448,6 +2436,7 @@ protected function displayResults($outputs, $results, $rt, $outputType, $surveyi

break;
case 'html':
/*
$statisticsoutput .= "\t\t&nbsp;\n\t</tr>\n";
$statisticsoutput .= "<tr><td align='center'><strong>".gT("Sum")." (".gT("Answers").")</strong></td>";
$statisticsoutput .= "<td align='center' ><strong>".$sumitems."</strong></td>";
Expand All @@ -2460,6 +2449,7 @@ protected function displayResults($outputs, $results, $rt, $outputType, $surveyi
$statisticsoutput .= "<td align='center' >$casepercentage%</td>";
//there has to be a whitespace within the table cell to display correctly
$statisticsoutput .= "<td align='center' >&nbsp;</td></tr>";
*/
break;
default:

Expand Down Expand Up @@ -2491,12 +2481,14 @@ protected function displayResults($outputs, $results, $rt, $outputType, $surveyi
break;
case 'html':
//output percentage
/*
$statisticsoutput .= "\t\t<td align='center' >";
$statisticsoutput .= sprintf("%01.2f", $gdata[$i]) . "%";
$statisticsoutput .= "\t\t";
//end output per line. there has to be a whitespace within the table cell to display correctly
$statisticsoutput .= "\t\t&nbsp;</td>\n\t</tr>\n";
if(isset($extraline)) {$statisticsoutput .= $extraline;}
*/
break;
default:

Expand All @@ -2518,6 +2510,20 @@ protected function displayResults($outputs, $results, $rt, $outputType, $surveyi
//Clear extraline
unset($extraline);

///// HERE RENDER statisticsoutput_answer
$aData['label']=$label;
$aData['grawdata']=$grawdata;
$aData['gdata']=$gdata;
$aData['extraline']=(isset($extraline))?$extraline:false;
$aData['aggregated']=(isset($aggregated))?$aggregated:false;
$aData['aggregatedPercentage']=(isset($aggregatedPercentage))?$aggregatedPercentage:false;
$aData['sumitems']=(isset($sumitems))?$sumitems:false;
$aData['sumpercentage']=(isset($sumpercentage))?$sumpercentage:false;
$aData['TotalCompleted']=(isset($TotalCompleted))?$TotalCompleted:false;
$aData['casepercentage']=(isset($casepercentage))?$casepercentage:false;

$statisticsoutput .= Yii::app()->getController()->renderPartial('/admin/export/generatestats/_statisticsoutput_answer', $aData, true);

} //end while

//only show additional values when this setting is enabled
Expand Down
6 changes: 3 additions & 3 deletions application/views/admin/export/generatestats/_header.php
Expand Up @@ -15,11 +15,11 @@
<!-- Message Box -->
<div style="clear: both; margin-bottom: 10px;"></div><div class="jumbotron message-box">
<h2><?php eT("Results"); ?></h2>
<p><?php eT("Number of records in this query:")?> <?php echo $results;?></p>
<p><?php eT("Total records in survey:"); ?> <?php echo $total; ?></p>
<p><?php eT("Number of records in this query:")?>&nbsp;<?php echo $results;?></p>
<p><?php eT("Total records in survey:"); ?>&nbsp;<?php echo $total; ?></p>

<?php if($total): ?>
<p><?php eT("Percentage of total:"); ?> <?php echo $percent; ?>%</p>
<p><?php eT("Percentage of total:"); ?>&nbsp;<?php echo $percent; ?>%</p>
<?php endif;?>

<?php if($browse): ?>
Expand Down
@@ -0,0 +1,97 @@
<?php
/**
* This view render the list of answers in top of the graph
*
* @var $label
* @var $grawdata
* @var $gdata
* @var $i
* @var $extraline
* @var $sColumnNameForView
* potentialy not set when controller will try to load them in $aData (so will need defaut values)
* @var $aggregated
* @var $aggregatedPercentage
* @var $sumitems
* @var $sumpercentage
* @var $TotalCompleted
* @var $casepercentage
*/
?>

<tr>
<td align='center' ><?php echo $label[$i]; ?></td>
<td align='center' ><?php echo $grawdata[$i]; ?></td>

<?php if ($gdata[$i] === "N/A"): ?>
<td align='center' >
<?php echo sprintf("%01.2f", $gdata[$i]); ?>%
</td>
<?php else: ?>
<?php if($aggregated):?>
<td align='center' >
<?php echo sprintf("%01.2f", $gdata[$i]); ?>%
</td>
<td align='center' >
<?php echo sprintf("%01.2f", $aggregatedPercentage); ?>%
</td>
<td align='center'>
<strong>
<?php eT("Sum");?>&nbsp;&nbsp;<?php eT("Answers"); ?>
</strong>
</td>
<td align='center'>
<strong>
<?php echo $sumitems; ?>
</strong>
</td>
<td align='center'>
<strong>
<?php echo $sumpercentage; ?>%
</strong>
</td>
<td align='center'>
<strong>
<?php echo $sumpercentage; ?>%
</strong>
</td>
<?php else: ?>
<td align='center' >
<?php echo sprintf("%01.2f", $gdata[$i]);?>%
</td>
<?php endif;?>
<?php endif;?>
</tr>

<?php if ($gdata[$i] != "N/A"): ?>
<?php if($aggregated): ?>
<tr>
<td align='center'>
<strong>
<?php eT("Number of cases");?>
</strong>
</td>
<td align='center'>
<strong>
<?php echo $TotalCompleted; ?>
</strong>
</td>
<td align='center'>
<strong>
<?php echo $casepercentage; ?>%
</strong>
</td>
<td align='center'>
&nbsp;
</td>
</tr>
<?php endif; ?>
<?php endif; ?>


<?php if($extraline): ?>
<tr>
<td class='statisticsbrowsecolumn' colspan='3' style='display: none'>
<div class='statisticsbrowsecolumn' id='columnlist_<?php echo $sColumnNameForView; ?>'>
</td>
</tr>
<?php endif; ?>

0 comments on commit 30b1e77

Please sign in to comment.