fix: [appTable:table_statistics] Compute timeline only if the fields exist in the DB schema

pull/93/head
Sami Mokaddem 2022-01-20 13:44:19 +01:00
parent f3813dd5a7
commit e6ec31ff23
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
2 changed files with 14 additions and 9 deletions

View File

@ -94,8 +94,12 @@ class AppTable extends Table
{
$statistics = [];
if ($table->hasBehavior('Timestamp')) {
$statistics['created'] = $this->getActivityStatistic($table, $days, 'created');
$statistics['modified'] = $this->getActivityStatistic($table, $days, 'modified');
if ($table->getSchema()->getColumnType('created') == 'datetime') {
$statistics['created'] = $this->getActivityStatistic($table, $days, 'created');
}
if ($table->getSchema()->getColumnType('modified') == 'datetime') {
$statistics['modified'] = $this->getActivityStatistic($table, $days, 'modified');
}
}
return $statistics;
}
@ -132,7 +136,7 @@ class AppTable extends Table
->where(["{$field} >" => new \DateTime("-{$days} days")])
->group(['date'])
->order(['date']);
$data = $query->toArray();
$data = $query->all()->toArray();
$interval = new \DateInterval('P1D');
$period = new \DatePeriod(new \DateTime("-{$days} days"), $interval, (new \DateTime())->modify( '+1 day' ));
foreach ($period as $date) {

View File

@ -43,18 +43,19 @@ $panelControlHtml = sprintf(
]
])
);
$activityNumbers = sprintf(
'<div class="my-1 fs-5">
<div class="lh-1 d-flex align-items-center" title="%s">%s<span class="ms-1"> %s</span></div>
<div class="lh-1 d-flex align-items-center" title="%s">%s<span class="ms-1">%s</span></div>
</div>',
$createdNumber = empty($timeline['created']) ? '' : sprintf(
'<div class="lh-1 d-flex align-items-center" title="%s">%s<span class="ms-1"> %s</span></div>',
__('{0} Created', $timeline['created']['variation']),
$this->Bootstrap->icon('plus', ['class' => ['fa-fw'], 'params' => ['style' => 'font-size: 60%;']]),
$timeline['created']['variation'],
$timeline['created']['variation']
);
$modifiedNumber = empty($timeline['modified']) ? '' : sprintf(
'<div class="lh-1 d-flex align-items-center" title="%s">%s<span class="ms-1"> %s</span></div>',
__('{0} Modified', $timeline['modified']['variation']),
$this->Bootstrap->icon('edit', ['class' => ['fa-fw'], 'params' => ['style' => 'font-size: 60%;']]),
$timeline['modified']['variation']
);
$activityNumbers = sprintf('<div class="my-1 fs-5">%s%s</div>', $createdNumber, $modifiedNumber);
$leftContent = sprintf(
'%s%s',