. */ namespace Volkszaehler\Controller; use Volkszaehler\Util; /** * data controller * * @author Steffen Vogel * @todo call via redirect from Controller\Channel * @package default */ class DataController extends Controller { /** * @todo authentification/indentification */ public function get() { // TODO use uuids for groups or channels $ids = explode(',', trim($this->view->request->getParameter('ids'))); $q = $this->em->createQuery('SELECT c FROM Volkszaehler\Model\Channel c WHERE c.id IN (' . implode(', ', $ids) . ')'); $channels = $q->execute(); $from = ($this->view->request->getParameter('from')) ? (int) $this->view->request->getParameter('from') : NULL; $to = ($this->view->request->getParameter('to')) ? (int) $this->view->request->getParameter('to') : NULL; $groupBy = ($this->view->request->getParameter('groupBy')) ? $this->view->request->getParameter('groupBy') : NULL; // get all readings by default foreach ($channels as $channel) { $interpreter = $channel->getInterpreter($this->em); $this->view->addChannel($channel, $interpreter->getValues($from, $to, $groupBy)); } } /** * */ public function add() { $ucid = $this->view->request->getParameter('ucid'); $channel = $this->em->getRepository('Volkszaehler\Model\Channel\Channel')->findOneBy(array('uuid' => $ucid)); $value = (float) $this->view->request->getParameter('value'); $ts = (int) $this->view->request->getParameter('timestamp'); if ($ts == 0) { $ts = microtime(TRUE) * 1000; } $data = new \Volkszaehler\Model\Data($channel, $value, $ts); $channel->addData($data); $this->em->persist($data); $this->em->flush(); } /** * prune data from database * * @todo authentification/indentification */ public function delete() { $dql = 'DELETE FROM \Volkszaehler\Model\Data WHERE channel_id = ' . $this->id; if ($this->view->request->getParameter('from')) { $dql .= ' && timestamp > ' . (int) $this->view->request->getParameter('from'); } if ($this->view->request->getParameter('to')) { $dql .= ' && timestamp < ' . $this->view->request->getParameter('to'); } $q = $em->createQuery($dql); $q->execute(); } } ?>