Skip to content

Commit

Permalink
Fixed issue #06317 : Time statistics is not active
Browse files Browse the repository at this point in the history
Dev: fix for modification and adpatation, maybe use Yii Relationship
  • Loading branch information
Shnoulle committed Jul 17, 2012
1 parent 0edc978 commit 9ae5230
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 48 deletions.
55 changes: 26 additions & 29 deletions application/controllers/admin/browse.php
Expand Up @@ -665,14 +665,14 @@ public function time($iSurveyId)
}
}
}

$aData['fnames'] = $fnames;
$start = Yii::app()->request->getParam('start', 0);
$limit = Yii::app()->request->getParam('limit', 50);

//LETS COUNT THE DATA
$oCriteria = new CdbCriteria();
$oCriteria->select = 'tid';
$oCriteria->join = "INNER JOIN {{survey_{$iSurveyId}}} ON {{survey_{$iSurveyId}_timings}}.id={{survey_{$iSurveyId}}}.id";
$oCriteria->join = "INNER JOIN {{survey_{$iSurveyId}}} s ON t.id=s.id";
$oCriteria->condition = 'submitdate IS NOT NULL';
$dtcount = Survey_timings::model($iSurveyId)->count($oCriteria); // or die("Couldn't get response data");

Expand All @@ -683,17 +683,13 @@ public function time($iSurveyId)

//NOW LETS SHOW THE DATA
$oCriteria = new CdbCriteria();
$oCriteria->join = "INNER JOIN {{survey_{$iSurveyId}}} ON {{survey_{$iSurveyId}_timings}}.id = {{survey_{$iSurveyId}}}.id";
$oCriteria->join = "INNER JOIN {{survey_{$iSurveyId}}} s ON t.id=s.id";
$oCriteria->condition = 'submitdate IS NOT NULL';
$oCriteria->order = "{{survey_{$iSurveyId}}}.id";
$oCriteria->limit = $limit;
$oCriteria->order = "s.id " . (Yii::app()->request->getParam('order') == 'desc' ? 'desc' : 'asc');
$oCriteria->offset = $start;
if ($aData['order'] == "desc")
{
$oCriteria->order .= " DESC";
}
$oCriteria->limit = $limit;

$dtresult = Survey_timings::model($iSurveyId)->findAll($oCriteria) or die("Couldn't get surveys");
$dtresult = Survey_timings::model($iSurveyId)->findAllAsArray($oCriteria) or die("Couldn't get surveys");
$dtcount2 = count($dtresult);
$cells = $fncount + 1;

Expand Down Expand Up @@ -734,10 +730,16 @@ public function time($iSurveyId)
{
$selectshow = " selected='selected'";
}

$aData['start'] = $start;
$aData['limit'] = $limit;
$aData['last'] = $last;
$aData['next'] = $next;
$aData['end'] = $end;
$aViewUrls[] = 'browsetimeheader_view';


$aData['fncount'] = $fncount;
$bgcc = 'oddrow';

foreach ($dtresult as $dtrow)
{
if ($bgcc == "evenrow")
Expand All @@ -748,23 +750,21 @@ public function time($iSurveyId)
{
$bgcc = "evenrow";
}

$browsedatafield=array();
for ($i = 0; $i < $fncount; $i++)
{
$browsedatafield = htmlspecialchars($dtrow[$fnames[$i][0]]);

$browsedatafield[$i] = $dtrow[$fnames[$i][0]];
// seconds -> minutes & seconds
if (strtolower(substr($fnames[$i][0], -4)) == "time")
{
$minutes = (int) ($browsedatafield / 60);
$seconds = $browsedatafield % 60;
$browsedatafield = '';
$minutes = (int) ($browsedatafield[$i] / 60);
$seconds = $browsedatafield[$i] % 60;
$browsedatafield[$i] = '';
if ($minutes > 0)
$browsedatafield .= "$minutes min ";
$browsedatafield .= "$seconds s";
$browsedatafield[$i] .= "$minutes min ";
$browsedatafield[$i] .= "$seconds s";
}
}

$aData['browsedatafield'] = $browsedatafield;
$aData['bgcc'] = $bgcc;
$aData['dtrow'] = $dtrow;
Expand All @@ -775,15 +775,16 @@ public function time($iSurveyId)
$count = false;
//$survstats=substr($surveytableNq);
$oCriteria = new CDbCriteria;
$oCriteria->select = 'AVG(interviewtime) AS avg, COUNT(id)';
$oCriteria->join = "{{survey_{$iSurveyId}}} AS surv ON id = surv.id";
$oCriteria->condition = 'surv.submitdate IS NOT NULL';
$oCriteria->select = 'AVG(interviewtime) AS avg, COUNT(*) as count';
$oCriteria->join = " INNER JOIN {{survey_{$iSurveyId}}} s ON t.id = s.id";
$oCriteria->condition = 'submitdate IS NOT NULL';
$oCriteria->order = 'interviewtime';
$queryAvg = Survey_timings::model($iSurveyId)->find($oCriteria);

$oCriteria->select = 'interviewtime';
$queryAll = Survey_timings::model($iSurveyId)->findAll($oCriteria);

$count = count($queryAll);
if ($aData['result'] = $row = $queryAvg)
{
$aData['avgmin'] = (int) ($row['avg'] / 60);
Expand Down Expand Up @@ -825,13 +826,9 @@ public function time($iSurveyId)
$aData['allsec'] = $median % 60;
}

$aViewUrls[] = 'browsetimefooter_view';

$aData['num_total_answers'] = Survey_dynamic::model($iSurveyId)->count();
$aData['num_completed_answers'] = Survey_dynamic::model($iSurveyId)->count('submitdate IS NOT NULL');

$aViewUrls[] = 'browseindex_view';

$aViewUrls[] = 'browsetimefooter_view';
$this->_renderWrappedTemplate('',$aViewUrls, $aData);
}

Expand Down
7 changes: 4 additions & 3 deletions application/models/Survey_timings.php
Expand Up @@ -14,11 +14,12 @@
* Files Purpose: lots of common functions
*/

class Survey_timings extends CActiveRecord
class Survey_timings extends LSActiveRecord
{

protected static $sid = 0;

public $avg;
public $count;
/**
* Returns the static model
*
Expand Down Expand Up @@ -56,7 +57,7 @@ public static function sid($sid)
*/
public function tableName()
{
return '{{survey_' . intval(self::sid) . '_timings}}';
return '{{survey_' . intval(self::$sid) . '_timings}}';
}

}
Expand Down
2 changes: 1 addition & 1 deletion application/views/admin/browse/browsemenubar_view.php
Expand Up @@ -44,7 +44,7 @@
<img src='<?php echo $sImageURL; ?>statistics.png' alt='<?php $clang->eT("Get statistics from these responses"); ?>' /></a>
<?php if ($thissurvey['savetimings'] == "Y")
{ ?>
<a href='<?php echo $this->createUrl("admin/browse/browse/surveyid/$surveyid/subaction/time"); ?>'>
<a href='<?php echo $this->createUrl("admin/browse/time/surveyid/$surveyid"); ?>'>
<img src='<?php echo $sImageURL; ?>statistics_time.png' alt='<?php $clang->eT("Get time statistics from these responses"); ?>' /></a>
<?php }
} ?>
Expand Down
6 changes: 2 additions & 4 deletions application/views/admin/browse/browsetimefooter_view.php
Expand Up @@ -6,12 +6,10 @@
<div class="header ui-widget-header"><?php $clang->eT('Interview time'); ?></div>
<table class="statisticssummary">
<?php if ($result) { ?>
<tr><th><?php $clang->eT('Average interview time:'); ?></th><td><?php echo $aData['avgmin']; ?> min. <?php echo $aData['avgsec']; ?> sec.</td></tr>
<tr><th><?php $clang->eT('Average interview time:'); ?></th><td><?php echo $avgmin; ?> min. <?php echo $avgsec; ?> sec.</td></tr>
<?php } ?>
<?php if ($count) { ?>
<tr><th><?php $clang->eT('Median:'); ?></th><td><?php echo $aData['allmin']; ?> min. <?php echo $aData['allsec']; ?> sec.</td></tr>
<tr><th><?php $clang->eT('Median:'); ?></th><td><?php echo $allmin; ?> min. <?php echo $allsec; ?> sec.</td></tr>
<?php } ?>
</table>

<div class='header ui-widget-header'><?php $clang->eT('Timings'); ?></div>
<?php $clang->eT("Timing saving is disabled or the timing table does not exist. Try to reactivate survey."); ?>
62 changes: 55 additions & 7 deletions application/views/admin/browse/browsetimeheader_view.php
Expand Up @@ -11,24 +11,24 @@
<?php if (!Yii::app()->request->getPost('sql'))
{ ?>
<a href='<?php echo $this->createUrl("/admin/browse/time/surveyid/$iSurveyId/start/0/limit/$limit"); ?>' title='<?php $clang->eT("Show start..."); ?>' >
<img name='DataBegin' align='left' src='<?php echo $imageurl; ?>/databegin.png' alt='<?php $clang->eT("Show start..."); ?>' />
<img name='DataBegin' align='left' src='<?php echo $sImageURL; ?>/databegin.png' alt='<?php $clang->eT("Show start..."); ?>' />
</a>
<a href='<?php echo $this->createUrl("/admin/browse/time/surveyid/$iSurveyId/start/$last/limit/$limit"); ?>' title='<?php $clang->eT("Show previous.."); ?>'>
<img name='DataBack' align='left' src='<?php echo $imageurl; ?>/databack.png' alt='<?php $clang->eT("Show previous.."); ?>' />
<img name='DataBack' align='left' src='<?php echo $sImageURL; ?>/databack.png' alt='<?php $clang->eT("Show previous.."); ?>' />
</a>
<img src='<?php echo $imageurl; ?>/blank.gif' width='13' height='20' alt='' />
<a href='<?php echo $this->createUrl("/admin/browse/time/surveyid/$iSurveyId/start/$next/limit/$limit"); ?>' title='<?php $clang->eT("Show next..."); ?>'>
<img name='DataForward' align='left' src='<?php echo $imageurl; ?>/dataforward.png' alt='<?php $clang->eT("Show next.."); ?>' />
<img name='DataForward' align='left' src='<?php echo $sImageURL; ?>/dataforward.png' alt='<?php $clang->eT("Show next.."); ?>' />
</a>
<a href='<?php echo $this->createUrl("/admin/browse/time/surveyid/$iSurveyId/start/$end/imit/$limit"); ?>' title='<?php $clang->eT("Show last..."); ?>'>
<img name='DataEnd' align='left' src='<?php echo $imageurl; ?>/dataend.png' alt='<?php $clang->eT("Show last.."); ?>' />
<img name='DataEnd' align='left' src='<?php echo $sImageURL; ?>/dataend.png' alt='<?php $clang->eT("Show last.."); ?>' />
</a>
<img src='<?php echo $imageurl; ?>/separator.gif' alt='' />
<img src='<?php echo $sImageURL; ?>/separator.gif' alt='' />
<?php } ?>
<form action='<?php echo $this->createUrl("/admin/browse/time/surveyid/{$iSurveyId}"); ?>' id='browseresults' method='post'>
<font size='1' face='verdana'>
<img src='<?php echo $imageurl; ?>/blank.gif' width='31' height='20' alt='' />
<?php $clang->eT("Records displayed:"); ?> <input type='text' size='4' value='$dtcount2' name='limit' id='<?php echo $limit; ?>' />
<img src='<?php echo $sImageURL; ?>/blank.gif' width='31' height='20' alt='' />
<?php $clang->eT("Records displayed:"); ?> <input type='text' size='4' value='<?php echo $limit ?>' name='limit' id='limit' />
<?php $clang->eT("Starting from:"); ?> <input type='text' size='4' value='<?php echo $start; ?>' name='start' id='start' />
<input type='submit' value='<?php $clang->eT("Show"); ?>' />
</font>
Expand All @@ -41,3 +41,51 @@
</div>

<form action='<?php echo $this->createUrl("/admin/browse/time/surveyid/{$iSurveyId}"); ?>' id='resulttableform' method='post'>

<!-- DATA TABLE -->
<?php if ($fncount < 10) { ?>
<table class='browsetable' style='width:100%'>
<?php } else { ?>
<table class='browsetable'>
<?php } ?>

<thead>
<tr>
<th><input type='checkbox' id='selectall'></th>
<th><?php $clang->eT('Actions'); ?></th>
<?php
foreach ($fnames as $fn)
{
if (!isset($currentgroup))
{
$currentgroup = $fn[1];
$gbc = "odd";
}
if ($currentgroup != $fn[1])
{
$currentgroup = $fn[1];
if ($gbc == "odd")
{
$gbc = "even";
}
else
{
$gbc = "odd";
}
}
?>
<th class='<?php echo $gbc; ?>'>
<strong><?php echo flattenText(stripJavaScript($fn[1]), true); ?></strong>
</th>
<?php } ?>
</tr>
</thead>
<tfoot>
<tr>
<td colspan=<?php echo $fncount + 2; ?>>
<?php if (hasSurveyPermission($iSurveyId, 'responses', 'delete')) { ?>
<img id='imgDeleteMarkedResponses' src='<?php echo $sImageURL; ?>token_delete.png' alt='<?php $clang->eT('Delete marked responses'); ?>' />
<?php } ?>
</td>
</tr>
</tfoot>
22 changes: 18 additions & 4 deletions application/views/admin/browse/browsetimerow_view.php
@@ -1,9 +1,23 @@
<tr class='<?php echo $bgcc; ?>' valign='top'>
<td align='center'><input type='checkbox' class='cbResponseMarker' value='<?php echo $dtrow['id']; ?>' name='markedresponses[]' /></td>
<td align='center'>
<a href='<?php echo $this->createUrl("/admin/browse/view/surveyid/{$iSurveyId}/id/{$dtrow['id']}"); ?>'><img src='<?php echo $imageurl; ?>/token_viewanswer.png' alt='<?php $clang->eT('View response details'); ?>'/></a>
<a href='<?php echo $this->createUrl("/admin/dataentry/surveyid/{$iSurveyId}/edit/id/{$dtrow['id']}"); ?>'><img src='<?php echo $imageurl; ?>/edit_16.png' alt='<?php $clang->eT('Edit this response'); ?>'/></a>
<a><img id='deleteresponse_<?php echo $dtrow['id']; ?>' src='<?php echo $imageurl; ?>/token_delete.png' alt='<?php $clang->eT('Delete this response'); ?>' class='deleteresponse'/></a>
<a href='<?php echo $this->createUrl("admin/browse/view/surveyid/$surveyid/id/{$dtrow['id']}"); ?>'><img src='<?php echo $sImageURL; ?>/token_viewanswer.png' alt='<?php $clang->eT('View response details'); ?>'/></a>

<?php if (hasSurveyPermission($surveyid, 'responses', 'update'))
{ ?>
<a href='<?php echo $this->createUrl("admin/dataentry/editdata/subaction/edit/surveyid/{$surveyid}/id/{$dtrow['id']}"); ?>'><img src='<?php echo $sImageURL; ?>/edit_16.png' alt='<?php $clang->eT('Edit this response'); ?>'/></a>
<?php } ?>
<?php if (hasSurveyPermission($surveyid, 'responses', 'delete'))
{ ?>
<a><img id='deleteresponse_<?php echo $dtrow['id']; ?>' src='<?php echo $sImageURL; ?>/token_delete.png' alt='<?php $clang->eT('Delete this response'); ?>' class='deleteresponse'/></a>
<?php } ?>
</td>
<td align='center'>$browsedatafield</td>
<?php
$i = 0;
for ($i; $i < $fncount; $i++)
{
echo "<td align='center'>{$browsedatafield[$i]}</td>";
}
?>

</tr>

0 comments on commit 9ae5230

Please sign in to comment.