/** * @Route("/import", name="massimport") */ public function massImportAction(Request $request) { $form = $this->createFormBuilder(null, array('action' => $this->generateUrl('massimport')))->add('file', 'file')->getForm(); if ($request->getMethod() === 'POST') { $request = $this->getRequest(); $form->bind($request); // It always gets overwritten $form['file']->getData()->move('/tmp', 'example.tmp'); $lines = explode(PHP_EOL, file_get_contents('/tmp/example.tmp')); // since we don't care about first line or last line array_shift($lines); array_pop($lines); foreach ($lines as $line) { $data = explode("\t", $line); $product = new Product(); $product->setTitle($data[0]); $product->setDescription($this->sanitize($data[1])); $product->setPrice($data[2]); // I'm not dealing with timezones as I'd need another field for it to work with doctrine and I didn't notice until the end of the exam $product->setInitDate(new \DateTime($data[3])); $product->setExpiryDate(new \DateTime($data[4])); $product->setMerchantAddress($data[5]); $product->setMerchantName($this->sanitize($data[6])); // I'm currently just enabling all of them $product->setStatus(1); $this->saveProduct($product); } } return $this->render('default/success.html.twig'); }
/** * @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); } }
/** * {@inheritDoc} */ public function setTitle($title) { $this->__initializer__ && $this->__initializer__->__invoke($this, 'setTitle', array($title)); return parent::setTitle($title); }