public static function deleteQty(Item $item)
 {
     $product = $item->getProduct();
     $qty = $product->getQty();
     $qty_out = $item->getQty();
     $product->setQty($qty + $qty_out);
 }
Example #2
0
 /**
  * @param string $id
  * @param string $name
  *
  * @return Item
  */
 public function createItem($id, $name)
 {
     $item = new Item();
     $item->setName($name);
     $this->setEntityId($item, $id);
     return $item;
 }
 public function testDeleteQty()
 {
     $product = new Product();
     $product->setQty(6);
     $item = new Item();
     $item->setQty(4);
     $item->setProduct($product);
     PurchaseItemManager::deleteQty($item);
     $this->assertEquals(2, $item->getProduct()->getQty(), "Unexpected value for qty in product for deleteQty method ");
 }
 /**
  * @Route("/invoice/{invoiceId}/item/new", name="new-item")
  * @Security("has_role('ROLE_USER')")
  */
 public function newItemAction(Request $request, $invoiceId)
 {
     $item = new Item();
     $invoice = $this->getDoctrine()->getRepository('AppBundle:Invoice')->find($invoiceId);
     $item->setInvoice($invoice);
     $form = $this->createForm($this->get('form_item_type'), $item);
     $form->handleRequest($request);
     if ($form->isSubmitted() && $form->isValid()) {
         $em = $this->getDoctrine()->getManager();
         $em->persist($item);
         $em->flush();
         $this->addFlash('success', 'Item has been added.');
         return $this->redirectToRoute('invoice', array('invoiceId' => $invoiceId));
     }
     return $this->render('default/new-item.html.twig', array('form' => $form->createView(), 'invoice' => $invoice));
 }
 /**
  * @Route("/item/add")
  * @Template()
  */
 public function addAction(Request $request)
 {
     $user = $this->getUser();
     $item = new Item();
     $item->setCreatedBy($user);
     $form = $this->createForm(new ItemType(), $item);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $em = $this->getDoctrine()->getEntityManager();
         $em->persist($item);
         $em->flush();
         $this->addFlash('notice', 'Item added');
         return $this->redirectToRoute('app_app_index');
     }
     return array('form' => $form->createView());
 }
Example #6
0
 /**
  * @ApiDoc(
  *  section="Items",
  *  description="Create a new item",
  *  input="AppBundle\Controller\Form\ItemFormType",
  *  output="AppBundle\Controller\ItemController",
  *  parameters={
  *      {"name"="Request", "dataType"="HTTP request", "required"=true, "description"="The HTTP Request"}
  *     },
  *  statusCodes={
  *       201="Returned when an item has been created",
  *       400="Returned when form is not filled correctly"
  * }
  * )
  */
 public function postItemAction(Request $request)
 {
     $item = new Item();
     // let's just set itemuserid(foreignKey)
     $item->setItemuserid($this->getUserInstance());
     $form = $this->getForm($item);
     $form->handleRequest($request);
     if ($form->isSubmitted() && $form->isValid()) {
         $em = $this->getDoctrine()->getManager();
         $em->persist($item);
         $em->flush();
         // response
         $view = $this->get('raiponce')->getView('Your item has been added!', 201);
         return $this->handleView($view);
     } else {
         throw new HttpException(400, 'the form is not filled correctly');
     }
 }
 private function getWeaponsInfo()
 {
     $parameters = array('iDisplayStart' => 0, 'iDisplayLenght' => 50, 'type' => 1);
     $response = file_get_contents($this->url . '?' . http_build_query($parameters));
     $response = json_decode($response, true);
     $data = $response['aaData'];
     $formattedData = array();
     //Formatting Data
     foreach ($data as $value) {
         $index = $value[0]['name'] . $value[0]['requiredLevel'];
         $formattedData[$index] = array('name' => $value[0]['name'], 'description' => $value[0]['description'], 'level' => $value[0]['requiredLevel']);
     }
     $i = 0;
     foreach ($formattedData as $value) {
         $i++;
         $item = new Item();
         $item->setName($value['name']);
         $item->setDescription($value['description']);
         $item->setLevel($value['level']);
         $item->setType('weapon');
         $this->em->persist($item);
         if ($i % 20 === 0) {
             $this->em->flush();
             $this->em->clear();
         }
     }
     $this->em->flush();
     $this->em->clear();
 }
 /**
  * @Route("/order/checkout")
  */
 public function checkoutAction(Request $request)
 {
     $session = $request->getSession();
     $cart = $session->get('cart', []);
     $order = new Order();
     $order->setDate(new \DateTime());
     $order->setStatus(Order::STATUS_PENDING);
     $order->setCustomer($this->get('security.token_storage')->getToken()->getUser());
     $service = $this->get('ProductService');
     $items = new ArrayCollection();
     foreach ($cart as $product) {
         $item = new Item();
         $item->setProduct($service->getProduct($product['id']));
         $item->setQuantity($product['quantity']);
         $items->add($item);
     }
     $order->setItems($items);
     $em = $this->getDoctrine()->getEntityManager();
     $em->persist($order);
     $em->flush();
     $session->remove('cart');
     return $this->render('order/checkout.html.twig', ['order' => $order]);
 }
 /**
  * Get item requests
  *
  * @param Item $item Item
  *
  * @return array
  */
 public function getItemRequests(Item $item)
 {
     $qb = $this->createQueryBuilder('i');
     return $qb->select('i.title')->addSelect('ir.createdAt AS createdAt')->addSelect('us.fullName AS userName')->addSelect('us.facebookId')->join('i.userRequests', 'ir')->join('ir.user', 'us')->where($qb->expr()->eq('i.id', ':id'))->setParameter('id', $item->getId())->getQuery()->getArrayResult();
 }
 /**
  * Add item
  *
  * @param \AppBundle\Entity\Item $item
  *
  * @return Operation
  */
 public function addItem(\AppBundle\Entity\Item $item)
 {
     $this->items[] = $item;
     $item->setOperation($this);
     return $this;
 }
 /**
  * Add item
  *
  * @param Item $item Item
  *
  * @return $this
  */
 public function addItem(Item $item)
 {
     $this->items->add($item->setCategory($this));
     return $this;
 }
Example #12
0
 public function __construct()
 {
     parent::__construct();
 }
 /**
  * Show item requests
  *
  * @param Item $item Item
  *
  * @return Response
  *
  * @Route("/item/{id}/requests", name="user_item_requests")
  * @ParamConverter("item", class="AppBundle\Entity\Item")
  */
 public function showItemRequestsAction(Item $item)
 {
     if ($item->getCreatedBy()->getId() != $this->getUser()->getId()) {
         throw $this->createAccessDeniedException();
     }
     $itemRepository = $this->getDoctrine()->getRepository('AppBundle:Item');
     $requests = $itemRepository->getItemRequests($item);
     return $this->render('frontend/user/show_item_requests.html.twig', ['requests' => $requests, 'title' => $item->getTitle()]);
 }
Example #14
0
 /**
  * @Route("/item/markAsDone/{item}", name="item_markAsDone")
  */
 public function markAsDoneAction(Item $item)
 {
     if (!$item) {
         throw $this->createNotFoundException('No item found');
     }
     $item->setCompleted(true);
     $em = $this->getDoctrine()->getEntityManager();
     $em->persist($item);
     $em->flush();
     $this->addFlash('success', 'Označeno jako vyřízené');
     return $this->redirect($this->getRequest()->headers->get('referer'));
 }
 /**
  * Test add and remove photos
  */
 public function testAddRemovePhotos()
 {
     $item = new Item();
     $this->assertEquals(0, $item->getPhotos()->count());
     $item->addPhoto(new ItemPhoto());
     $this->assertEquals(1, $item->getPhotos()->count());
     $photos = $item->getPhotos()->first();
     $item->removePhoto($photos);
     $this->assertEquals(0, $item->getPhotos()->count());
 }
 /**
  * Request user facebook page
  *
  * @param Item    $item    Item
  * @param Request $request Request
  *
  * @return Response
  *
  * @Method("POST")
  * @Route("item/{id}/request-user", name="item_user_get_facebook", options={"expose"=true, "i18n"=false}))
  * @ParamConverter("item", class="AppBundle\Entity\Item")
  */
 public function requestUserAction(Item $item, Request $request)
 {
     if (!$request->isXmlHttpRequest()) {
         throw new AccessDeniedException();
     }
     $form = $this->createForm('item_details');
     if ($request->isMethod('post')) {
         $form->submit($request);
         if ($form->isValid()) {
             $user = $item->getCreatedBy();
             $userItemRequest = (new ItemRequest())->setItem($item)->setUser($this->getUser());
             $em = $this->getDoctrine()->getManager();
             $em->persist($userItemRequest);
             $em->flush();
             return new JsonResponse($user->getFacebookId());
         }
     }
     throw new BadRequestHttpException();
 }