method serieByPeriod documentation in bbn\Appui\Statistic
function(int $values = 30, string $unit = 'm', string $end = NULL, string $pstart = NULL)
{
if ($this->ocfg && $values) {
if (!$end) {
$end = date('Y-m-d');
}
if (bbn\Str::isDateSql($end)) {
switch (strtolower($unit)) {
case 'y':
$funit = 'years';
$tmp = date('Y-m-d', mktime(23, 59, 59, 12, 31, substr($end, 0, 4)));
if ($end !== $tmp) {
$end = date('Y-m-d', mktime(23, 59, 59, 12, 31, (int)substr($end, 0, 4) - 1));
}
break;
case 't':
$funit = 'months';
$values *= 3;
case 'm':
$funit = 'months';
$month = (int)substr($end, 5, 2);
$remain = $month % 3;
if ($remain) {
$remain = 3 - $remain;
}
$tmp = date('Y-m-d', mktime(23, 59, 59, $month + 1, 0, substr($end, 0, 4)));
if (($end !== $tmp) || $remain) {
$end = date('Y-m-d', mktime(23, 59, 59, $month - $remain + 1, 0, (int)substr($end, 0, 4)));
}
break;
case 'w':
$funit = 'weeks';
break;
case 'd':
$funit = 'days';
break;
}
if (isset($funit)) {
$dend = new \DateTime($end);
$dstart = $dend->sub(date_interval_create_from_date_string("$values $funit"));
$start = $dstart->format('Y-m-d');
$res = [
'labels' => [],
'series' => []
];
if ($all = $this->db->rselectAll(
'bbn_statistics',
['day', 'res'],
[
[
'field' => 'id_option',
'value' => $this->id_option
], [
'field' => 'day',
'operator' => '<=',
'value' => $end
], [
'field' => 'day',
'operator' => '>=',
'value' => $start
]
],
[
'day' => 'ASC'
]
)) {
$last = count($all) - 1;
if (($all[$last]['day'] !== $end) && ($tmp = $this->db->rselect(
'bbn_statistics',
['day', 'res'],
[
[
'field' => 'id_option',
'value' => $this->id_option
], [
'field' => 'day',
'operator' => '>',
'value' => $end
]
],
[
'day' => 'ASC'
]
))
) {
$all[] = $tmp;
$last++;
}
$dcurrent = new \DateTime($start);
$num_days = (int)$dend->diff($dcurrent)->format('%a');
$diff = $num_days;
$interval = (int)floor($num_days / $values);
$num = 0;
$idx = 0;
$didx = 0;
while ($diff >= 0) {
$current = $dcurrent->format('Y-m-d');
if ($num === $interval) {
$num = 0;
}
if (!$num) {
$res['labels'][$didx] = $current;
$res['series'][$didx] = $all[$idx]['res'];
$didx++;
} elseif (empty($this->ocfg['total'])) {
$res['labels'][$didx] = $current;
$res['series'][$didx] += (int)$all[$idx]['res'];
}
if (!$diff) {
break;
}
if ($current === $all[$idx]['day']) {
$idx++;
}
$dcurrent = $dcurrent->add(date_interval_create_from_date_string('1 days'));
$diff = (int)$dend->diff($dcurrent)->format('%a');
$num++;
}
}
return $res;
}
}
}
return null;
}
BBN is a suite of PHP and JS libraries and VueJS components - all open-source! bbn.io, build applications, the quick way
This website uses cookies to ensure you get the best experience on our website.
© 2011-2023
BBN Solutions