-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBaseAnalytics.php
146 lines (130 loc) · 3.54 KB
/
BaseAnalytics.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
/**
* Created by PhpStorm.
* User: vinay
* Date: 5/12/16
* Time: 3:36 PM
*/
namespace Revinate\AnalyticsBundle;
use Revinate\AnalyticsBundle\Filter\CustomFilterInterface;
use Revinate\AnalyticsBundle\FilterSource\AbstractFilterSource;
use Symfony\Component\DependencyInjection\ContainerInterface;
abstract class BaseAnalytics implements BaseAnalyticsInterface, AnalyticsViewInterface {
/** @var ContainerInterface */
protected $container;
/** @var array */
protected $context = array();
/** @var array Date Range context for analytics */
protected $dateRange = array();
/**
* @param ContainerInterface $container
*/
public function __construct(ContainerInterface $container) {
$this->container = $container;
}
/**
* @return CustomFilterInterface[]
*/
public function getCustomFilters() {
return array();
}
/**
* @param $name
* @throws \Exception
* @return CustomFilterInterface
*/
public function getCustomFilter($name) {
foreach ($this->getCustomFilters() as $customFilter) {
if ($customFilter->getName() == $name) {
return $customFilter;
}
}
throw new \Exception(__METHOD__ . " Invalid Custom Filter: " . $name);
}
/**
* @param $name
* @throws \Exception
* @return AbstractFilterSource
*/
public function getFilterSource($name) {
foreach ($this->getFilterSources() as $filterSource) {
if ($filterSource->getName() == $name) {
return $filterSource;
}
}
throw new \Exception(__METHOD__ . " Invalid Filter: " . $name);
}
/**
* @return array
*/
public function getFilterSourcesArray() {
$config = array();
foreach ($this->getFilterSources() as $filterSource) {
$config[] = $filterSource->toArray();
}
return $config;
}
/**
* @return array
*/
public function getCustomFiltersArray() {
$config = array();
foreach ($this->getCustomFilters() as $customFilter) {
$config[] = $customFilter->toArray();
}
return $config;
}
/**
* Gets Analytics Config
*
* @param $query
* @param $page
* @param $size
* @return array
*/
public function getConfig($query, $page, $size) {
$config = array();
$config['dimensions'] = $this->getDimensionsArray($query, $page, $size);
$config['metrics'] = $this->getMetricsArray($query, $page, $size);
$config['filterSources'] = $this->getFilterSourcesArray();
$config['customFilters'] = $this->getCustomFiltersArray();
return $config;
}
/**
* @return \Symfony\Component\DependencyInjection\ContainerInterface
*/
public function getContainer() {
return $this->container;
}
/**
* @return array
*/
public function getContext() {
return $this->context;
}
/**
* @param array $context
*/
public function setContext($context) {
$this->context = $context;
}
/**
* @param $key
* @return null
*/
public function getContextValue($key) {
return isset($this->context[$key]) ? $this->context[$key] : null;
}
/**
* @return array
*/
public function getDateRange() {
return $this->dateRange;
}
/**
* @param array $dateRange
*/
public function setDateRange($dateRange) {
$this->dateRange = $dateRange;
}
}