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