1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author Oleg Krivtsov <[email protected]> |
4
|
|
|
* @date 10 October 2016 |
5
|
|
|
* @copyright (c) 2016, Web Marketing ROI |
6
|
|
|
*/ |
7
|
|
|
namespace WebMarketingROI\OptimizelyPHP\Resource\v2; |
8
|
|
|
|
9
|
|
|
use WebMarketingROI\OptimizelyPHP\Exception; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* An Optimizely campaign change. |
13
|
|
|
*/ |
14
|
|
|
class Change |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* The type of change to apply to the Page. Can be 'custom_code', 'custom_css', |
18
|
|
|
* 'attribute', 'mobile_live_variable', 'mobile_code_block', 'mobile_visual_change', |
19
|
|
|
* 'widget', 'insert_html', 'insert_image' or 'redirect'. |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
private $type; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Whether or not to allow additional redirects after redirecting to |
26
|
|
|
* destination. Required for changes of type redirect. |
27
|
|
|
* @var boolean |
28
|
|
|
*/ |
29
|
|
|
private $allowAdditionalRedirect; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Indicates whether or not to execute the change asyncronously. |
33
|
|
|
* @var boolean |
34
|
|
|
*/ |
35
|
|
|
private $async; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* CSS selector to determine where changes are applied. Required for changes |
39
|
|
|
* of type custom_css, insert_html and insert_image. |
40
|
|
|
* @var string |
41
|
|
|
*/ |
42
|
|
|
private $cssSelector; |
|
|
|
|
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* A list of dependent change IDs that must happen before this change |
46
|
|
|
* @var array[string] |
47
|
|
|
*/ |
48
|
|
|
private $dependencies; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* URL to redirect to. Required for changes of type redirect. |
52
|
|
|
* @var string |
53
|
|
|
*/ |
54
|
|
|
private $destination; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* ID of the extension to insert. Required for changes of type extension. |
58
|
|
|
* @var string |
59
|
|
|
*/ |
60
|
|
|
private $extensionId; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Whether or not to preserve parameters from original request when |
64
|
|
|
* redirecting to new destination URL. Required for changes of type redirect. |
65
|
|
|
* @var boolean |
66
|
|
|
*/ |
67
|
|
|
private $preserveParameters; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* The Page ID to apply changes to |
71
|
|
|
* @var string |
72
|
|
|
*/ |
73
|
|
|
private $src; |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* The value for the change |
77
|
|
|
* @var string |
78
|
|
|
*/ |
79
|
|
|
private $value; |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* The ID of the change |
83
|
|
|
* @var integer |
84
|
|
|
*/ |
85
|
|
|
private $id; |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* CSS selector to determine where changes are applied. Required for changes |
89
|
|
|
* of type 'attribute', 'insert_html', and 'insert_image' |
90
|
|
|
* @var string |
91
|
|
|
*/ |
92
|
|
|
private $selector; |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* New value(s) for the element(s) matched by 'selector'. This field is only |
96
|
|
|
* applicable to changes of type 'attribute'. |
97
|
|
|
* @var ChangeAttribute |
98
|
|
|
*/ |
99
|
|
|
private $attributes; |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* A directive to place the DOM element(s) matched by 'selector' to the position |
103
|
|
|
* of the element matched by 'insertSelector', with the relation specified by |
104
|
|
|
* 'operator'. The supplied example moves element matched by 'selector' above the element of class .greyBox |
105
|
|
|
* @var array |
106
|
|
|
*/ |
107
|
|
|
private $rearrange; |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Configuration properties for the extension |
111
|
|
|
* @var array |
112
|
|
|
*/ |
113
|
|
|
private $config; |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* CSS to apply to element(s) matched by 'selector'. |
117
|
|
|
* @var CssAttribute |
118
|
|
|
*/ |
119
|
|
|
private $css; |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Name of the change |
123
|
|
|
* @var string |
124
|
|
|
*/ |
125
|
|
|
private $name; |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Where to instert HTML or image for types 'insert_html' and 'insert_image' |
129
|
|
|
* with respect to the element(s) matched by 'selector' |
130
|
|
|
* @var string |
131
|
|
|
*/ |
132
|
|
|
private $operator; |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* Constructor. |
136
|
|
|
*/ |
137
|
14 |
|
public function __construct($options = array()) |
138
|
|
|
{ |
139
|
14 |
|
foreach ($options as $name=>$value) { |
140
|
|
|
switch ($name) { |
141
|
12 |
|
case 'type': $this->setType($value); break; |
|
|
|
|
142
|
12 |
|
case 'allow_additional_redirect': $this->setAllowAdditionalRedirect($value); break; |
|
|
|
|
143
|
12 |
|
case 'async': $this->setAsync($value); break; |
|
|
|
|
144
|
12 |
|
case 'dependencies': $this->setDependencies($value); break; |
|
|
|
|
145
|
12 |
|
case 'destination': $this->setDestination($value); break; |
|
|
|
|
146
|
12 |
|
case 'extension_id': $this->setExtensionId($value); break; |
|
|
|
|
147
|
12 |
|
case 'preserve_parameters': $this->setPreserveParameters($value); break; |
|
|
|
|
148
|
12 |
|
case 'src': $this->setSrc($value); break; |
|
|
|
|
149
|
12 |
|
case 'value': $this->setValue($value); break; |
|
|
|
|
150
|
12 |
|
case 'id': $this->setId($value); break; |
|
|
|
|
151
|
12 |
|
case 'selector': $this->setSelector($value); break; |
|
|
|
|
152
|
2 |
|
case 'attributes': |
153
|
2 |
|
$attrs = new ChangeAttribute($value); |
154
|
2 |
|
$this->setAttributes($attrs); |
155
|
2 |
|
break; |
156
|
1 |
|
case 'rearrange': $this->getRearrange($value); break; |
|
|
|
|
157
|
|
|
case 'config': $this->setConfig($value); break; |
|
|
|
|
158
|
|
|
case 'css': |
159
|
|
|
$attr = new CssAttribute($value); |
160
|
|
|
$this->setCss($attr); break; |
|
|
|
|
161
|
|
|
case 'name': $this->setName($value); break; |
|
|
|
|
162
|
|
|
case 'operator': $this->setOperator($value); break; |
|
|
|
|
163
|
|
|
default: |
164
|
|
|
throw new Exception('Unknown option found in the Change entity: ' . $name); |
165
|
|
|
} |
166
|
14 |
|
} |
167
|
14 |
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* Returns this object as array. |
171
|
|
|
*/ |
172
|
6 |
|
public function toArray() |
173
|
|
|
{ |
174
|
|
|
$options = array( |
175
|
6 |
|
'type' => $this->getType(), |
176
|
6 |
|
'allow_additional_redirect' => $this->getAllowAdditionalRedirect(), |
177
|
6 |
|
'async' => $this->getAsync(), |
178
|
6 |
|
'dependencies' => $this->getDependencies(), |
179
|
6 |
|
'destination' => $this->getDestination(), |
180
|
6 |
|
'extension_id' => $this->getExtensionId(), |
181
|
6 |
|
'preserve_parameters' => $this->getPreserveParameters(), |
182
|
6 |
|
'src' => $this->getSrc(), |
183
|
6 |
|
'value' => $this->getValue(), |
184
|
6 |
|
'id' => $this->getId(), |
185
|
6 |
|
'selector' => $this->getSelector(), |
186
|
6 |
|
'attributes' => $this->getAttributes()?$this->getAttributes()->toArray():null, |
187
|
6 |
|
'rearrange' => $this->getRearrange(), |
188
|
6 |
|
'config' => $this->getConfig(), |
189
|
6 |
|
'css' => $this->getCss()?$this->getCss()->toArray():null, |
190
|
6 |
|
'name' => $this->getName(), |
191
|
6 |
|
'operator' => $this->getOperator(), |
192
|
6 |
|
); |
193
|
|
|
|
194
|
|
|
// Remove options with empty values |
195
|
6 |
|
$cleanedOptions = array(); |
196
|
6 |
|
foreach ($options as $name=>$value) { |
197
|
6 |
|
if ($value!==null) |
198
|
6 |
|
$cleanedOptions[$name] = $value; |
199
|
6 |
|
} |
200
|
|
|
|
201
|
6 |
|
return $cleanedOptions; |
202
|
|
|
} |
203
|
|
|
|
204
|
7 |
|
public function getType() |
205
|
|
|
{ |
206
|
7 |
|
return $this->type; |
207
|
|
|
} |
208
|
|
|
|
209
|
14 |
|
public function setType($type) |
210
|
|
|
{ |
211
|
14 |
|
$this->type = $type; |
212
|
14 |
|
} |
213
|
|
|
|
214
|
6 |
|
public function getAllowAdditionalRedirect() |
215
|
|
|
{ |
216
|
6 |
|
return $this->allowAdditionalRedirect; |
217
|
|
|
} |
218
|
|
|
|
219
|
14 |
|
public function setAllowAdditionalRedirect($allowAdditionalRedirect) |
220
|
|
|
{ |
221
|
14 |
|
$this->allowAdditionalRedirect = $allowAdditionalRedirect; |
222
|
14 |
|
} |
223
|
|
|
|
224
|
6 |
|
public function getAsync() |
225
|
|
|
{ |
226
|
6 |
|
return $this->async; |
227
|
|
|
} |
228
|
|
|
|
229
|
14 |
|
public function setAsync($async) |
230
|
|
|
{ |
231
|
14 |
|
$this->async = $async; |
232
|
14 |
|
} |
233
|
|
|
|
234
|
6 |
|
public function getDependencies() |
235
|
|
|
{ |
236
|
6 |
|
return $this->dependencies; |
237
|
|
|
} |
238
|
|
|
|
239
|
14 |
|
public function setDependencies($dependencies) |
240
|
|
|
{ |
241
|
14 |
|
$this->dependencies = $dependencies; |
242
|
14 |
|
} |
243
|
|
|
|
244
|
6 |
|
public function getDestination() |
245
|
|
|
{ |
246
|
6 |
|
return $this->destination; |
247
|
|
|
} |
248
|
|
|
|
249
|
14 |
|
public function setDestination($destination) |
250
|
|
|
{ |
251
|
14 |
|
$this->destination = $destination; |
252
|
14 |
|
} |
253
|
|
|
|
254
|
6 |
|
public function getExtensionId() |
255
|
|
|
{ |
256
|
6 |
|
return $this->extensionId; |
257
|
|
|
} |
258
|
|
|
|
259
|
12 |
|
public function setExtensionId($extensionId) |
260
|
|
|
{ |
261
|
12 |
|
$this->extensionId = $extensionId; |
262
|
12 |
|
} |
263
|
|
|
|
264
|
6 |
|
public function getPreserveParameters() |
265
|
|
|
{ |
266
|
6 |
|
return $this->preserveParameters; |
267
|
|
|
} |
268
|
|
|
|
269
|
14 |
|
public function setPreserveParameters($preserveParameters) |
270
|
|
|
{ |
271
|
14 |
|
$this->preserveParameters = $preserveParameters; |
272
|
14 |
|
} |
273
|
|
|
|
274
|
7 |
|
public function getSrc() |
275
|
|
|
{ |
276
|
7 |
|
return $this->src; |
277
|
|
|
} |
278
|
|
|
|
279
|
14 |
|
public function setSrc($src) |
280
|
|
|
{ |
281
|
14 |
|
$this->src = $src; |
282
|
14 |
|
} |
283
|
|
|
|
284
|
7 |
|
public function getValue() |
285
|
|
|
{ |
286
|
7 |
|
return $this->value; |
287
|
|
|
} |
288
|
|
|
|
289
|
14 |
|
public function setValue($value) |
290
|
|
|
{ |
291
|
14 |
|
$this->value = $value; |
292
|
14 |
|
} |
293
|
|
|
|
294
|
6 |
|
public function getId() |
295
|
|
|
{ |
296
|
6 |
|
return $this->id; |
297
|
|
|
} |
298
|
|
|
|
299
|
10 |
|
public function setId($id) |
300
|
|
|
{ |
301
|
10 |
|
$this->id = $id; |
302
|
10 |
|
} |
303
|
|
|
|
304
|
6 |
|
public function getSelector() |
305
|
|
|
{ |
306
|
6 |
|
return $this->selector; |
307
|
|
|
} |
308
|
|
|
|
309
|
14 |
|
public function setSelector($selector) |
310
|
|
|
{ |
311
|
14 |
|
$this->selector = $selector; |
312
|
14 |
|
} |
313
|
|
|
|
314
|
7 |
|
public function getAttributes() |
315
|
|
|
{ |
316
|
7 |
|
return $this->attributes; |
317
|
|
|
} |
318
|
|
|
|
319
|
3 |
|
public function setAttributes($attributes) |
320
|
|
|
{ |
321
|
3 |
|
$this->attributes = $attributes; |
322
|
3 |
|
} |
323
|
|
|
|
324
|
7 |
|
public function getRearrange() |
325
|
|
|
{ |
326
|
7 |
|
return $this->rearrange; |
327
|
|
|
} |
328
|
|
|
|
329
|
1 |
|
public function setRearrange($rearrange) |
330
|
|
|
{ |
331
|
1 |
|
$this->rearrange = $rearrange; |
332
|
1 |
|
} |
333
|
|
|
|
334
|
6 |
|
public function getConfig() |
335
|
|
|
{ |
336
|
6 |
|
return $this->config; |
337
|
|
|
} |
338
|
|
|
|
339
|
|
|
public function setConfig($config) |
340
|
|
|
{ |
341
|
|
|
$this->config = $config; |
342
|
|
|
} |
343
|
|
|
|
344
|
6 |
|
public function getCss() |
345
|
|
|
{ |
346
|
6 |
|
return $this->css; |
347
|
|
|
} |
348
|
|
|
|
349
|
|
|
public function setCss($css) |
350
|
|
|
{ |
351
|
|
|
$this->css = $css; |
352
|
|
|
} |
353
|
|
|
|
354
|
6 |
|
public function getName() |
355
|
|
|
{ |
356
|
6 |
|
return $this->name; |
357
|
|
|
} |
358
|
|
|
|
359
|
|
|
public function setName($name) |
360
|
|
|
{ |
361
|
|
|
$this->name = $name; |
362
|
|
|
} |
363
|
|
|
|
364
|
6 |
|
public function getOperator() |
365
|
|
|
{ |
366
|
6 |
|
return $this->operator; |
367
|
|
|
} |
368
|
|
|
|
369
|
|
|
public function setOperator($operator) |
370
|
|
|
{ |
371
|
|
|
$this->operator = $operator; |
372
|
|
|
} |
373
|
|
|
} |
374
|
|
|
|
375
|
|
|
|
376
|
|
|
|
377
|
|
|
|
378
|
|
|
|
379
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.