1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author Oleg Krivtsov <[email protected]> |
4
|
|
|
* @date 07 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\EventFilter; |
11
|
|
|
use WebMarketingROI\OptimizelyPHP\Resource\v2\InPageEventConfig; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* An Optimizely event. |
15
|
|
|
*/ |
16
|
|
|
class Event |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* A machine readable name for this Event |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
private $apiName; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Whether or not this Event has been archived |
26
|
|
|
* @var boolean |
27
|
|
|
*/ |
28
|
|
|
private $archived; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* A category for this Event. Can be 'add_to_cart', 'save', 'search', 'share', |
32
|
|
|
* 'purchase', 'convert', 'sign_up', 'subscribe' or 'other'. |
33
|
|
|
* @var type |
34
|
|
|
*/ |
35
|
|
|
private $category; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Creation date for this Event |
39
|
|
|
* @var string |
40
|
|
|
*/ |
41
|
|
|
private $created; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Last modified date. |
45
|
|
|
* @var string |
46
|
|
|
*/ |
47
|
|
|
private $lastModified; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* A description for this Event |
51
|
|
|
* @var string |
52
|
|
|
*/ |
53
|
|
|
private $description; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* A filter object for this Event |
57
|
|
|
* @var EventFilter |
58
|
|
|
*/ |
59
|
|
|
private $eventFilter; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* The type of this Event. Can be custom, click, pageview, classic_custom, |
63
|
|
|
* classic_click, classic_pageview, classic_engagement, classic_revenue, |
64
|
|
|
* classic_mobile_tap, classic_mobile_view, classic_mobile_session, |
65
|
|
|
* classic_mobile_session_length or classic_mobile_num_session |
66
|
|
|
* @var string |
67
|
|
|
*/ |
68
|
|
|
private $eventType; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Unique string identifier for this event within the project. |
72
|
|
|
* @var string |
73
|
|
|
*/ |
74
|
|
|
private $key; |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* A human readable name for this Event |
78
|
|
|
* @var string |
79
|
|
|
*/ |
80
|
|
|
private $name; |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* The Page ID associated with this Event |
84
|
|
|
* @var integer |
85
|
|
|
*/ |
86
|
|
|
private $pageId; |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* The parent Project ID of this Event |
90
|
|
|
* @var integer |
91
|
|
|
*/ |
92
|
|
|
private $projectId; |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* The unique identifier of the Event |
96
|
|
|
* @var integer |
97
|
|
|
*/ |
98
|
|
|
private $id; |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Whether or not this Event is a classic Event |
102
|
|
|
* @var boolean |
103
|
|
|
*/ |
104
|
|
|
private $isClassic; |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Whether this Event may be edited |
108
|
|
|
* @var boolean |
109
|
|
|
*/ |
110
|
|
|
private $isEditable; |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* |
114
|
|
|
* @var InPageEventConfig |
115
|
|
|
*/ |
116
|
|
|
private $config; |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Constructor. |
120
|
|
|
*/ |
121
|
9 |
|
public function __construct($options = array()) |
122
|
|
|
{ |
123
|
9 |
|
foreach ($options as $name=>$value) { |
124
|
|
|
switch ($name) { |
125
|
8 |
|
case 'api_name': $this->setApiName($value); break; |
126
|
8 |
|
case 'archived': $this->setArchived($value); break; |
127
|
8 |
|
case 'category': $this->setCategory($value); break; |
128
|
8 |
|
case 'created': $this->setCreated($value); break; |
129
|
8 |
|
case 'last_modified': $this->setLastModified($value); break; |
130
|
8 |
|
case 'description': $this->setDescription($value); break; |
131
|
8 |
|
case 'event_filter': $this->setEventFilter(new EventFilter($value)); break; |
132
|
8 |
|
case 'event_type': $this->setEventType($value); break; |
133
|
8 |
|
case 'key': $this->setKey($value); break; |
134
|
8 |
|
case 'name': $this->setName($value); break; |
135
|
8 |
|
case 'page_id': $this->setPageId($value); break; |
136
|
8 |
|
case 'project_id': $this->setProjectId($value); break; |
137
|
8 |
|
case 'id': $this->setId($value); break; |
138
|
8 |
|
case 'is_classic': $this->setIsClassic($value); break; |
139
|
8 |
|
case 'is_editable': $this->setIsEditable($value); break; |
140
|
|
|
case 'config': $this->setConfig(new InPageEventConfig($value)); break; |
141
|
|
|
default: |
142
|
8 |
|
throw new Exception('Unknown option found in the Event entity: ' . $name); |
143
|
|
|
} |
144
|
|
|
} |
145
|
9 |
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* Returns this object as array. |
149
|
|
|
*/ |
150
|
5 |
|
public function toArray() |
151
|
|
|
{ |
152
|
|
|
$options = array( |
153
|
5 |
|
'api_name' => $this->getApiName(), |
154
|
5 |
|
'archived' => $this->getArchived(), |
155
|
5 |
|
'category' => $this->getCategory(), |
156
|
5 |
|
'created' => $this->getCreated(), |
157
|
5 |
|
'last_modified' => $this->getLastModified(), |
158
|
5 |
|
'description' => $this->getDescription(), |
159
|
5 |
|
'event_filter' => $this->getEventFilter()?$this->getEventFilter()->toArray():null, |
160
|
5 |
|
'event_type' => $this->getEventType(), |
161
|
5 |
|
'key' => $this->getKey(), |
162
|
5 |
|
'name' => $this->getName(), |
163
|
5 |
|
'page_id' => $this->getPageId(), |
164
|
5 |
|
'project_id' => $this->getProjectId(), |
165
|
5 |
|
'id' => $this->getId(), |
166
|
5 |
|
'is_classic' => $this->getIsClassic(), |
167
|
5 |
|
'is_editable' => $this->getIsEditable(), |
168
|
5 |
|
'config' => $this->getConfig()?$this->getConfig()->toArray():null, |
169
|
|
|
); |
170
|
|
|
|
171
|
|
|
// Remove options with empty values |
172
|
5 |
|
$cleanedOptions = array(); |
173
|
5 |
|
foreach ($options as $name=>$value) { |
174
|
5 |
|
if ($value!==null) |
175
|
5 |
|
$cleanedOptions[$name] = $value; |
176
|
|
|
} |
177
|
|
|
|
178
|
5 |
|
return $cleanedOptions; |
179
|
|
|
} |
180
|
|
|
|
181
|
5 |
|
public function getApiName() |
182
|
|
|
{ |
183
|
5 |
|
return $this->apiName; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
public function setApiName($apiName) |
187
|
|
|
{ |
188
|
|
|
$this->apiName = $apiName; |
189
|
|
|
} |
190
|
|
|
|
191
|
7 |
|
public function getArchived() |
192
|
|
|
{ |
193
|
7 |
|
return $this->archived; |
194
|
|
|
} |
195
|
|
|
|
196
|
9 |
|
public function setArchived($archived) |
197
|
|
|
{ |
198
|
9 |
|
$this->archived = $archived; |
199
|
9 |
|
} |
200
|
|
|
|
201
|
7 |
|
public function getCategory() |
202
|
|
|
{ |
203
|
7 |
|
return $this->category; |
204
|
|
|
} |
205
|
|
|
|
206
|
9 |
|
public function setCategory($category) |
207
|
|
|
{ |
208
|
9 |
|
$this->category = $category; |
209
|
9 |
|
} |
210
|
|
|
|
211
|
5 |
|
public function getCreated() |
212
|
|
|
{ |
213
|
5 |
|
return $this->created; |
214
|
|
|
} |
215
|
|
|
|
216
|
9 |
|
public function setCreated($created) |
217
|
|
|
{ |
218
|
9 |
|
$this->created = $created; |
219
|
9 |
|
} |
220
|
|
|
|
221
|
5 |
|
public function getLastModified() |
222
|
|
|
{ |
223
|
5 |
|
return $this->lastModified; |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
public function setLastModified($lastModified) |
227
|
|
|
{ |
228
|
|
|
$this->lastModified = $lastModified; |
229
|
|
|
} |
230
|
|
|
|
231
|
5 |
|
public function getDescription() |
232
|
|
|
{ |
233
|
5 |
|
return $this->description; |
234
|
|
|
} |
235
|
|
|
|
236
|
9 |
|
public function setDescription($description) |
237
|
|
|
{ |
238
|
9 |
|
$this->description = $description; |
239
|
9 |
|
} |
240
|
|
|
|
241
|
7 |
|
public function getEventFilter() |
242
|
|
|
{ |
243
|
7 |
|
return $this->eventFilter; |
244
|
|
|
} |
245
|
|
|
|
246
|
7 |
|
public function setEventFilter($eventFilter) |
247
|
|
|
{ |
248
|
7 |
|
$this->eventFilter = $eventFilter; |
249
|
7 |
|
} |
250
|
|
|
|
251
|
5 |
|
public function getEventType() |
252
|
|
|
{ |
253
|
5 |
|
return $this->eventType; |
254
|
|
|
} |
255
|
|
|
|
256
|
9 |
|
public function setEventType($eventType) |
257
|
|
|
{ |
258
|
9 |
|
$this->eventType = $eventType; |
259
|
9 |
|
} |
260
|
|
|
|
261
|
5 |
|
public function getKey() |
262
|
|
|
{ |
263
|
5 |
|
return $this->key; |
264
|
|
|
} |
265
|
|
|
|
266
|
9 |
|
public function setKey($key) |
267
|
|
|
{ |
268
|
9 |
|
$this->key = $key; |
269
|
9 |
|
} |
270
|
|
|
|
271
|
9 |
|
public function getName() |
272
|
|
|
{ |
273
|
9 |
|
return $this->name; |
274
|
|
|
} |
275
|
|
|
|
276
|
9 |
|
public function setName($name) |
277
|
|
|
{ |
278
|
9 |
|
$this->name = $name; |
279
|
9 |
|
} |
280
|
|
|
|
281
|
5 |
|
public function getPageId() |
282
|
|
|
{ |
283
|
5 |
|
return $this->pageId; |
284
|
|
|
} |
285
|
|
|
|
286
|
9 |
|
public function setPageId($pageId) |
287
|
|
|
{ |
288
|
9 |
|
$this->pageId = $pageId; |
289
|
9 |
|
} |
290
|
|
|
|
291
|
5 |
|
public function getProjectId() |
292
|
|
|
{ |
293
|
5 |
|
return $this->projectId; |
294
|
|
|
} |
295
|
|
|
|
296
|
9 |
|
public function setProjectId($projectId) |
297
|
|
|
{ |
298
|
9 |
|
$this->projectId = $projectId; |
299
|
9 |
|
} |
300
|
|
|
|
301
|
5 |
|
public function getId() |
302
|
|
|
{ |
303
|
5 |
|
return $this->id; |
304
|
|
|
} |
305
|
|
|
|
306
|
9 |
|
public function setId($id) |
307
|
|
|
{ |
308
|
9 |
|
$this->id = $id; |
309
|
9 |
|
} |
310
|
|
|
|
311
|
5 |
|
public function getIsClassic() |
312
|
|
|
{ |
313
|
5 |
|
return $this->isClassic; |
314
|
|
|
} |
315
|
|
|
|
316
|
9 |
|
public function setIsClassic($isClassic) |
317
|
|
|
{ |
318
|
9 |
|
$this->isClassic = $isClassic; |
319
|
9 |
|
} |
320
|
|
|
|
321
|
7 |
|
public function getIsEditable() |
322
|
|
|
{ |
323
|
7 |
|
return $this->isEditable; |
324
|
|
|
} |
325
|
|
|
|
326
|
9 |
|
public function setIsEditable($isEditable) |
327
|
|
|
{ |
328
|
9 |
|
$this->isEditable = $isEditable; |
329
|
9 |
|
} |
330
|
|
|
|
331
|
5 |
|
public function getConfig() |
332
|
|
|
{ |
333
|
5 |
|
return $this->config; |
334
|
|
|
} |
335
|
|
|
|
336
|
|
|
public function setConfig($config) |
337
|
|
|
{ |
338
|
|
|
$this->config = $config; |
339
|
|
|
} |
340
|
|
|
} |
341
|
|
|
|
342
|
|
|
|
343
|
|
|
|
344
|
|
|
|
345
|
|
|
|
346
|
|
|
|
347
|
|
|
|