Skip to content

Commit

Permalink
Make reporting work on PostgreSQL too
Browse files Browse the repository at this point in the history
  • Loading branch information
cebe committed Dec 4, 2018
1 parent b989c9e commit cb6451b
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions views/default/report.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,45 @@


// status
$db = Yii::$app->db;
switch ($db->driverName) {
case 'pgsql':
$selectExpression = "to_char(to_timestamp(created_at), 'YYYY-MM-DD')";
break;
default:
case 'mysql':
$selectExpression = "DATE_FORMAT(FROM_UNIXTIME(created_at), '%Y-%m-%d')";
break;
}
$subQuery = (new \yii\db\Query())
->select([
'dd' => new \yii\db\Expression($selectExpression),
'status',
])->from('queue_manager');
$data = (new \yii\db\Query())
->select(new \yii\db\Expression('DATE_FORMAT(FROM_UNIXTIME(created_at), \'%d-%m-%Y\') AS dd,
status,
count(*)as cnt'))
->from('queue_manager')
->groupBy('status,dd')
->orderBy('created_at')
->select([
'dd',
'status',
'cnt' => 'COUNT(*)',
])
->from(['q' => $subQuery])
->groupBy(['status', 'dd'])
->orderBy('dd')
->all();

$labels = [];
foreach ($data as $item) {
$dd = $item['dd'];
$dd = Yii::$app->formatter->asDate($item['dd']);
if (!in_array($dd, $labels)) {
$labels[] = $dd;
}
}
$status1 = array_fill_keys($labels, '0');
$status1 = array_fill_keys($labels, '0');
$status2 = array_fill_keys($labels, '0');
$status3 = array_fill_keys($labels, '0');
$status4 = array_fill_keys($labels, '0');
foreach ($data as $item) {
$dd = $item['dd'];
$dd = Yii::$app->formatter->asDate($item['dd']);
if ($item['status'] == QueueManager::STATUS_WAITING) {
$status1[$dd] = $item['cnt'];
}
Expand Down

0 comments on commit cb6451b

Please sign in to comment.