/**
  * @Route("/device/create", name="device_create")
  */
 public function createDeviceAction()
 {
     $request = Request::createFromGlobals();
     $idDevice = $request->request->get('idDevice');
     $last_visit = $request->request->get('last_visit');
     $device = new device();
     $device->setIdDevice($idDevice);
     $device->setLastVisit($last_visit);
     $em = $this->getDoctrine()->getManager();
     $em->persist($device);
     $em->flush();
     return $this->redirectToRoute('device_show');
 }
 /**
  * @Route("/api/data", name="api_data")
  */
 public function dataAction()
 {
     $request = Request::createFromGlobals();
     $id = $request->query->get('id');
     $device = $this->getDoctrine()->getRepository('AppBundle:Device')->findOneBy(array('idDevice' => $id));
     if (!$device) {
         $device = new device();
         $device->setIdDevice($id);
         $device->setLastVisit();
         $em = $this->getDoctrine()->getManager();
         $em->persist($device);
         $em->flush();
     }
     $channel = $this->getDoctrine()->getRepository('AppBundle:Channel')->findAll();
     $response = new Response();
     $response->setContent(json_encode($channel));
     $response->headers->set('Content-Type', 'application/json');
     return $response;
 }