Delete a basket

@param  Request $request
@param  Basket  $basket

@return array
331184
public function deleteBasketAction(Request $request, Basket $basket)
    {
        /** @var EntityManager $em */
        $em = $this->app['orm.em'];
        $em->remove($basket);
        $em->flush();

        return $this->searchBasketsAction($request);
    }
869348
protected function handleWriteBasket($request, $id = null)
    {
        $basket = $id ? $this->getBasket($id) : null;

        $form = $this->formFactory->createNamed(null, 'sonata_basket_api_form_basket', $basket, [
            'csrf_protection' => false,
        ]);

        $form->handleRequest($request);

        if ($form->isValid()) {
            $basket = $form->getData();
            if ($basket->getCustomerId()) {
                $this->checkExistingCustomerBasket($basket->getCustomerId());
            }
            $this->basketManager->save($basket);

            $context = new Context();
            $context->setGroups(['sonata_api_read']);

            // simplify when dropping FOSRest < 2.1
            if (method_exists($context, 'enableMaxDepth')) {
                $context->enableMaxDepth();
            } else {
                $context->setMaxDepth(10);
            }

            $view = FOSRestView::create($basket);
            $view->setContext($context);

            return $view;
        }

        return $form;
    }
1296477
public function deleteLessThanAction(Request $request)
    {
        $lastTweetId = $this->getLastTweetIdFromCookie($request);

        if (!is_null($lastTweetId)) {
            /** @var TweetRepository $tweetRepository */
            $tweetRepository = $this->getDoctrine()
                ->getRepository('AsyncTweetsBundle:Tweet');

            $count = $tweetRepository
                ->deleteAndHideTweetsLessThanId($lastTweetId);

            /** @var Session $session */
            $session = $this->get('session');

            $session->getFlashBag()->add(
                'message',
                sprintf('%s tweets deleted.', $count)
            );
        }

        return $this->redirect($this->generateUrl('asynctweets_homepage'));
    }
460090
public function destroy(Request $request)
    {
        $this->api('category.delete', $request->route('category'))->parameters($request->all())->delete();

        Forum::alert('success', 'categories.deleted', 1);

        return redirect(config('forum.routing.prefix'));
    }
186491
public function deleteCollectionAction(Request $request)
    {
        if (null === $uids = $request->get('uids', null)) {
            throw new BadRequestHttpException('uid is missing.');
        }

        $result = [];
        $statusCode = 204;
        $pages = $this->getPageRepository()->findBy(['_uid' => $uids]);
        foreach ($pages as $page) {
            try {
                if ($page->isDeleted()) {
                    $this->hardDelete($page);
                } else {
                    $this->softDelete($page);
                }

                $result[] = [
                    'uid'        => $page->getUid(),
                    'statusCode' => 204,
                    'message'    => 'OK',
                ];
            } catch (AccessDeniedException $e) {
                $result[] = [
                    'uid'        => $page->getUid(),
                    'statusCode' => 401,
                    'message'    => $e->getMessage(),
                ];
                $statusCode = ($statusCode < 401) ? 401 : $statusCode;
            } catch (\Exception $e) {
                if ($e instanceof BadRequestHttpException || $e instanceof InsufficientAuthenticationException) {
                    $result[] = [
                        'uid'        => $page->getUid(),
                        'statusCode' => 403,
                        'message'    => $e->getMessage(),
                    ];
                    $statusCode = ($statusCode < 403) ? 403 : $statusCode;
                } else {
                    $result[] = [
                        'uid'        => $page->getUid(),
                        'statusCode' => 500,
                        'message'    => $e->getMessage(),
                    ];
                    $statusCode = ($statusCode < 500) ? 500 : $statusCode;
                }
            }
        }

        $this->getEntityManager()->flush();

        return $this->createJsonResponse($result, $statusCode);
    }
295308
def destroy_basket(request):
    
    items, bid = get_basket_items(request)
    for item in items:
        item.delete()
    return bid
953397
public function setBasketDescriptionAction(Request $request, Basket $basket)
    {
        $basket->setDescription($request->get('description'));

        /** @var EntityManager $em */
        $em = $this->app['orm.em'];
        $em->persist($basket);
        $em->flush();

        return Result::create($request, ["basket" => $this->listBasket($basket)])->createResponse();
    }
362838
public function deleteAction(Request $request, $id)
    {
        $locale = $this->getProductLocaleManager()->retrieveLocale($this->getUser(), $request->get('locale'));

        $delete = function ($id) use ($locale) {
            try {
                $this->getManager()->delete($id, $this->getUser()->getId());
            } catch (ProductChildrenExistException $exc) {
                throw new RestException('Deletion not allowed, because the product has sub products', 400);
            }
        };
        $view = $this->responseDelete($id, $delete);

        return $this->handleView($view);
    }
257718
private function listBasketContent(Request $request, Basket $basket)
    {
        return array_map(function (BasketElement $element) use ($request) {
            return $this->listBasketElement($request, $element);
        }, iterator_to_array($basket->getElements()));
    }
51815
public function deleteAction(Request $request, Departamento $departamento)
    {
        $form = $this->createDeleteForm($departamento);
        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            $em = $this->getDoctrine()->getManager();
            $em->remove($departamento);
            $em->flush();
        }

        return $this->redirectToRoute('departamento_index');
    }
69185
public function deleteAction(MeasureUnit $measureunit, Request $request)
    {
        $form = $this->createDeleteForm($measureunit->getId(), 'admin_shop_measure_unit_delete');
        if ($form->handleRequest($request)->isValid()) {
            $em = $this->getDoctrine()->getManager();
            $em->remove($measureunit);
            $em->flush();
        }

        return $this->redirect($this->generateUrl('admin_shop_measure_unit'));
    }
1293957
public function delete(Request $request, $bas_id)
    {
        $success = false;
        $msg = $this->app->trans('An error occured');

        $collection = \collection::getByBaseId($this->app, $bas_id);

        try {
            if ($collection->get_record_amount() > 0) {
                $msg = $this->app->trans('Empty the collection before removing');
            } else {
                $collection->unmount();
                $collection->delete();
                $success = true;
                $msg = $this->app->trans('Successful removal');
            }
        } catch (\Exception $e) {
        }

        if ('json' === $request->getRequestFormat()) {
            return $this->app->json([
                'success' => $success,
                'msg'     => $msg
            ]);
        }

        if ($collection->get_record_amount() > 0) {
            return $this->app->redirectPath('admin_display_collection', [
                'bas_id'  => $collection->get_sbas_id(),
                'success' => 0,
                'error'   => 'collection-not-empty',
            ]);
        }

        if ($success) {
            return $this->app->redirectPath('admin_display_collection', [
                'bas_id'      => $collection->get_sbas_id(),
                'success'     => 1,
                'reload-tree' => 1,
            ]);
        }

        return $this->app->redirectPath('admin_display_collection', [
            'bas_id'  => $collection->get_sbas_id(),
            'success' => 0,
        ]);
    }
1236538
public function cdeleteAction(Request $request)
    {
        $manager = $this->getTaskManager();

        $ids = array_filter(explode(',', $request->get('ids')));
        foreach ($ids as $id) {
            $manager->remove($id);
        }

        $this->getEntityManager()->flush();

        return $this->handleView($this->view());
    }
887171
public function removeItemAction(Request $request)
    {
        $cart = $this->getCart();
        $item = $this->getDoctrine()
            ->getRepository('EkynaOrderBundle:OrderItem')
            ->findOneBy([
                'id' => $request->attributes->get('itemId'),
                'orderId' => $cart->getId(),
            ]);

        if (null === $item) {
            throw new NotFoundHttpException($this->getTranslator()->trans('ekyna_cart.message.item_not_found'));
        }

        $event = new OrderItemEvent($cart, $item);
        $this->getDispatcher()->dispatch(OrderItemEvents::REMOVE, $event);
        if (!$event->isPropagationStopped()) {
            $message = 'ekyna_cart.message.item_remove.success';
            $type    = 'success';
        } else {
            $message = 'ekyna_cart.message.item_remove.failure';
            $type    = 'danger';
        }
        $this->addFlash($this->getTranslator()->trans($message, [
            '{{ name }}' => $item->getDesignation(),
            '{{ path }}' => $this->generateUrl('ekyna_cart_index'),
        ]), $type);

        if ($request->isXmlHttpRequest()) {
            // TODO
            return new Response();
        }

        return $this->redirectAfterContentChange($request);
    }
1187921
public function removeAction(Request $request): Response
    {
        $form = $this->formFactory->removeCustomUrl();
        $form->handleRequest($request);

        $location = $form->getData()->getLocation();

        if ($form->isSubmitted()) {
            $result = $this->submitHandler->handle($form, function (CustomUrlRemoveData $data) {
                $aliasToRemoveList = [];
                foreach ($data->getUrlAliases() as $customUrlId => $selected) {
                    $aliasToRemoveList[] = $this->urlAliasService->load($customUrlId);
                }
                $this->urlAliasService->removeAliases($aliasToRemoveList);

                return $this->redirectToLocation($data->getLocation(), UrlsTab::URI_FRAGMENT);
            });

            if ($result instanceof Response) {
                return $result;
            }
        }

        if ($location) {
            return $this->redirectToLocation($location, UrlsTab::URI_FRAGMENT);
        }

        return $this->redirectToRoute('ezplatform.dashboard');
    }
334264
public function send(Request $request)
    {
        $response      = new DeleteIndexResponse();
        $rpbDeleteReq  = $this->createRpbMessage($request);

        $this->client->send($rpbDeleteReq, RiakMessageCodes::YOKOZUNA_INDEX_DELETE_REQ, RiakMessageCodes::DEL_RESP);

        return $response;
    }
247061
public function destroy(Request $request, $id)
    {
        $deleted = (new Services\GroupsService)->dataDelete($id, $request->all());
        return response()->json(['deleted' => $deleted]);
    }