/** * @Route( * "/product/create", * name="create_product" * ) * @Method("POST") */ public function createProductAction() { if ($this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) { $request = Request::createFromGlobals(); $order_id = intval($request->request->get('order_id', 0)); $title = strval($request->request->get('title')); $price = floatval($request->request->get('price')); $link = strval($request->request->get('link')); $quantity = intval($request->request->get('quantity')); if ($order_id > 0 && $price > 0 && $quantity > 0 && $title != '') { // Check whether order with such ID exist $order = $this->getDoctrine()->getRepository('AppBundle:Orders')->find($order_id); if ($order) { // Check whether order is still open to join / change quantities $closing_after = Utilities::countTimeRemaining(date_timestamp_get($order->getJoiningDeadline())); if ($closing_after != Utilities::$STATUS_JOINING_TIME_IS_OVER) { $user = $this->getUser(); $product = new Product(); $product->setTitle($title); $product->setPrice($price); $product->setLink($link); $product->setOrders($order); $userProduct = new UserProduct(); $userProduct->setProduct($product); $userProduct->setQuantity($quantity); $userProduct->setUser($user); $product->addUserProduct($userProduct); $em = $this->getDoctrine()->getManager(); $em->persist($userProduct); $em->persist($product); $em->flush(); return $this->render('default/product.html.twig', array('order' => $order, 'product' => $product, 'quantity' => $quantity)); } else { return new Response(AjaxResponses::$ORDER_JOINING_TIME_IS_OVER, Response::HTTP_NOT_FOUND); } } else { return new Response(AjaxResponses::$ORDER_NOT_FOUND, Response::HTTP_NOT_FOUND); } } else { return new Response(AjaxResponses::$WRONG_REQUEST_PARAMETERS, Response::HTTP_BAD_REQUEST); } } else { return new Response(AjaxResponses::$UNAUTHORIZED, Response::HTTP_UNAUTHORIZED); } }