Exemplo n.º 1
0
     * @return int         	  number of affected rows
     */
    public function aggregate($uuid = null, $level = 'day', $mode = 'full', $period = null)
    {
        // validate settings
        if (!in_array($mode, array('full', 'delta'))) {
            throw new \RuntimeException('Unsupported aggregation mode ' . $mode);
        }
        if (!$this->isValidAggregationLevel($level)) {
            throw new \RuntimeException('Unsupported aggregation level ' . $level);
        }
        // get channel definition to select correct aggregation function
        $sqlParameters = array('channel');
        $sql = 'SELECT id, uuid, type FROM entities WHERE class = ?';
        if ($uuid) {
            $sqlParameters[] = $uuid;
            $sql .= ' AND uuid = ?';
        }
        $rows = 0;
        // aggregate each channel
        foreach ($this->conn->fetchAll($sql, $sqlParameters) as $row) {
            $entity = Definition\EntityDefinition::get($row['type']);
            $interpreter = $entity->getInterpreter();
            $rows += $this->aggregateChannel($row['id'], $interpreter, $mode, $level, $period);
        }
        return $rows;
    }
}
// initialize static variables
Aggregation::init();