From da70f95de0ac9f4f3505f6cb302c5d1a4cbfaa3b Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Sun, 12 Jun 2011 21:38:19 +0200 Subject: [PATCH] implemented new submission protocol --- lib/Controller/DataController.php | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/lib/Controller/DataController.php b/lib/Controller/DataController.php index b5ddfa3..cf8b788 100644 --- a/lib/Controller/DataController.php +++ b/lib/Controller/DataController.php @@ -53,19 +53,29 @@ class DataController extends Controller { * @todo replace by pluggable api parser */ public function add(Model\Channel $channel) { - $timestamp = $this->view->request->getParameter('ts'); - $value = $this->view->request->getParameter('value'); + $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 = round(microtime(TRUE) * 1000); + if (is_null($timestamp)) { + $timestamp = (double) round(microtime(TRUE) * 1000); + } + + if (is_null($value)) { + $value = 1; + } + + $channel->addData(new Model\Data($channel, $timestamp, $value)); } - if (is_null($value)) { - $value = 1; - } - - $data = new Model\Data($channel, $timestamp, $value); - $channel->addData($data); $this->em->flush(); }