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
|
|
|
/** |
10
|
|
|
* An Optimizely project page. |
11
|
|
|
*/ |
12
|
|
|
class Page |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* URL of the Page |
16
|
|
|
* @var string |
17
|
|
|
*/ |
18
|
|
|
private $editUrl; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Name of the Page |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
private $name; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* ID of the Page's project |
28
|
|
|
* @var integer |
29
|
|
|
*/ |
30
|
|
|
private $projectId; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Code to determine Experiment start |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
private $activationCode; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Page activation type. Can be immediate, manual, polling or callback |
40
|
|
|
* @var string |
41
|
|
|
*/ |
42
|
|
|
private $activationType; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* |
46
|
|
|
* @var string |
47
|
|
|
*/ |
48
|
|
|
private $apiName; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Whether the Page has been archived |
52
|
|
|
* @var boolean |
53
|
|
|
*/ |
54
|
|
|
private $archived; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* The category this Page is grouped under. Can be article, cart, category, |
58
|
|
|
* checkout, home, landing_page, pricing, product_detail, search_results or other |
59
|
|
|
* @var string |
60
|
|
|
*/ |
61
|
|
|
private $category; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Conditions that activate the Page |
65
|
|
|
* @var string |
66
|
|
|
*/ |
67
|
|
|
private $conditions; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Unique string identifier for this page within the project. |
71
|
|
|
* @var string |
72
|
|
|
*/ |
73
|
|
|
private $key; |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Type of Page. Can be single_url, url_set or global |
77
|
|
|
* @var string |
78
|
|
|
*/ |
79
|
|
|
private $pageType; |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Date created |
83
|
|
|
* @var string |
84
|
|
|
*/ |
85
|
|
|
private $created; |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* The unique identifier of the Page |
89
|
|
|
* @var integer |
90
|
|
|
*/ |
91
|
|
|
private $id; |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Date last modified |
95
|
|
|
* @var string |
96
|
|
|
*/ |
97
|
|
|
private $lastModified; |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Constructor. |
101
|
|
|
*/ |
102
|
7 |
View Code Duplication |
public function __construct($options = array()) |
|
|
|
|
103
|
|
|
{ |
104
|
7 |
|
foreach ($options as $name=>$value) { |
105
|
|
|
switch ($name) { |
106
|
6 |
|
case 'edit_url': $this->setEditUrl($value); break; |
|
|
|
|
107
|
6 |
|
case 'name': $this->setName($value); break; |
|
|
|
|
108
|
6 |
|
case 'project_id': $this->setProjectId($value); break; |
|
|
|
|
109
|
6 |
|
case 'activation_code': $this->setActivationCode($value); break; |
|
|
|
|
110
|
6 |
|
case 'activation_type': $this->setActivationType($value); break; |
|
|
|
|
111
|
6 |
|
case 'api_name': $this->setApiName($value); break; |
|
|
|
|
112
|
6 |
|
case 'archived': $this->setArchived($value); break; |
|
|
|
|
113
|
6 |
|
case 'category': $this->setCategory($value); break; |
|
|
|
|
114
|
6 |
|
case 'conditions': $this->setConditions($value); break; |
|
|
|
|
115
|
6 |
|
case 'key': $this->setKey($value); break; |
|
|
|
|
116
|
6 |
|
case 'page_type': $this->setPageType($value); break; |
|
|
|
|
117
|
6 |
|
case 'created': $this->setCreated($value); break; |
|
|
|
|
118
|
6 |
|
case 'id': $this->setId($value); break; |
|
|
|
|
119
|
6 |
|
case 'last_modified': $this->setLastModified($value); break; |
|
|
|
|
120
|
|
|
default: |
121
|
|
|
throw new \Exception('Unknown option: ' . $name); |
122
|
|
|
} |
123
|
7 |
|
} |
124
|
7 |
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Returns this object as array. |
128
|
|
|
*/ |
129
|
3 |
View Code Duplication |
public function toArray() |
|
|
|
|
130
|
|
|
{ |
131
|
|
|
$options = array( |
132
|
3 |
|
'edit_url' => $this->getEditUrl(), |
133
|
3 |
|
'name' => $this->getName(), |
134
|
3 |
|
'project_id' => $this->getProjectId(), |
135
|
3 |
|
'activation_code' => $this->getActivationCode(), |
136
|
3 |
|
'activation_type' => $this->getActivationType(), |
137
|
3 |
|
'api_name' => $this->getApiName(), |
138
|
3 |
|
'archived' => $this->getArchived(), |
139
|
3 |
|
'category' => $this->getCategory(), |
140
|
3 |
|
'conditions' => $this->getConditions(), |
141
|
3 |
|
'key' => $this->getKey(), |
142
|
3 |
|
'page_type' => $this->getPageType(), |
143
|
3 |
|
'created' => $this->getCreated(), |
144
|
3 |
|
'id' => $this->getId(), |
145
|
3 |
|
'last_modified' => $this->getLastModified() |
146
|
3 |
|
); |
147
|
|
|
|
148
|
|
|
// Remove options with empty values |
149
|
3 |
|
$cleanedOptions = array(); |
150
|
3 |
|
foreach ($options as $name=>$value) { |
151
|
3 |
|
if ($value!==null) |
152
|
3 |
|
$cleanedOptions[$name] = $value; |
153
|
3 |
|
} |
154
|
|
|
|
155
|
3 |
|
return $cleanedOptions; |
156
|
|
|
} |
157
|
|
|
|
158
|
5 |
|
public function getEditUrl() |
159
|
|
|
{ |
160
|
5 |
|
return $this->editUrl; |
161
|
|
|
} |
162
|
|
|
|
163
|
7 |
|
public function setEditUrl($editUrl) |
164
|
|
|
{ |
165
|
7 |
|
$this->editUrl = $editUrl; |
166
|
7 |
|
} |
167
|
|
|
|
168
|
7 |
|
public function getName() |
169
|
|
|
{ |
170
|
7 |
|
return $this->name; |
171
|
|
|
} |
172
|
|
|
|
173
|
7 |
|
public function setName($name) |
174
|
|
|
{ |
175
|
7 |
|
$this->name = $name; |
176
|
7 |
|
} |
177
|
|
|
|
178
|
5 |
|
public function getProjectId() |
179
|
|
|
{ |
180
|
5 |
|
return $this->projectId; |
181
|
|
|
} |
182
|
|
|
|
183
|
7 |
|
public function setProjectId($projectId) |
184
|
|
|
{ |
185
|
7 |
|
$this->projectId = $projectId; |
186
|
7 |
|
} |
187
|
|
|
|
188
|
5 |
|
public function getActivationCode() |
189
|
|
|
{ |
190
|
5 |
|
return $this->activationCode; |
191
|
|
|
} |
192
|
|
|
|
193
|
7 |
|
public function setActivationCode($activationCode) |
194
|
|
|
{ |
195
|
7 |
|
$this->activationCode = $activationCode; |
196
|
7 |
|
} |
197
|
|
|
|
198
|
5 |
|
public function getActivationType() |
199
|
|
|
{ |
200
|
5 |
|
return $this->activationType; |
201
|
|
|
} |
202
|
|
|
|
203
|
7 |
|
public function setActivationType($activationType) |
204
|
|
|
{ |
205
|
7 |
|
$this->activationType = $activationType; |
206
|
7 |
|
} |
207
|
|
|
|
208
|
3 |
|
public function getApiName() |
209
|
|
|
{ |
210
|
3 |
|
return $this->apiName; |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
public function setApiName($apiName) |
214
|
|
|
{ |
215
|
|
|
$this->apiName = $apiName; |
216
|
|
|
} |
217
|
|
|
|
218
|
5 |
|
public function getArchived() |
219
|
|
|
{ |
220
|
5 |
|
return $this->archived; |
221
|
|
|
} |
222
|
|
|
|
223
|
7 |
|
public function setArchived($archived) |
224
|
|
|
{ |
225
|
7 |
|
$this->archived = $archived; |
226
|
7 |
|
} |
227
|
|
|
|
228
|
3 |
|
public function getCategory() |
229
|
|
|
{ |
230
|
3 |
|
return $this->category; |
231
|
|
|
} |
232
|
|
|
|
233
|
7 |
|
public function setCategory($category) |
234
|
|
|
{ |
235
|
7 |
|
$this->category = $category; |
236
|
7 |
|
} |
237
|
|
|
|
238
|
3 |
|
public function getConditions() |
239
|
|
|
{ |
240
|
3 |
|
return $this->conditions; |
241
|
|
|
} |
242
|
|
|
|
243
|
7 |
|
public function setConditions($conditions) |
244
|
|
|
{ |
245
|
7 |
|
$this->conditions = $conditions; |
246
|
7 |
|
} |
247
|
|
|
|
248
|
3 |
|
public function getKey() |
249
|
|
|
{ |
250
|
3 |
|
return $this->key; |
251
|
|
|
} |
252
|
|
|
|
253
|
7 |
|
public function setKey($key) |
254
|
|
|
{ |
255
|
7 |
|
$this->key = $key; |
256
|
7 |
|
} |
257
|
|
|
|
258
|
3 |
|
public function getPageType() |
259
|
|
|
{ |
260
|
3 |
|
return $this->pageType; |
261
|
|
|
} |
262
|
|
|
|
263
|
7 |
|
public function setPageType($pageType) |
264
|
|
|
{ |
265
|
7 |
|
$this->pageType = $pageType; |
266
|
7 |
|
} |
267
|
|
|
|
268
|
3 |
|
public function getCreated() |
269
|
|
|
{ |
270
|
3 |
|
return $this->created; |
271
|
|
|
} |
272
|
|
|
|
273
|
7 |
|
public function setCreated($created) |
274
|
|
|
{ |
275
|
7 |
|
$this->created = $created; |
276
|
7 |
|
} |
277
|
|
|
|
278
|
3 |
|
public function getId() |
279
|
|
|
{ |
280
|
3 |
|
return $this->id; |
281
|
|
|
} |
282
|
|
|
|
283
|
7 |
|
public function setId($id) |
284
|
|
|
{ |
285
|
7 |
|
$this->id = $id; |
286
|
7 |
|
} |
287
|
|
|
|
288
|
3 |
|
public function getLastModified() |
289
|
|
|
{ |
290
|
3 |
|
return $this->lastModified; |
291
|
|
|
} |
292
|
|
|
|
293
|
7 |
|
public function setLastModified($lastModified) |
294
|
|
|
{ |
295
|
7 |
|
$this->lastModified = $lastModified; |
296
|
7 |
|
} |
297
|
|
|
} |
298
|
|
|
|
299
|
|
|
|
300
|
|
|
|
301
|
|
|
|
302
|
|
|
|
303
|
|
|
|
304
|
|
|
|
305
|
|
|
|
306
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.