1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author Oleg Krivtsov <[email protected]> |
4
|
|
|
* @date 05 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\Schedule; |
11
|
|
|
use WebMarketingROI\OptimizelyPHP\Resource\v2\Variation; |
12
|
|
|
use WebMarketingROI\OptimizelyPHP\Resource\v2\Change; |
13
|
|
|
use WebMarketingROI\OptimizelyPHP\Resource\v2\Metric; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* An Optimizely experiment. |
17
|
|
|
*/ |
18
|
|
|
class Experiment |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* The project the Experiment is in |
22
|
|
|
* @var integer |
23
|
|
|
*/ |
24
|
|
|
private $projectId; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* List of IDs of all audiences the Experiment is targeted at |
28
|
|
|
* @var array[integer] |
29
|
|
|
*/ |
30
|
|
|
private $audienceIds; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* The ID for the Campaign that the Experiment is in |
34
|
|
|
* @var integer |
35
|
|
|
*/ |
36
|
|
|
private $campaignId; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Experiment-level changes that will run before all Variations. Typically |
40
|
|
|
* this is custom CSS or custom JavaScript. |
41
|
|
|
* @var array[Change] |
42
|
|
|
*/ |
43
|
|
|
private $changes; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* The time the experiment was initially created |
47
|
|
|
* @var string |
48
|
|
|
*/ |
49
|
|
|
private $created; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* The description or hypothesis for an Experiment |
53
|
|
|
* @var string |
54
|
|
|
*/ |
55
|
|
|
private $description; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Percentage expressed as a number from 0-10000 to hold back from being |
59
|
|
|
* included in the experiment |
60
|
|
|
* @var integer |
61
|
|
|
*/ |
62
|
|
|
private $holdback; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Unique string identifier for this experiment within the project. |
66
|
|
|
* @var string |
67
|
|
|
*/ |
68
|
|
|
private $key; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* The last time the experiment was modified |
72
|
|
|
* @var string |
73
|
|
|
*/ |
74
|
|
|
private $lastModified; |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* An ordered list of metrics to track for the experiment |
78
|
|
|
* @var array[Metric] |
79
|
|
|
*/ |
80
|
|
|
private $metrics; |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Name of the Experiment |
84
|
|
|
* @var string |
85
|
|
|
*/ |
86
|
|
|
private $name; |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* The last time the experiment was modified |
90
|
|
|
* @var Schedule |
91
|
|
|
*/ |
92
|
|
|
private $schedule; |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Current state of the experiment. Can be 'active', 'paused' or 'archived'. |
96
|
|
|
* @var string |
97
|
|
|
*/ |
98
|
|
|
private $status; |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* A list of Variations that each define an experience to show in the context |
102
|
|
|
* of the Experiment for the purpose of comparison against each other |
103
|
|
|
* @var array[Variation] |
104
|
|
|
*/ |
105
|
|
|
private $variations = array(); |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* The unique identifier for the Experiment |
109
|
|
|
* @var integer |
110
|
|
|
*/ |
111
|
|
|
private $id; |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Whether or not the Experiment is a classic Experiment |
115
|
|
|
* @var boolean |
116
|
|
|
*/ |
117
|
|
|
private $isClassic; |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Indicates whether this is a standalone a/b experiment or an experience within a personalization campaign |
121
|
|
|
* Can be a/b or personalization |
122
|
|
|
* @var string |
123
|
|
|
*/ |
124
|
|
|
private $type; |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* The audiences that should see this experiment. If the field is null or |
128
|
|
|
* omitted, the experiment will target everyone. Multiple audiences can be |
129
|
|
|
* combined with "and" or "or" using the same structure as audience conditions |
130
|
|
|
* @var string |
131
|
|
|
*/ |
132
|
|
|
private $audienceConditions; |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* Traffic allocation policy across variations in this experiment |
136
|
|
|
* @var string |
137
|
|
|
*/ |
138
|
|
|
private $allocationPolicy; |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* The first time the Experiment was activated |
142
|
|
|
* @var type |
143
|
|
|
*/ |
144
|
|
|
private $earliest; |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* Constructor. |
148
|
|
|
*/ |
149
|
7 |
|
public function __construct($options = array()) |
150
|
|
|
{ |
151
|
7 |
|
foreach ($options as $name=>$value) { |
152
|
|
|
switch ($name) { |
153
|
6 |
|
case 'project_id': $this->setProjectId($value); break; |
|
|
|
|
154
|
6 |
|
case 'audience_ids': $this->setAudienceIds($value); break; |
|
|
|
|
155
|
6 |
|
case 'campaign_id': $this->setCampaignId($value); break; |
|
|
|
|
156
|
6 |
View Code Duplication |
case 'changes': { |
|
|
|
|
157
|
6 |
|
$changes = array(); |
158
|
6 |
|
foreach ($value as $changeInfo) { |
159
|
6 |
|
$changes[] = new Change($changeInfo); |
160
|
|
|
} |
161
|
6 |
|
$this->setChanges($changes); |
162
|
6 |
|
break; |
163
|
|
|
} |
164
|
6 |
|
case 'created': $this->setCreated($value); break; |
|
|
|
|
165
|
6 |
|
case 'description': $this->setDescription($value); break; |
|
|
|
|
166
|
6 |
|
case 'holdback': $this->setHoldback($value); break; |
|
|
|
|
167
|
6 |
|
case 'key': $this->setKey($value); break; |
|
|
|
|
168
|
6 |
|
case 'last_modified': $this->setLastModified($value); break; |
|
|
|
|
169
|
6 |
|
case 'metrics': { |
|
|
|
|
170
|
6 |
|
$metrics = array(); |
171
|
6 |
|
foreach ($value as $metricInfo) { |
172
|
6 |
|
$metrics[] = new Metric($metricInfo); |
173
|
|
|
} |
174
|
6 |
|
$this->setMetrics($metrics); |
175
|
6 |
|
break; |
176
|
|
|
} |
177
|
6 |
|
case 'name': $this->setName($value); break; |
|
|
|
|
178
|
6 |
|
case 'schedule': $this->setSchedule(new Schedule($value)); break; |
|
|
|
|
179
|
6 |
|
case 'status': $this->setStatus($value); break; |
|
|
|
|
180
|
6 |
View Code Duplication |
case 'variations': { |
|
|
|
|
181
|
6 |
|
$variations = array(); |
182
|
6 |
|
foreach ($value as $variationInfo) { |
183
|
6 |
|
$variations[] = new Variation($variationInfo); |
184
|
|
|
} |
185
|
6 |
|
$this->setVariations($variations); |
186
|
6 |
|
break; |
187
|
|
|
} |
188
|
5 |
|
case 'id': $this->setId($value); break; |
|
|
|
|
189
|
5 |
|
case 'is_classic': $this->setIsClassic($value); break; |
|
|
|
|
190
|
1 |
|
case 'type': $this->setType($value); break; |
|
|
|
|
191
|
1 |
|
case 'audience_conditions': $this->setAudienceConditions($value); break; |
|
|
|
|
192
|
|
|
case 'allocation_policy': $this->setAllocationPolicy($value); break; |
|
|
|
|
193
|
|
|
case 'earliest': $this->setEarliest($value); break; |
|
|
|
|
194
|
|
|
default: |
195
|
6 |
|
throw new Exception('Unknown option found in the Experiment entity: ' . $name); |
196
|
|
|
} |
197
|
|
|
} |
198
|
7 |
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* Returns this object as array. |
202
|
|
|
*/ |
203
|
3 |
|
public function toArray() |
204
|
|
|
{ |
205
|
|
|
$options = array( |
206
|
3 |
|
'project_id' => $this->getProjectId(), |
207
|
3 |
|
'audience_ids' => $this->getAudienceIds(), |
208
|
3 |
|
'campaign_id' => $this->getCampaignId(), |
209
|
3 |
|
'created' => $this->getCreated(), |
210
|
3 |
|
'description' => $this->getDescription(), |
211
|
3 |
|
'holdback' => $this->getHoldback(), |
212
|
3 |
|
'key' => $this->getKey(), |
213
|
3 |
|
'last_modified' => $this->getLastModified(), |
214
|
3 |
|
'name' => $this->getName(), |
215
|
3 |
|
'schedule' => $this->getSchedule()?$this->getSchedule()->toArray():null, |
216
|
3 |
|
'status' => $this->getStatus(), |
217
|
3 |
|
'id' => $this->getId(), |
218
|
3 |
|
'is_classic' => $this->getIsClassic(), |
219
|
3 |
|
'type' => $this->getType(), |
220
|
3 |
|
'audience_conditions' => $this->getAudienceConditions(), |
221
|
3 |
|
'allocation_policy' => $this->getAllocationPolicy(), |
222
|
3 |
|
'earliest' => $this->getEarliest(), |
223
|
|
|
); |
224
|
|
|
|
225
|
3 |
|
if ($this->getChanges()) { |
226
|
|
|
|
227
|
3 |
|
$options['changes'] = array(); |
228
|
|
|
|
229
|
3 |
|
foreach ($this->getChanges() as $change) { |
230
|
3 |
|
$options['changes'][] = $change->toArray(); |
231
|
|
|
} |
232
|
|
|
} |
233
|
|
|
|
234
|
3 |
|
if ($this->getMetrics()) { |
235
|
|
|
|
236
|
3 |
|
$options['metrics'] = array(); |
237
|
|
|
|
238
|
3 |
|
foreach ($this->getMetrics() as $metric) { |
239
|
3 |
|
$options['metrics'][] = $metric->toArray(); |
240
|
|
|
} |
241
|
|
|
} |
242
|
|
|
|
243
|
3 |
|
if ($this->getVariations()) { |
244
|
|
|
|
245
|
3 |
|
$options['variations'] = array(); |
246
|
|
|
|
247
|
3 |
|
foreach ($this->getVariations() as $variation) { |
248
|
3 |
|
$options['variations'][] = $variation->toArray(); |
249
|
|
|
} |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
// Remove options with empty values |
253
|
3 |
|
$cleanedOptions = array(); |
254
|
3 |
|
foreach ($options as $name=>$value) { |
255
|
3 |
|
if ($value!==null) |
256
|
3 |
|
$cleanedOptions[$name] = $value; |
257
|
|
|
} |
258
|
|
|
|
259
|
3 |
|
return $cleanedOptions; |
260
|
|
|
} |
261
|
|
|
|
262
|
5 |
|
public function getProjectId() |
263
|
|
|
{ |
264
|
5 |
|
return $this->projectId; |
265
|
|
|
} |
266
|
|
|
|
267
|
7 |
|
public function setProjectId($projectId) |
268
|
|
|
{ |
269
|
7 |
|
$this->projectId = $projectId; |
270
|
7 |
|
} |
271
|
|
|
|
272
|
4 |
|
public function getAudienceIds() |
273
|
|
|
{ |
274
|
4 |
|
return $this->audienceIds; |
275
|
|
|
} |
276
|
|
|
|
277
|
7 |
|
public function setAudienceIds($audienceIds) |
278
|
|
|
{ |
279
|
7 |
|
$this->audienceIds = $audienceIds; |
280
|
7 |
|
} |
281
|
|
|
|
282
|
4 |
|
public function getCampaignId() |
283
|
|
|
{ |
284
|
4 |
|
return $this->campaignId; |
285
|
|
|
} |
286
|
|
|
|
287
|
7 |
|
public function setCampaignId($campaignId) |
288
|
|
|
{ |
289
|
7 |
|
$this->campaignId = $campaignId; |
290
|
7 |
|
} |
291
|
|
|
|
292
|
4 |
|
public function getChanges() |
293
|
|
|
{ |
294
|
4 |
|
return $this->changes; |
295
|
|
|
} |
296
|
|
|
|
297
|
7 |
|
public function setChanges($changes) |
298
|
|
|
{ |
299
|
7 |
|
$this->changes = $changes; |
300
|
7 |
|
} |
301
|
|
|
|
302
|
4 |
|
public function getCreated() |
303
|
|
|
{ |
304
|
4 |
|
return $this->created; |
305
|
|
|
} |
306
|
|
|
|
307
|
5 |
|
public function setCreated($created) |
308
|
|
|
{ |
309
|
5 |
|
$this->created = $created; |
310
|
5 |
|
} |
311
|
|
|
|
312
|
4 |
|
public function getDescription() |
313
|
|
|
{ |
314
|
4 |
|
return $this->description; |
315
|
|
|
} |
316
|
|
|
|
317
|
7 |
|
public function setDescription($description) |
318
|
|
|
{ |
319
|
7 |
|
$this->description = $description; |
320
|
7 |
|
} |
321
|
|
|
|
322
|
4 |
|
public function getHoldback() |
323
|
|
|
{ |
324
|
4 |
|
return $this->holdback; |
325
|
|
|
} |
326
|
|
|
|
327
|
7 |
|
public function setHoldback($holdback) |
328
|
|
|
{ |
329
|
7 |
|
$this->holdback = $holdback; |
330
|
7 |
|
} |
331
|
|
|
|
332
|
4 |
|
public function getKey() |
333
|
|
|
{ |
334
|
4 |
|
return $this->key; |
335
|
|
|
} |
336
|
|
|
|
337
|
7 |
|
public function setKey($key) |
338
|
|
|
{ |
339
|
7 |
|
$this->key = $key; |
340
|
7 |
|
} |
341
|
|
|
|
342
|
4 |
|
public function getLastModified() |
343
|
|
|
{ |
344
|
4 |
|
return $this->lastModified; |
345
|
|
|
} |
346
|
|
|
|
347
|
5 |
|
public function setLastModified($lastModified) |
348
|
|
|
{ |
349
|
5 |
|
$this->lastModified = $lastModified; |
350
|
5 |
|
} |
351
|
|
|
|
352
|
4 |
|
public function getMetrics() |
353
|
|
|
{ |
354
|
4 |
|
return $this->metrics; |
355
|
|
|
} |
356
|
|
|
|
357
|
7 |
|
public function setMetrics($metrics) |
358
|
|
|
{ |
359
|
7 |
|
$this->metrics = $metrics; |
360
|
7 |
|
} |
361
|
|
|
|
362
|
7 |
|
public function getName() |
363
|
|
|
{ |
364
|
7 |
|
return $this->name; |
365
|
|
|
} |
366
|
|
|
|
367
|
7 |
|
public function setName($name) |
368
|
|
|
{ |
369
|
7 |
|
$this->name = $name; |
370
|
7 |
|
} |
371
|
|
|
|
372
|
4 |
|
public function getSchedule() |
373
|
|
|
{ |
374
|
4 |
|
return $this->schedule; |
375
|
|
|
} |
376
|
|
|
|
377
|
7 |
|
public function setSchedule($schedule) |
378
|
|
|
{ |
379
|
7 |
|
$this->schedule = $schedule; |
380
|
7 |
|
} |
381
|
|
|
|
382
|
4 |
|
public function getStatus() |
383
|
|
|
{ |
384
|
4 |
|
return $this->status; |
385
|
|
|
} |
386
|
|
|
|
387
|
7 |
|
public function setStatus($status) |
388
|
|
|
{ |
389
|
7 |
|
$this->status = $status; |
390
|
7 |
|
} |
391
|
|
|
|
392
|
4 |
|
public function getVariations() |
393
|
|
|
{ |
394
|
4 |
|
return $this->variations; |
395
|
|
|
} |
396
|
|
|
|
397
|
7 |
|
public function setVariations($variations) |
398
|
|
|
{ |
399
|
7 |
|
$this->variations = $variations; |
400
|
7 |
|
} |
401
|
|
|
|
402
|
4 |
|
public function getId() |
403
|
|
|
{ |
404
|
4 |
|
return $this->id; |
405
|
|
|
} |
406
|
|
|
|
407
|
5 |
|
public function setId($id) |
408
|
|
|
{ |
409
|
5 |
|
$this->id = $id; |
410
|
5 |
|
} |
411
|
|
|
|
412
|
4 |
|
public function getIsClassic() |
413
|
|
|
{ |
414
|
4 |
|
return $this->isClassic; |
415
|
|
|
} |
416
|
|
|
|
417
|
5 |
|
public function setIsClassic($isClassic) |
418
|
|
|
{ |
419
|
5 |
|
$this->isClassic = $isClassic; |
420
|
5 |
|
} |
421
|
|
|
|
422
|
3 |
|
public function getType() |
423
|
|
|
{ |
424
|
3 |
|
return $this->type; |
425
|
|
|
} |
426
|
|
|
|
427
|
2 |
|
public function setType($type) |
428
|
|
|
{ |
429
|
2 |
|
$this->type = $type; |
430
|
2 |
|
} |
431
|
|
|
|
432
|
3 |
|
public function getAudienceConditions() |
433
|
|
|
{ |
434
|
3 |
|
return $this->audienceConditions; |
435
|
|
|
} |
436
|
|
|
|
437
|
2 |
|
public function setAudienceConditions($audienceConditions) |
438
|
|
|
{ |
439
|
2 |
|
$this->audienceConditions = $audienceConditions; |
440
|
2 |
|
} |
441
|
|
|
|
442
|
|
|
public function getConfig() |
443
|
|
|
{ |
444
|
|
|
return $this->config; |
|
|
|
|
445
|
|
|
} |
446
|
|
|
|
447
|
|
|
public function setConfig($config) |
448
|
|
|
{ |
449
|
|
|
$this->config = $config; |
450
|
|
|
} |
451
|
|
|
|
452
|
3 |
|
public function getAllocationPolicy() |
453
|
|
|
{ |
454
|
3 |
|
return $this->allocationPolicy; |
455
|
|
|
} |
456
|
|
|
|
457
|
|
|
public function setAllocationPolicy($allocationPolicy) |
458
|
|
|
{ |
459
|
|
|
$this->allocationPolicy = $allocationPolicy; |
460
|
|
|
} |
461
|
|
|
|
462
|
3 |
|
public function getEarliest() |
463
|
|
|
{ |
464
|
3 |
|
return $this->earliest; |
465
|
|
|
} |
466
|
|
|
|
467
|
|
|
public function setEarliest($earliest) |
468
|
|
|
{ |
469
|
|
|
$this->earliest = $earliest; |
470
|
|
|
} |
471
|
|
|
} |
472
|
|
|
|
473
|
|
|
|
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.