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\Entity\Subscription; |
16
|
|
|
use Newscoop\PaywallBundle\Criteria\SubscriptionCriteria; |
17
|
|
|
use Newscoop\PaywallBundle\Permissions; |
18
|
|
|
|
19
|
|
|
class ManageSubscriptionsController extends BaseController |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @Route("/admin/paywall_plugin/manage", options={"expose"=true}) |
23
|
|
|
* @Template() |
24
|
|
|
*/ |
25
|
|
View Code Duplication |
public function manageAction(Request $request) |
|
|
|
|
26
|
|
|
{ |
27
|
|
|
$this->hasPermission(Permissions::SUBSCRIPTIONS_VIEW); |
28
|
|
|
$subscription = new Subscription(); |
29
|
|
|
$form = $this->createForm('subscriptionconf', $subscription); |
30
|
|
|
$em = $this->getDoctrine()->getManager(); |
31
|
|
|
$criteria = new SubscriptionCriteria(); |
32
|
|
|
$subscriptions = $em->getRepository('Newscoop\PaywallBundle\Entity\Subscription') |
33
|
|
|
->getListByCriteria($criteria, true) |
34
|
|
|
->getResult(); |
35
|
|
|
|
36
|
|
|
return array( |
37
|
|
|
'subscriptions' => $subscriptions, |
38
|
|
|
'form' => $form->createView(), |
39
|
|
|
); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @Route("/admin/paywall_plugin/manage/delete/{id}") |
44
|
|
|
*/ |
45
|
|
|
public function deleteAction(Request $request, $id) |
46
|
|
|
{ |
47
|
|
|
$this->hasPermission(Permissions::SUBSCRIPTIONS_MANAGE); |
48
|
|
|
if ($request->isMethod('POST')) { |
49
|
|
|
$em = $this->getDoctrine()->getManager(); |
50
|
|
|
$subscription = $em->getRepository('Newscoop\PaywallBundle\Entity\Subscription') |
51
|
|
|
->findOneBy(array('id' => $id)); |
52
|
|
|
|
53
|
|
|
foreach ($subscription->getSpecification() as $value) { |
54
|
|
|
$value->setIsActive(false); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
$subscription->setIsActive(false); |
58
|
|
|
$em->flush(); |
59
|
|
|
|
60
|
|
|
return new Response(json_encode(array('status' => true))); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.