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
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* An Optimizely audience. |
13
|
|
|
*/ |
14
|
|
|
class Audience |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* The project the Audience was created in |
18
|
|
|
* @var integer |
19
|
|
|
*/ |
20
|
|
|
private $projectId; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Whether the Audience has been archived |
24
|
|
|
* @var boolean |
25
|
|
|
*/ |
26
|
|
|
private $archived; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* A string defining the targeting rules for an audience. |
30
|
|
|
* @var string |
31
|
|
|
*/ |
32
|
|
|
private $conditions; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* A short description of the Audience |
36
|
|
|
* @var string |
37
|
|
|
*/ |
38
|
|
|
private $description; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* The name of the Audience |
42
|
|
|
* @var string |
43
|
|
|
*/ |
44
|
|
|
private $name; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* True if the audiences is available for segmentation on the results page (Platinum only). |
48
|
|
|
* @var boolean |
49
|
|
|
*/ |
50
|
|
|
private $segmentation; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* The time the Audience was initially created |
54
|
|
|
* @var string |
55
|
|
|
*/ |
56
|
|
|
private $created; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* The unique identifier for the Audience. |
60
|
|
|
* @var integer |
61
|
|
|
*/ |
62
|
|
|
private $id; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* The last time the Audience was modified |
66
|
|
|
* @var string |
67
|
|
|
*/ |
68
|
|
|
private $lastModified; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Whether or not Audience is a classic Audience. If true, the Audience is |
72
|
|
|
* only compatible with classic Experiments. Otherwise, the Audience may be |
73
|
|
|
* used in Optimizely X Campaigns. |
74
|
|
|
* @var boolean |
75
|
|
|
*/ |
76
|
|
|
private $isClassic; |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Constructor. |
80
|
|
|
*/ |
81
|
7 |
|
public function __construct($options = array()) |
82
|
|
|
{ |
83
|
7 |
|
foreach ($options as $name=>$value) { |
84
|
|
|
switch ($name) { |
85
|
6 |
|
case 'project_id': $this->setProjectId($value); break; |
|
|
|
|
86
|
6 |
|
case 'archived': $this->setArchived($value); break; |
|
|
|
|
87
|
6 |
|
case 'conditions': $this->setConditions($value); break; |
|
|
|
|
88
|
6 |
|
case 'description': $this->setDescription($value); break; |
|
|
|
|
89
|
6 |
|
case 'name': $this->setName($value); break; |
|
|
|
|
90
|
6 |
|
case 'segmentation': $this->setSegmentation($value); break; |
|
|
|
|
91
|
4 |
|
case 'created': $this->setCreated($value); break; |
|
|
|
|
92
|
4 |
|
case 'id': $this->setId($value); break; |
|
|
|
|
93
|
4 |
|
case 'last_modified': $this->setLastModified($value); break; |
|
|
|
|
94
|
|
|
case 'is_classic': $this->getIsClassic($value); break; |
|
|
|
|
95
|
|
|
default: |
96
|
|
|
throw new Exception('Unknown option: ' . $name); |
97
|
|
|
} |
98
|
7 |
|
} |
99
|
7 |
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Returns this object as array. |
103
|
|
|
*/ |
104
|
3 |
|
public function toArray() |
105
|
|
|
{ |
106
|
|
|
$options = array( |
107
|
3 |
|
'project_id' => $this->projectId, |
108
|
3 |
|
'archived' => $this->archived, |
109
|
3 |
|
'conditions' => $this->conditions, |
110
|
3 |
|
'description' => $this->description, |
111
|
3 |
|
'name' => $this->name, |
112
|
3 |
|
'segmentation' => $this->segmentation, |
113
|
3 |
|
'created' => $this->created, |
114
|
3 |
|
'id' => $this->id, |
115
|
3 |
|
'last_modified' => $this->lastModified, |
116
|
3 |
|
'is_classic' => $this->isClassic |
117
|
3 |
|
); |
118
|
|
|
|
119
|
|
|
// Remove options with empty values |
120
|
3 |
|
$cleanedOptions = array(); |
121
|
3 |
|
foreach ($options as $name=>$value) { |
122
|
3 |
|
if ($value!==null) |
123
|
3 |
|
$cleanedOptions[$name] = $value; |
124
|
3 |
|
} |
125
|
|
|
|
126
|
3 |
|
return $cleanedOptions; |
127
|
|
|
} |
128
|
|
|
|
129
|
2 |
|
public function getProjectId() |
130
|
|
|
{ |
131
|
2 |
|
return $this->projectId; |
132
|
|
|
} |
133
|
|
|
|
134
|
7 |
|
public function setProjectId($projectId) |
135
|
|
|
{ |
136
|
7 |
|
$this->projectId = $projectId; |
137
|
7 |
|
} |
138
|
|
|
|
139
|
2 |
|
public function getArchived() |
140
|
|
|
{ |
141
|
2 |
|
return $this->archived; |
142
|
|
|
} |
143
|
|
|
|
144
|
7 |
|
public function setArchived($archived) |
145
|
|
|
{ |
146
|
7 |
|
$this->archived = $archived; |
147
|
7 |
|
} |
148
|
|
|
|
149
|
2 |
|
public function getConditions() |
150
|
|
|
{ |
151
|
2 |
|
return $this->conditions; |
152
|
|
|
} |
153
|
|
|
|
154
|
7 |
|
public function setConditions($conditions) |
155
|
|
|
{ |
156
|
7 |
|
$this->conditions = $conditions; |
157
|
7 |
|
} |
158
|
|
|
|
159
|
2 |
|
public function getDescription() |
160
|
|
|
{ |
161
|
2 |
|
return $this->description; |
162
|
|
|
} |
163
|
|
|
|
164
|
7 |
|
public function setDescription($description) |
165
|
|
|
{ |
166
|
7 |
|
$this->description = $description; |
167
|
7 |
|
} |
168
|
|
|
|
169
|
6 |
|
public function getName() |
170
|
|
|
{ |
171
|
6 |
|
return $this->name; |
172
|
|
|
} |
173
|
|
|
|
174
|
7 |
|
public function setName($name) |
175
|
|
|
{ |
176
|
7 |
|
$this->name = $name; |
177
|
7 |
|
} |
178
|
|
|
|
179
|
2 |
|
public function getSegmentation() |
180
|
|
|
{ |
181
|
2 |
|
return $this->segmentation; |
182
|
|
|
} |
183
|
|
|
|
184
|
7 |
|
public function setSegmentation($segmentation) |
185
|
|
|
{ |
186
|
7 |
|
$this->segmentation = $segmentation; |
187
|
7 |
|
} |
188
|
|
|
|
189
|
1 |
|
public function getCreated() |
190
|
|
|
{ |
191
|
1 |
|
return $this->created; |
192
|
|
|
} |
193
|
|
|
|
194
|
5 |
|
public function setCreated($created) |
195
|
|
|
{ |
196
|
5 |
|
$this->created = $created; |
197
|
5 |
|
} |
198
|
|
|
|
199
|
1 |
|
public function getId() |
200
|
|
|
{ |
201
|
1 |
|
return $this->id; |
202
|
|
|
} |
203
|
|
|
|
204
|
5 |
|
public function setId($id) |
205
|
|
|
{ |
206
|
5 |
|
$this->id = $id; |
207
|
5 |
|
} |
208
|
|
|
|
209
|
1 |
|
public function getLastModified() |
210
|
|
|
{ |
211
|
1 |
|
return $this->lastModified; |
212
|
|
|
} |
213
|
|
|
|
214
|
5 |
|
public function setLastModified($lastModified) |
215
|
|
|
{ |
216
|
5 |
|
$this->lastModified = $lastModified; |
217
|
5 |
|
} |
218
|
|
|
|
219
|
|
|
public function getIsClassic() |
220
|
|
|
{ |
221
|
|
|
return $this->isClassic; |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
public function setIsClassic($isClassic) |
225
|
|
|
{ |
226
|
|
|
$this->isClassic = $isClassic; |
227
|
|
|
} |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
|
231
|
|
|
|
232
|
|
|
|
233
|
|
|
|
234
|
|
|
|
235
|
|
|
|
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.