. */ 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) { $rawPost = file_get_contents('php://input'); try { /* to parse new submission protocol */ $json = Util\JSON::decode($rawPost); foreach ($json as $tuple) { $channel->addData(new Model\Data($channel, $tuple[0], $tuple[1])); } } catch (Util\JSONException $e) { /* fallback to old method */ $timestamp = $this->view->request->getParameter('ts'); $value = $this->view->request->getParameter('value'); if (is_null($timestamp)) { $timestamp = (double) round(microtime(TRUE) * 1000); } if (is_null($value)) { $value = 1; } $channel->addData(new Model\Data($channel, $timestamp, $value)); } $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); } } ?>