. */ namespace Volkszaehler\Controller; use Volkszaehler\Model; use Volkszaehler\Util; /** * Data controller * * @author Steffen Vogel * @package default */ class DataController extends Controller { /** * Query for data by given channel or group */ public function get(Model\Entity $entity) { $from = $this->view->request->getParameter('from'); $to = $this->view->request->getParameter('to'); $tuples = $this->view->request->getParameter('tuples'); $groupBy = $this->view->request->getParameter('group'); $class = $entity->getDefinition()->getInterpreter(); return new $class($entity, $this->em, $from, $to, $tuples, $groupBy); } /** * Sporadic test/demo implemenation * * @todo replace by pluggable api parser */ public function add(Model\Channel $channel) { $timestamp = $this->view->request->getParameter('ts'); $value = $this->view->request->getParameter('value'); if (is_null($timestamp)) { $timestamp = round(microtime(TRUE) * 1000); } if (is_null($value)) { $value = 1; } $data = new Model\Data($channel, $timestamp, $value); $channel->addData($data); $this->em->flush(); } public function run($operation, array $identifiers = array()) { $ec = new EntityController($this->view, $this->em); $entity = $ec->get($identifiers[0]); return $this->{$operation}($entity); } } ?>