1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author Oleg Krivtsov <[email protected]> |
4
|
|
|
* @date 12 October 2016 |
5
|
|
|
* @copyright (c) 2016, Web Marketing ROI |
6
|
|
|
*/ |
7
|
|
|
namespace WebMarketingROI\OptimizelyPHP\Resource\v2; |
8
|
|
|
|
9
|
|
|
use WebMarketingROI\OptimizelyPHP\Exception; |
10
|
|
|
use WebMarketingROI\OptimizelyPHP\Resource\v2\VariantResults; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Optimizely campaign metric results. |
14
|
|
|
*/ |
15
|
|
|
class CampaignMetricResults |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
private $event; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
private $eventName; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Conversions indicate the total number of visitors or sessions where the |
31
|
|
|
* event happened. Impressions indicate the total number of times the event |
32
|
|
|
* happened (possibly multiple per visitor or session). Revenue indicates |
33
|
|
|
* the sum of all revenue sent from all events in the Campaign. |
34
|
|
|
* Can be 'conversions', 'impressions' or 'revenue'. |
35
|
|
|
* @var string |
36
|
|
|
*/ |
37
|
|
|
private $measure; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* |
41
|
|
|
* @var string |
42
|
|
|
*/ |
43
|
|
|
private $metricId; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* |
47
|
|
|
* @var integer |
48
|
|
|
*/ |
49
|
|
|
private $priority; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* A map of results for the variants affected by the campaign. Variants may |
53
|
|
|
* represent aggregated results scoped to the campaign and/or individual |
54
|
|
|
* experiment results scoped to just that experiment. The special variant |
55
|
|
|
* 'baseline' represents visitors that have been held back from any change |
56
|
|
|
* in experience across all Experiments in the Campaign. The special variant |
57
|
|
|
* 'campaign' represents the aggregated effect of all experiments included in |
58
|
|
|
* the Campaign. |
59
|
|
|
* @var VariantResults |
60
|
|
|
*/ |
61
|
|
|
private $results; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Can be 'session', 'visitor' or 'event'. |
65
|
|
|
* @var string |
66
|
|
|
*/ |
67
|
|
|
private $unit; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Constructor. |
71
|
|
|
*/ |
72
|
3 |
|
public function __construct($options = array()) |
73
|
|
|
{ |
74
|
3 |
|
foreach ($options as $name=>$value) { |
75
|
|
|
switch ($name) { |
76
|
3 |
|
case 'event': $this->setEvent($value); break; |
|
|
|
|
77
|
3 |
|
case 'event_name': $this->setEventName($value); break; |
|
|
|
|
78
|
3 |
|
case 'measure': $this->setMeasure($value); break; |
|
|
|
|
79
|
3 |
|
case 'metric_id': $this->setMetricId($value); break; |
|
|
|
|
80
|
3 |
|
case 'priority': $this->setPriority($value); break; |
|
|
|
|
81
|
3 |
|
case 'results': { |
|
|
|
|
82
|
3 |
|
$results = array(); |
83
|
3 |
|
foreach ($value as $name=>$info) { |
84
|
3 |
|
$results[$name] = new VariantResults($info); |
85
|
3 |
|
} |
86
|
3 |
|
$this->setResults($results); |
87
|
3 |
|
break; |
88
|
|
|
} |
89
|
3 |
|
case 'unit': $this->setUnit($value); break; |
|
|
|
|
90
|
|
|
default: |
91
|
|
|
throw new Exception('Unknown option found in CampaignMetricResults entity: ' . $name); |
92
|
|
|
} |
93
|
3 |
|
} |
94
|
3 |
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Returns this object as array. |
98
|
|
|
*/ |
99
|
1 |
|
public function toArray() |
100
|
|
|
{ |
101
|
|
|
$options = array( |
102
|
1 |
|
'event' => $this->getEvent(), |
103
|
1 |
|
'event_name' => $this->getEventName(), |
104
|
1 |
|
'measure' => $this->getMeasure(), |
105
|
1 |
|
'metric_id' => $this->getMetricId(), |
106
|
1 |
|
'priority' => $this->getPriority(), |
107
|
1 |
|
'results' => array(), |
108
|
1 |
|
'unit' => $this->getUnit() |
109
|
1 |
|
); |
110
|
|
|
|
111
|
1 |
|
foreach ($this->getResults() as $name=>$result) { |
|
|
|
|
112
|
1 |
|
$options['results'][$name] = $result->toArray(); |
113
|
1 |
|
} |
114
|
|
|
|
115
|
|
|
// Remove options with empty values |
116
|
1 |
|
$cleanedOptions = array(); |
117
|
1 |
|
foreach ($options as $name=>$value) { |
118
|
1 |
|
if ($value!==null) |
119
|
1 |
|
$cleanedOptions[$name] = $value; |
120
|
1 |
|
} |
121
|
|
|
|
122
|
1 |
|
return $cleanedOptions; |
123
|
|
|
} |
124
|
|
|
|
125
|
1 |
|
public function getEvent() |
126
|
|
|
{ |
127
|
1 |
|
return $this->event; |
128
|
|
|
} |
129
|
|
|
|
130
|
3 |
|
public function setEvent($event) |
131
|
|
|
{ |
132
|
3 |
|
$this->event = $event; |
133
|
3 |
|
} |
134
|
|
|
|
135
|
1 |
|
public function getEventName() |
136
|
|
|
{ |
137
|
1 |
|
return $this->eventName; |
138
|
|
|
} |
139
|
|
|
|
140
|
3 |
|
public function setEventName($eventName) |
141
|
|
|
{ |
142
|
3 |
|
$this->eventName = $eventName; |
143
|
3 |
|
} |
144
|
|
|
|
145
|
1 |
|
public function getMeasure() |
146
|
|
|
{ |
147
|
1 |
|
return $this->measure; |
148
|
|
|
} |
149
|
|
|
|
150
|
3 |
|
public function setMeasure($measure) |
151
|
|
|
{ |
152
|
3 |
|
$this->measure = $measure; |
153
|
3 |
|
} |
154
|
|
|
|
155
|
1 |
|
public function getMetricId() |
156
|
|
|
{ |
157
|
1 |
|
return $this->metricId; |
158
|
|
|
} |
159
|
|
|
|
160
|
3 |
|
public function setMetricId($metricId) |
161
|
|
|
{ |
162
|
3 |
|
$this->metricId = $metricId; |
163
|
3 |
|
} |
164
|
|
|
|
165
|
1 |
|
public function getPriority() |
166
|
|
|
{ |
167
|
1 |
|
return $this->priority; |
168
|
|
|
} |
169
|
|
|
|
170
|
3 |
|
public function setPriority($priority) |
171
|
|
|
{ |
172
|
3 |
|
$this->priority = $priority; |
173
|
3 |
|
} |
174
|
|
|
|
175
|
1 |
|
public function getResults() |
176
|
|
|
{ |
177
|
1 |
|
return $this->results; |
178
|
|
|
} |
179
|
|
|
|
180
|
3 |
|
public function setResults($results) |
181
|
|
|
{ |
182
|
3 |
|
$this->results = $results; |
183
|
3 |
|
} |
184
|
|
|
|
185
|
1 |
|
public function getUnit() |
186
|
|
|
{ |
187
|
1 |
|
return $this->unit; |
188
|
|
|
} |
189
|
|
|
|
190
|
3 |
|
public function setUnit($unit) |
191
|
|
|
{ |
192
|
3 |
|
$this->unit = $unit; |
193
|
3 |
|
} |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
|
197
|
|
|
|
198
|
|
|
|
199
|
|
|
|
200
|
|
|
|
201
|
|
|
|
According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.
}
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.