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
|
|
|
* Constructor. |
136
|
|
|
*/ |
137
|
7 |
|
public function __construct($options = array()) |
138
|
|
|
{ |
139
|
7 |
|
foreach ($options as $name=>$value) { |
140
|
|
|
switch ($name) { |
141
|
6 |
|
case 'project_id': $this->setProjectId($value); break; |
|
|
|
|
142
|
6 |
|
case 'audience_ids': $this->setAudienceIds($value); break; |
|
|
|
|
143
|
6 |
|
case 'campaign_id': $this->setCampaignId($value); break; |
|
|
|
|
144
|
6 |
|
case 'changes': { |
|
|
|
|
145
|
6 |
|
$changes = array(); |
146
|
6 |
|
foreach ($value as $changeInfo) { |
147
|
6 |
|
$changes[] = new Change($changeInfo); |
148
|
|
|
} |
149
|
6 |
|
$this->setChanges($changes); |
150
|
6 |
|
break; |
151
|
|
|
} |
152
|
6 |
|
case 'created': $this->setCreated($value); break; |
|
|
|
|
153
|
6 |
|
case 'description': $this->setDescription($value); break; |
|
|
|
|
154
|
6 |
|
case 'holdback': $this->setHoldback($value); break; |
|
|
|
|
155
|
6 |
|
case 'key': $this->setKey($value); break; |
|
|
|
|
156
|
6 |
|
case 'last_modified': $this->setLastModified($value); break; |
|
|
|
|
157
|
6 |
|
case 'metrics': { |
|
|
|
|
158
|
6 |
|
$metrics = array(); |
159
|
6 |
|
foreach ($value as $metricInfo) { |
160
|
6 |
|
$metrics[] = new Metric($metricInfo); |
161
|
|
|
} |
162
|
6 |
|
$this->setMetrics($metrics); |
163
|
6 |
|
break; |
164
|
|
|
} |
165
|
6 |
|
case 'name': $this->setName($value); break; |
|
|
|
|
166
|
6 |
|
case 'schedule': $this->setSchedule(new Schedule($value)); break; |
|
|
|
|
167
|
6 |
|
case 'status': $this->setStatus($value); break; |
|
|
|
|
168
|
6 |
View Code Duplication |
case 'variations': { |
|
|
|
|
169
|
6 |
|
$variations = array(); |
170
|
6 |
|
foreach ($value as $variationInfo) { |
171
|
6 |
|
$variations[] = new Variation($variationInfo); |
172
|
|
|
} |
173
|
6 |
|
$this->setVariations($variations); |
174
|
6 |
|
break; |
175
|
|
|
} |
176
|
5 |
|
case 'id': $this->setId($value); break; |
|
|
|
|
177
|
5 |
|
case 'is_classic': $this->setIsClassic($value); break; |
|
|
|
|
178
|
1 |
|
case 'type': $this->setType($value); break; |
|
|
|
|
179
|
1 |
|
case 'audience_conditions': $this->setAudienceConditions($value); break; |
|
|
|
|
180
|
|
|
default: |
181
|
6 |
|
throw new Exception('Unknown option found in the Experiment entity: ' . $name); |
182
|
|
|
} |
183
|
|
|
} |
184
|
7 |
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* Returns this object as array. |
188
|
|
|
*/ |
189
|
3 |
|
public function toArray() |
190
|
|
|
{ |
191
|
|
|
$options = array( |
192
|
3 |
|
'project_id' => $this->getProjectId(), |
193
|
3 |
|
'audience_ids' => $this->getAudienceIds(), |
194
|
3 |
|
'campaign_id' => $this->getCampaignId(), |
195
|
3 |
|
'created' => $this->getCreated(), |
196
|
3 |
|
'description' => $this->getDescription(), |
197
|
3 |
|
'holdback' => $this->getHoldback(), |
198
|
3 |
|
'key' => $this->getKey(), |
199
|
3 |
|
'last_modified' => $this->getLastModified(), |
200
|
3 |
|
'name' => $this->getName(), |
201
|
3 |
|
'schedule' => $this->getSchedule()?$this->getSchedule()->toArray():null, |
202
|
3 |
|
'status' => $this->getStatus(), |
203
|
3 |
|
'id' => $this->getId(), |
204
|
3 |
|
'is_classic' => $this->getIsClassic(), |
205
|
3 |
|
'type' => $this->getType(), |
206
|
3 |
|
'audience_conditions' => $this->getAudienceConditions(), |
207
|
|
|
); |
208
|
|
|
|
209
|
3 |
|
if ($this->getChanges()) { |
210
|
|
|
|
211
|
3 |
|
$options['changes'] = array(); |
212
|
|
|
|
213
|
3 |
|
foreach ($this->getChanges() as $change) { |
214
|
3 |
|
$options['changes'][] = $change->toArray(); |
215
|
|
|
} |
216
|
|
|
} |
217
|
|
|
|
218
|
3 |
|
if ($this->getMetrics()) { |
219
|
|
|
|
220
|
3 |
|
$options['metrics'] = array(); |
221
|
|
|
|
222
|
3 |
|
foreach ($this->getMetrics() as $metric) { |
223
|
3 |
|
$options['metrics'][] = $metric->toArray(); |
224
|
|
|
} |
225
|
|
|
} |
226
|
|
|
|
227
|
3 |
|
if ($this->getVariations()) { |
228
|
|
|
|
229
|
3 |
|
$options['variations'] = array(); |
230
|
|
|
|
231
|
3 |
|
foreach ($this->getVariations() as $variation) { |
232
|
3 |
|
$options['variations'][] = $variation->toArray(); |
233
|
|
|
} |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
// Remove options with empty values |
237
|
3 |
|
$cleanedOptions = array(); |
238
|
3 |
|
foreach ($options as $name=>$value) { |
239
|
3 |
|
if ($value!==null) |
240
|
3 |
|
$cleanedOptions[$name] = $value; |
241
|
|
|
} |
242
|
|
|
|
243
|
3 |
|
return $cleanedOptions; |
244
|
|
|
} |
245
|
|
|
|
246
|
5 |
|
public function getProjectId() |
247
|
|
|
{ |
248
|
5 |
|
return $this->projectId; |
249
|
|
|
} |
250
|
|
|
|
251
|
7 |
|
public function setProjectId($projectId) |
252
|
|
|
{ |
253
|
7 |
|
$this->projectId = $projectId; |
254
|
7 |
|
} |
255
|
|
|
|
256
|
4 |
|
public function getAudienceIds() |
257
|
|
|
{ |
258
|
4 |
|
return $this->audienceIds; |
259
|
|
|
} |
260
|
|
|
|
261
|
7 |
|
public function setAudienceIds($audienceIds) |
262
|
|
|
{ |
263
|
7 |
|
$this->audienceIds = $audienceIds; |
264
|
7 |
|
} |
265
|
|
|
|
266
|
4 |
|
public function getCampaignId() |
267
|
|
|
{ |
268
|
4 |
|
return $this->campaignId; |
269
|
|
|
} |
270
|
|
|
|
271
|
7 |
|
public function setCampaignId($campaignId) |
272
|
|
|
{ |
273
|
7 |
|
$this->campaignId = $campaignId; |
274
|
7 |
|
} |
275
|
|
|
|
276
|
4 |
|
public function getChanges() |
277
|
|
|
{ |
278
|
4 |
|
return $this->changes; |
279
|
|
|
} |
280
|
|
|
|
281
|
7 |
|
public function setChanges($changes) |
282
|
|
|
{ |
283
|
7 |
|
$this->changes = $changes; |
284
|
7 |
|
} |
285
|
|
|
|
286
|
4 |
|
public function getCreated() |
287
|
|
|
{ |
288
|
4 |
|
return $this->created; |
289
|
|
|
} |
290
|
|
|
|
291
|
5 |
|
public function setCreated($created) |
292
|
|
|
{ |
293
|
5 |
|
$this->created = $created; |
294
|
5 |
|
} |
295
|
|
|
|
296
|
4 |
|
public function getDescription() |
297
|
|
|
{ |
298
|
4 |
|
return $this->description; |
299
|
|
|
} |
300
|
|
|
|
301
|
7 |
|
public function setDescription($description) |
302
|
|
|
{ |
303
|
7 |
|
$this->description = $description; |
304
|
7 |
|
} |
305
|
|
|
|
306
|
4 |
|
public function getHoldback() |
307
|
|
|
{ |
308
|
4 |
|
return $this->holdback; |
309
|
|
|
} |
310
|
|
|
|
311
|
7 |
|
public function setHoldback($holdback) |
312
|
|
|
{ |
313
|
7 |
|
$this->holdback = $holdback; |
314
|
7 |
|
} |
315
|
|
|
|
316
|
4 |
|
public function getKey() |
317
|
|
|
{ |
318
|
4 |
|
return $this->key; |
319
|
|
|
} |
320
|
|
|
|
321
|
7 |
|
public function setKey($key) |
322
|
|
|
{ |
323
|
7 |
|
$this->key = $key; |
324
|
7 |
|
} |
325
|
|
|
|
326
|
4 |
|
public function getLastModified() |
327
|
|
|
{ |
328
|
4 |
|
return $this->lastModified; |
329
|
|
|
} |
330
|
|
|
|
331
|
5 |
|
public function setLastModified($lastModified) |
332
|
|
|
{ |
333
|
5 |
|
$this->lastModified = $lastModified; |
334
|
5 |
|
} |
335
|
|
|
|
336
|
4 |
|
public function getMetrics() |
337
|
|
|
{ |
338
|
4 |
|
return $this->metrics; |
339
|
|
|
} |
340
|
|
|
|
341
|
7 |
|
public function setMetrics($metrics) |
342
|
|
|
{ |
343
|
7 |
|
$this->metrics = $metrics; |
344
|
7 |
|
} |
345
|
|
|
|
346
|
7 |
|
public function getName() |
347
|
|
|
{ |
348
|
7 |
|
return $this->name; |
349
|
|
|
} |
350
|
|
|
|
351
|
7 |
|
public function setName($name) |
352
|
|
|
{ |
353
|
7 |
|
$this->name = $name; |
354
|
7 |
|
} |
355
|
|
|
|
356
|
4 |
|
public function getSchedule() |
357
|
|
|
{ |
358
|
4 |
|
return $this->schedule; |
359
|
|
|
} |
360
|
|
|
|
361
|
7 |
|
public function setSchedule($schedule) |
362
|
|
|
{ |
363
|
7 |
|
$this->schedule = $schedule; |
364
|
7 |
|
} |
365
|
|
|
|
366
|
4 |
|
public function getStatus() |
367
|
|
|
{ |
368
|
4 |
|
return $this->status; |
369
|
|
|
} |
370
|
|
|
|
371
|
7 |
|
public function setStatus($status) |
372
|
|
|
{ |
373
|
7 |
|
$this->status = $status; |
374
|
7 |
|
} |
375
|
|
|
|
376
|
4 |
|
public function getVariations() |
377
|
|
|
{ |
378
|
4 |
|
return $this->variations; |
379
|
|
|
} |
380
|
|
|
|
381
|
7 |
|
public function setVariations($variations) |
382
|
|
|
{ |
383
|
7 |
|
$this->variations = $variations; |
384
|
7 |
|
} |
385
|
|
|
|
386
|
4 |
|
public function getId() |
387
|
|
|
{ |
388
|
4 |
|
return $this->id; |
389
|
|
|
} |
390
|
|
|
|
391
|
5 |
|
public function setId($id) |
392
|
|
|
{ |
393
|
5 |
|
$this->id = $id; |
394
|
5 |
|
} |
395
|
|
|
|
396
|
4 |
|
public function getIsClassic() |
397
|
|
|
{ |
398
|
4 |
|
return $this->isClassic; |
399
|
|
|
} |
400
|
|
|
|
401
|
5 |
|
public function setIsClassic($isClassic) |
402
|
|
|
{ |
403
|
5 |
|
$this->isClassic = $isClassic; |
404
|
5 |
|
} |
405
|
|
|
|
406
|
3 |
|
public function getType() |
407
|
|
|
{ |
408
|
3 |
|
return $this->type; |
409
|
|
|
} |
410
|
|
|
|
411
|
2 |
|
public function setType($type) |
412
|
|
|
{ |
413
|
2 |
|
$this->type = $type; |
414
|
2 |
|
} |
415
|
|
|
|
416
|
3 |
|
public function getAudienceConditions() |
417
|
|
|
{ |
418
|
3 |
|
return $this->audienceConditions; |
419
|
|
|
} |
420
|
|
|
|
421
|
2 |
|
public function setAudienceConditions($audienceConditions) |
422
|
|
|
{ |
423
|
2 |
|
$this->audienceConditions = $audienceConditions; |
424
|
2 |
|
} |
425
|
|
|
|
426
|
|
|
public function getConfig() |
427
|
|
|
{ |
428
|
|
|
return $this->config; |
|
|
|
|
429
|
|
|
} |
430
|
|
|
|
431
|
|
|
public function setConfig($config) |
432
|
|
|
{ |
433
|
|
|
$this->config = $config; |
434
|
|
|
} |
435
|
|
|
} |
436
|
|
|
|
437
|
|
|
|
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.