method serie documentation in bbn\Appui\Statistic

function(int $values = 30, string $start = NULL, string $end = NULL) { if ($this->check()) { if (!$end) { $end = date('Y-m-d'); } if (!$start) { $start = date('Y-m-d', strtotime($end.' 12:00:00') - ($values * 24 * 3600)); } if (bbn\Str::isDateSql($start, $end)) { $res = [ 'labels' => [], 'series' => [] ]; // All the values between start and end $all = $this->db->rselectAll( 'bbn_statistics', ['day', 'res'], [ [ 'field' => 'id_option', 'value' => $this->id_option ], [ 'field' => 'day', 'operator' => '>=', 'value' => $start ], [ 'field' => 'day', 'operator' => '<=', 'value' => $end ] ], [ 'day' => 'ASC' ] ); // As the row appears with its last date for value we pick the nextr row if the last row is not the last day $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++; } if (count($all)) { $dcurrent = new \DateTime($start); $dend = new \DateTime($end); $num_days = (int)$dend->diff($dcurrent)->format('%a'); $diff = $num_days; $interval = (int)floor(($num_days + 1) / $values); $num = 0; $idx = 0; $didx = 0; $pstart = false; while ($diff >= 0) { $current = $dcurrent->format('Y-m-d'); if (!$pstart) { $pstart = $current; } if ($num === $interval) { $num = 0; } if (!$num) { if (!empty($this->ocfg['total']) || ($interval === 1)) { $res['labels'][$didx] = $current; } else { $res['labels'][$didx] = bbn\Date::format($pstart, 's').' - '.bbn\Date::format($current, 's'); } if (isset($res['series'][$didx]) && empty($this->ocfg['total'])) { $res['series'][$didx] = $res['series'][$didx] + $all[$idx]['res']; } else { $res['series'][$didx] = $all[$idx]['res']; } $pstart = false; $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.