public function indexAction()
 {
     if ($this->get('session')->get('user') === null) {
         return $this->redirect('/login');
     }
     $user = $this->get('session')->get('user');
     $canvasRepo = $this->getDoctrine()->getRepository('Emicro\\Bundles\\CoreBundle\\Entity\\Canvas');
     $canvases = $canvasRepo->getByUser($user->getId());
     $serializer = new JsonSerializer();
     return $this->render('EmicroCoreBundle:App:index.html.twig', array('user' => $user, 'userJson' => $serializer->serialize($user), 'canvases' => $serializer->serialize($canvases)));
 }
 public function createAction()
 {
     $response = new Response();
     $response->headers->set('Content-type', 'application/json');
     if ($this->get('session')->get('user') === null) {
         $response->setStatusCode(401);
         $response->setContent(json_encode(array('response' => Response::$statusTexts[401])));
         return $response;
     }
     $data = $this->getRequest()->request->all();
     if (empty($data)) {
         $data = json_decode($this->getRequest()->getContent(), true);
     }
     $this->handleUpload($data);
     $userRepo = $this->getDoctrine()->getRepository('Emicro\\Bundles\\CoreBundle\\Entity\\User');
     $canvasRepo = $this->getDoctrine()->getRepository('Emicro\\Bundles\\CoreBundle\\Entity\\Canvas');
     $user = $this->get('session')->get('user');
     $canvasRepo->setUser($userRepo->find($user->getId()));
     if (isset($data['id'])) {
         $canvas = $canvasRepo->update($data, $data['id']);
         $response->setStatusCode(200);
     } else {
         $canvas = $canvasRepo->insert($data);
         $response->setStatusCode(201);
     }
     $serializer = new JsonSerializer();
     $response->setContent($serializer->serialize($canvas));
     return $response;
 }
 public function createAction()
 {
     if ($this->get('session')->get('user') === null) {
         $response = new Response();
         $response->setStatusCode(401);
         $response->setContent(json_encode(array('response' => Response::$statusTexts[401])));
         return $response;
     }
     $data = json_decode($this->getRequest()->getContent(), true);
     $user = $this->get('session')->get('user');
     $userRepo = $this->getDoctrine()->getRepository('Emicro\\Bundles\\CoreBundle\\Entity\\User');
     $projectRepo = $this->getDoctrine()->getRepository('Emicro\\Bundles\\CoreBundle\\Entity\\Project');
     $projectRepo->setUser($userRepo->find($user->getId()));
     $newProject = $projectRepo->insert($data);
     $serializer = new JsonSerializer();
     $response = new Response();
     $response->setStatusCode(200);
     $response->setContent($serializer->serialize($newProject));
     $response->headers->set('Content-type', 'application/json');
     return $response;
 }