Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 54 lines (45 sloc) 1.451 kb
984da12 Matt Fitzgerald first commit
matthewfitz authored
1 <?php
2
3 namespace AntiMattr\GoogleBundle;
4
5 use AntiMattr\GoogleBundle\Adwords\Conversion;
6 use Symfony\Component\DependencyInjection\ContainerInterface;
7
8 class Adwords
9 {
10 const CONVERSION_KEY = 'google_adwords/conversion';
11
12 private $activeConversion;
13 private $container;
14 private $conversions;
15
16 public function __construct(ContainerInterface $container, array $conversions = array())
17 {
18 $this->container = $container;
19 $this->conversions = $conversions;
20 }
21
22 /**
23 * @param string $key
24 */
25 public function activateConversionByKey($key)
26 {
27 if (array_key_exists($key, $this->conversions)) {
28 $this->container->get('session')->set(self::CONVERSION_KEY, $key);
29 }
30 }
31
32 /**
33 * @return Conversion $conversion
34 */
35 public function getActiveConversion()
36 {
37 if ($this->hasActiveConversion()) {
38 $key = $this->container->get('session')->get(self::CONVERSION_KEY);
39 $this->container->get('session')->remove(self::CONVERSION_KEY);
40 $config = $this->conversions[$key];
41 $this->activeConversion = new Conversion($config['id'], $config['label'], $config['value']);
42 }
43 return $this->activeConversion;
44 }
45
46 /**
47 * @param boolean $hasActiveConversion
48 */
49 public function hasActiveConversion()
50 {
51 return $this->container->get('session')->has(self::CONVERSION_KEY);
52 }
53 }
Something went wrong with that request. Please try again.