|
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
|
|
|
/** |
|
10
|
|
|
* Optimizely variation reach. |
|
11
|
|
|
*/ |
|
12
|
|
|
class VariationReach |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* Total number of visitors exposed to this particular variation |
|
16
|
|
|
* @var integer |
|
17
|
|
|
*/ |
|
18
|
|
|
private $count; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* The name of the variation |
|
22
|
|
|
* @var string |
|
23
|
|
|
*/ |
|
24
|
|
|
private $name; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* The unique identifier for the variation |
|
28
|
|
|
* @var string |
|
29
|
|
|
*/ |
|
30
|
|
|
private $variationId; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* |
|
34
|
|
|
* @var number |
|
35
|
|
|
*/ |
|
36
|
|
|
private $variationReach; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Constructor. |
|
40
|
|
|
*/ |
|
41
|
3 |
|
public function __construct($options = array()) |
|
42
|
|
|
{ |
|
43
|
3 |
|
foreach ($options as $name=>$value) { |
|
44
|
|
|
switch ($name) { |
|
45
|
3 |
|
case 'count': $this->setCount($value); break; |
|
|
|
|
|
|
46
|
3 |
|
case 'name': $this->setName($value); break; |
|
|
|
|
|
|
47
|
3 |
|
case 'variation_id': $this->setVariationId($value); break; |
|
|
|
|
|
|
48
|
3 |
|
case 'variation_reach': $this->setVariationReach($value); break; |
|
|
|
|
|
|
49
|
|
|
default: |
|
50
|
|
|
throw new \Exception('Unknown option: ' . $name); |
|
51
|
|
|
} |
|
52
|
3 |
|
} |
|
53
|
3 |
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Returns this object as array. |
|
57
|
|
|
*/ |
|
58
|
1 |
|
public function toArray() |
|
59
|
|
|
{ |
|
60
|
|
|
$options = array( |
|
61
|
1 |
|
'count' => $this->getCount(), |
|
62
|
1 |
|
'name' => $this->getName(), |
|
63
|
1 |
|
'variation_id' => $this->getVariationId(), |
|
64
|
1 |
|
'variation_reach' => $this->getVariationReach(), |
|
65
|
1 |
|
); |
|
66
|
|
|
|
|
67
|
|
|
// Remove options with empty values |
|
68
|
1 |
|
$cleanedOptions = array(); |
|
69
|
1 |
|
foreach ($options as $name=>$value) { |
|
70
|
1 |
|
if ($value!==null) |
|
71
|
1 |
|
$cleanedOptions[$name] = $value; |
|
72
|
1 |
|
} |
|
73
|
|
|
|
|
74
|
1 |
|
return $cleanedOptions; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
1 |
|
public function getCount() |
|
78
|
|
|
{ |
|
79
|
1 |
|
return $this->count; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
3 |
|
public function setCount($count) |
|
83
|
|
|
{ |
|
84
|
3 |
|
$this->count = $count; |
|
85
|
3 |
|
} |
|
86
|
|
|
|
|
87
|
1 |
|
public function getName() |
|
88
|
|
|
{ |
|
89
|
1 |
|
return $this->name; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
3 |
|
public function setName($name) |
|
93
|
|
|
{ |
|
94
|
3 |
|
$this->name = $name; |
|
95
|
3 |
|
} |
|
96
|
|
|
|
|
97
|
1 |
|
public function getVariationId() |
|
98
|
|
|
{ |
|
99
|
1 |
|
return $this->variationId; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
3 |
|
public function setVariationId($variationId) |
|
103
|
|
|
{ |
|
104
|
3 |
|
$this->variationId = $variationId; |
|
105
|
3 |
|
} |
|
106
|
|
|
|
|
107
|
1 |
|
public function getVariationReach() |
|
108
|
|
|
{ |
|
109
|
1 |
|
return $this->variationReach; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
3 |
|
public function setVariationReach($variationReach) |
|
113
|
|
|
{ |
|
114
|
3 |
|
$this->variationReach = $variationReach; |
|
115
|
3 |
|
} |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
|
|
119
|
|
|
|
|
120
|
|
|
|
|
121
|
|
|
|
|
122
|
|
|
|
|
123
|
|
|
|
|
124
|
|
|
|
|
125
|
|
|
|
|
126
|
|
|
|
|
127
|
|
|
|
|
128
|
|
|
|
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.