| @@ 80-112 (lines=33) @@ | ||
| 77 | /** |
|
| 78 | * @Route("/admin/paywall_plugin/currencies/edit/{id}", name="paywall_plugin_currency_edit", options={"expose"=true}) |
|
| 79 | */ |
|
| 80 | public function editAction(Request $request, Currency $currency) |
|
| 81 | { |
|
| 82 | $this->hasPermission(Permissions::CURRENCIES_MANAGE); |
|
| 83 | $form = $this->createForm(new CurrencyType(), $currency); |
|
| 84 | $em = $this->get('em'); |
|
| 85 | $translator = $this->get('translator'); |
|
| 86 | if ($request->isMethod('POST')) { |
|
| 87 | $form->handleRequest($request); |
|
| 88 | if ($form->isValid()) { |
|
| 89 | if (!$this->checkForExistenceBy($currency)) { |
|
| 90 | $currency->setUpdatedAt(new \DateTime('now')); |
|
| 91 | $em->flush(); |
|
| 92 | ||
| 93 | $this->get('session')->getFlashBag()->add('success', $translator->trans('paywall.success.saved')); |
|
| 94 | ||
| 95 | return $this->redirect($this->generateUrl('paywall_plugin_currency_index')); |
|
| 96 | } |
|
| 97 | ||
| 98 | $this->get('session')->getFlashBag()->add('error', $translator->trans('paywall.error.exists', array( |
|
| 99 | '%resource%' => $currency->getName(), |
|
| 100 | ))); |
|
| 101 | ||
| 102 | return $this->redirect($this->generateUrl('paywall_plugin_currency_edit', array( |
|
| 103 | 'id' => $currency->getId(), |
|
| 104 | ))); |
|
| 105 | } |
|
| 106 | } |
|
| 107 | ||
| 108 | return $this->render('NewscoopPaywallBundle:Currency:edit.html.twig', array( |
|
| 109 | 'form' => $form->createView(), |
|
| 110 | 'currency' => $currency, |
|
| 111 | )); |
|
| 112 | } |
|
| 113 | ||
| 114 | /** |
|
| 115 | * @Route("/admin/paywall_plugin/currencies/delete/{id}", name="paywall_plugin_currency_delete", options={"expose"=true}) |
|
| @@ 95-125 (lines=31) @@ | ||
| 92 | /** |
|
| 93 | * @Route("/admin/paywall_plugin/discounts/edit/{id}", options={"expose"=true}, name="paywall_plugin_discount_edit") |
|
| 94 | */ |
|
| 95 | public function editAction(Request $request, Discount $discount) |
|
| 96 | { |
|
| 97 | $this->hasPermission(Permissions::DISCOUNTS_MANAGE); |
|
| 98 | $form = $this->createForm(new DiscountType(), $discount); |
|
| 99 | $em = $this->get('em'); |
|
| 100 | $translator = $this->get('translator'); |
|
| 101 | if ($request->isMethod('POST')) { |
|
| 102 | $form->handleRequest($request); |
|
| 103 | if ($form->isValid()) { |
|
| 104 | if (!$this->checkForExistenceBy($discount)) { |
|
| 105 | $discount->setUpdatedAt(new \DateTime('now')); |
|
| 106 | $em->flush(); |
|
| 107 | ||
| 108 | $this->get('session')->getFlashBag()->add('success', $translator->trans('paywall.success.saved')); |
|
| 109 | ||
| 110 | return $this->redirect($this->generateUrl('newscoop_paywall_discount_index')); |
|
| 111 | } |
|
| 112 | ||
| 113 | $this->get('session')->getFlashBag()->add('error', $translator->trans('paywall.success.exists')); |
|
| 114 | ||
| 115 | return $this->redirect($this->generateUrl('paywall_plugin_discount_edit', array( |
|
| 116 | 'id' => $discount->getId(), |
|
| 117 | ))); |
|
| 118 | } |
|
| 119 | } |
|
| 120 | ||
| 121 | return $this->render('NewscoopPaywallBundle:Discount:edit.html.twig', array( |
|
| 122 | 'form' => $form->createView(), |
|
| 123 | 'discountId' => $discount->getId(), |
|
| 124 | )); |
|
| 125 | } |
|
| 126 | ||
| 127 | private function exists(Discount $discount) |
|
| 128 | { |
|