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