1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author Rafał Muszyński <[email protected]> |
4
|
|
|
* @copyright 2015 Sourcefabric z.ú. |
5
|
|
|
* @license http://www.gnu.org/licenses/gpl-3.0.txt |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace Newscoop\PaywallBundle\EventListener; |
9
|
|
|
|
10
|
|
|
use Newscoop\EventDispatcher\Events\PluginHooksEvent; |
11
|
|
|
use Newscoop\PaywallBundle\Permissions; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Hook listener. |
15
|
|
|
*/ |
16
|
|
|
class HookListener |
17
|
|
|
{ |
18
|
|
|
private $templating; |
19
|
|
|
private $entityManager; |
20
|
|
|
private $templatesProvider; |
21
|
|
|
private $pluginsService; |
22
|
|
|
private $userService; |
23
|
|
|
|
24
|
|
|
public function __construct( |
25
|
|
|
$templating, |
26
|
|
|
$entityManager, |
27
|
|
|
$templatesProvider, |
28
|
|
|
$pluginsService, |
29
|
|
|
$userService |
30
|
|
|
) { |
31
|
|
|
$this->templating = $templating; |
32
|
|
|
$this->entityManager = $entityManager; |
33
|
|
|
$this->templatesProvider = $templatesProvider; |
34
|
|
|
$this->pluginsService = $pluginsService; |
35
|
|
|
$this->userService = $userService; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function sidebar(PluginHooksEvent $event) |
39
|
|
|
{ |
40
|
|
|
$user = $this->userService->getCurrentUser(); |
41
|
|
|
if (!$this->pluginsService->isEnabled(LifecycleSubscriber::PLUGIN_NAME) || !$user->hasPermission(Permissions::SIDEBAR)) { |
42
|
|
|
return; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
$article = $event->getArgument('article'); |
46
|
|
|
$user = $this->userService->getCurrentUser(); |
47
|
|
|
$specification = $this->entityManager |
48
|
|
|
->getRepository('Newscoop\PaywallBundle\Entity\SubscriptionSpecification') |
49
|
|
|
->findSpecification( |
50
|
|
|
$article->getArticleNumber(), |
51
|
|
|
$article->getPublicationId() |
52
|
|
|
); |
53
|
|
|
|
54
|
|
|
$language = $this->entityManager |
55
|
|
|
->getReference('Newscoop\Entity\Language', $article->getLanguageId()); |
56
|
|
|
$templates = $this->templatesProvider->getAvailableTemplates('article', $language->getCode()); |
57
|
|
|
|
58
|
|
|
$response = $this->templating->renderResponse( |
59
|
|
|
'NewscoopPaywallBundle:Hook:sidebar.html.twig', |
60
|
|
|
array( |
61
|
|
|
'templates' => $templates, |
62
|
|
|
'specification' => $specification ?: null, |
63
|
|
|
'status' => $specification ? true : false, |
64
|
|
|
'articleNumber' => $article->getArticleNumber(), |
65
|
|
|
'articleLanguage' => $article->getLanguageId(), |
66
|
|
|
'isPublic' => $article->isPublic(), |
67
|
|
|
'hasPermission' => (!$article->userCanModify($user) || !$user->hasPermission('Publish')), |
68
|
|
|
) |
69
|
|
|
); |
70
|
|
|
|
71
|
|
|
$event->addHookResponse($response); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|