forked from ddeboer/GoogleBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Adwords.php
53 lines (45 loc) · 1.42 KB
/
Adwords.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
<?php
namespace AntiMattr\GoogleBundle;
use AntiMattr\GoogleBundle\Adwords\Conversion;
use Symfony\Component\DependencyInjection\ContainerInterface;
class Adwords
{
const CONVERSION_KEY = 'google_adwords/conversion';
private $activeConversion;
private $container;
private $conversions;
public function __construct(ContainerInterface $container, array $conversions = array())
{
$this->container = $container;
$this->conversions = $conversions;
}
/**
* @param string $key
*/
public function activateConversionByKey($key)
{
if (array_key_exists($key, $this->conversions)) {
$this->container->get('session')->set(self::CONVERSION_KEY, $key);
}
}
/**
* @return Conversion $conversion
*/
public function getActiveConversion()
{
if ($this->hasActiveConversion()) {
$key = $this->container->get('session')->get(self::CONVERSION_KEY);
$this->container->get('session')->remove(self::CONVERSION_KEY);
$config = $this->conversions[$key];
$this->activeConversion = new Conversion($config['id'], $config['label'], $config['value']);
}
return $this->activeConversion;
}
/**
* @param boolean $hasActiveConversion
*/
public function hasActiveConversion()
{
return $this->container->get('session')->has(self::CONVERSION_KEY);
}
}