public function getSeries() { $times = tokenize_time($this->begin, $this->end, $this->mode, $this->step); $results = array(); $categories = array(); $CI =& get_instance(); for ($i = 0; $i <= count($times) - 2; $i++) { $rows = $this->queryRows($times[$i], $times[$i + 1]); if (count($rows)) { $categories[] = $times[$i]->format('Y-m-d'); } foreach ($rows as $row) { $item = $row[0]; $method = 'report_label_' . $this->name; if (method_exists($CI, $method)) { $item = $CI->{$method}($row[0]); } $value = doubleval($row[1]); $index = $this->getRowIndex($results, $item); if ($index === null) { $results[] = array('name' => $item, 'data' => array($value)); } else { $results[$index]['data'][] = $value; } } } $this->xAxis->categories = $categories; $this->series = $results; }
public function testTokenizeTime() { $begin = new DateTime('yesterday'); $end = new DateTime('today'); $arr = tokenize_time($begin, $end, 'hour'); $this->assertEquals(count($arr), 25); $begin = new DateTime('yesterday'); $end = new DateTime('3 days'); $arr = tokenize_time($begin, $end, 'day'); $this->assertEquals(count($arr), 6); $arr = tokenize_time('yesterday'); $this->assertEquals(count($arr), 3); $begin = new DateTime('today'); $end = new DateTime('today'); $arr = tokenize_time($begin, $end, 'day'); print_r($arr); }