|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @author Oleg Krivtsov <[email protected]> |
|
4
|
|
|
* @date 06 October 2016 |
|
5
|
|
|
* @copyright (c) 2016, Web Marketing ROI |
|
6
|
|
|
*/ |
|
7
|
|
|
namespace WebMarketingROI\OptimizelyPHP\Resource\v2; |
|
8
|
|
|
|
|
9
|
|
|
use WebMarketingROI\OptimizelyPHP\Resource\v2\Change; |
|
10
|
|
|
use WebMarketingROI\OptimizelyPHP\Resource\v2\Metric; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* An Optimizely campaign. |
|
14
|
|
|
*/ |
|
15
|
|
|
class Campaign |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* The Project ID the Campaign is in |
|
19
|
|
|
* @var integer |
|
20
|
|
|
*/ |
|
21
|
|
|
private $projectId; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* A list of changes to apply to the Campaign |
|
25
|
|
|
* @var array |
|
26
|
|
|
*/ |
|
27
|
|
|
private $changes; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* The time the Experiment was initially created |
|
31
|
|
|
* @var string |
|
32
|
|
|
*/ |
|
33
|
|
|
private $created; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* The first time the Experiment was activated |
|
37
|
|
|
* @var string |
|
38
|
|
|
*/ |
|
39
|
|
|
private $earliest; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* An ordered list of Experiment IDs used by the Campaign |
|
43
|
|
|
* @var array |
|
44
|
|
|
*/ |
|
45
|
|
|
private $experimentIds; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Percentage expressed as a number from 0-10000 to holdback from being |
|
49
|
|
|
* included in the experiment. |
|
50
|
|
|
* @var integer |
|
51
|
|
|
*/ |
|
52
|
|
|
private $holdback; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* The last time the Experiment was modified |
|
56
|
|
|
* @var string |
|
57
|
|
|
*/ |
|
58
|
|
|
private $lastModified; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* The last time the Experiment was activated (not present if it is still activated) |
|
62
|
|
|
* @var string |
|
63
|
|
|
*/ |
|
64
|
|
|
private $latest; |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* An ordered list of Metrics to track for the Campaign |
|
68
|
|
|
* @var array |
|
69
|
|
|
*/ |
|
70
|
|
|
private $metrics; |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* The name of the Campaign |
|
74
|
|
|
* @var string |
|
75
|
|
|
*/ |
|
76
|
|
|
private $name; |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* A list of Page IDs used in the Campaign. |
|
80
|
|
|
* @var array |
|
81
|
|
|
*/ |
|
82
|
|
|
private $pageIds; |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Current state of the Campaign. Can be 'active', 'paused' or 'archived' |
|
86
|
|
|
* @var string |
|
87
|
|
|
*/ |
|
88
|
|
|
private $status; |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* The type of the Campaign. Can be a/b or personalization. |
|
92
|
|
|
* @var string |
|
93
|
|
|
*/ |
|
94
|
|
|
private $type; |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* The unique identifier for the Campaign |
|
98
|
|
|
* @var integer |
|
99
|
|
|
*/ |
|
100
|
|
|
private $id; |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Constructor. |
|
104
|
|
|
*/ |
|
105
|
7 |
|
public function __construct($options = array()) |
|
106
|
|
|
{ |
|
107
|
7 |
|
foreach ($options as $name=>$value) { |
|
108
|
|
|
switch ($name) { |
|
109
|
6 |
|
case 'project_id': $this->setProjectId($value); break; |
|
|
|
|
|
|
110
|
6 |
View Code Duplication |
case 'changes': { |
|
|
|
|
|
|
111
|
6 |
|
$changes = array(); |
|
112
|
6 |
|
foreach ($value as $changeInfo) { |
|
113
|
6 |
|
$changes[] = new Change($changeInfo); |
|
114
|
6 |
|
} |
|
115
|
6 |
|
$this->setChanges($changes); break; |
|
116
|
|
|
} |
|
117
|
6 |
|
case 'created': $this->setCreated($value); break; |
|
|
|
|
|
|
118
|
6 |
|
case 'earliest': $this->setEarliest($value); break; |
|
|
|
|
|
|
119
|
6 |
|
case 'experiment_ids': $this->setExperimentIds($value); break; |
|
|
|
|
|
|
120
|
6 |
|
case 'holdback': $this->setHoldback($value); break; |
|
|
|
|
|
|
121
|
6 |
|
case 'last_modified': $this->setLastModified($value); break; |
|
|
|
|
|
|
122
|
6 |
|
case 'latest': $this->setLatest($value); break; |
|
|
|
|
|
|
123
|
6 |
|
case 'metrics': { |
|
|
|
|
|
|
124
|
6 |
|
$metrics = array(); |
|
125
|
6 |
|
foreach ($value as $metricInfo) { |
|
126
|
6 |
|
$metrics[] = new Metric($metricInfo); |
|
127
|
6 |
|
} |
|
128
|
6 |
|
$this->setMetrics($metrics); break; |
|
129
|
|
|
} |
|
130
|
6 |
|
case 'name': $this->setName($value); break; |
|
|
|
|
|
|
131
|
6 |
|
case 'page_ids': $this->setPageIds($value); break; |
|
|
|
|
|
|
132
|
6 |
|
case 'status': $this->setStatus($value); break; |
|
|
|
|
|
|
133
|
6 |
|
case 'type': $this->setType($value); break; |
|
|
|
|
|
|
134
|
4 |
|
case 'id': $this->setId($value); break; |
|
|
|
|
|
|
135
|
|
|
default: |
|
136
|
|
|
throw new \Exception('Unknown option: ' . $name); |
|
137
|
|
|
} |
|
138
|
7 |
|
} |
|
139
|
7 |
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* Returns this object as array. |
|
143
|
|
|
*/ |
|
144
|
3 |
|
public function toArray() |
|
145
|
|
|
{ |
|
146
|
|
|
$options = array( |
|
147
|
3 |
|
'project_id' => $this->getProjectId(), |
|
148
|
3 |
|
'changes' => array(), |
|
149
|
3 |
|
'created' => $this->getCreated(), |
|
150
|
3 |
|
'earliest' => $this->getEarliest(), |
|
151
|
3 |
|
'experiment_ids' => $this->getExperimentIds(), |
|
152
|
3 |
|
'holdback' => $this->getHoldback(), |
|
153
|
3 |
|
'last_modified' => $this->getLastModified(), |
|
154
|
3 |
|
'latest' => $this->getLatest(), |
|
155
|
3 |
|
'metrics' => array(), |
|
156
|
3 |
|
'name' => $this->getName(), |
|
157
|
3 |
|
'page_ids' => $this->getPageIds(), |
|
158
|
3 |
|
'status' => $this->getStatus(), |
|
159
|
3 |
|
'type' => $this->getType(), |
|
160
|
3 |
|
'id' => $this->getId() |
|
161
|
3 |
|
); |
|
162
|
|
|
|
|
163
|
3 |
|
foreach ($this->getChanges() as $change) { |
|
164
|
3 |
|
$options['changes'][] = $change->toArray(); |
|
165
|
3 |
|
} |
|
166
|
|
|
|
|
167
|
3 |
|
foreach ($this->getMetrics() as $metric) { |
|
168
|
3 |
|
$options['metrics'][] = $metric->toArray(); |
|
169
|
3 |
|
} |
|
170
|
|
|
|
|
171
|
|
|
// Remove options with empty values |
|
172
|
3 |
|
$cleanedOptions = array(); |
|
173
|
3 |
|
foreach ($options as $name=>$value) { |
|
174
|
3 |
|
if ($value!==null) |
|
175
|
3 |
|
$cleanedOptions[$name] = $value; |
|
176
|
3 |
|
} |
|
177
|
|
|
|
|
178
|
3 |
|
return $cleanedOptions; |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
5 |
|
public function getProjectId() |
|
182
|
|
|
{ |
|
183
|
5 |
|
return $this->projectId; |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
7 |
|
public function setProjectId($projectId) |
|
187
|
|
|
{ |
|
188
|
7 |
|
$this->projectId = $projectId; |
|
189
|
7 |
|
} |
|
190
|
|
|
|
|
191
|
5 |
|
public function getChanges() |
|
192
|
|
|
{ |
|
193
|
5 |
|
return $this->changes; |
|
194
|
|
|
} |
|
195
|
|
|
|
|
196
|
7 |
|
public function setChanges($changes) |
|
197
|
|
|
{ |
|
198
|
7 |
|
$this->changes = $changes; |
|
199
|
7 |
|
} |
|
200
|
|
|
|
|
201
|
4 |
|
public function getCreated() |
|
202
|
|
|
{ |
|
203
|
4 |
|
return $this->created; |
|
204
|
|
|
} |
|
205
|
|
|
|
|
206
|
7 |
|
public function setCreated($created) |
|
207
|
|
|
{ |
|
208
|
7 |
|
$this->created = $created; |
|
209
|
7 |
|
} |
|
210
|
|
|
|
|
211
|
3 |
|
public function getEarliest() |
|
212
|
|
|
{ |
|
213
|
3 |
|
return $this->earliest; |
|
214
|
|
|
} |
|
215
|
|
|
|
|
216
|
7 |
|
public function setEarliest($earliest) |
|
217
|
|
|
{ |
|
218
|
7 |
|
$this->earliest = $earliest; |
|
219
|
7 |
|
} |
|
220
|
|
|
|
|
221
|
3 |
|
public function getExperimentIds() |
|
222
|
|
|
{ |
|
223
|
3 |
|
return $this->experimentIds; |
|
224
|
|
|
} |
|
225
|
|
|
|
|
226
|
7 |
|
public function setExperimentIds($experimentIds) |
|
227
|
|
|
{ |
|
228
|
7 |
|
$this->experimentIds = $experimentIds; |
|
229
|
7 |
|
} |
|
230
|
|
|
|
|
231
|
3 |
|
public function getHoldback() |
|
232
|
|
|
{ |
|
233
|
3 |
|
return $this->holdback; |
|
234
|
|
|
} |
|
235
|
|
|
|
|
236
|
7 |
|
public function setHoldback($holdback) |
|
237
|
|
|
{ |
|
238
|
7 |
|
$this->holdback = $holdback; |
|
239
|
7 |
|
} |
|
240
|
|
|
|
|
241
|
3 |
|
public function getLastModified() |
|
242
|
|
|
{ |
|
243
|
3 |
|
return $this->lastModified; |
|
244
|
|
|
} |
|
245
|
|
|
|
|
246
|
7 |
|
public function setLastModified($lastModified) |
|
247
|
|
|
{ |
|
248
|
7 |
|
$this->lastModified = $lastModified; |
|
249
|
7 |
|
} |
|
250
|
|
|
|
|
251
|
3 |
|
public function getLatest() |
|
252
|
|
|
{ |
|
253
|
3 |
|
return $this->latest; |
|
254
|
|
|
} |
|
255
|
|
|
|
|
256
|
7 |
|
public function setLatest($latest) |
|
257
|
|
|
{ |
|
258
|
7 |
|
$this->latest = $latest; |
|
259
|
7 |
|
} |
|
260
|
|
|
|
|
261
|
5 |
|
public function getMetrics() |
|
262
|
|
|
{ |
|
263
|
5 |
|
return $this->metrics; |
|
264
|
|
|
} |
|
265
|
|
|
|
|
266
|
7 |
|
public function setMetrics($metrics) |
|
267
|
|
|
{ |
|
268
|
7 |
|
$this->metrics = $metrics; |
|
269
|
7 |
|
} |
|
270
|
|
|
|
|
271
|
6 |
|
public function getName() |
|
272
|
|
|
{ |
|
273
|
6 |
|
return $this->name; |
|
274
|
|
|
} |
|
275
|
|
|
|
|
276
|
7 |
|
public function setName($name) |
|
277
|
|
|
{ |
|
278
|
7 |
|
$this->name = $name; |
|
279
|
7 |
|
} |
|
280
|
|
|
|
|
281
|
3 |
|
public function getPageIds() |
|
282
|
|
|
{ |
|
283
|
3 |
|
return $this->pageIds; |
|
284
|
|
|
} |
|
285
|
|
|
|
|
286
|
7 |
|
public function setPageIds($pageIds) |
|
287
|
|
|
{ |
|
288
|
7 |
|
$this->pageIds = $pageIds; |
|
289
|
7 |
|
} |
|
290
|
|
|
|
|
291
|
3 |
|
public function getStatus() |
|
292
|
|
|
{ |
|
293
|
3 |
|
return $this->status; |
|
294
|
|
|
} |
|
295
|
|
|
|
|
296
|
7 |
|
public function setStatus($status) |
|
297
|
|
|
{ |
|
298
|
7 |
|
$this->status = $status; |
|
299
|
7 |
|
} |
|
300
|
|
|
|
|
301
|
4 |
|
public function getType() |
|
302
|
|
|
{ |
|
303
|
4 |
|
return $this->type; |
|
304
|
|
|
} |
|
305
|
|
|
|
|
306
|
7 |
|
public function setType($type) |
|
307
|
|
|
{ |
|
308
|
7 |
|
$this->type = $type; |
|
309
|
7 |
|
} |
|
310
|
|
|
|
|
311
|
4 |
|
public function getId() |
|
312
|
|
|
{ |
|
313
|
4 |
|
return $this->id; |
|
314
|
|
|
} |
|
315
|
|
|
|
|
316
|
5 |
|
public function setId($id) |
|
317
|
|
|
{ |
|
318
|
5 |
|
$this->id = $id; |
|
319
|
5 |
|
} |
|
320
|
|
|
} |
|
321
|
|
|
|
|
322
|
|
|
|
|
323
|
|
|
|
|
324
|
|
|
|
|
325
|
|
|
|
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.