1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @author Rafał Muszyński <[email protected]> |
5
|
|
|
* @copyright 2013 Sourcefabric o.p.s. |
6
|
|
|
* @license http://www.gnu.org/licenses/gpl-3.0.txt |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Newscoop\PaywallBundle\Controller; |
10
|
|
|
|
11
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
12
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; |
13
|
|
|
use Symfony\Component\HttpFoundation\Request; |
14
|
|
|
use Symfony\Component\HttpFoundation\Response; |
15
|
|
|
use Newscoop\PaywallBundle\Form\Type\SettingsFormType; |
16
|
|
|
use Newscoop\PaywallBundle\Permissions; |
17
|
|
|
|
18
|
|
|
class ConfigurePaywallController extends BaseController |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @Route("/admin/paywall_plugin/configure-paywall", options={"expose"=true}) |
22
|
|
|
* @Template() |
23
|
|
|
*/ |
24
|
|
|
public function indexAction(Request $request) |
25
|
|
|
{ |
26
|
|
|
$this->hasPermission(Permissions::CONFIGURE); |
27
|
|
|
$em = $this->getDoctrine()->getManager(); |
28
|
|
|
$preferencesService = $this->container->get('system_preferences_service'); |
29
|
|
|
$translator = $this->container->get('translator'); |
30
|
|
|
$active = $em->getRepository('Newscoop\PaywallBundle\Entity\Gateway') |
31
|
|
|
->findOneBy(array( |
32
|
|
|
'isActive' => true, |
33
|
|
|
)); |
34
|
|
|
|
35
|
|
|
$form = $this->container->get('form.factory')->create(new SettingsFormType(), array( |
36
|
|
|
'notificationEmail' => $preferencesService->PaywallMembershipNotifyEmail, |
37
|
|
|
'enableNotify' => $preferencesService->PaywallEmailNotifyEnabled == '1' ? true : false, |
38
|
|
|
'notificationFromEmail' => $preferencesService->PaywallMembershipNotifyFromEmail, |
39
|
|
|
'currency' => $preferencesService->PaywallDefaultCurrency, |
40
|
|
|
)); |
41
|
|
|
|
42
|
|
|
if ($request->isMethod('POST')) { |
43
|
|
|
$form->bind($request); |
44
|
|
|
if ($form->isValid()) { |
45
|
|
|
$data = $form->getData(); |
46
|
|
|
$preferencesService->set('PaywallMembershipNotifyEmail', $data['notificationEmail']); |
47
|
|
|
$preferencesService->set('PaywallEmailNotifyEnabled', $data['enableNotify']); |
48
|
|
|
$preferencesService->set('PaywallMembershipNotifyFromEmail', $data['notificationFromEmail']); |
49
|
|
|
$preferencesService->set('PaywallDefaultCurrency', $data['currency']); |
50
|
|
|
|
51
|
|
|
if (is_numeric($data['adapter'])) { |
52
|
|
|
$settings = $em->getRepository('Newscoop\PaywallBundle\Entity\Gateway') |
53
|
|
|
->findOneBy(array( |
54
|
|
|
'id' => $data['adapter'], |
55
|
|
|
)); |
56
|
|
|
|
57
|
|
|
$all = $em->getRepository('Newscoop\PaywallBundle\Entity\Gateway') |
58
|
|
|
->findAll(); |
59
|
|
|
|
60
|
|
|
foreach ($all as $value) { |
61
|
|
|
$value->setActive(false); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
$settings->setActive(true); |
65
|
|
|
$em->flush(); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
$this->get('session')->getFlashBag()->add('success', $translator->trans('paywall.success.settingssaved')); |
69
|
|
|
|
70
|
|
|
return $this->redirect($this->generateUrl('newscoop_paywall_configurepaywall_index')); |
71
|
|
|
} else { |
72
|
|
|
$this->get('session')->getFlashBag()->add('error', $translator->trans('paywall.error.settingserror')); |
73
|
|
|
|
74
|
|
|
return $this->redirect($this->generateUrl('newscoop_paywall_configurepaywall_index')); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
if ($request->isXmlHttpRequest()) { |
79
|
|
|
$inactive = $em->getRepository('Newscoop\PaywallBundle\Entity\Gateway') |
80
|
|
|
->findBy(array( |
81
|
|
|
'isActive' => false, |
82
|
|
|
)); |
83
|
|
|
|
84
|
|
|
$adapters = array(); |
85
|
|
|
foreach ($inactive as $value) { |
86
|
|
|
$adapters[] = array( |
87
|
|
|
'id' => $value->getId(), |
88
|
|
|
'text' => $value->getName(), |
89
|
|
|
); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
return new Response(json_encode($adapters)); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
return array( |
96
|
|
|
'form' => $form->createView(), |
97
|
|
|
'current' => $active->getName(), |
98
|
|
|
); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|