/** * Retrieve chart data per date interval * @param StatsDataProvider $dataprovider Provider class for chart data * @param bool $aggregated Should counts be added * @param array $intervals List of Interval objects * @param bool $countable If true, result can be listet. * @return array List of numbers */ public static function getDataPerDateInterval($dataprovider, $aggregated, $intervals, $countable = false) { $data = array(); $sum = 0; if ($aggregated == 'aggregated') { $intervalBefore = new Interval(); $intervalBefore->setStartTS(0); $intervalBefore->setEndTS($intervals[0]->getStartTS()); $sum = $dataprovider->countInInterval($intervalBefore, $countable); } foreach ($intervals as $interval) { $item = $dataprovider->countInInterval($interval, $countable); if ($aggregated == 'aggregated') { $sum += $item; $data[] = $sum; } else { $data[] = $item; } } return $data; }
/** * Get a list of intervals for a given period * @param string $step Interval descriptor as defined in BsDiagram * @param string $offset Date string * @param string $limit Date string * @param string $modLabel Date format item, e.g. "M" for "Jan, Feb" * @return Interval */ public static function getIntervals($step = "W", $offset = '05/01/2007', $limit = '01/31/2009', $modLabel = false) { $intervals = array(); $starttime = strtotime($offset); $endtime = strtotime($limit); $interval = new Interval(); $interval->setStartTS($starttime); $old = idate($step, $starttime); if ($modLabel) { $interval->setLabel(date($modLabel, $starttime)); } else { $interval->setLabel($old); } $oldts = $starttime; for ($ts = $starttime; $ts <= $endtime; $ts += 86400) { $oldts = $ts - 1; $cur = idate($step, $ts); if ($old != $cur) { $interval->setEndTS($oldts); $intervals[] = $interval; $interval = new Interval(); $interval->setStartTS($ts); if ($modLabel) { $interval->setLabel(date($modLabel, $ts)); } else { $interval->setLabel($cur); } //echo "<br/>-----------------------"; } $old = $cur; //echo "<br/>".$oldts." :: ".date("d.m.YHis", $oldts-1); } $oldts = $oldts + 86400; $interval->setEndTS($oldts); $intervals[] = $interval; //var_dump($intervals); return $intervals; }