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
|
|
|
* Constructor. |
105
|
|
|
*/ |
106
|
7 |
|
public function __construct($options = array()) |
107
|
|
|
{ |
108
|
7 |
|
foreach ($options as $name=>$value) { |
109
|
|
|
switch ($name) { |
110
|
6 |
|
case 'project_id': $this->setProjectId($value); break; |
|
|
|
|
111
|
6 |
View Code Duplication |
case 'changes': { |
|
|
|
|
112
|
6 |
|
$changes = array(); |
113
|
6 |
|
foreach ($value as $changeInfo) { |
114
|
6 |
|
$changes[] = new Change($changeInfo); |
115
|
|
|
} |
116
|
6 |
|
$this->setChanges($changes); break; |
117
|
|
|
} |
118
|
6 |
|
case 'created': $this->setCreated($value); break; |
|
|
|
|
119
|
6 |
|
case 'earliest': $this->setEarliest($value); break; |
|
|
|
|
120
|
6 |
|
case 'experiment_ids': $this->setExperimentIds($value); break; |
|
|
|
|
121
|
6 |
|
case 'holdback': $this->setHoldback($value); break; |
|
|
|
|
122
|
6 |
|
case 'last_modified': $this->setLastModified($value); break; |
|
|
|
|
123
|
6 |
|
case 'latest': $this->setLatest($value); break; |
|
|
|
|
124
|
6 |
|
case 'metrics': { |
|
|
|
|
125
|
6 |
|
$metrics = array(); |
126
|
6 |
|
foreach ($value as $metricInfo) { |
127
|
6 |
|
$metrics[] = new Metric($metricInfo); |
128
|
|
|
} |
129
|
6 |
|
$this->setMetrics($metrics); break; |
130
|
|
|
} |
131
|
6 |
|
case 'name': $this->setName($value); break; |
|
|
|
|
132
|
6 |
|
case 'page_ids': $this->setPageIds($value); break; |
|
|
|
|
133
|
6 |
|
case 'status': $this->setStatus($value); break; |
|
|
|
|
134
|
6 |
|
case 'type': $this->setType($value); break; |
|
|
|
|
135
|
4 |
|
case 'id': $this->setId($value); break; |
|
|
|
|
136
|
|
|
default: |
137
|
6 |
|
throw new Exception('Unknown option: ' . $name); |
138
|
|
|
} |
139
|
|
|
} |
140
|
7 |
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* Returns this object as array. |
144
|
|
|
*/ |
145
|
3 |
|
public function toArray() |
146
|
|
|
{ |
147
|
|
|
$options = array( |
148
|
3 |
|
'project_id' => $this->getProjectId(), |
149
|
|
|
'changes' => array(), |
150
|
3 |
|
'created' => $this->getCreated(), |
151
|
3 |
|
'earliest' => $this->getEarliest(), |
152
|
3 |
|
'experiment_ids' => $this->getExperimentIds(), |
153
|
3 |
|
'holdback' => $this->getHoldback(), |
154
|
3 |
|
'last_modified' => $this->getLastModified(), |
155
|
3 |
|
'latest' => $this->getLatest(), |
156
|
|
|
'metrics' => array(), |
157
|
3 |
|
'name' => $this->getName(), |
158
|
3 |
|
'page_ids' => $this->getPageIds(), |
159
|
3 |
|
'status' => $this->getStatus(), |
160
|
3 |
|
'type' => $this->getType(), |
161
|
3 |
|
'id' => $this->getId() |
162
|
|
|
); |
163
|
|
|
|
164
|
3 |
|
foreach ($this->getChanges() as $change) { |
165
|
3 |
|
$options['changes'][] = $change->toArray(); |
166
|
|
|
} |
167
|
|
|
|
168
|
3 |
|
foreach ($this->getMetrics() as $metric) { |
169
|
3 |
|
$options['metrics'][] = $metric->toArray(); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
// Remove options with empty values |
173
|
3 |
|
$cleanedOptions = array(); |
174
|
3 |
|
foreach ($options as $name=>$value) { |
175
|
3 |
|
if ($value!==null) |
176
|
3 |
|
$cleanedOptions[$name] = $value; |
177
|
|
|
} |
178
|
|
|
|
179
|
3 |
|
return $cleanedOptions; |
180
|
|
|
} |
181
|
|
|
|
182
|
5 |
|
public function getProjectId() |
183
|
|
|
{ |
184
|
5 |
|
return $this->projectId; |
185
|
|
|
} |
186
|
|
|
|
187
|
7 |
|
public function setProjectId($projectId) |
188
|
|
|
{ |
189
|
7 |
|
$this->projectId = $projectId; |
190
|
7 |
|
} |
191
|
|
|
|
192
|
5 |
|
public function getChanges() |
193
|
|
|
{ |
194
|
5 |
|
return $this->changes; |
195
|
|
|
} |
196
|
|
|
|
197
|
7 |
|
public function setChanges($changes) |
198
|
|
|
{ |
199
|
7 |
|
$this->changes = $changes; |
200
|
7 |
|
} |
201
|
|
|
|
202
|
4 |
|
public function getCreated() |
203
|
|
|
{ |
204
|
4 |
|
return $this->created; |
205
|
|
|
} |
206
|
|
|
|
207
|
7 |
|
public function setCreated($created) |
208
|
|
|
{ |
209
|
7 |
|
$this->created = $created; |
210
|
7 |
|
} |
211
|
|
|
|
212
|
3 |
|
public function getEarliest() |
213
|
|
|
{ |
214
|
3 |
|
return $this->earliest; |
215
|
|
|
} |
216
|
|
|
|
217
|
7 |
|
public function setEarliest($earliest) |
218
|
|
|
{ |
219
|
7 |
|
$this->earliest = $earliest; |
220
|
7 |
|
} |
221
|
|
|
|
222
|
3 |
|
public function getExperimentIds() |
223
|
|
|
{ |
224
|
3 |
|
return $this->experimentIds; |
225
|
|
|
} |
226
|
|
|
|
227
|
7 |
|
public function setExperimentIds($experimentIds) |
228
|
|
|
{ |
229
|
7 |
|
$this->experimentIds = $experimentIds; |
230
|
7 |
|
} |
231
|
|
|
|
232
|
3 |
|
public function getHoldback() |
233
|
|
|
{ |
234
|
3 |
|
return $this->holdback; |
235
|
|
|
} |
236
|
|
|
|
237
|
7 |
|
public function setHoldback($holdback) |
238
|
|
|
{ |
239
|
7 |
|
$this->holdback = $holdback; |
240
|
7 |
|
} |
241
|
|
|
|
242
|
3 |
|
public function getLastModified() |
243
|
|
|
{ |
244
|
3 |
|
return $this->lastModified; |
245
|
|
|
} |
246
|
|
|
|
247
|
7 |
|
public function setLastModified($lastModified) |
248
|
|
|
{ |
249
|
7 |
|
$this->lastModified = $lastModified; |
250
|
7 |
|
} |
251
|
|
|
|
252
|
3 |
|
public function getLatest() |
253
|
|
|
{ |
254
|
3 |
|
return $this->latest; |
255
|
|
|
} |
256
|
|
|
|
257
|
7 |
|
public function setLatest($latest) |
258
|
|
|
{ |
259
|
7 |
|
$this->latest = $latest; |
260
|
7 |
|
} |
261
|
|
|
|
262
|
5 |
|
public function getMetrics() |
263
|
|
|
{ |
264
|
5 |
|
return $this->metrics; |
265
|
|
|
} |
266
|
|
|
|
267
|
7 |
|
public function setMetrics($metrics) |
268
|
|
|
{ |
269
|
7 |
|
$this->metrics = $metrics; |
270
|
7 |
|
} |
271
|
|
|
|
272
|
6 |
|
public function getName() |
273
|
|
|
{ |
274
|
6 |
|
return $this->name; |
275
|
|
|
} |
276
|
|
|
|
277
|
7 |
|
public function setName($name) |
278
|
|
|
{ |
279
|
7 |
|
$this->name = $name; |
280
|
7 |
|
} |
281
|
|
|
|
282
|
3 |
|
public function getPageIds() |
283
|
|
|
{ |
284
|
3 |
|
return $this->pageIds; |
285
|
|
|
} |
286
|
|
|
|
287
|
7 |
|
public function setPageIds($pageIds) |
288
|
|
|
{ |
289
|
7 |
|
$this->pageIds = $pageIds; |
290
|
7 |
|
} |
291
|
|
|
|
292
|
3 |
|
public function getStatus() |
293
|
|
|
{ |
294
|
3 |
|
return $this->status; |
295
|
|
|
} |
296
|
|
|
|
297
|
7 |
|
public function setStatus($status) |
298
|
|
|
{ |
299
|
7 |
|
$this->status = $status; |
300
|
7 |
|
} |
301
|
|
|
|
302
|
4 |
|
public function getType() |
303
|
|
|
{ |
304
|
4 |
|
return $this->type; |
305
|
|
|
} |
306
|
|
|
|
307
|
7 |
|
public function setType($type) |
308
|
|
|
{ |
309
|
7 |
|
$this->type = $type; |
310
|
7 |
|
} |
311
|
|
|
|
312
|
4 |
|
public function getId() |
313
|
|
|
{ |
314
|
4 |
|
return $this->id; |
315
|
|
|
} |
316
|
|
|
|
317
|
5 |
|
public function setId($id) |
318
|
|
|
{ |
319
|
5 |
|
$this->id = $id; |
320
|
5 |
|
} |
321
|
|
|
} |
322
|
|
|
|
323
|
|
|
|
324
|
|
|
|
325
|
|
|
|
326
|
|
|
|
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.