|
1
|
|
|
<?php |
|
2
|
|
|
namespace Route4Me; |
|
3
|
|
|
|
|
4
|
|
|
use Route4Me\Common; |
|
5
|
|
|
use Route4Me\Enum\Endpoint; |
|
6
|
|
|
|
|
7
|
|
|
class Member extends Common |
|
8
|
|
|
{ |
|
9
|
|
|
public $device_id; |
|
10
|
|
|
public $device_type; |
|
11
|
|
|
public $format; |
|
12
|
|
|
|
|
13
|
|
|
public $strEmail; |
|
14
|
|
|
public $strPassword; |
|
15
|
|
|
public $strPassword_1; |
|
16
|
|
|
public $strPassword_2; |
|
17
|
|
|
public $strFirstName; |
|
18
|
|
|
public $strLastName; |
|
19
|
|
|
public $strIndustry; |
|
20
|
|
|
public $chkTerms; |
|
21
|
|
|
public $plan; |
|
22
|
|
|
|
|
23
|
|
|
public $session_guid; |
|
24
|
|
|
public $member_id; |
|
25
|
|
|
|
|
26
|
|
|
public $email_address; |
|
27
|
|
|
public $first_name; |
|
28
|
|
|
public $last_name; |
|
29
|
|
|
public $phone_number; |
|
30
|
|
|
public $company_name; |
|
31
|
|
|
public $webiinar_date; |
|
32
|
|
|
|
|
33
|
|
|
public $subscription_name; |
|
34
|
|
|
public $token; |
|
35
|
|
|
public $payload; |
|
36
|
|
|
|
|
37
|
|
|
public $HIDE_ROUTED_ADDRESSES; |
|
38
|
|
|
public $member_phone; |
|
39
|
|
|
public $member_zipcode; |
|
40
|
|
|
public $route_count; |
|
41
|
|
|
public $member_email; |
|
42
|
|
|
public $HIDE_VISITED_ADDRESSES; |
|
43
|
|
|
public $READONLY_USER; |
|
44
|
|
|
public $member_type; |
|
45
|
|
|
public $date_of_birth; |
|
46
|
|
|
public $member_first_name; |
|
47
|
|
|
public $member_password; |
|
48
|
|
|
public $HIDE_NONFUTURE_ROUTES; |
|
49
|
|
|
public $member_last_name; |
|
50
|
|
|
public $SHOW_ALL_VEHICLES; |
|
51
|
|
|
public $SHOW_ALL_DRIVERS; |
|
52
|
|
|
|
|
53
|
|
|
public $config_key; |
|
54
|
|
|
public $config_value; |
|
55
|
|
|
|
|
56
|
|
|
public $preferred_units; |
|
57
|
|
|
public $preferred_language; |
|
58
|
|
|
public $timezone; |
|
59
|
|
|
public $OWNER_MEMBER_ID; |
|
60
|
|
|
public $user_reg_state_id; |
|
61
|
|
|
public $user_reg_country_id; |
|
62
|
|
|
public $member_picture; |
|
63
|
|
|
public $api_key; |
|
64
|
|
|
public $custom_data; |
|
65
|
|
|
|
|
66
|
|
|
public static function fromArray(array $params) |
|
67
|
|
|
{ |
|
68
|
|
|
$member= new Member(); |
|
69
|
|
|
|
|
70
|
|
|
foreach($params as $key => $value) { |
|
71
|
|
|
if (property_exists($member, $key)) { |
|
72
|
|
|
$member->{$key} = $value; |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
return $member; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public static function getUsers() |
|
80
|
|
|
{ |
|
81
|
|
|
$response = Route4Me::makeRequst(array( |
|
82
|
|
|
'url' => Endpoint::USER_V4, |
|
83
|
|
|
'method' => 'GET' |
|
84
|
|
|
)); |
|
85
|
|
|
|
|
86
|
|
|
return $response; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
View Code Duplication |
public static function getUser($params) |
|
|
|
|
|
|
90
|
|
|
{ |
|
91
|
|
|
$response = Route4Me::makeRequst(array( |
|
92
|
|
|
'url' => Endpoint::USER_V4, |
|
93
|
|
|
'method' => 'GET', |
|
94
|
|
|
'query' => array( |
|
95
|
|
|
'member_id' => isset($params['member_id']) ? $params['member_id'] : null |
|
96
|
|
|
) |
|
97
|
|
|
)); |
|
98
|
|
|
|
|
99
|
|
|
return $response; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
public static function getUserLocations($param) |
|
103
|
|
|
{ |
|
104
|
|
|
$response = Route4Me::makeRequst(array( |
|
105
|
|
|
'url' => Endpoint::VIEW_USER_LOCATIONS, |
|
106
|
|
|
'method' => 'GET', |
|
107
|
|
|
'query' => array( |
|
108
|
|
|
'query' => $param |
|
109
|
|
|
) |
|
110
|
|
|
)); |
|
111
|
|
|
|
|
112
|
|
|
return $response; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
View Code Duplication |
public static function addDeviceRecord($body) |
|
|
|
|
|
|
116
|
|
|
{ |
|
117
|
|
|
$response = Route4Me::makeRequst(array( |
|
118
|
|
|
'url' => Endpoint::VERIFY_DEVICE_LICENSE, |
|
119
|
|
|
'method' => 'POST', |
|
120
|
|
|
'query' => array( |
|
121
|
|
|
'device_id' => isset($body->device_id) ? $body->device_id : null, |
|
122
|
|
|
'device_type' => isset($body->device_type) ? $body->device_type : null, |
|
123
|
|
|
), |
|
124
|
|
|
'body' => array( |
|
125
|
|
|
'device_id' => isset($body->device_id) ? $body->device_id : null, |
|
126
|
|
|
'device_type' => isset($body->device_type) ? $body->device_type : null, |
|
127
|
|
|
'format' => isset($body->format) ? $body->format : null |
|
128
|
|
|
) |
|
129
|
|
|
|
|
130
|
|
|
)); |
|
131
|
|
|
|
|
132
|
|
|
return $response; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
View Code Duplication |
public static function createMember($body) |
|
|
|
|
|
|
136
|
|
|
{ |
|
137
|
|
|
$response = Route4Me::makeRequst(array( |
|
138
|
|
|
'url' => Endpoint::USER_V4, |
|
139
|
|
|
'method' => 'POST', |
|
140
|
|
|
'body' => array( |
|
141
|
|
|
'HIDE_ROUTED_ADDRESSES' => isset($body->HIDE_ROUTED_ADDRESSES) ? $body->HIDE_ROUTED_ADDRESSES : null, |
|
142
|
|
|
'member_phone' => isset($body->member_phone) ? $body->member_phone : null, |
|
143
|
|
|
'member_zipcode' => isset($body->member_zipcode) ? $body->member_zipcode : null, |
|
144
|
|
|
'route_count' => isset($body->route_count) ? $body->route_count : null, |
|
145
|
|
|
'member_email' => isset($body->member_email) ? $body->member_email : null, |
|
146
|
|
|
'HIDE_VISITED_ADDRESSES' => isset($body->HIDE_VISITED_ADDRESSES) ? $body->HIDE_VISITED_ADDRESSES : null, |
|
147
|
|
|
'READONLY_USER' => isset($body->READONLY_USER) ? $body->READONLY_USER : null, |
|
148
|
|
|
'member_type' => isset($body->member_type) ? $body->member_type : null, |
|
149
|
|
|
'date_of_birth' => isset($body->date_of_birth) ? $body->date_of_birth : null, |
|
150
|
|
|
'member_first_name' => isset($body->member_first_name) ? $body->member_first_name : null, |
|
151
|
|
|
'member_password' => isset($body->member_password) ? $body->member_password : null, |
|
152
|
|
|
'HIDE_NONFUTURE_ROUTES' => isset($body->HIDE_NONFUTURE_ROUTES) ? $body->HIDE_NONFUTURE_ROUTES : null, |
|
153
|
|
|
'member_last_name' => isset($body->member_last_name) ? $body->member_last_name : null, |
|
154
|
|
|
'SHOW_ALL_VEHICLES' => isset($body->SHOW_ALL_VEHICLES) ? $body->SHOW_ALL_VEHICLES : null, |
|
155
|
|
|
'SHOW_ALL_DRIVERS' => isset($body->SHOW_ALL_DRIVERS) ? $body->SHOW_ALL_DRIVERS : null |
|
156
|
|
|
) |
|
157
|
|
|
)); |
|
158
|
|
|
|
|
159
|
|
|
return $response; |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
public static function getRandomMemberByType($memberType) |
|
163
|
|
|
{ |
|
164
|
|
|
$members = self::getUsers(); |
|
165
|
|
|
|
|
166
|
|
|
if (is_null($members)) return null; |
|
167
|
|
|
if (!isset($members['results'])) return null; |
|
168
|
|
|
|
|
169
|
|
|
$memberIDs = array(); |
|
170
|
|
|
|
|
171
|
|
|
foreach ($members['results'] as $memb) { |
|
172
|
|
|
if (isset($memb['member_id']) && isset($memb['member_type'])) { |
|
173
|
|
|
if ($memberType==$memb['member_type']) $memberIDs[]=$memb['member_id']; |
|
174
|
|
|
} |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
if (sizeof($memberIDs)<1) return null; |
|
178
|
|
|
|
|
179
|
|
|
$randomIndex = rand(0, sizeof($memberIDs)-1); |
|
180
|
|
|
|
|
181
|
|
|
return $memberIDs[$randomIndex]; |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
|
|
185
|
|
View Code Duplication |
public static function updateMember($body) |
|
|
|
|
|
|
186
|
|
|
{ |
|
187
|
|
|
$response = Route4Me::makeRequst(array( |
|
188
|
|
|
'url' => Endpoint::USER_V4, |
|
189
|
|
|
'method' => 'PUT', |
|
190
|
|
|
'body' => array( |
|
191
|
|
|
'member_id' => isset($body->member_id) ? $body->member_id : null, |
|
192
|
|
|
'member_phone' => isset($body->member_phone) ? $body->member_phone : null, |
|
193
|
|
|
'HIDE_ROUTED_ADDRESSES' => isset($body->HIDE_ROUTED_ADDRESSES) ? $body->HIDE_ROUTED_ADDRESSES : null, |
|
194
|
|
|
'member_zipcode' => isset($body->member_zipcode) ? $body->member_zipcode : null, |
|
195
|
|
|
'route_count' => isset($body->route_count) ? $body->route_count : null, |
|
196
|
|
|
'member_email' => isset($body->member_email) ? $body->member_email : null, |
|
197
|
|
|
'HIDE_VISITED_ADDRESSES' => isset($body->HIDE_VISITED_ADDRESSES) ? $body->HIDE_VISITED_ADDRESSES : null, |
|
198
|
|
|
'READONLY_USER' => isset($body->READONLY_USER) ? $body->READONLY_USER : null, |
|
199
|
|
|
'date_of_birth' => isset($body->date_of_birth) ? $body->date_of_birth : null, |
|
200
|
|
|
'member_first_name' => isset($body->member_first_name) ? $body->member_first_name : null, |
|
201
|
|
|
'member_password' => isset($body->member_password) ? $body->member_password : null, |
|
202
|
|
|
'HIDE_NONFUTURE_ROUTES' => isset($body->HIDE_NONFUTURE_ROUTES) ? $body->HIDE_NONFUTURE_ROUTES : null, |
|
203
|
|
|
'member_last_name' => isset($body->member_last_name) ? $body->member_last_name : null, |
|
204
|
|
|
'SHOW_ALL_VEHICLES' => isset($body->SHOW_ALL_VEHICLES) ? $body->SHOW_ALL_VEHICLES : null, |
|
205
|
|
|
'SHOW_ALL_DRIVERS' => isset($body->SHOW_ALL_DRIVERS) ? $body->SHOW_ALL_DRIVERS : null |
|
206
|
|
|
) |
|
207
|
|
|
|
|
208
|
|
|
)); |
|
209
|
|
|
|
|
210
|
|
|
return $response; |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
View Code Duplication |
public static function deleteMember($body) |
|
|
|
|
|
|
214
|
|
|
{ |
|
215
|
|
|
$response = Route4Me::makeRequst(array( |
|
216
|
|
|
'url' => Endpoint::USER_V4, |
|
217
|
|
|
'method' => 'DELETE', |
|
218
|
|
|
'body' => array( |
|
219
|
|
|
'member_id' => isset($body->member_id) ? $body->member_id : null |
|
220
|
|
|
) |
|
221
|
|
|
|
|
222
|
|
|
)); |
|
223
|
|
|
|
|
224
|
|
|
return $response; |
|
225
|
|
|
} |
|
226
|
|
|
|
|
227
|
|
|
public static function newAccountRegistration($body) |
|
228
|
|
|
{ |
|
229
|
|
|
$response = Route4Me::makeRequst(array( |
|
230
|
|
|
'url' => Endpoint::REGISTER_ACTION, |
|
231
|
|
|
'method' => 'POST', |
|
232
|
|
|
'query' => array( |
|
233
|
|
|
'plan' => isset($body->plan) ? $body->plan : null |
|
234
|
|
|
), |
|
235
|
|
|
'body' => array( |
|
236
|
|
|
'strEmail' => isset($body->strEmail) ? $body->strEmail : null, |
|
237
|
|
|
'strPassword_1' => isset($body->strPassword_1) ? $body->strPassword_1 : null, |
|
238
|
|
|
'strPassword_2' => isset($body->strPassword_2) ? $body->strPassword_2 : null, |
|
239
|
|
|
'strFirstName' => isset($body->strFirstName) ? $body->strFirstName : null, |
|
240
|
|
|
'strLastName' => isset($body->strLastName) ? $body->strLastName : null, |
|
241
|
|
|
'format' => isset($body->format) ? $body->format : null, |
|
242
|
|
|
'strIndustry' => isset($body->strIndustry) ? $body->strIndustry : null, |
|
243
|
|
|
'chkTerms' => isset($body->chkTerms) ? $body->chkTerms : null, |
|
244
|
|
|
'device_type' => isset($body->device_type) ? $body->device_type : null, |
|
245
|
|
|
'strSubAccountType' => isset($body->strSubAccountType) ? $body->strSubAccountType : null, |
|
246
|
|
|
'blDisableMarketing' => isset($body->blDisableMarketing) ? $body->blDisableMarketing : false, |
|
247
|
|
|
'blDisableAccountActivationEmail' => isset($body->blDisableAccountActivationEmail) |
|
248
|
|
|
? $body->blDisableAccountActivationEmail : false |
|
249
|
|
|
), |
|
250
|
|
|
'HTTPHEADER' => 'Content-Type: multipart/form-data' |
|
251
|
|
|
)); |
|
252
|
|
|
|
|
253
|
|
|
return $response; |
|
254
|
|
|
} |
|
255
|
|
|
|
|
256
|
|
|
public static function validateSession($params) |
|
257
|
|
|
{ |
|
258
|
|
|
$response = Route4Me::makeRequst(array( |
|
259
|
|
|
'url' => Endpoint::VALIDATE_SESSION, |
|
260
|
|
|
'method' => 'GET', |
|
261
|
|
|
'query' => array( |
|
262
|
|
|
'session_guid' => isset($params->session_guid) ? $params->session_guid : null, |
|
263
|
|
|
'member_id' => isset($params->member_id) ? $params->member_id : null, |
|
264
|
|
|
'format' => isset($params->format) ? $params->format : null |
|
265
|
|
|
) |
|
266
|
|
|
)); |
|
267
|
|
|
|
|
268
|
|
|
return $response; |
|
269
|
|
|
} |
|
270
|
|
|
|
|
271
|
|
View Code Duplication |
public static function memberAuthentication($body) |
|
|
|
|
|
|
272
|
|
|
{ |
|
273
|
|
|
$response = Route4Me::makeRequst(array( |
|
274
|
|
|
'url' => Endpoint::AUTHENTICATE, |
|
275
|
|
|
'method' => 'POST', |
|
276
|
|
|
'body' => array( |
|
277
|
|
|
'strEmail' => isset($body->strEmail) ? $body->strEmail : null, |
|
278
|
|
|
'strPassword' => isset($body->strPassword) ? $body->strPassword : null, |
|
279
|
|
|
'format' => isset($body->format) ? $body->format : null |
|
280
|
|
|
), |
|
281
|
|
|
'HTTPHEADER' => 'Content-Type: multipart/form-data' |
|
282
|
|
|
)); |
|
283
|
|
|
|
|
284
|
|
|
return $response; |
|
285
|
|
|
} |
|
286
|
|
|
|
|
287
|
|
|
public static function webinarRegistration($body) |
|
288
|
|
|
{ |
|
289
|
|
|
$response = Route4Me::makeRequst(array( |
|
290
|
|
|
'url' => Endpoint::WEBINAR_REGISTER, |
|
291
|
|
|
'method' => 'POST', |
|
292
|
|
|
'body' => array( |
|
293
|
|
|
'email_address' => isset($body->email_address) ? $body->email_address : null, |
|
294
|
|
|
'first_name' => isset($body->first_name) ? $body->first_name : null, |
|
295
|
|
|
'last_name' => isset($body->last_name) ? $body->last_name : null, |
|
296
|
|
|
'phone_number' => isset($body->phone_number) ? $body->phone_number : null, |
|
297
|
|
|
'phone_number' => isset($body->phone_number) ? $body->phone_number : null, |
|
298
|
|
|
'member_id' => isset($body->member_id) ? $body->member_id : null, |
|
299
|
|
|
'webiinar_date' => isset($body->webiinar_date) ? $body->webiinar_date : null, |
|
300
|
|
|
) |
|
301
|
|
|
|
|
302
|
|
|
)); |
|
303
|
|
|
|
|
304
|
|
|
return $response; |
|
305
|
|
|
} |
|
306
|
|
|
|
|
307
|
|
|
public static function purchaseUserLicense($body) |
|
308
|
|
|
{ |
|
309
|
|
|
$response = Route4Me::makeRequst(array( |
|
310
|
|
|
'url' => Endpoint::USER_LICENSE, |
|
311
|
|
|
'method' => 'POST', |
|
312
|
|
|
'query' => array( |
|
313
|
|
|
'device_id' => isset($body->device_id) ? $body->device_id : null |
|
314
|
|
|
), |
|
315
|
|
|
'body' => array( |
|
316
|
|
|
'member_id' => isset($body->member_id) ? $body->member_id : null, |
|
317
|
|
|
'session_guid' => isset($body->session_guid) ? $body->session_guid : null, |
|
318
|
|
|
'device_id' => isset($body->device_id) ? $body->device_id : null, |
|
319
|
|
|
'device_type' => isset($body->device_type) ? $body->device_type : null, |
|
320
|
|
|
'subscription_name' => isset($body->subscription_name) ? $body->subscription_name : null, |
|
321
|
|
|
'token' => isset($body->token) ? $body->token : null, |
|
322
|
|
|
'payload' => isset($body->payload) ? $body->payload : null, |
|
323
|
|
|
'format' => isset($body->format) ? $body->format : null, |
|
324
|
|
|
) |
|
325
|
|
|
)); |
|
326
|
|
|
|
|
327
|
|
|
return $response; |
|
328
|
|
|
} |
|
329
|
|
|
|
|
330
|
|
View Code Duplication |
public static function newMemberConfigKey($body) |
|
|
|
|
|
|
331
|
|
|
{ |
|
332
|
|
|
$response = Route4Me::makeRequst(array( |
|
333
|
|
|
'url' => Endpoint::CONFIGURATION_SETTINGS, |
|
334
|
|
|
'method' => 'POST', |
|
335
|
|
|
'body' => array( |
|
336
|
|
|
'config_key' => isset($body->config_key) ? $body->config_key : null, |
|
337
|
|
|
'config_value' => isset($body->config_value) ? $body->config_value : null |
|
338
|
|
|
) |
|
339
|
|
|
)); |
|
340
|
|
|
|
|
341
|
|
|
return $response; |
|
342
|
|
|
} |
|
343
|
|
|
|
|
344
|
|
View Code Duplication |
public static function removeMemberConfigKey($body) |
|
|
|
|
|
|
345
|
|
|
{ |
|
346
|
|
|
$response = Route4Me::makeRequst(array( |
|
347
|
|
|
'url' => Endpoint::CONFIGURATION_SETTINGS, |
|
348
|
|
|
'method' => 'DELETE', |
|
349
|
|
|
'body' => array( |
|
350
|
|
|
'config_key' => isset($body->config_key) ? $body->config_key : null |
|
351
|
|
|
) |
|
352
|
|
|
)); |
|
353
|
|
|
|
|
354
|
|
|
return $response; |
|
355
|
|
|
} |
|
356
|
|
|
|
|
357
|
|
View Code Duplication |
public static function getMemberConfigData($body) |
|
|
|
|
|
|
358
|
|
|
{ |
|
359
|
|
|
$response = Route4Me::makeRequst(array( |
|
360
|
|
|
'url' => Endpoint::CONFIGURATION_SETTINGS, |
|
361
|
|
|
'method' => 'GET', |
|
362
|
|
|
'query' => array( |
|
363
|
|
|
'config_key' => isset($body->config_key) ? $body->config_key : null |
|
364
|
|
|
) |
|
365
|
|
|
)); |
|
366
|
|
|
|
|
367
|
|
|
return $response; |
|
368
|
|
|
} |
|
369
|
|
|
|
|
370
|
|
View Code Duplication |
public static function updateMemberConfigKey($body) |
|
|
|
|
|
|
371
|
|
|
{ |
|
372
|
|
|
$response = Route4Me::makeRequst(array( |
|
373
|
|
|
'url' => Endpoint::CONFIGURATION_SETTINGS, |
|
374
|
|
|
'method' => 'PUT', |
|
375
|
|
|
'body' => array( |
|
376
|
|
|
'config_key' => isset($body->config_key) ? $body->config_key : null, |
|
377
|
|
|
'config_value' => isset($body->config_value) ? $body->config_value : null |
|
378
|
|
|
) |
|
379
|
|
|
)); |
|
380
|
|
|
|
|
381
|
|
|
return $response; |
|
382
|
|
|
} |
|
383
|
|
|
} |
|
384
|
|
|
|
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.