Guest User

Untitled

a guest
Jan 24th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. /**
  2. * @Route("/delete/{id}", name="ci_item_delete", requirements={"id"="d+"}, options={"expose"=true})
  3. * @Security("has_role('ROLE_USER') && is_granted('delete', item)")
  4. * @param Request $request
  5. * @param Item $item
  6. * @return RedirectResponse
  7. */
  8. public function deleteAction(Request $request, Item $item)
  9. {
  10. $referer = $request
  11. ->headers
  12. ->get('referer');
  13. $rpath = parse_url($referer, PHP_URL_PATH );
  14. $badreferrers = array(
  15. $this->generateUrl('ci_item_show', ['id' => $item->getId()]),
  16. $this->generateUrl('ci_item_edit', ['id' => $item->getId()])
  17. );
  18.  
  19. if(in_array($rpath, $badreferrers) ){ //coming from a page that won't exist once the Item is deleted
  20. $redirect = $this->generateUrl('ci_item_list_format_room', ['format_id'=> $item->getFormat()->getId(), 'room_id'=> $item->getRoom()->getId()]);
  21. } else {
  22. $redirect = $referer;
  23. }
  24.  
  25. $em = $this->getDoctrine()->getManager();
  26. $em->remove($item);
  27. $em->flush();
  28. $this->addFlash('success', 'msg.delete.item.success');
  29.  
  30. return $this->redirect($redirect);
  31. }
  32.  
  33. /**
  34. * @Route("/delete/{id}", name="ci_item_delete", requirements={"id"="d+"}, options={"expose"=true})
  35. * @Route("/deletefromlist/{id}", name="ci_item_delete_from_list", requirements={"id"="d+"}, options={"expose"=true})
  36. * @Security("has_role('ROLE_USER') && is_granted('delete', item)")
  37. * @param Request $request
  38. * @param Item $item
  39. * @return RedirectResponse
  40. */
  41. public function deleteAction(Request $request, Item $item)
  42. {
  43. $referer = $request
  44. ->headers
  45. ->get('referer');
  46.  
  47. if($request->get('_route') == 'ci_item_delete' ){ //coming from a page that won't exist once the Item is deleted
  48. $redirect = $this->generateUrl('ci_item_list_format_room', ['format_id'=> $item->getFormat()->getId(), 'room_id'=> $item->getRoom()->getId()]);
  49. } else {
  50. $redirect = $referer;
  51. }
  52.  
  53. $em = $this->getDoctrine()->getManager();
  54. $em->remove($item);
  55. $em->flush();
  56. $this->addFlash('success', 'msg.delete.item.success');
  57.  
  58. return $this->redirect($redirect);
  59. }
Add Comment
Please, Sign In to add comment