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\VariationReach; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Optimizely experiment variation reach. |
14
|
|
|
*/ |
15
|
|
|
class ExperimentVariationReach |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* Baseline count |
19
|
|
|
* @var integer |
20
|
|
|
*/ |
21
|
|
|
private $baselineCount; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Baseline reach |
25
|
|
|
* @var number |
26
|
|
|
*/ |
27
|
|
|
private $baselineReach; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Total number of visitors exposed to the experiment |
31
|
|
|
* @var integer |
32
|
|
|
*/ |
33
|
|
|
private $totalCount; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Treatment count |
37
|
|
|
* @var number |
38
|
|
|
*/ |
39
|
|
|
private $treatmentCount; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Treatment reach |
43
|
|
|
* @var number |
44
|
|
|
*/ |
45
|
|
|
private $treatmentReach; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* A map of reach for each Variation keyed by Variation ID |
49
|
|
|
* @var array[VariationReach] |
50
|
|
|
*/ |
51
|
|
|
private $variations; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Constructor. |
55
|
|
|
*/ |
56
|
3 |
|
public function __construct($options = array()) |
57
|
|
|
{ |
58
|
3 |
|
foreach ($options as $name=>$value) { |
59
|
|
|
switch ($name) { |
60
|
3 |
|
case 'baseline_count': $this->setBaselineCount($value); break; |
|
|
|
|
61
|
3 |
|
case 'baseline_reach': $this->setBaselineReach($value); break; |
|
|
|
|
62
|
3 |
|
case 'total_count': $this->setTotalCount($value); break; |
|
|
|
|
63
|
3 |
|
case 'treatment_count': $this->setTreatmentCount($value); break; |
|
|
|
|
64
|
3 |
|
case 'treatment_reach': $this->setTreatmentReach($value); break; |
|
|
|
|
65
|
3 |
View Code Duplication |
case 'variations': { |
|
|
|
|
66
|
3 |
|
$variations = array(); |
67
|
3 |
|
foreach ($value as $name=>$variationInfo) { |
68
|
3 |
|
$variations[$name] = new VariationReach($variationInfo); |
69
|
3 |
|
} |
70
|
3 |
|
$this->setVariations($variations); |
71
|
3 |
|
break; |
72
|
|
|
} |
73
|
|
|
default: |
74
|
|
|
throw new Exception('Unknown option: ' . $name); |
75
|
|
|
} |
76
|
3 |
|
} |
77
|
3 |
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Returns this object as array. |
81
|
|
|
*/ |
82
|
1 |
|
public function toArray() |
83
|
|
|
{ |
84
|
|
|
$options = array( |
85
|
1 |
|
'baseline_count' => $this->getBaselineCount(), |
86
|
1 |
|
'baseline_reach' => $this->getBaselineReach(), |
87
|
1 |
|
'total_count' => $this->getTotalCount(), |
88
|
1 |
|
'treatment_count' => $this->getTreatmentCount(), |
89
|
1 |
|
'treatment_reach' => $this->getTreatmentReach(), |
90
|
1 |
|
'variations' => array(), |
91
|
1 |
|
); |
92
|
|
|
|
93
|
1 |
|
foreach ($this->getVariations() as $name=>$variation) { |
94
|
1 |
|
$options['variations'][$name] = $variation->toArray(); |
95
|
1 |
|
} |
96
|
|
|
|
97
|
|
|
// Remove options with empty values |
98
|
1 |
|
$cleanedOptions = array(); |
99
|
1 |
|
foreach ($options as $name=>$value) { |
100
|
1 |
|
if ($value!==null) |
101
|
1 |
|
$cleanedOptions[$name] = $value; |
102
|
1 |
|
} |
103
|
|
|
|
104
|
1 |
|
return $cleanedOptions; |
105
|
|
|
} |
106
|
|
|
|
107
|
1 |
|
public function getBaselineCount() |
108
|
|
|
{ |
109
|
1 |
|
return $this->baselineCount; |
110
|
|
|
} |
111
|
|
|
|
112
|
3 |
|
public function setBaselineCount($baselineCount) |
113
|
|
|
{ |
114
|
3 |
|
$this->baselineCount = $baselineCount; |
115
|
3 |
|
} |
116
|
|
|
|
117
|
1 |
|
public function getBaselineReach() |
118
|
|
|
{ |
119
|
1 |
|
return $this->baselineReach; |
120
|
|
|
} |
121
|
|
|
|
122
|
3 |
|
public function setBaselineReach($baselineReach) |
123
|
|
|
{ |
124
|
3 |
|
$this->baselineReach = $baselineReach; |
125
|
3 |
|
} |
126
|
|
|
|
127
|
1 |
|
public function getTotalCount() |
128
|
|
|
{ |
129
|
1 |
|
return $this->totalCount; |
130
|
|
|
} |
131
|
|
|
|
132
|
3 |
|
public function setTotalCount($totalCount) |
133
|
|
|
{ |
134
|
3 |
|
$this->totalCount = $totalCount; |
135
|
3 |
|
} |
136
|
|
|
|
137
|
1 |
|
public function getTreatmentCount() |
138
|
|
|
{ |
139
|
1 |
|
return $this->treatmentCount; |
140
|
|
|
} |
141
|
|
|
|
142
|
3 |
|
public function setTreatmentCount($treatmentCount) |
143
|
|
|
{ |
144
|
3 |
|
$this->treatmentCount = $treatmentCount; |
145
|
3 |
|
} |
146
|
|
|
|
147
|
1 |
|
public function getTreatmentReach() |
148
|
|
|
{ |
149
|
1 |
|
return $this->treatmentReach; |
150
|
|
|
} |
151
|
|
|
|
152
|
3 |
|
public function setTreatmentReach($treatmentReach) |
153
|
|
|
{ |
154
|
3 |
|
$this->treatmentReach = $treatmentReach; |
155
|
3 |
|
} |
156
|
|
|
|
157
|
1 |
|
public function getVariations() |
158
|
|
|
{ |
159
|
1 |
|
return $this->variations; |
160
|
|
|
} |
161
|
|
|
|
162
|
3 |
|
public function setVariations($variations) |
163
|
|
|
{ |
164
|
3 |
|
$this->variations = $variations; |
165
|
3 |
|
} |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
|
169
|
|
|
|
170
|
|
|
|
171
|
|
|
|
172
|
|
|
|
173
|
|
|
|
174
|
|
|
|
175
|
|
|
|
176
|
|
|
|
177
|
|
|
|
178
|
|
|
|
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.