This repository has been archived by the owner on Mar 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTinectMatomo.php
81 lines (61 loc) · 2.41 KB
/
TinectMatomo.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
namespace TinectMatomo;
use Doctrine\Common\Collections\ArrayCollection;
use Shopware\Components\Plugin;
use Shopware\Components\Plugin\Context\ActivateContext;
use Shopware\Components\Plugin\Context\InstallContext;
use Shopware\Components\Plugin\Context\UpdateContext;
class TinectMatomo extends Plugin
{
public function activate(ActivateContext $context)
{
$context->scheduleClearCache(InstallContext::CACHE_LIST_ALL);
}
public function update(UpdateContext $context)
{
$context->scheduleClearCache(InstallContext::CACHE_LIST_ALL);
}
public function install(InstallContext $context)
{
}
public static function getSubscribedEvents()
{
return [
'Enlight_Controller_Action_PostDispatchSecure_Frontend' => 'onFrontendDispatch',
'Theme_Compiler_Collect_Plugin_Javascript' => 'onCollectJavascriptFiles',
'Enlight_Controller_Action_PostDispatchSecure_Backend_Index' => 'onPostDispatchSecureBackendIndex'
];
}
public function onPostDispatchSecureBackendIndex(\Enlight_Controller_ActionEventArgs $args)
{
/** @var \Shopware_Controllers_Backend_Index $subject */
$subject = $args->getSubject();
$view = $subject->View();
$this->container->get('Template')->addTemplateDir(
$this->getPath() . '/Resources/Views/'
);
$config = Shopware()->Container()->get('shopware.plugin.config_reader')->getByPluginName('TinectMatomo');
$view->assign('MatomoPath', $config['matomopath']);
$args->getSubject()->View()->extendsTemplate('backend/matomo/index/header.tpl');
}
public function onCollectJavascriptFiles(\Enlight_Event_EventArgs $args)
{
$config = $this->container->get('shopware.plugin.config_reader')->getByPluginName(
$this->getName(),
$args->get('shop')
);
if ($config['compilejs']) {
$jsPath = $this->container->get('kernel')->getCacheDir() . '/' . 'matomo.js';
copy($config['matomopath'] . '/' . $config['jspath'], $jsPath);
return new ArrayCollection(array(
$jsPath
));
}
return null;
}
public function onFrontendDispatch(\Enlight_Controller_ActionEventArgs $args)
{
$subject = $args->getSubject();
$subject->View()->addTemplateDir($this->getPath() . '/Resources/Views/');
}
}