1 | <?php |
||
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 | } |
||
86 | 3 | $this->setResults($results); |
|
87 | 3 | break; |
|
88 | } |
||
89 | 3 | case 'unit': $this->setUnit($value); break; |
|
90 | default: |
||
91 | 3 | throw new Exception('Unknown option found in CampaignMetricResults entity: ' . $name); |
|
92 | } |
||
93 | } |
||
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 | 'results' => array(), |
||
108 | 1 | 'unit' => $this->getUnit() |
|
109 | ); |
||
110 | |||
111 | 1 | foreach ($this->getResults() as $name=>$result) { |
|
112 | 1 | $options['results'][$name] = $result->toArray(); |
|
113 | } |
||
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 | } |
||
121 | |||
122 | 1 | return $cleanedOptions; |
|
123 | } |
||
124 | |||
125 | 1 | public function getEvent() |
|
129 | |||
130 | 3 | public function setEvent($event) |
|
134 | |||
135 | 1 | public function getEventName() |
|
139 | |||
140 | 3 | public function setEventName($eventName) |
|
144 | |||
145 | 1 | public function getMeasure() |
|
149 | |||
150 | 3 | public function setMeasure($measure) |
|
154 | |||
155 | 1 | public function getMetricId() |
|
159 | |||
160 | 3 | public function setMetricId($metricId) |
|
164 | |||
165 | 1 | public function getPriority() |
|
169 | |||
170 | 3 | public function setPriority($priority) |
|
174 | |||
175 | 1 | public function getResults() |
|
179 | |||
180 | 3 | public function setResults($results) |
|
184 | |||
185 | 1 | public function getUnit() |
|
189 | |||
190 | 3 | public function setUnit($unit) |
|
194 | } |
||
195 | |||
196 | |||
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.