GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Test Failed
Push — master ( e5b8eb...47d764 )
by Igor
01:54 queued 12s
created
examples/SingleDriverMultipleTimeWindows.php 2 patches
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -19,18 +19,18 @@  discard block
 block discarded – undo
19 19
 
20 20
 $addresses = [];
21 21
 foreach ($json as $address) {
22
-    $addresses[] = Address::fromArray($address);
22
+	$addresses[] = Address::fromArray($address);
23 23
 }
24 24
 
25 25
 $parameters = RouteParameters::fromArray([
26
-    'algorithm_type'    => Algorithmtype::TSP,
27
-    'route_name'        => 'Single Driver Multiple TimeWindows 12 Stops',
28
-    'route_date'        => time() + 24 * 60 * 60,
29
-    'route_time'        => 5 * 3600 + 30 * 60,
30
-    'distance_unit'     => DistanceUnit::MILES,
31
-    'device_type'       => DeviceType::WEB,
32
-    'optimize'          => OptimizationType::DISTANCE,
33
-    'metric'            => Metric::GEODESIC,
26
+	'algorithm_type'    => Algorithmtype::TSP,
27
+	'route_name'        => 'Single Driver Multiple TimeWindows 12 Stops',
28
+	'route_date'        => time() + 24 * 60 * 60,
29
+	'route_time'        => 5 * 3600 + 30 * 60,
30
+	'distance_unit'     => DistanceUnit::MILES,
31
+	'device_type'       => DeviceType::WEB,
32
+	'optimize'          => OptimizationType::DISTANCE,
33
+	'metric'            => Metric::GEODESIC,
34 34
 ]);
35 35
 
36 36
 $optimizationParams = new OptimizationProblemParams();
@@ -40,11 +40,11 @@  discard block
 block discarded – undo
40 40
 $problem = OptimizationProblem::optimize($optimizationParams);
41 41
 
42 42
 foreach ((array) $problem as $key => $value) {
43
-    if (is_string($value)) {
44
-        echo $key.' --> '.$value.'<br>';
45
-    } else {
46
-        echo "************ $key ************* <br>";
47
-        Route4Me::simplePrint((array) $value, true);
48
-        echo '******************************* <br>';
49
-    }
43
+	if (is_string($value)) {
44
+		echo $key.' --> '.$value.'<br>';
45
+	} else {
46
+		echo "************ $key ************* <br>";
47
+		Route4Me::simplePrint((array) $value, true);
48
+		echo '******************************* <br>';
49
+	}
50 50
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -47,12 +47,12 @@
 block discarded – undo
47 47
 
48 48
 $problem = OptimizationProblem::optimize($optimizationParams);
49 49
 
50
-foreach ((array) $problem as $key => $value) {
50
+foreach ((array)$problem as $key => $value) {
51 51
     if (is_string($value)) {
52 52
         echo $key.' --> '.$value.'<br>';
53 53
     } else {
54 54
         echo "************ $key ************* <br>";
55
-        Route4Me::simplePrint((array) $value, true);
55
+        Route4Me::simplePrint((array)$value, true);
56 56
         echo '******************************* <br>';
57 57
     }
58 58
 }
Please login to merge, or discard this patch.
examples/OptimizationWithBundledAddresses.php 2 patches
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
 
22 22
 $addresses = [];
23 23
 foreach ($json as $address) {
24
-    $addresses[] = Address::fromArray($address);
24
+	$addresses[] = Address::fromArray($address);
25 25
 }
26 26
 
27 27
 $bundling = new AddressBundling();
@@ -32,15 +32,15 @@  discard block
 block discarded – undo
32 32
 $bundling->service_time_rules->additional_items_mode = Enum\AddressBundlingModes\AdditionalItemsMode::KEEP_ORIGINAL;
33 33
 
34 34
 $parameters = RouteParameters::fromArray([
35
-    'algorithm_type'    => Algorithmtype::TSP,
36
-    'route_name'        => 'Single Driver Multiple TimeWindows 12 Stops',
37
-    'route_date'        => time() + 24 * 60 * 60,
38
-    'route_time'        => 5 * 3600 + 30 * 60,
39
-    'distance_unit'     => DistanceUnit::MILES,
40
-    'device_type'       => DeviceType::WEB,
41
-    'optimize'          => OptimizationType::DISTANCE,
42
-    'metric'            => Metric::GEODESIC,
43
-    'bundling'          => $bundling,
35
+	'algorithm_type'    => Algorithmtype::TSP,
36
+	'route_name'        => 'Single Driver Multiple TimeWindows 12 Stops',
37
+	'route_date'        => time() + 24 * 60 * 60,
38
+	'route_time'        => 5 * 3600 + 30 * 60,
39
+	'distance_unit'     => DistanceUnit::MILES,
40
+	'device_type'       => DeviceType::WEB,
41
+	'optimize'          => OptimizationType::DISTANCE,
42
+	'metric'            => Metric::GEODESIC,
43
+	'bundling'          => $bundling,
44 44
 ]);
45 45
 
46 46
 $optimizationParams = new OptimizationProblemParams();
@@ -50,11 +50,11 @@  discard block
 block discarded – undo
50 50
 $problem = OptimizationProblem::optimize($optimizationParams);
51 51
 
52 52
 foreach ((array) $problem as $key => $value) {
53
-    if (is_string($value)) {
54
-        echo $key.' --> '.$value.'<br>';
55
-    } else {
56
-        echo "************ $key ************* <br>";
57
-        Route4Me::simplePrint((array) $value, true);
58
-        echo '******************************* <br>';
59
-    }
53
+	if (is_string($value)) {
54
+		echo $key.' --> '.$value.'<br>';
55
+	} else {
56
+		echo "************ $key ************* <br>";
57
+		Route4Me::simplePrint((array) $value, true);
58
+		echo '******************************* <br>';
59
+	}
60 60
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -47,12 +47,12 @@
 block discarded – undo
47 47
 
48 48
 $problem = OptimizationProblem::optimize($optimizationParams);
49 49
 
50
-foreach ((array) $problem as $key => $value) {
50
+foreach ((array)$problem as $key => $value) {
51 51
     if (is_string($value)) {
52 52
         echo $key.' --> '.$value.'<br>';
53 53
     } else {
54 54
         echo "************ $key ************* <br>";
55
-        Route4Me::simplePrint((array) $value, true);
55
+        Route4Me::simplePrint((array)$value, true);
56 56
         echo '******************************* <br>';
57 57
     }
58 58
 }
Please login to merge, or discard this patch.
src/Route4Me/AddressBundling.php 2 patches
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -9,31 +9,31 @@
 block discarded – undo
9 9
  */
10 10
 class AddressBundling extends Common
11 11
 {
12
-    /**
13
-     * Address bundling mode
14
-     */
15
-    public $mode = AddressBundlingModes\Mode::ADDRESS;
16
-
17
-    /**
18
-     * Address bundling mode parameters:
19
-     * - If Mode=3, contains an array of the field names of the Address object;
20
-     * - If Mode=4, contains an array of the custom fields of the Address object.
21
-     */
22
-    public $mode_params= [];
23
-
24
-    /**
25
-     * Address bundling merge mode
26
-     */
27
-    public $merge_mode = AddressBundlingModes\MergeMode::KEEP_AS_SEPARATE_DESTINATIONS;
28
-
29
-    /**
30
-     * Service time rules of the address bundling
31
-     */
32
-    public $service_time_rules;
33
-
34
-    public function __construct()
35
-    {
36
-        $this->service_time_rules = new ServiceTimeRulesClass();
37
-    }
12
+	/**
13
+	 * Address bundling mode
14
+	 */
15
+	public $mode = AddressBundlingModes\Mode::ADDRESS;
16
+
17
+	/**
18
+	 * Address bundling mode parameters:
19
+	 * - If Mode=3, contains an array of the field names of the Address object;
20
+	 * - If Mode=4, contains an array of the custom fields of the Address object.
21
+	 */
22
+	public $mode_params= [];
23
+
24
+	/**
25
+	 * Address bundling merge mode
26
+	 */
27
+	public $merge_mode = AddressBundlingModes\MergeMode::KEEP_AS_SEPARATE_DESTINATIONS;
28
+
29
+	/**
30
+	 * Service time rules of the address bundling
31
+	 */
32
+	public $service_time_rules;
33
+
34
+	public function __construct()
35
+	{
36
+		$this->service_time_rules = new ServiceTimeRulesClass();
37
+	}
38 38
 
39 39
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@
 block discarded – undo
19 19
      * - If Mode=3, contains an array of the field names of the Address object;
20 20
      * - If Mode=4, contains an array of the custom fields of the Address object.
21 21
      */
22
-    public $mode_params= [];
22
+    public $mode_params = [];
23 23
 
24 24
     /**
25 25
      * Address bundling merge mode
Please login to merge, or discard this patch.
src/Route4Me/AddressBookLocation.php 4 patches
Indentation   +673 added lines, -673 removed lines patch added patch discarded remove patch
@@ -11,677 +11,677 @@
 block discarded – undo
11 11
  */
12 12
 class AddressBookLocation extends Common
13 13
 {
14
-    /**
15
-     * A territory shape name the contact belongs.
16
-     * @var string
17
-     */
18
-    public $address_id;
19
-
20
-    /**
21
-     * A group the contact belongs.
22
-     * @var string
23
-     */
24
-    public $address_group;
25
-
26
-    /**
27
-     * The contact's alias.
28
-     * @var string
29
-     */
30
-    public $address_alias;
31
-
32
-    /**
33
-     * The geographic address of the contact.
34
-     * @var string
35
-     */
36
-    public $address_1;
37
-
38
-    /**
39
-     * Second geographic address of the contact.
40
-     * @var string
41
-     */
42
-    public $address_2;
43
-
44
-    /**
45
-     * The first name of the contact person.
46
-     * @var string
47
-     */
48
-    public $first_name;
49
-
50
-    /**
51
-     * The last name of the contact person.
52
-     * @var string
53
-     */
54
-    public $last_name;
55
-
56
-    /**
57
-     * The contact's email.
58
-     * @var string
59
-     */
60
-    public $address_email;
61
-
62
-    /**
63
-     * The contact's phone number.
64
-     * @var string
65
-     */
66
-    public $address_phone_number;
67
-
68
-    /**
69
-     * A city the contact belongs.
70
-     * @var string
71
-     */
72
-    public $address_city;
73
-
74
-    /**
75
-     * The ID of the state the contact belongs.
76
-     * @var string
77
-     */
78
-    public $address_state_id;
79
-
80
-    /**
81
-     * The ID of the country the contact belongs.
82
-     * @var string
83
-     */
84
-    public $address_country_id;
85
-
86
-    /**
87
-     * The contact's ZIP code.
88
-     * @var string
89
-     */
90
-    public $address_zip;
91
-
92
-    /**
93
-     * A latitude of the contact's cached position.
94
-     * @var double
95
-     */
96
-    public $cached_lat;
97
-
98
-    /**
99
-     * A longitude of the contact's cached position.
100
-     * @var double
101
-     */
102
-    public $cached_lng;
103
-
104
-    /**
105
-     * A latitude of the contact's curbside.
106
-     * @var double
107
-     */
108
-    public $curbside_lat;
109
-
110
-    /**
111
-     * A longitude of the contact's curbside.
112
-     * @var double
113
-     */
114
-    public $curbside_lng;
115
-
116
-    /**
117
-     * The contact's color on the map.
118
-     * @var string
119
-     */
120
-    public $color;
121
-
122
-    /**
123
-     * An array of the contact's custom field-value pairs.
124
-     * @var array
125
-     */
126
-    public $address_custom_data;
127
-
128
-    /**
129
-     * An array of the contact's schedules.
130
-     * @var Schedule[]
131
-     */
132
-    public $schedule;
133
-
134
-    /**
135
-     * Time when the contact was created.
136
-     * @var long
137
-     */
138
-    public $created_timestamp;
139
-
140
-    /**
141
-     * Unique ID of the member.
142
-     * @var integer
143
-     */
144
-    public $member_id;
145
-
146
-    /**
147
-     * The list of dates that should be omitted from the schedules.
148
-     * @var string[]
149
-     */
150
-    public $schedule_blacklist;
151
-
152
-    /**
153
-     * Number of the routes containing the contact.
154
-     * @var integer
155
-     */
156
-    public $in_route_count;
157
-
158
-    /**
159
-     * When the contact was last visited.
160
-     * @var long
161
-     */
162
-    public $last_visited_timestamp;
163
-
164
-    /**
165
-     * When the contact was last routed.
166
-     * @var long
167
-     */
168
-    public $last_routed_timestamp;
169
-
170
-    /**
171
-     * Start of the contact's local time window.
172
-     * @var long
173
-     */
174
-    public $local_time_window_start;
175
-
176
-    /**
177
-     * End of the contact's local time window.
178
-     * @var long
179
-     */
180
-    public $local_time_window_end;
181
-
182
-    /**
183
-     * Start of the contact's second local time window.
184
-     * @var long
185
-     */
186
-    public $local_time_window_start_2;
187
-
188
-    /**
189
-     * End of the contact's second local time window.
190
-     * @var long
191
-     */
192
-    public $local_time_window_end_2;
193
-
194
-    /**
195
-     * The service time at the contact's address.
196
-     * @var integer
197
-     */
198
-    public $service_time;
199
-
200
-    /**
201
-     * The contact's local timezone.
202
-     * @var string
203
-     */
204
-    public $local_timezone_string;
205
-
206
-    /**
207
-     * The contact's icon on the map.
208
-     * @var string
209
-     */
210
-    public $address_icon;
211
-
212
-    /**
213
-     * The contact's stop type.
214
-     * @var string
215
-     */
216
-    public $address_stop_type;
217
-
218
-    /**
219
-     * The cubic volume of the contact's cargo.
220
-     * @var double
221
-     */
222
-    public $address_cube;
223
-
224
-    /**
225
-     * The number of pieces/pallets that this destination/order/line-item consumes/contains on a vehicle.
226
-     * @var integer
227
-     */
228
-    public $address_pieces;
229
-
230
-    /**
231
-     * The reference number of the address.
232
-     * @var string
233
-     */
234
-    public $address_reference_no;
235
-
236
-    /**
237
-     * The revenue from the contact.
238
-     * @var double
239
-     */
240
-    public $address_revenue;
241
-
242
-    /**
243
-     * The weight of the contact's cargo.
244
-     * @var double
245
-     */
246
-    public $address_weight;
247
-
248
-    /**
249
-     * If present, the priority will sequence addresses in all the optimal routes so that
250
-     * higher priority addresses are general at the beginning of the route sequence.<br>
251
-     * 1 is the highest priority, 100000 is the lowest.
252
-     * @var integer
253
-     */
254
-    public $address_priority;
255
-
256
-    /**
257
-     * The customer purchase order of the contact.
258
-     * @var string
259
-     */
260
-    public $address_customer_po;
261
-
262
-    public function __construct()
263
-    {
264
-        Route4Me::setBaseUrl(Endpoint::BASE_URL);
265
-    }
266
-
267
-    public static function fromArray(array $params)
268
-    {
269
-        $addressbooklocation = new self();
270
-
271
-        foreach ($params as $key => $value) {
272
-            if (property_exists($addressbooklocation, $key)) {
273
-                $addressbooklocation->{$key} = $value;
274
-            }
275
-        }
276
-
277
-        return $addressbooklocation;
278
-    }
279
-
280
-    public static function getAddressBookLocation($addressId)
281
-    {
282
-        $ablocations = Route4Me::makeRequst([
283
-            'url' => Endpoint::ADDRESS_BOOK_V4,
284
-            'method' => 'GET',
285
-            'query'  => [
286
-                'query' => $addressId,
287
-                'limit' => 30,
288
-            ],
289
-        ]);
290
-
291
-        return $ablocations;
292
-    }
293
-
294
-    public static function searchAddressBookLocations($params)
295
-    {
296
-        $allQueryFields = ['display', 'query', 'fields', 'limit', 'offset'];
297
-
298
-        $result = Route4Me::makeRequst([
299
-            'url' => Endpoint::ADDRESS_BOOK_V4,
300
-            'method' => 'GET',
301
-            'query'  => Route4Me::generateRequestParameters($allQueryFields, $params),
302
-        ]);
303
-
304
-        return $result;
305
-    }
306
-
307
-    public static function getAddressBookLocations($params)
308
-    {
309
-        $allQueryFields = ['limit', 'offset', 'address_id'];
310
-
311
-        $ablocations = Route4Me::makeRequst([
312
-            'url' => Endpoint::ADDRESS_BOOK_V4,
313
-            'method' => 'GET',
314
-            'query'  => Route4Me::generateRequestParameters($allQueryFields, $params),
315
-        ]);
316
-
317
-        return $ablocations;
318
-    }
319
-
320
-    public static function getRandomAddressBookLocation($params)
321
-    {
322
-        $ablocations = self::getAddressBookLocations($params);
323
-
324
-        if (isset($ablocations['results'])) {
325
-            $locationsSize = sizeof($ablocations['results']);
326
-
327
-            if ($locationsSize > 0) {
328
-                $randomLocationIndex = rand(0, $locationsSize - 1);
329
-
330
-                return $ablocations['results'][$randomLocationIndex];
331
-            }
332
-        }
333
-
334
-        return null;
335
-    }
336
-
337
-    /**
338
-     * @param AddressBookLocation $params
339
-     */
340
-    public static function addAdressBookLocation($params)
341
-    {
342
-        $allBodyFields = Route4Me::getObjectProperties(new self(), ['address_id', 'in_route_count']);
343
-
344
-        $response = Route4Me::makeRequst([
345
-            'url'       => Endpoint::ADDRESS_BOOK_V4,
346
-            'method'    => 'POST',
347
-            'body'      => Route4Me::generateRequestParameters($allBodyFields, $params),
348
-        ]);
349
-
350
-        return $response;
351
-    }
352
-
353
-    public function deleteAdressBookLocation($address_ids)
354
-    {
355
-        $result = Route4Me::makeRequst([
356
-            'url'       => Endpoint::ADDRESS_BOOK_V4,
357
-            'method'    => 'DELETEARRAY',
358
-            'query'     => [
359
-                'address_ids' => $address_ids,
360
-            ],
361
-        ]);
362
-
363
-        return $result;
364
-    }
365
-
366
-    public function updateAddressBookLocation($params)
367
-    {
368
-        $allBodyFields = Route4Me::getObjectProperties(new self(), ['in_route_count']);
369
-
370
-        $response = Route4Me::makeRequst([
371
-            'url'       => Endpoint::ADDRESS_BOOK_V4,
372
-            'method'    => 'PUT',
373
-            'body'      => Route4Me::generateRequestParameters($allBodyFields, $params),
374
-        ]);
375
-
376
-        return $response;
377
-    }
378
-
379
-    public static function validateScheduleMode($scheduleMode)
380
-    {
381
-        $schedModes = ['daily', 'weekly', 'monthly', 'annually'];
382
-
383
-        if (in_array($scheduleMode, $schedModes)) {
384
-            return true;
385
-        } else {
386
-            return false;
387
-        }
388
-    }
389
-
390
-    public static function validateScheduleEnable($scheduleEnabled)
391
-    {
392
-        if (is_string($scheduleEnabled)) {
393
-            if (strtolower($scheduleEnabled)=="true") $scheduleEnabled = true;
394
-            if (strtolower($scheduleEnabled)=="false") $scheduleEnabled = false;
395
-        }
396
-
397
-        $schedEnables = [true, false,];
398
-
399
-        if (in_array($scheduleEnabled, $schedEnables,true)) {
400
-            return true;
401
-        } else {
402
-            return false;
403
-        }
404
-    }
405
-
406
-    public static function validateScheduleEvery($scheduleEvery)
407
-    {
408
-        if (is_numeric($scheduleEvery)) {
409
-            if ($scheduleEvery>0) {
410
-                return true;
411
-            } else {
412
-                return false;
413
-            }
414
-        } else {
415
-            return false;
416
-        }
417
-    }
418
-
419
-    public static function validateScheduleWeekDays($scheduleWeekDays)
420
-    {
421
-        if (is_bool($scheduleWeekDays)) return false;
422
-
423
-        $weekdays = explode(',', $scheduleWeekDays);
424
-        $weekdaysSize = sizeof($weekdays);
425
-
426
-        if ($weekdaysSize < 1) {
427
-            return false;
428
-        }
429
-
430
-        $isValid = true;
431
-
432
-        for ($i = 0; $i < $weekdaysSize; ++$i) {
433
-            if (is_bool($weekdays[$i])) {
434
-                $isValid = false;
435
-            } elseif (is_numeric($weekdays[$i])) {
436
-                $wday = intval($weekdays[$i]);
437
-                if ($wday < 1 || $wday > 7) {
438
-                    $isValid = false;
439
-                }
440
-            } else {
441
-                $isValid = false;
442
-            }
443
-        }
444
-
445
-        return $isValid;
446
-    }
447
-
448
-    public static function validateScheduleMonthlyMode($scheduleMonthlyMode)
449
-    {
450
-        $schedMonthlyMmodes = ['dates', 'nth'];
451
-
452
-        if (in_array($scheduleMonthlyMode, $schedMonthlyMmodes,true)) {
453
-            return true;
454
-        } else {
455
-            return false;
456
-        }
457
-    }
458
-
459
-    public static function validateScheduleMonthlyDates($scheduleMonthlyDates)
460
-    {
461
-        if (is_bool($scheduleMonthlyDates)) return false;
462
-
463
-        $monthlyDates = explode(',', $scheduleMonthlyDates);
464
-        $monthlyDatesSize = sizeof($monthlyDates);
465
-
466
-        if ($monthlyDatesSize < 1) {
467
-            return false;
468
-        }
469
-
470
-        $isValid = true;
471
-
472
-        for ($i = 0; $i < $monthlyDatesSize; ++$i) {
473
-            if (is_numeric($monthlyDates[$i])) {
474
-                $mday = intval($monthlyDates[$i]);
475
-                if ($mday < 1 || $mday > 31) {
476
-                    $isValid = false;
477
-                }
478
-            } else {
479
-                $isValid = false;
480
-            }
481
-        }
482
-
483
-        return $isValid;
484
-    }
485
-
486
-    public static function validateScheduleNthN($scheduleNthN)
487
-    {
488
-        if (!is_numeric($scheduleNthN)) {
489
-            return false;
490
-        }
491
-
492
-        $schedNthNs = [1, 2, 3, 4, 5, -1];
493
-
494
-        if (in_array($scheduleNthN, $schedNthNs)) {
495
-            return true;
496
-        } else {
497
-            return false;
498
-        }
499
-    }
500
-
501
-    public static function validateScheduleNthWhat($scheduleNthWhat)
502
-    {
503
-        if (!is_numeric($scheduleNthWhat)) {
504
-            return false;
505
-        }
506
-
507
-        $schedNthWhats = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
508
-
509
-        if (in_array($scheduleNthWhat, $schedNthWhats)) {
510
-            return true;
511
-        } else {
512
-            return false;
513
-        }
514
-    }
515
-
516
-    /** Function adds the locations (with/without schedule) from the CSV file.
517
-     * $csvFileHandle - a file handler.
518
-     * Returns array $results which contains two arrays: fail and succes.
519
-     */
520
-    public function addLocationsFromCsvFile($csvFileHandle, $locationsFieldsMapping)
521
-    {
522
-        $max_line_length = 512;
523
-        $delemietr = ',';
524
-
525
-        $results = [];
526
-        $results['fail'] = [];
527
-        $results['success'] = [];
528
-
529
-        $columns = fgetcsv($csvFileHandle, $max_line_length, $delemietr);
530
-
531
-        $addressBookFields = Route4Me::getObjectProperties(new self(), ['address_id', 'in_route_count']);
532
-
533
-        if (empty($columns)) {
534
-            array_push($results['fail'], 'Empty CSV table');
535
-
536
-            return $results;
537
-        }
538
-
539
-        $iRow = 1;
540
-
541
-        while (false !== ($rows = fgetcsv($csvFileHandle, $max_line_length, $delemietr))) {
542
-            if (!isset($rows[$locationsFieldsMapping['cached_lat']]) || !isset($rows[$locationsFieldsMapping['cached_lng']])
543
-                  || !isset($rows[$locationsFieldsMapping['address_1']]) || [null] == $rows) {
544
-                continue;
545
-            }
546
-
547
-            $curSchedule = '';
548
-            $mode = '';
549
-
550
-            $failCount = sizeof($results['fail']);
551
-
552
-            if (isset($rows[$locationsFieldsMapping['schedule_mode']])) {
553
-                if ($this->validateScheduleMode($rows[$locationsFieldsMapping['schedule_mode']])) {
554
-                    $curSchedule = '"mode":"'.$rows[$locationsFieldsMapping['schedule_mode']].'",';
555
-                    $mode = $rows[$locationsFieldsMapping['schedule_mode']];
556
-                } else {
557
-                    array_push($results['fail'], "$iRow --> Wrong schedule mode parameter");
558
-                }
559
-            } else {
560
-                array_push($results['fail'], "$iRow --> The schedule mode parameter is not set");
561
-            }
562
-
563
-            if (isset($rows[$locationsFieldsMapping['schedule_enabled']])) {
564
-                if ($this->validateScheduleEnable($rows[$locationsFieldsMapping['schedule_enabled']])) {
565
-                    $curSchedule .= '"enabled":'.$rows[$locationsFieldsMapping['schedule_enabled']].',';
566
-                } else {
567
-                    array_push($results['fail'], "$iRow --> The schedule enabled parameter is not set ");
568
-                }
569
-            }
570
-
571
-            if (isset($rows[$locationsFieldsMapping['schedule_every']])) {
572
-                if ($this->validateScheduleEvery($rows[$locationsFieldsMapping['schedule_every']])) {
573
-                    $curSchedule .= '"'.$mode.'":{'.'"every":'.$rows[$locationsFieldsMapping['schedule_every']].',';
574
-                    if ('daily' == $mode) {
575
-                        $curSchedule = trim($curSchedule, ',');
576
-                        $curSchedule .= '}';
577
-                    }
578
-                } else {
579
-                    array_push($results['fail'], "$iRow --> The parameter sched_every is not set");
580
-                }
581
-            }
582
-
583
-            if ('daily' != $mode) {
584
-                switch ($mode) {
585
-                    case 'weekly':
586
-                        if (isset($rows[$locationsFieldsMapping['schedule_weekdays']])) {
587
-                            if ($this->validateScheduleWeekDays($rows[$locationsFieldsMapping['schedule_weekdays']])) {
588
-                                $curSchedule .= '"weekdays":['.$rows[$locationsFieldsMapping['schedule_weekdays']].']}';
589
-                            } else {
590
-                                array_push($results['fail'], "$iRow --> Wrong weekdays");
591
-                            }
592
-                        } else {
593
-                            array_push($results['fail'], "$iRow --> The parameters sched_weekdays is not set");
594
-                        }
595
-                        break;
596
-                    case 'monthly':
597
-                        $monthlyMode = '';
598
-                        if (isset($rows[$locationsFieldsMapping['monthly_mode']])) {
599
-                            if ($this->validateScheduleMonthlyMode($rows[$locationsFieldsMapping['monthly_mode']])) {
600
-                                $monthlyMode = $rows[$locationsFieldsMapping['monthly_mode']];
601
-                                $curSchedule .= '"mode": "'.$rows[$locationsFieldsMapping['monthly_mode']].'",';
602
-                            } else {
603
-                                array_push($results['fail'], "$iRow --> Wrong monthly mode");
604
-                            }
605
-                        } else {
606
-                            array_push($results['fail'], "$iRow --> The parameter sched_monthly_mode is not set");
607
-                        }
608
-
609
-                        if ('' != $monthlyMode) {
610
-                            switch ($monthlyMode) {
611
-                                case 'dates':
612
-                                    if (isset($rows[$locationsFieldsMapping['monthly_dates']])) {
613
-                                        if ($this->validateScheduleMonthlyDates($rows[$locationsFieldsMapping['monthly_dates']])) {
614
-                                            $curSchedule .= '"dates":['.$rows[$locationsFieldsMapping['monthly_dates']].']}';
615
-                                        } else {
616
-                                            array_push($results['fail'], "$iRow --> Wrong monthly dates");
617
-                                        }
618
-                                    }
619
-                                    break;
620
-                                case 'nth':
621
-                                    if (isset($rows[$locationsFieldsMapping['monthly_nth_n']])) {
622
-                                        if ($this->validateScheduleNthN($rows[$locationsFieldsMapping['monthly_nth_n']])) {
623
-                                            $curSchedule .= '"nth":{"n":'.$rows[$locationsFieldsMapping['monthly_nth_n']].',';
624
-                                        } else {
625
-                                            array_push($results['fail'], "$iRow --> Wrong parameter sched_nth_n");
626
-                                        }
627
-                                    } else {
628
-                                        array_push($results['fail'], "$iRow --> The parameter sched_nth_n is not set");
629
-                                    }
630
-
631
-                                    if ('' != $curSchedule) {
632
-                                        if (isset($rows[$locationsFieldsMapping['monthly_nth_what']])) {
633
-                                            if ($this->validateScheduleNthWhat($rows[$locationsFieldsMapping['monthly_nth_what']])) {
634
-                                                $curSchedule .= '"what":'.$rows[$locationsFieldsMapping['monthly_nth_what']].'}}';
635
-                                            } else {
636
-                                                array_push($results['fail'], "$iRow --> Wrong parameter sched_nth_what");
637
-                                            }
638
-                                        } else {
639
-                                            array_push($results['fail'], "$iRow --> The parameter sched_nth_what is not set");
640
-                                        }
641
-                                    }
642
-                                    break;
643
-                            }
644
-                        }
645
-                        break;
646
-                    default:
647
-                        $curSchedule = '';
648
-                        break;
649
-                }
650
-            }
651
-
652
-            if (sizeof($results['fail']) > $failCount) {
653
-                $curSchedule = '';
654
-            }
655
-
656
-            if (('daily' == $mode || 'weekly' == $mode || 'monthy' == $mode) && '' == $curSchedule) {
657
-                ++$iRow;
658
-                continue;
659
-            }
660
-
661
-            $curSchedule = strtolower($curSchedule);
662
-
663
-            $curSchedule = '[{'.$curSchedule.'}]';
664
-
665
-            $parametersArray = [];
666
-
667
-            foreach ($addressBookFields as $addressBookField) {
668
-                if (isset($locationsFieldsMapping[$addressBookField])) {
669
-                    $parametersArray[$addressBookField] = $rows[$locationsFieldsMapping[$addressBookField]];
670
-                }
671
-            }
672
-
673
-            $AdressBookLocationParameters = self::fromArray($parametersArray);
674
-
675
-            $abContacts = new self();
676
-
677
-            $abcResults = $abContacts->addAdressBookLocation($AdressBookLocationParameters); //temporarry
678
-
679
-            array_push(
680
-                $results['success'],
681
-                'The schedule location with address_id = '.strval($abcResults['address_id']).' added successfuly.'
682
-            );
683
-        }
684
-
685
-        return $results;
686
-    }
14
+	/**
15
+	 * A territory shape name the contact belongs.
16
+	 * @var string
17
+	 */
18
+	public $address_id;
19
+
20
+	/**
21
+	 * A group the contact belongs.
22
+	 * @var string
23
+	 */
24
+	public $address_group;
25
+
26
+	/**
27
+	 * The contact's alias.
28
+	 * @var string
29
+	 */
30
+	public $address_alias;
31
+
32
+	/**
33
+	 * The geographic address of the contact.
34
+	 * @var string
35
+	 */
36
+	public $address_1;
37
+
38
+	/**
39
+	 * Second geographic address of the contact.
40
+	 * @var string
41
+	 */
42
+	public $address_2;
43
+
44
+	/**
45
+	 * The first name of the contact person.
46
+	 * @var string
47
+	 */
48
+	public $first_name;
49
+
50
+	/**
51
+	 * The last name of the contact person.
52
+	 * @var string
53
+	 */
54
+	public $last_name;
55
+
56
+	/**
57
+	 * The contact's email.
58
+	 * @var string
59
+	 */
60
+	public $address_email;
61
+
62
+	/**
63
+	 * The contact's phone number.
64
+	 * @var string
65
+	 */
66
+	public $address_phone_number;
67
+
68
+	/**
69
+	 * A city the contact belongs.
70
+	 * @var string
71
+	 */
72
+	public $address_city;
73
+
74
+	/**
75
+	 * The ID of the state the contact belongs.
76
+	 * @var string
77
+	 */
78
+	public $address_state_id;
79
+
80
+	/**
81
+	 * The ID of the country the contact belongs.
82
+	 * @var string
83
+	 */
84
+	public $address_country_id;
85
+
86
+	/**
87
+	 * The contact's ZIP code.
88
+	 * @var string
89
+	 */
90
+	public $address_zip;
91
+
92
+	/**
93
+	 * A latitude of the contact's cached position.
94
+	 * @var double
95
+	 */
96
+	public $cached_lat;
97
+
98
+	/**
99
+	 * A longitude of the contact's cached position.
100
+	 * @var double
101
+	 */
102
+	public $cached_lng;
103
+
104
+	/**
105
+	 * A latitude of the contact's curbside.
106
+	 * @var double
107
+	 */
108
+	public $curbside_lat;
109
+
110
+	/**
111
+	 * A longitude of the contact's curbside.
112
+	 * @var double
113
+	 */
114
+	public $curbside_lng;
115
+
116
+	/**
117
+	 * The contact's color on the map.
118
+	 * @var string
119
+	 */
120
+	public $color;
121
+
122
+	/**
123
+	 * An array of the contact's custom field-value pairs.
124
+	 * @var array
125
+	 */
126
+	public $address_custom_data;
127
+
128
+	/**
129
+	 * An array of the contact's schedules.
130
+	 * @var Schedule[]
131
+	 */
132
+	public $schedule;
133
+
134
+	/**
135
+	 * Time when the contact was created.
136
+	 * @var long
137
+	 */
138
+	public $created_timestamp;
139
+
140
+	/**
141
+	 * Unique ID of the member.
142
+	 * @var integer
143
+	 */
144
+	public $member_id;
145
+
146
+	/**
147
+	 * The list of dates that should be omitted from the schedules.
148
+	 * @var string[]
149
+	 */
150
+	public $schedule_blacklist;
151
+
152
+	/**
153
+	 * Number of the routes containing the contact.
154
+	 * @var integer
155
+	 */
156
+	public $in_route_count;
157
+
158
+	/**
159
+	 * When the contact was last visited.
160
+	 * @var long
161
+	 */
162
+	public $last_visited_timestamp;
163
+
164
+	/**
165
+	 * When the contact was last routed.
166
+	 * @var long
167
+	 */
168
+	public $last_routed_timestamp;
169
+
170
+	/**
171
+	 * Start of the contact's local time window.
172
+	 * @var long
173
+	 */
174
+	public $local_time_window_start;
175
+
176
+	/**
177
+	 * End of the contact's local time window.
178
+	 * @var long
179
+	 */
180
+	public $local_time_window_end;
181
+
182
+	/**
183
+	 * Start of the contact's second local time window.
184
+	 * @var long
185
+	 */
186
+	public $local_time_window_start_2;
187
+
188
+	/**
189
+	 * End of the contact's second local time window.
190
+	 * @var long
191
+	 */
192
+	public $local_time_window_end_2;
193
+
194
+	/**
195
+	 * The service time at the contact's address.
196
+	 * @var integer
197
+	 */
198
+	public $service_time;
199
+
200
+	/**
201
+	 * The contact's local timezone.
202
+	 * @var string
203
+	 */
204
+	public $local_timezone_string;
205
+
206
+	/**
207
+	 * The contact's icon on the map.
208
+	 * @var string
209
+	 */
210
+	public $address_icon;
211
+
212
+	/**
213
+	 * The contact's stop type.
214
+	 * @var string
215
+	 */
216
+	public $address_stop_type;
217
+
218
+	/**
219
+	 * The cubic volume of the contact's cargo.
220
+	 * @var double
221
+	 */
222
+	public $address_cube;
223
+
224
+	/**
225
+	 * The number of pieces/pallets that this destination/order/line-item consumes/contains on a vehicle.
226
+	 * @var integer
227
+	 */
228
+	public $address_pieces;
229
+
230
+	/**
231
+	 * The reference number of the address.
232
+	 * @var string
233
+	 */
234
+	public $address_reference_no;
235
+
236
+	/**
237
+	 * The revenue from the contact.
238
+	 * @var double
239
+	 */
240
+	public $address_revenue;
241
+
242
+	/**
243
+	 * The weight of the contact's cargo.
244
+	 * @var double
245
+	 */
246
+	public $address_weight;
247
+
248
+	/**
249
+	 * If present, the priority will sequence addresses in all the optimal routes so that
250
+	 * higher priority addresses are general at the beginning of the route sequence.<br>
251
+	 * 1 is the highest priority, 100000 is the lowest.
252
+	 * @var integer
253
+	 */
254
+	public $address_priority;
255
+
256
+	/**
257
+	 * The customer purchase order of the contact.
258
+	 * @var string
259
+	 */
260
+	public $address_customer_po;
261
+
262
+	public function __construct()
263
+	{
264
+		Route4Me::setBaseUrl(Endpoint::BASE_URL);
265
+	}
266
+
267
+	public static function fromArray(array $params)
268
+	{
269
+		$addressbooklocation = new self();
270
+
271
+		foreach ($params as $key => $value) {
272
+			if (property_exists($addressbooklocation, $key)) {
273
+				$addressbooklocation->{$key} = $value;
274
+			}
275
+		}
276
+
277
+		return $addressbooklocation;
278
+	}
279
+
280
+	public static function getAddressBookLocation($addressId)
281
+	{
282
+		$ablocations = Route4Me::makeRequst([
283
+			'url' => Endpoint::ADDRESS_BOOK_V4,
284
+			'method' => 'GET',
285
+			'query'  => [
286
+				'query' => $addressId,
287
+				'limit' => 30,
288
+			],
289
+		]);
290
+
291
+		return $ablocations;
292
+	}
293
+
294
+	public static function searchAddressBookLocations($params)
295
+	{
296
+		$allQueryFields = ['display', 'query', 'fields', 'limit', 'offset'];
297
+
298
+		$result = Route4Me::makeRequst([
299
+			'url' => Endpoint::ADDRESS_BOOK_V4,
300
+			'method' => 'GET',
301
+			'query'  => Route4Me::generateRequestParameters($allQueryFields, $params),
302
+		]);
303
+
304
+		return $result;
305
+	}
306
+
307
+	public static function getAddressBookLocations($params)
308
+	{
309
+		$allQueryFields = ['limit', 'offset', 'address_id'];
310
+
311
+		$ablocations = Route4Me::makeRequst([
312
+			'url' => Endpoint::ADDRESS_BOOK_V4,
313
+			'method' => 'GET',
314
+			'query'  => Route4Me::generateRequestParameters($allQueryFields, $params),
315
+		]);
316
+
317
+		return $ablocations;
318
+	}
319
+
320
+	public static function getRandomAddressBookLocation($params)
321
+	{
322
+		$ablocations = self::getAddressBookLocations($params);
323
+
324
+		if (isset($ablocations['results'])) {
325
+			$locationsSize = sizeof($ablocations['results']);
326
+
327
+			if ($locationsSize > 0) {
328
+				$randomLocationIndex = rand(0, $locationsSize - 1);
329
+
330
+				return $ablocations['results'][$randomLocationIndex];
331
+			}
332
+		}
333
+
334
+		return null;
335
+	}
336
+
337
+	/**
338
+	 * @param AddressBookLocation $params
339
+	 */
340
+	public static function addAdressBookLocation($params)
341
+	{
342
+		$allBodyFields = Route4Me::getObjectProperties(new self(), ['address_id', 'in_route_count']);
343
+
344
+		$response = Route4Me::makeRequst([
345
+			'url'       => Endpoint::ADDRESS_BOOK_V4,
346
+			'method'    => 'POST',
347
+			'body'      => Route4Me::generateRequestParameters($allBodyFields, $params),
348
+		]);
349
+
350
+		return $response;
351
+	}
352
+
353
+	public function deleteAdressBookLocation($address_ids)
354
+	{
355
+		$result = Route4Me::makeRequst([
356
+			'url'       => Endpoint::ADDRESS_BOOK_V4,
357
+			'method'    => 'DELETEARRAY',
358
+			'query'     => [
359
+				'address_ids' => $address_ids,
360
+			],
361
+		]);
362
+
363
+		return $result;
364
+	}
365
+
366
+	public function updateAddressBookLocation($params)
367
+	{
368
+		$allBodyFields = Route4Me::getObjectProperties(new self(), ['in_route_count']);
369
+
370
+		$response = Route4Me::makeRequst([
371
+			'url'       => Endpoint::ADDRESS_BOOK_V4,
372
+			'method'    => 'PUT',
373
+			'body'      => Route4Me::generateRequestParameters($allBodyFields, $params),
374
+		]);
375
+
376
+		return $response;
377
+	}
378
+
379
+	public static function validateScheduleMode($scheduleMode)
380
+	{
381
+		$schedModes = ['daily', 'weekly', 'monthly', 'annually'];
382
+
383
+		if (in_array($scheduleMode, $schedModes)) {
384
+			return true;
385
+		} else {
386
+			return false;
387
+		}
388
+	}
389
+
390
+	public static function validateScheduleEnable($scheduleEnabled)
391
+	{
392
+		if (is_string($scheduleEnabled)) {
393
+			if (strtolower($scheduleEnabled)=="true") $scheduleEnabled = true;
394
+			if (strtolower($scheduleEnabled)=="false") $scheduleEnabled = false;
395
+		}
396
+
397
+		$schedEnables = [true, false,];
398
+
399
+		if (in_array($scheduleEnabled, $schedEnables,true)) {
400
+			return true;
401
+		} else {
402
+			return false;
403
+		}
404
+	}
405
+
406
+	public static function validateScheduleEvery($scheduleEvery)
407
+	{
408
+		if (is_numeric($scheduleEvery)) {
409
+			if ($scheduleEvery>0) {
410
+				return true;
411
+			} else {
412
+				return false;
413
+			}
414
+		} else {
415
+			return false;
416
+		}
417
+	}
418
+
419
+	public static function validateScheduleWeekDays($scheduleWeekDays)
420
+	{
421
+		if (is_bool($scheduleWeekDays)) return false;
422
+
423
+		$weekdays = explode(',', $scheduleWeekDays);
424
+		$weekdaysSize = sizeof($weekdays);
425
+
426
+		if ($weekdaysSize < 1) {
427
+			return false;
428
+		}
429
+
430
+		$isValid = true;
431
+
432
+		for ($i = 0; $i < $weekdaysSize; ++$i) {
433
+			if (is_bool($weekdays[$i])) {
434
+				$isValid = false;
435
+			} elseif (is_numeric($weekdays[$i])) {
436
+				$wday = intval($weekdays[$i]);
437
+				if ($wday < 1 || $wday > 7) {
438
+					$isValid = false;
439
+				}
440
+			} else {
441
+				$isValid = false;
442
+			}
443
+		}
444
+
445
+		return $isValid;
446
+	}
447
+
448
+	public static function validateScheduleMonthlyMode($scheduleMonthlyMode)
449
+	{
450
+		$schedMonthlyMmodes = ['dates', 'nth'];
451
+
452
+		if (in_array($scheduleMonthlyMode, $schedMonthlyMmodes,true)) {
453
+			return true;
454
+		} else {
455
+			return false;
456
+		}
457
+	}
458
+
459
+	public static function validateScheduleMonthlyDates($scheduleMonthlyDates)
460
+	{
461
+		if (is_bool($scheduleMonthlyDates)) return false;
462
+
463
+		$monthlyDates = explode(',', $scheduleMonthlyDates);
464
+		$monthlyDatesSize = sizeof($monthlyDates);
465
+
466
+		if ($monthlyDatesSize < 1) {
467
+			return false;
468
+		}
469
+
470
+		$isValid = true;
471
+
472
+		for ($i = 0; $i < $monthlyDatesSize; ++$i) {
473
+			if (is_numeric($monthlyDates[$i])) {
474
+				$mday = intval($monthlyDates[$i]);
475
+				if ($mday < 1 || $mday > 31) {
476
+					$isValid = false;
477
+				}
478
+			} else {
479
+				$isValid = false;
480
+			}
481
+		}
482
+
483
+		return $isValid;
484
+	}
485
+
486
+	public static function validateScheduleNthN($scheduleNthN)
487
+	{
488
+		if (!is_numeric($scheduleNthN)) {
489
+			return false;
490
+		}
491
+
492
+		$schedNthNs = [1, 2, 3, 4, 5, -1];
493
+
494
+		if (in_array($scheduleNthN, $schedNthNs)) {
495
+			return true;
496
+		} else {
497
+			return false;
498
+		}
499
+	}
500
+
501
+	public static function validateScheduleNthWhat($scheduleNthWhat)
502
+	{
503
+		if (!is_numeric($scheduleNthWhat)) {
504
+			return false;
505
+		}
506
+
507
+		$schedNthWhats = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
508
+
509
+		if (in_array($scheduleNthWhat, $schedNthWhats)) {
510
+			return true;
511
+		} else {
512
+			return false;
513
+		}
514
+	}
515
+
516
+	/** Function adds the locations (with/without schedule) from the CSV file.
517
+	 * $csvFileHandle - a file handler.
518
+	 * Returns array $results which contains two arrays: fail and succes.
519
+	 */
520
+	public function addLocationsFromCsvFile($csvFileHandle, $locationsFieldsMapping)
521
+	{
522
+		$max_line_length = 512;
523
+		$delemietr = ',';
524
+
525
+		$results = [];
526
+		$results['fail'] = [];
527
+		$results['success'] = [];
528
+
529
+		$columns = fgetcsv($csvFileHandle, $max_line_length, $delemietr);
530
+
531
+		$addressBookFields = Route4Me::getObjectProperties(new self(), ['address_id', 'in_route_count']);
532
+
533
+		if (empty($columns)) {
534
+			array_push($results['fail'], 'Empty CSV table');
535
+
536
+			return $results;
537
+		}
538
+
539
+		$iRow = 1;
540
+
541
+		while (false !== ($rows = fgetcsv($csvFileHandle, $max_line_length, $delemietr))) {
542
+			if (!isset($rows[$locationsFieldsMapping['cached_lat']]) || !isset($rows[$locationsFieldsMapping['cached_lng']])
543
+				  || !isset($rows[$locationsFieldsMapping['address_1']]) || [null] == $rows) {
544
+				continue;
545
+			}
546
+
547
+			$curSchedule = '';
548
+			$mode = '';
549
+
550
+			$failCount = sizeof($results['fail']);
551
+
552
+			if (isset($rows[$locationsFieldsMapping['schedule_mode']])) {
553
+				if ($this->validateScheduleMode($rows[$locationsFieldsMapping['schedule_mode']])) {
554
+					$curSchedule = '"mode":"'.$rows[$locationsFieldsMapping['schedule_mode']].'",';
555
+					$mode = $rows[$locationsFieldsMapping['schedule_mode']];
556
+				} else {
557
+					array_push($results['fail'], "$iRow --> Wrong schedule mode parameter");
558
+				}
559
+			} else {
560
+				array_push($results['fail'], "$iRow --> The schedule mode parameter is not set");
561
+			}
562
+
563
+			if (isset($rows[$locationsFieldsMapping['schedule_enabled']])) {
564
+				if ($this->validateScheduleEnable($rows[$locationsFieldsMapping['schedule_enabled']])) {
565
+					$curSchedule .= '"enabled":'.$rows[$locationsFieldsMapping['schedule_enabled']].',';
566
+				} else {
567
+					array_push($results['fail'], "$iRow --> The schedule enabled parameter is not set ");
568
+				}
569
+			}
570
+
571
+			if (isset($rows[$locationsFieldsMapping['schedule_every']])) {
572
+				if ($this->validateScheduleEvery($rows[$locationsFieldsMapping['schedule_every']])) {
573
+					$curSchedule .= '"'.$mode.'":{'.'"every":'.$rows[$locationsFieldsMapping['schedule_every']].',';
574
+					if ('daily' == $mode) {
575
+						$curSchedule = trim($curSchedule, ',');
576
+						$curSchedule .= '}';
577
+					}
578
+				} else {
579
+					array_push($results['fail'], "$iRow --> The parameter sched_every is not set");
580
+				}
581
+			}
582
+
583
+			if ('daily' != $mode) {
584
+				switch ($mode) {
585
+					case 'weekly':
586
+						if (isset($rows[$locationsFieldsMapping['schedule_weekdays']])) {
587
+							if ($this->validateScheduleWeekDays($rows[$locationsFieldsMapping['schedule_weekdays']])) {
588
+								$curSchedule .= '"weekdays":['.$rows[$locationsFieldsMapping['schedule_weekdays']].']}';
589
+							} else {
590
+								array_push($results['fail'], "$iRow --> Wrong weekdays");
591
+							}
592
+						} else {
593
+							array_push($results['fail'], "$iRow --> The parameters sched_weekdays is not set");
594
+						}
595
+						break;
596
+					case 'monthly':
597
+						$monthlyMode = '';
598
+						if (isset($rows[$locationsFieldsMapping['monthly_mode']])) {
599
+							if ($this->validateScheduleMonthlyMode($rows[$locationsFieldsMapping['monthly_mode']])) {
600
+								$monthlyMode = $rows[$locationsFieldsMapping['monthly_mode']];
601
+								$curSchedule .= '"mode": "'.$rows[$locationsFieldsMapping['monthly_mode']].'",';
602
+							} else {
603
+								array_push($results['fail'], "$iRow --> Wrong monthly mode");
604
+							}
605
+						} else {
606
+							array_push($results['fail'], "$iRow --> The parameter sched_monthly_mode is not set");
607
+						}
608
+
609
+						if ('' != $monthlyMode) {
610
+							switch ($monthlyMode) {
611
+								case 'dates':
612
+									if (isset($rows[$locationsFieldsMapping['monthly_dates']])) {
613
+										if ($this->validateScheduleMonthlyDates($rows[$locationsFieldsMapping['monthly_dates']])) {
614
+											$curSchedule .= '"dates":['.$rows[$locationsFieldsMapping['monthly_dates']].']}';
615
+										} else {
616
+											array_push($results['fail'], "$iRow --> Wrong monthly dates");
617
+										}
618
+									}
619
+									break;
620
+								case 'nth':
621
+									if (isset($rows[$locationsFieldsMapping['monthly_nth_n']])) {
622
+										if ($this->validateScheduleNthN($rows[$locationsFieldsMapping['monthly_nth_n']])) {
623
+											$curSchedule .= '"nth":{"n":'.$rows[$locationsFieldsMapping['monthly_nth_n']].',';
624
+										} else {
625
+											array_push($results['fail'], "$iRow --> Wrong parameter sched_nth_n");
626
+										}
627
+									} else {
628
+										array_push($results['fail'], "$iRow --> The parameter sched_nth_n is not set");
629
+									}
630
+
631
+									if ('' != $curSchedule) {
632
+										if (isset($rows[$locationsFieldsMapping['monthly_nth_what']])) {
633
+											if ($this->validateScheduleNthWhat($rows[$locationsFieldsMapping['monthly_nth_what']])) {
634
+												$curSchedule .= '"what":'.$rows[$locationsFieldsMapping['monthly_nth_what']].'}}';
635
+											} else {
636
+												array_push($results['fail'], "$iRow --> Wrong parameter sched_nth_what");
637
+											}
638
+										} else {
639
+											array_push($results['fail'], "$iRow --> The parameter sched_nth_what is not set");
640
+										}
641
+									}
642
+									break;
643
+							}
644
+						}
645
+						break;
646
+					default:
647
+						$curSchedule = '';
648
+						break;
649
+				}
650
+			}
651
+
652
+			if (sizeof($results['fail']) > $failCount) {
653
+				$curSchedule = '';
654
+			}
655
+
656
+			if (('daily' == $mode || 'weekly' == $mode || 'monthy' == $mode) && '' == $curSchedule) {
657
+				++$iRow;
658
+				continue;
659
+			}
660
+
661
+			$curSchedule = strtolower($curSchedule);
662
+
663
+			$curSchedule = '[{'.$curSchedule.'}]';
664
+
665
+			$parametersArray = [];
666
+
667
+			foreach ($addressBookFields as $addressBookField) {
668
+				if (isset($locationsFieldsMapping[$addressBookField])) {
669
+					$parametersArray[$addressBookField] = $rows[$locationsFieldsMapping[$addressBookField]];
670
+				}
671
+			}
672
+
673
+			$AdressBookLocationParameters = self::fromArray($parametersArray);
674
+
675
+			$abContacts = new self();
676
+
677
+			$abcResults = $abContacts->addAdressBookLocation($AdressBookLocationParameters); //temporarry
678
+
679
+			array_push(
680
+				$results['success'],
681
+				'The schedule location with address_id = '.strval($abcResults['address_id']).' added successfuly.'
682
+			);
683
+		}
684
+
685
+		return $results;
686
+	}
687 687
 }
Please login to merge, or discard this patch.
Switch Indentation   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -582,70 +582,70 @@
 block discarded – undo
582 582
 
583 583
             if ('daily' != $mode) {
584 584
                 switch ($mode) {
585
-                    case 'weekly':
586
-                        if (isset($rows[$locationsFieldsMapping['schedule_weekdays']])) {
587
-                            if ($this->validateScheduleWeekDays($rows[$locationsFieldsMapping['schedule_weekdays']])) {
588
-                                $curSchedule .= '"weekdays":['.$rows[$locationsFieldsMapping['schedule_weekdays']].']}';
589
-                            } else {
590
-                                array_push($results['fail'], "$iRow --> Wrong weekdays");
591
-                            }
585
+                case 'weekly':
586
+                    if (isset($rows[$locationsFieldsMapping['schedule_weekdays']])) {
587
+                        if ($this->validateScheduleWeekDays($rows[$locationsFieldsMapping['schedule_weekdays']])) {
588
+                            $curSchedule .= '"weekdays":['.$rows[$locationsFieldsMapping['schedule_weekdays']].']}';
589
+                        } else {
590
+                            array_push($results['fail'], "$iRow --> Wrong weekdays");
591
+                        }
592
+                    } else {
593
+                        array_push($results['fail'], "$iRow --> The parameters sched_weekdays is not set");
594
+                    }
595
+                    break;
596
+                case 'monthly':
597
+                    $monthlyMode = '';
598
+                    if (isset($rows[$locationsFieldsMapping['monthly_mode']])) {
599
+                        if ($this->validateScheduleMonthlyMode($rows[$locationsFieldsMapping['monthly_mode']])) {
600
+                            $monthlyMode = $rows[$locationsFieldsMapping['monthly_mode']];
601
+                            $curSchedule .= '"mode": "'.$rows[$locationsFieldsMapping['monthly_mode']].'",';
592 602
                         } else {
593
-                            array_push($results['fail'], "$iRow --> The parameters sched_weekdays is not set");
603
+                            array_push($results['fail'], "$iRow --> Wrong monthly mode");
604
+                        }
605
+                    } else {
606
+                        array_push($results['fail'], "$iRow --> The parameter sched_monthly_mode is not set");
607
+                    }
608
+
609
+                    if ('' != $monthlyMode) {
610
+                        switch ($monthlyMode) {
611
+                        case 'dates':
612
+                        if (isset($rows[$locationsFieldsMapping['monthly_dates']])) {
613
+                        if ($this->validateScheduleMonthlyDates($rows[$locationsFieldsMapping['monthly_dates']])) {
614
+                            $curSchedule .= '"dates":['.$rows[$locationsFieldsMapping['monthly_dates']].']}';
615
+                        } else {
616
+                            array_push($results['fail'], "$iRow --> Wrong monthly dates");
617
+                        }
594 618
                         }
595 619
                         break;
596
-                    case 'monthly':
597
-                        $monthlyMode = '';
598
-                        if (isset($rows[$locationsFieldsMapping['monthly_mode']])) {
599
-                            if ($this->validateScheduleMonthlyMode($rows[$locationsFieldsMapping['monthly_mode']])) {
600
-                                $monthlyMode = $rows[$locationsFieldsMapping['monthly_mode']];
601
-                                $curSchedule .= '"mode": "'.$rows[$locationsFieldsMapping['monthly_mode']].'",';
602
-                            } else {
603
-                                array_push($results['fail'], "$iRow --> Wrong monthly mode");
604
-                            }
620
+                        case 'nth':
621
+                        if (isset($rows[$locationsFieldsMapping['monthly_nth_n']])) {
622
+                        if ($this->validateScheduleNthN($rows[$locationsFieldsMapping['monthly_nth_n']])) {
623
+                            $curSchedule .= '"nth":{"n":'.$rows[$locationsFieldsMapping['monthly_nth_n']].',';
605 624
                         } else {
606
-                            array_push($results['fail'], "$iRow --> The parameter sched_monthly_mode is not set");
625
+                            array_push($results['fail'], "$iRow --> Wrong parameter sched_nth_n");
626
+                        }
627
+                        } else {
628
+                        array_push($results['fail'], "$iRow --> The parameter sched_nth_n is not set");
607 629
                         }
608 630
 
609
-                        if ('' != $monthlyMode) {
610
-                            switch ($monthlyMode) {
611
-                                case 'dates':
612
-                                    if (isset($rows[$locationsFieldsMapping['monthly_dates']])) {
613
-                                        if ($this->validateScheduleMonthlyDates($rows[$locationsFieldsMapping['monthly_dates']])) {
614
-                                            $curSchedule .= '"dates":['.$rows[$locationsFieldsMapping['monthly_dates']].']}';
615
-                                        } else {
616
-                                            array_push($results['fail'], "$iRow --> Wrong monthly dates");
617
-                                        }
618
-                                    }
619
-                                    break;
620
-                                case 'nth':
621
-                                    if (isset($rows[$locationsFieldsMapping['monthly_nth_n']])) {
622
-                                        if ($this->validateScheduleNthN($rows[$locationsFieldsMapping['monthly_nth_n']])) {
623
-                                            $curSchedule .= '"nth":{"n":'.$rows[$locationsFieldsMapping['monthly_nth_n']].',';
624
-                                        } else {
625
-                                            array_push($results['fail'], "$iRow --> Wrong parameter sched_nth_n");
626
-                                        }
627
-                                    } else {
628
-                                        array_push($results['fail'], "$iRow --> The parameter sched_nth_n is not set");
629
-                                    }
630
-
631
-                                    if ('' != $curSchedule) {
632
-                                        if (isset($rows[$locationsFieldsMapping['monthly_nth_what']])) {
633
-                                            if ($this->validateScheduleNthWhat($rows[$locationsFieldsMapping['monthly_nth_what']])) {
634
-                                                $curSchedule .= '"what":'.$rows[$locationsFieldsMapping['monthly_nth_what']].'}}';
635
-                                            } else {
636
-                                                array_push($results['fail'], "$iRow --> Wrong parameter sched_nth_what");
637
-                                            }
638
-                                        } else {
639
-                                            array_push($results['fail'], "$iRow --> The parameter sched_nth_what is not set");
640
-                                        }
641
-                                    }
642
-                                    break;
631
+                        if ('' != $curSchedule) {
632
+                        if (isset($rows[$locationsFieldsMapping['monthly_nth_what']])) {
633
+                            if ($this->validateScheduleNthWhat($rows[$locationsFieldsMapping['monthly_nth_what']])) {
634
+                                $curSchedule .= '"what":'.$rows[$locationsFieldsMapping['monthly_nth_what']].'}}';
635
+                            } else {
636
+                                array_push($results['fail'], "$iRow --> Wrong parameter sched_nth_what");
643 637
                             }
638
+                        } else {
639
+                            array_push($results['fail'], "$iRow --> The parameter sched_nth_what is not set");
640
+                        }
644 641
                         }
645 642
                         break;
646
-                    default:
647
-                        $curSchedule = '';
643
+                        }
644
+                        }
648 645
                         break;
646
+                default:
647
+                    $curSchedule = '';
648
+                    break;
649 649
                 }
650 650
             }
651 651
 
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -324,7 +324,7 @@  discard block
 block discarded – undo
324 324
         if (isset($ablocations['results'])) {
325 325
             $locationsSize = sizeof($ablocations['results']);
326 326
 
327
-            if ($locationsSize > 0) {
327
+            if ($locationsSize>0) {
328 328
                 $randomLocationIndex = rand(0, $locationsSize - 1);
329 329
 
330 330
                 return $ablocations['results'][$randomLocationIndex];
@@ -394,9 +394,9 @@  discard block
 block discarded – undo
394 394
             if (strtolower($scheduleEnabled)=="false") $scheduleEnabled = false;
395 395
         }
396 396
 
397
-        $schedEnables = [true, false,];
397
+        $schedEnables = [true, false, ];
398 398
 
399
-        if (in_array($scheduleEnabled, $schedEnables,true)) {
399
+        if (in_array($scheduleEnabled, $schedEnables, true)) {
400 400
             return true;
401 401
         } else {
402 402
             return false;
@@ -423,18 +423,18 @@  discard block
 block discarded – undo
423 423
         $weekdays = explode(',', $scheduleWeekDays);
424 424
         $weekdaysSize = sizeof($weekdays);
425 425
 
426
-        if ($weekdaysSize < 1) {
426
+        if ($weekdaysSize<1) {
427 427
             return false;
428 428
         }
429 429
 
430 430
         $isValid = true;
431 431
 
432
-        for ($i = 0; $i < $weekdaysSize; ++$i) {
432
+        for ($i = 0; $i<$weekdaysSize; ++$i) {
433 433
             if (is_bool($weekdays[$i])) {
434 434
                 $isValid = false;
435 435
             } elseif (is_numeric($weekdays[$i])) {
436 436
                 $wday = intval($weekdays[$i]);
437
-                if ($wday < 1 || $wday > 7) {
437
+                if ($wday<1 || $wday>7) {
438 438
                     $isValid = false;
439 439
                 }
440 440
             } else {
@@ -449,7 +449,7 @@  discard block
 block discarded – undo
449 449
     {
450 450
         $schedMonthlyMmodes = ['dates', 'nth'];
451 451
 
452
-        if (in_array($scheduleMonthlyMode, $schedMonthlyMmodes,true)) {
452
+        if (in_array($scheduleMonthlyMode, $schedMonthlyMmodes, true)) {
453 453
             return true;
454 454
         } else {
455 455
             return false;
@@ -463,16 +463,16 @@  discard block
 block discarded – undo
463 463
         $monthlyDates = explode(',', $scheduleMonthlyDates);
464 464
         $monthlyDatesSize = sizeof($monthlyDates);
465 465
 
466
-        if ($monthlyDatesSize < 1) {
466
+        if ($monthlyDatesSize<1) {
467 467
             return false;
468 468
         }
469 469
 
470 470
         $isValid = true;
471 471
 
472
-        for ($i = 0; $i < $monthlyDatesSize; ++$i) {
472
+        for ($i = 0; $i<$monthlyDatesSize; ++$i) {
473 473
             if (is_numeric($monthlyDates[$i])) {
474 474
                 $mday = intval($monthlyDates[$i]);
475
-                if ($mday < 1 || $mday > 31) {
475
+                if ($mday<1 || $mday>31) {
476 476
                     $isValid = false;
477 477
                 }
478 478
             } else {
@@ -538,9 +538,9 @@  discard block
 block discarded – undo
538 538
 
539 539
         $iRow = 1;
540 540
 
541
-        while (false !== ($rows = fgetcsv($csvFileHandle, $max_line_length, $delemietr))) {
541
+        while (false!==($rows = fgetcsv($csvFileHandle, $max_line_length, $delemietr))) {
542 542
             if (!isset($rows[$locationsFieldsMapping['cached_lat']]) || !isset($rows[$locationsFieldsMapping['cached_lng']])
543
-                  || !isset($rows[$locationsFieldsMapping['address_1']]) || [null] == $rows) {
543
+                  || !isset($rows[$locationsFieldsMapping['address_1']]) || [null]==$rows) {
544 544
                 continue;
545 545
             }
546 546
 
@@ -571,7 +571,7 @@  discard block
 block discarded – undo
571 571
             if (isset($rows[$locationsFieldsMapping['schedule_every']])) {
572 572
                 if ($this->validateScheduleEvery($rows[$locationsFieldsMapping['schedule_every']])) {
573 573
                     $curSchedule .= '"'.$mode.'":{'.'"every":'.$rows[$locationsFieldsMapping['schedule_every']].',';
574
-                    if ('daily' == $mode) {
574
+                    if ('daily'==$mode) {
575 575
                         $curSchedule = trim($curSchedule, ',');
576 576
                         $curSchedule .= '}';
577 577
                     }
@@ -580,7 +580,7 @@  discard block
 block discarded – undo
580 580
                 }
581 581
             }
582 582
 
583
-            if ('daily' != $mode) {
583
+            if ('daily'!=$mode) {
584 584
                 switch ($mode) {
585 585
                     case 'weekly':
586 586
                         if (isset($rows[$locationsFieldsMapping['schedule_weekdays']])) {
@@ -606,7 +606,7 @@  discard block
 block discarded – undo
606 606
                             array_push($results['fail'], "$iRow --> The parameter sched_monthly_mode is not set");
607 607
                         }
608 608
 
609
-                        if ('' != $monthlyMode) {
609
+                        if (''!=$monthlyMode) {
610 610
                             switch ($monthlyMode) {
611 611
                                 case 'dates':
612 612
                                     if (isset($rows[$locationsFieldsMapping['monthly_dates']])) {
@@ -628,7 +628,7 @@  discard block
 block discarded – undo
628 628
                                         array_push($results['fail'], "$iRow --> The parameter sched_nth_n is not set");
629 629
                                     }
630 630
 
631
-                                    if ('' != $curSchedule) {
631
+                                    if (''!=$curSchedule) {
632 632
                                         if (isset($rows[$locationsFieldsMapping['monthly_nth_what']])) {
633 633
                                             if ($this->validateScheduleNthWhat($rows[$locationsFieldsMapping['monthly_nth_what']])) {
634 634
                                                 $curSchedule .= '"what":'.$rows[$locationsFieldsMapping['monthly_nth_what']].'}}';
@@ -649,11 +649,11 @@  discard block
 block discarded – undo
649 649
                 }
650 650
             }
651 651
 
652
-            if (sizeof($results['fail']) > $failCount) {
652
+            if (sizeof($results['fail'])>$failCount) {
653 653
                 $curSchedule = '';
654 654
             }
655 655
 
656
-            if (('daily' == $mode || 'weekly' == $mode || 'monthy' == $mode) && '' == $curSchedule) {
656
+            if (('daily'==$mode || 'weekly'==$mode || 'monthy'==$mode) && ''==$curSchedule) {
657 657
                 ++$iRow;
658 658
                 continue;
659 659
             }
Please login to merge, or discard this patch.
Braces   +12 added lines, -4 removed lines patch added patch discarded remove patch
@@ -390,8 +390,12 @@  discard block
 block discarded – undo
390 390
     public static function validateScheduleEnable($scheduleEnabled)
391 391
     {
392 392
         if (is_string($scheduleEnabled)) {
393
-            if (strtolower($scheduleEnabled)=="true") $scheduleEnabled = true;
394
-            if (strtolower($scheduleEnabled)=="false") $scheduleEnabled = false;
393
+            if (strtolower($scheduleEnabled)=="true") {
394
+            	$scheduleEnabled = true;
395
+            }
396
+            if (strtolower($scheduleEnabled)=="false") {
397
+            	$scheduleEnabled = false;
398
+            }
395 399
         }
396 400
 
397 401
         $schedEnables = [true, false,];
@@ -418,7 +422,9 @@  discard block
 block discarded – undo
418 422
 
419 423
     public static function validateScheduleWeekDays($scheduleWeekDays)
420 424
     {
421
-        if (is_bool($scheduleWeekDays)) return false;
425
+        if (is_bool($scheduleWeekDays)) {
426
+        	return false;
427
+        }
422 428
 
423 429
         $weekdays = explode(',', $scheduleWeekDays);
424 430
         $weekdaysSize = sizeof($weekdays);
@@ -458,7 +464,9 @@  discard block
 block discarded – undo
458 464
 
459 465
     public static function validateScheduleMonthlyDates($scheduleMonthlyDates)
460 466
     {
461
-        if (is_bool($scheduleMonthlyDates)) return false;
467
+        if (is_bool($scheduleMonthlyDates)) {
468
+        	return false;
469
+        }
462 470
 
463 471
         $monthlyDates = explode(',', $scheduleMonthlyDates);
464 472
         $monthlyDatesSize = sizeof($monthlyDates);
Please login to merge, or discard this patch.
src/Route4Me/CustomNoteTypeResponse.php 2 patches
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -6,42 +6,42 @@
 block discarded – undo
6 6
 
7 7
 class CustomNoteTypeResponse extends Common
8 8
 {
9
-    /**
10
-     * Note custom type ID
11
-     * @var integer
12
-     */
13
-    public $note_custom_type_id;
14
-
15
-    /**
16
-     * Note custom type
17
-     * @var CustomNoteType
18
-     */
19
-    public $note_custom_type;
20
-
21
-    /**
22
-     * ID of a root owner of the account
23
-     * @var integer
24
-     */
25
-    public $root_owner_member_id;
26
-
27
-    /**
28
-     * Values of the custom note type
29
-     * @var array
30
-     */
31
-    public $note_custom_type_values=[];
32
-
33
-    public static function fromArray(array $params)
34
-    {
35
-        $customNoteTypeResponse = new self();
36
-
37
-        foreach ($params as $key => $value) {
38
-            if (property_exists($customNoteTypeResponse, $key)) {
39
-                $customNoteTypeResponse->{$key} = $value;
40
-            } else {
41
-                throw new BadParam("Correct parameter must be provided. Wrong Parameter: $key");
42
-            }
43
-        }
44
-
45
-        return $customNoteTypeResponse;
46
-    }
9
+	/**
10
+	 * Note custom type ID
11
+	 * @var integer
12
+	 */
13
+	public $note_custom_type_id;
14
+
15
+	/**
16
+	 * Note custom type
17
+	 * @var CustomNoteType
18
+	 */
19
+	public $note_custom_type;
20
+
21
+	/**
22
+	 * ID of a root owner of the account
23
+	 * @var integer
24
+	 */
25
+	public $root_owner_member_id;
26
+
27
+	/**
28
+	 * Values of the custom note type
29
+	 * @var array
30
+	 */
31
+	public $note_custom_type_values=[];
32
+
33
+	public static function fromArray(array $params)
34
+	{
35
+		$customNoteTypeResponse = new self();
36
+
37
+		foreach ($params as $key => $value) {
38
+			if (property_exists($customNoteTypeResponse, $key)) {
39
+				$customNoteTypeResponse->{$key} = $value;
40
+			} else {
41
+				throw new BadParam("Correct parameter must be provided. Wrong Parameter: $key");
42
+			}
43
+		}
44
+
45
+		return $customNoteTypeResponse;
46
+	}
47 47
 }
48 48
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@
 block discarded – undo
28 28
      * Values of the custom note type
29 29
      * @var array
30 30
      */
31
-    public $note_custom_type_values=[];
31
+    public $note_custom_type_values = [];
32 32
 
33 33
     public static function fromArray(array $params)
34 34
     {
Please login to merge, or discard this patch.
src/Route4Me/GeocodingResponse.php 1 patch
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -10,52 +10,52 @@
 block discarded – undo
10 10
  */
11 11
 class GeocodingResponse extends Common
12 12
 {
13
-    /**
14
-     * A geocoded address
15
-     * @var string
16
-     */
17
-    public $address;
18
-
19
-    /**
20
-     * Latitude
21
-     * @var double
22
-     */
23
-    public $lat;
24
-
25
-    /**
26
-     * Longitude
27
-     * @var double
28
-     */
29
-    public $lng;
30
-
31
-    /**
32
-     * Geocoded area level type
33
-     * @var string
34
-     */
35
-    public $type;
36
-
37
-    /**
38
-     * Confidence ("high", "medium", "low")
39
-     * @var string
40
-     */
41
-    public $confidence;
42
-
43
-    /**
44
-     * Content of the original string (an address or geopoint) sent by HTTP
45
-     * @var Route
46
-     */
47
-    public $original;
48
-
49
-    public static function fromArray(array $params)
50
-    {
51
-        $geocodingResponse = new self();
52
-
53
-        foreach ($params as $key => $value) {
54
-            if (property_exists($geocodingResponse, $key)) {
55
-                $geocodingResponse->{$key} = $value;
56
-            }
57
-        }
58
-
59
-        return $geocodingResponse;
60
-    }
13
+	/**
14
+	 * A geocoded address
15
+	 * @var string
16
+	 */
17
+	public $address;
18
+
19
+	/**
20
+	 * Latitude
21
+	 * @var double
22
+	 */
23
+	public $lat;
24
+
25
+	/**
26
+	 * Longitude
27
+	 * @var double
28
+	 */
29
+	public $lng;
30
+
31
+	/**
32
+	 * Geocoded area level type
33
+	 * @var string
34
+	 */
35
+	public $type;
36
+
37
+	/**
38
+	 * Confidence ("high", "medium", "low")
39
+	 * @var string
40
+	 */
41
+	public $confidence;
42
+
43
+	/**
44
+	 * Content of the original string (an address or geopoint) sent by HTTP
45
+	 * @var Route
46
+	 */
47
+	public $original;
48
+
49
+	public static function fromArray(array $params)
50
+	{
51
+		$geocodingResponse = new self();
52
+
53
+		foreach ($params as $key => $value) {
54
+			if (property_exists($geocodingResponse, $key)) {
55
+				$geocodingResponse->{$key} = $value;
56
+			}
57
+		}
58
+
59
+		return $geocodingResponse;
60
+	}
61 61
 }
Please login to merge, or discard this patch.
src/Route4Me/AddressNote.php 3 patches
Indentation   +234 added lines, -234 removed lines patch added patch discarded remove patch
@@ -11,238 +11,238 @@
 block discarded – undo
11 11
  */
12 12
 class AddressNote extends Common
13 13
 {
14
-    /**
15
-     * An unique ID of a note
16
-     * @var integer
17
-     */
18
-    public $note_id;
19
-
20
-    /**
21
-     * The route ID
22
-     * @var string
23
-     */
24
-    public $route_id;
25
-
26
-    /**
27
-     * The route destination ID
28
-     * @var integer
29
-     */
30
-    public $route_destination_id;
31
-
32
-    /**
33
-     * An unique ID of an uploaded file
34
-     * @var string
35
-     */
36
-    public $upload_id;
37
-
38
-    /**
39
-     * When the note was added
40
-     * @var integer
41
-     */
42
-    public $ts_added;
43
-
44
-    /**
45
-     * The position latitude where the address note was added
46
-     * @var double
47
-     */
48
-    public $lat;
49
-
50
-    /**
51
-     * The position longitude where the address note was added
52
-     * @var double
53
-     */
54
-    public $lng;
55
-
56
-    /**
57
-     * The activity type
58
-     * @var string
59
-     */
60
-    public $activity_type;
61
-
62
-    /**
63
-     * The note text contents
64
-     * @var string
65
-     */
66
-    public $contents;
67
-
68
-    /**
69
-     * An upload type of the note
70
-     * @var string
71
-     */
72
-    public $upload_type;
73
-
74
-    /**
75
-     * An upload url - where a file-note was uploaded.
76
-     * @var string
77
-     */
78
-    public $upload_url;
79
-
80
-    /**
81
-     * An extension of the uploaded file.
82
-     * @var string
83
-     */
84
-    public $upload_extension;
85
-
86
-    /**
87
-     * The device a note was uploaded from.
88
-     * @var string
89
-     */
90
-    public $device_type;
91
-
92
-    /**
93
-     * Array of the custom type notes.
94
-     * @var CustomNoteType[]
95
-     */
96
-    public $custom_types;
97
-
98
-    public function __construct()
99
-    {
100
-
101
-    }
102
-
103
-    public static function fromArray(array $params)
104
-    {
105
-        $addressNote = new self();
106
-
107
-        foreach ($params as $key => $value) {
108
-            if (property_exists($addressNote, $key)) {
109
-                $addressNote->{$key} = $value;
110
-            } else {
111
-                throw new BadParam("Correct parameter must be provided. Wrong Parameter: $key");
112
-            }
113
-        }
114
-
115
-        return $addressNote;
116
-    }
117
-
118
-    /**
119
-     * Get notes from the specified route destination.<br>
120
-     * Returns an address object with notes, if an address exists, otherwise - return null.
121
-     */
122
-    public static function GetAddressesNotes($noteParams)
123
-    {
124
-        $address = Route4Me::makeRequst([
125
-            'url'       => Endpoint::ADDRESS_V4,
126
-            'method'    => 'GET',
127
-            'query'     => [
128
-                'route_id'              => isset($noteParams['route_id']) ? $noteParams['route_id'] : null,
129
-                'route_destination_id'  => isset($noteParams['route_destination_id'])
130
-                    ? $noteParams['route_destination_id'] : null,
131
-                'notes' => 1,
132
-            ],
133
-        ]);
134
-
135
-        return $address;
136
-    }
137
-
138
-    public function createCustomNoteType($params)
139
-    {
140
-        $allBodyFields = ['type', 'values'];
141
-
142
-        $result = Route4Me::makeRequst([
143
-            'url'       => Endpoint::NOTE_CUSTOM_TYPES_V4,
144
-            'method'    => 'POST',
145
-            'body'      => Route4Me::generateRequestParameters($allBodyFields, $params),
146
-        ]);
147
-
148
-        return $result;
149
-    }
150
-
151
-    public function removeCustomNoteType($params)
152
-    {
153
-        $result = Route4Me::makeRequst([
154
-            'url'       => Endpoint::NOTE_CUSTOM_TYPES_V4,
155
-            'method'    => 'DELETE',
156
-            'body'      => [
157
-                'id' => isset($params['id']) ? $params['id'] : null,
158
-            ],
159
-        ]);
160
-
161
-        return $result;
162
-    }
163
-
164
-    public function getAllCustomNoteTypes()
165
-    {
166
-        $result = Route4Me::makeRequst([
167
-            'url'       => Endpoint::NOTE_CUSTOM_TYPES_V4,
168
-            'method'    => 'GET',
169
-        ]);
170
-
171
-        return $result;
172
-    }
173
-
174
-    public function getCustomNoteTypeByKey($params)
175
-    {
176
-        $result = Route4Me::makeRequst([
177
-            'url'       => Endpoint::NOTE_CUSTOM_TYPES_V4,
178
-            'method'    => 'GET',
179
-        ]);
180
-
181
-        if (is_null($result) || !is_array($result)) return null;
182
-
183
-        foreach ($result as $custNoteType) {
184
-            if (isset($custNoteType["note_custom_type"]) && $custNoteType["note_custom_type"] == $params) {
185
-                return $custNoteType;
186
-            }
187
-        }
188
-    }
189
-
190
-    public function AddAddressNote($params)
191
-    {
192
-        $allQueryFields = ['route_id', 'address_id', 'dev_lat', 'dev_lng', 'device_type'];
193
-        $allBodyFields = ['strNoteContents', 'strUpdateType'];
194
-
195
-        $result = Route4Me::makeRequst([
196
-            'url'           => Endpoint::ROUTE_NOTES_ADD,
197
-            'method'        => 'POST',
198
-            'query'         => Route4Me::generateRequestParameters($allQueryFields, $params),
199
-            'body'          => Route4Me::generateRequestParameters($allBodyFields, $params),
200
-            'HTTPHEADER'    => 'Content-Type: multipart/form-data',
201
-        ]);
202
-
203
-        return $result;
204
-    }
205
-
206
-    public function AddNoteFile($params)
207
-    {
208
-        $fname = isset($params['strFilename']) ? $params['strFilename'] : null;
209
-
210
-        $allQueryFields = ['route_id', 'address_id', 'dev_lat', 'dev_lng', 'device_type'];
211
-        $allBodyFields = ['strFilename', 'strUpdateType', 'strNoteContents'];
212
-
213
-        $result = Route4Me::makeRequst([
214
-            'url'           => Endpoint::ROUTE_NOTES_ADD,
215
-            'method'        => 'POST',
216
-            'query'         => Route4Me::generateRequestParameters($allQueryFields, $params),
217
-            'body'          => Route4Me::generateRequestParameters($allBodyFields, $params),
218
-            'FILE'          => $fname,
219
-            'HTTPHEADER'    => 'Content-Type: multipart/form-data'
220
-        ]);
221
-
222
-        return $result;
223
-    }
224
-
225
-    public function addCustomNoteToRoute($params)
226
-    {
227
-        $customArray = [];
228
-
229
-        foreach ($params as $key => $value) {
230
-            if (false !== strpos($key, 'custom_note_type')) {
231
-                $customArray[$key] = $value;
232
-            }
233
-        }
234
-
235
-        $allQueryFields = ['route_id', 'address_id', 'format', 'dev_lat', 'dev_lng'];
236
-        $allBodyFields = ['strUpdateType', 'strUpdateType', 'strNoteContents'];
237
-
238
-        $result = Route4Me::makeRequst([
239
-            'url'           => Endpoint::ROUTE_NOTES_ADD,
240
-            'method'        => 'POST',
241
-            'query'         => Route4Me::generateRequestParameters($allQueryFields, $params),
242
-            'body'          => array_merge(Route4Me::generateRequestParameters($allBodyFields, $params), $customArray),
243
-            'HTTPHEADER'    => 'Content-Type: multipart/form-data',
244
-        ]);
245
-
246
-        return $result;
247
-    }
14
+	/**
15
+	 * An unique ID of a note
16
+	 * @var integer
17
+	 */
18
+	public $note_id;
19
+
20
+	/**
21
+	 * The route ID
22
+	 * @var string
23
+	 */
24
+	public $route_id;
25
+
26
+	/**
27
+	 * The route destination ID
28
+	 * @var integer
29
+	 */
30
+	public $route_destination_id;
31
+
32
+	/**
33
+	 * An unique ID of an uploaded file
34
+	 * @var string
35
+	 */
36
+	public $upload_id;
37
+
38
+	/**
39
+	 * When the note was added
40
+	 * @var integer
41
+	 */
42
+	public $ts_added;
43
+
44
+	/**
45
+	 * The position latitude where the address note was added
46
+	 * @var double
47
+	 */
48
+	public $lat;
49
+
50
+	/**
51
+	 * The position longitude where the address note was added
52
+	 * @var double
53
+	 */
54
+	public $lng;
55
+
56
+	/**
57
+	 * The activity type
58
+	 * @var string
59
+	 */
60
+	public $activity_type;
61
+
62
+	/**
63
+	 * The note text contents
64
+	 * @var string
65
+	 */
66
+	public $contents;
67
+
68
+	/**
69
+	 * An upload type of the note
70
+	 * @var string
71
+	 */
72
+	public $upload_type;
73
+
74
+	/**
75
+	 * An upload url - where a file-note was uploaded.
76
+	 * @var string
77
+	 */
78
+	public $upload_url;
79
+
80
+	/**
81
+	 * An extension of the uploaded file.
82
+	 * @var string
83
+	 */
84
+	public $upload_extension;
85
+
86
+	/**
87
+	 * The device a note was uploaded from.
88
+	 * @var string
89
+	 */
90
+	public $device_type;
91
+
92
+	/**
93
+	 * Array of the custom type notes.
94
+	 * @var CustomNoteType[]
95
+	 */
96
+	public $custom_types;
97
+
98
+	public function __construct()
99
+	{
100
+
101
+	}
102
+
103
+	public static function fromArray(array $params)
104
+	{
105
+		$addressNote = new self();
106
+
107
+		foreach ($params as $key => $value) {
108
+			if (property_exists($addressNote, $key)) {
109
+				$addressNote->{$key} = $value;
110
+			} else {
111
+				throw new BadParam("Correct parameter must be provided. Wrong Parameter: $key");
112
+			}
113
+		}
114
+
115
+		return $addressNote;
116
+	}
117
+
118
+	/**
119
+	 * Get notes from the specified route destination.<br>
120
+	 * Returns an address object with notes, if an address exists, otherwise - return null.
121
+	 */
122
+	public static function GetAddressesNotes($noteParams)
123
+	{
124
+		$address = Route4Me::makeRequst([
125
+			'url'       => Endpoint::ADDRESS_V4,
126
+			'method'    => 'GET',
127
+			'query'     => [
128
+				'route_id'              => isset($noteParams['route_id']) ? $noteParams['route_id'] : null,
129
+				'route_destination_id'  => isset($noteParams['route_destination_id'])
130
+					? $noteParams['route_destination_id'] : null,
131
+				'notes' => 1,
132
+			],
133
+		]);
134
+
135
+		return $address;
136
+	}
137
+
138
+	public function createCustomNoteType($params)
139
+	{
140
+		$allBodyFields = ['type', 'values'];
141
+
142
+		$result = Route4Me::makeRequst([
143
+			'url'       => Endpoint::NOTE_CUSTOM_TYPES_V4,
144
+			'method'    => 'POST',
145
+			'body'      => Route4Me::generateRequestParameters($allBodyFields, $params),
146
+		]);
147
+
148
+		return $result;
149
+	}
150
+
151
+	public function removeCustomNoteType($params)
152
+	{
153
+		$result = Route4Me::makeRequst([
154
+			'url'       => Endpoint::NOTE_CUSTOM_TYPES_V4,
155
+			'method'    => 'DELETE',
156
+			'body'      => [
157
+				'id' => isset($params['id']) ? $params['id'] : null,
158
+			],
159
+		]);
160
+
161
+		return $result;
162
+	}
163
+
164
+	public function getAllCustomNoteTypes()
165
+	{
166
+		$result = Route4Me::makeRequst([
167
+			'url'       => Endpoint::NOTE_CUSTOM_TYPES_V4,
168
+			'method'    => 'GET',
169
+		]);
170
+
171
+		return $result;
172
+	}
173
+
174
+	public function getCustomNoteTypeByKey($params)
175
+	{
176
+		$result = Route4Me::makeRequst([
177
+			'url'       => Endpoint::NOTE_CUSTOM_TYPES_V4,
178
+			'method'    => 'GET',
179
+		]);
180
+
181
+		if (is_null($result) || !is_array($result)) return null;
182
+
183
+		foreach ($result as $custNoteType) {
184
+			if (isset($custNoteType["note_custom_type"]) && $custNoteType["note_custom_type"] == $params) {
185
+				return $custNoteType;
186
+			}
187
+		}
188
+	}
189
+
190
+	public function AddAddressNote($params)
191
+	{
192
+		$allQueryFields = ['route_id', 'address_id', 'dev_lat', 'dev_lng', 'device_type'];
193
+		$allBodyFields = ['strNoteContents', 'strUpdateType'];
194
+
195
+		$result = Route4Me::makeRequst([
196
+			'url'           => Endpoint::ROUTE_NOTES_ADD,
197
+			'method'        => 'POST',
198
+			'query'         => Route4Me::generateRequestParameters($allQueryFields, $params),
199
+			'body'          => Route4Me::generateRequestParameters($allBodyFields, $params),
200
+			'HTTPHEADER'    => 'Content-Type: multipart/form-data',
201
+		]);
202
+
203
+		return $result;
204
+	}
205
+
206
+	public function AddNoteFile($params)
207
+	{
208
+		$fname = isset($params['strFilename']) ? $params['strFilename'] : null;
209
+
210
+		$allQueryFields = ['route_id', 'address_id', 'dev_lat', 'dev_lng', 'device_type'];
211
+		$allBodyFields = ['strFilename', 'strUpdateType', 'strNoteContents'];
212
+
213
+		$result = Route4Me::makeRequst([
214
+			'url'           => Endpoint::ROUTE_NOTES_ADD,
215
+			'method'        => 'POST',
216
+			'query'         => Route4Me::generateRequestParameters($allQueryFields, $params),
217
+			'body'          => Route4Me::generateRequestParameters($allBodyFields, $params),
218
+			'FILE'          => $fname,
219
+			'HTTPHEADER'    => 'Content-Type: multipart/form-data'
220
+		]);
221
+
222
+		return $result;
223
+	}
224
+
225
+	public function addCustomNoteToRoute($params)
226
+	{
227
+		$customArray = [];
228
+
229
+		foreach ($params as $key => $value) {
230
+			if (false !== strpos($key, 'custom_note_type')) {
231
+				$customArray[$key] = $value;
232
+			}
233
+		}
234
+
235
+		$allQueryFields = ['route_id', 'address_id', 'format', 'dev_lat', 'dev_lng'];
236
+		$allBodyFields = ['strUpdateType', 'strUpdateType', 'strNoteContents'];
237
+
238
+		$result = Route4Me::makeRequst([
239
+			'url'           => Endpoint::ROUTE_NOTES_ADD,
240
+			'method'        => 'POST',
241
+			'query'         => Route4Me::generateRequestParameters($allQueryFields, $params),
242
+			'body'          => array_merge(Route4Me::generateRequestParameters($allBodyFields, $params), $customArray),
243
+			'HTTPHEADER'    => 'Content-Type: multipart/form-data',
244
+		]);
245
+
246
+		return $result;
247
+	}
248 248
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
         if (is_null($result) || !is_array($result)) return null;
182 182
 
183 183
         foreach ($result as $custNoteType) {
184
-            if (isset($custNoteType["note_custom_type"]) && $custNoteType["note_custom_type"] == $params) {
184
+            if (isset($custNoteType["note_custom_type"]) && $custNoteType["note_custom_type"]==$params) {
185 185
                 return $custNoteType;
186 186
             }
187 187
         }
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
         $customArray = [];
228 228
 
229 229
         foreach ($params as $key => $value) {
230
-            if (false !== strpos($key, 'custom_note_type')) {
230
+            if (false!==strpos($key, 'custom_note_type')) {
231 231
                 $customArray[$key] = $value;
232 232
             }
233 233
         }
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -178,7 +178,9 @@
 block discarded – undo
178 178
             'method'    => 'GET',
179 179
         ]);
180 180
 
181
-        if (is_null($result) || !is_array($result)) return null;
181
+        if (is_null($result) || !is_array($result)) {
182
+        	return null;
183
+        }
182 184
 
183 185
         foreach ($result as $custNoteType) {
184 186
             if (isset($custNoteType["note_custom_type"]) && $custNoteType["note_custom_type"] == $params) {
Please login to merge, or discard this patch.
src/Route4Me/Territory.php 1 patch
Indentation   +106 added lines, -106 removed lines patch added patch discarded remove patch
@@ -7,110 +7,110 @@
 block discarded – undo
7 7
 
8 8
 class Territory extends Common
9 9
 {
10
-    /**
11
-     * @var
12
-     */
13
-    public $territory_id; // Territory id
14
-    public $territory_name;
15
-    public $territory_color;
16
-    public $addresses;
17
-    public $member_id;
18
-    public $territory; // Territory parameters
19
-
20
-    public function __construct()
21
-    {
22
-        Route4Me::setBaseUrl(Endpoint::BASE_URL);
23
-    }
24
-
25
-    public static function fromArray(array $params)
26
-    {
27
-        if (!isset($params['territory_name'])) {
28
-            throw new BadParam('Territory name must be provided');
29
-        }
30
-
31
-        if (!isset($params['territory_color'])) {
32
-            throw new BadParam('Territory color must be provided');
33
-        }
34
-
35
-        if (!isset($params['territory'])) {
36
-            throw new BadParam('Territory must be provided');
37
-        }
38
-
39
-        $territoryparameters = new self();
40
-
41
-        foreach ($params as $key => $value) {
42
-            if (property_exists($territoryparameters, $key)) {
43
-                $territoryparameters->{$key} = $value;
44
-            }
45
-        }
46
-
47
-        return $territoryparameters;
48
-    }
49
-
50
-    public static function getTerritory($params)
51
-    {
52
-        $allQueryFields = ['territory_id', 'addresses'];
53
-
54
-        $territory = Route4Me::makeRequst([
55
-            'url'       => Endpoint::TERRITORY_V4,
56
-            'method'    => 'GET',
57
-            'query'     => Route4Me::generateRequestParameters($allQueryFields, $params),
58
-        ]);
59
-
60
-        return $territory;
61
-    }
62
-
63
-    public static function getTerritories($params)
64
-    {
65
-        $allQueryFields = ['offset', 'limit', 'addresses'];
66
-
67
-        $response = Route4Me::makeRequst([
68
-            'url'       => Endpoint::TERRITORY_V4,
69
-            'method'    => 'GET',
70
-            'query'     => Route4Me::generateRequestParameters($allQueryFields, $params),
71
-        ]);
72
-
73
-        return $response;
74
-    }
75
-
76
-    public static function addTerritory($params)
77
-    {
78
-        $allBodyFields = ['territory_name', 'member_id', 'territory_color', 'territory'];
79
-
80
-        $response = Route4Me::makeRequst([
81
-            'url'       => Endpoint::TERRITORY_V4,
82
-            'method'    => 'POST',
83
-            'body'      => Route4Me::generateRequestParameters($allBodyFields, $params),
84
-        ]);
85
-
86
-        return $response;
87
-    }
88
-
89
-    public function deleteTerritory($territory_id)
90
-    {
91
-        $result = Route4Me::makeRequst([
92
-            'url'       => Endpoint::TERRITORY_V4,
93
-            'method'    => 'DELETE',
94
-            'query'     => [
95
-                'territory_id' => $territory_id,
96
-            ],
97
-        ]);
98
-
99
-        return $result;
100
-    }
101
-
102
-    public function updateTerritory($params)
103
-    {
104
-        $allQueryFields = ['territory_id'];
105
-        $allBodyFields = ['territory_name', 'member_id', 'territory_color', 'territory'];
106
-
107
-        $response = Route4Me::makeRequst([
108
-            'url'       => Endpoint::TERRITORY_V4,
109
-            'method'    => 'PUT',
110
-            'query'     => Route4Me::generateRequestParameters($allQueryFields, $params),
111
-            'body'      => Route4Me::generateRequestParameters($allBodyFields, $params),
112
-        ]);
113
-
114
-        return $response;
115
-    }
10
+	/**
11
+	 * @var
12
+	 */
13
+	public $territory_id; // Territory id
14
+	public $territory_name;
15
+	public $territory_color;
16
+	public $addresses;
17
+	public $member_id;
18
+	public $territory; // Territory parameters
19
+
20
+	public function __construct()
21
+	{
22
+		Route4Me::setBaseUrl(Endpoint::BASE_URL);
23
+	}
24
+
25
+	public static function fromArray(array $params)
26
+	{
27
+		if (!isset($params['territory_name'])) {
28
+			throw new BadParam('Territory name must be provided');
29
+		}
30
+
31
+		if (!isset($params['territory_color'])) {
32
+			throw new BadParam('Territory color must be provided');
33
+		}
34
+
35
+		if (!isset($params['territory'])) {
36
+			throw new BadParam('Territory must be provided');
37
+		}
38
+
39
+		$territoryparameters = new self();
40
+
41
+		foreach ($params as $key => $value) {
42
+			if (property_exists($territoryparameters, $key)) {
43
+				$territoryparameters->{$key} = $value;
44
+			}
45
+		}
46
+
47
+		return $territoryparameters;
48
+	}
49
+
50
+	public static function getTerritory($params)
51
+	{
52
+		$allQueryFields = ['territory_id', 'addresses'];
53
+
54
+		$territory = Route4Me::makeRequst([
55
+			'url'       => Endpoint::TERRITORY_V4,
56
+			'method'    => 'GET',
57
+			'query'     => Route4Me::generateRequestParameters($allQueryFields, $params),
58
+		]);
59
+
60
+		return $territory;
61
+	}
62
+
63
+	public static function getTerritories($params)
64
+	{
65
+		$allQueryFields = ['offset', 'limit', 'addresses'];
66
+
67
+		$response = Route4Me::makeRequst([
68
+			'url'       => Endpoint::TERRITORY_V4,
69
+			'method'    => 'GET',
70
+			'query'     => Route4Me::generateRequestParameters($allQueryFields, $params),
71
+		]);
72
+
73
+		return $response;
74
+	}
75
+
76
+	public static function addTerritory($params)
77
+	{
78
+		$allBodyFields = ['territory_name', 'member_id', 'territory_color', 'territory'];
79
+
80
+		$response = Route4Me::makeRequst([
81
+			'url'       => Endpoint::TERRITORY_V4,
82
+			'method'    => 'POST',
83
+			'body'      => Route4Me::generateRequestParameters($allBodyFields, $params),
84
+		]);
85
+
86
+		return $response;
87
+	}
88
+
89
+	public function deleteTerritory($territory_id)
90
+	{
91
+		$result = Route4Me::makeRequst([
92
+			'url'       => Endpoint::TERRITORY_V4,
93
+			'method'    => 'DELETE',
94
+			'query'     => [
95
+				'territory_id' => $territory_id,
96
+			],
97
+		]);
98
+
99
+		return $result;
100
+	}
101
+
102
+	public function updateTerritory($params)
103
+	{
104
+		$allQueryFields = ['territory_id'];
105
+		$allBodyFields = ['territory_name', 'member_id', 'territory_color', 'territory'];
106
+
107
+		$response = Route4Me::makeRequst([
108
+			'url'       => Endpoint::TERRITORY_V4,
109
+			'method'    => 'PUT',
110
+			'query'     => Route4Me::generateRequestParameters($allQueryFields, $params),
111
+			'body'      => Route4Me::generateRequestParameters($allBodyFields, $params),
112
+		]);
113
+
114
+		return $response;
115
+	}
116 116
 }
Please login to merge, or discard this patch.
src/Route4Me/MyQ.php 3 patches
Indentation   +210 added lines, -210 removed lines patch added patch discarded remove patch
@@ -13,214 +13,214 @@
 block discarded – undo
13 13
 
14 14
 class MyQ
15 15
 {
16
-    /** @var string|null $username contains the username used to authenticate with the MyQ API */
17
-    protected $username = null;
18
-    /** @var string|null $password contains the password used to authenticate with the MyQ API */
19
-    protected $password = null;
20
-    /** @var string|null $appId is the application ID used to register with the MyQ API */
21
-    protected $appId = 'NWknvuBd7LoFHfXmKNMBcgajXtZEgKUh4V7WNzMidrpUUluDpVYVZx+xT4PCM5Kx';
22
-    //protected $appId = 'Vj8pQggXLhLy0WHahglCD4N1nAkkXQtGYpq2HrHD7H1nvmbT55KqtN6RSF4ILB%2fi';
23
-    /** @var string|null $securityToken is the auth token returned after a successful login */
24
-    protected $securityToken = null;
25
-    /** @var string|null $userAgent is the User-Agent header value sent with each API request */
26
-    protected $userAgent = 'Chamberlain/3.4.1';
27
-    /** @var string|null $culture is the API culture code for the API */
28
-    protected $culture = 'en';
29
-    /** @var string|null $contentType is the content type used for all cURL requests */
30
-    protected $contentType = 'application/json';
31
-    /** @var array $headers contain HTTP headers for cURL requests */
32
-    protected $_headers = [];
33
-    protected $_deviceId = null;
34
-    protected $_locationName = null;
35
-    protected $_doorName = null;
36
-    protected $_loginUrl = 'https://myqexternal.myqdevice.com/api/v4/User/Validate';
37
-    protected $_getDeviceDetailUrl = 'https://myqexternal.myqdevice.com/api/v4/userdevicedetails/get?&filterOn=true';
38
-    protected $_putDeviceStateUrl = '/api/v4/DeviceAttribute/PutDeviceAttribute';
39
-    /** @var resource|null $_conn is the web connection to the MyQ API */
40
-    protected $_conn = null;
41
-
42
-    /**
43
-     * Initializes class. Optionally allows user to override variables.
44
-     *
45
-     * @param array $params A associative array for overwriting class variables
46
-     *
47
-     * @return MyQ
48
-     */
49
-    public function __construct($params = [])
50
-    {
51
-        // Overwrite class variables
52
-        foreach ($params as $k => $v) {
53
-            $this->$k = $v;
54
-        }
55
-
56
-        // Initialize cURL request headers
57
-        if (0 == sizeof($this->_headers)) {
58
-            $this->_headers = [
59
-                'MyQApplicationId' => $this->appId,
60
-                'Culture' => $this->culture,
61
-                'Content-Type' => $this->contentType,
62
-                'User-Agent' => $this->userAgent,
63
-            ];
64
-        }
65
-
66
-        // Initialize cURL connection
67
-        $this->_init();
68
-
69
-        return $this;
70
-    }
71
-
72
-    /**
73
-     * Perform a login request.
74
-     *
75
-     * @param string|null $username Username to use when logging in
76
-     * @param string|null $password Password to use for logging in
77
-     *
78
-     * @return MyQ
79
-     */
80
-    public function login($username = null, $password = null)
81
-    {
82
-        // Set username/password if not null
83
-        if (!is_null($username)) {
84
-            $this->username = $username;
85
-        }
86
-
87
-        if (!is_null($password)) {
88
-            $this->password = $password;
89
-        }
90
-
91
-        // confirm that we have a valid username/password
92
-        $error = [];
93
-        if (is_null($this->username)) {
94
-            $error[] = 'username';
95
-        }
96
-
97
-        if (is_null($this->password)) {
98
-            $error[] = 'password';
99
-        }
100
-
101
-        if (sizeof($error) > 0) {
102
-            throw new MyQException('Missing required auth credential: '.implode(',', $error));
103
-        }
104
-
105
-        $this->_login();
106
-    }
107
-
108
-    public function getState()
109
-    {
110
-        $this->_getDetails();
111
-        $timeInState = time() - $this->_doorStateTime;
112
-        echo implode(',', [
113
-            $this->_locationName,
114
-            $this->_doorName,
115
-            $this->_doorState,
116
-            (int) $timeInState,
117
-        ]);
118
-    }
119
-
120
-    public function getDetails()
121
-    {
122
-        return $this->_getDetails();
123
-    }
124
-
125
-    private function _init()
126
-    {
127
-        if (!isset($this->_conn)) {
128
-            $this->_conn = curl_init();
129
-
130
-            curl_setopt_array($this->_conn, [
131
-                CURLOPT_RETURNTRANSFER => true,
132
-                CURLOPT_ENCODING => '',
133
-                CURLOPT_MAXREDIRS => 10,
134
-                CURLOPT_TIMEOUT => 30,
135
-                CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
136
-                CURLOPT_FAILONERROR => true,
137
-                CURLOPT_FOLLOWLOCATION => true,
138
-                CURLOPT_FRESH_CONNECT => true,
139
-                CURLOPT_FORBID_REUSE => true,
140
-                CURLOPT_USERAGENT => $this->userAgent,
141
-            ]);
142
-        }
143
-
144
-        $this->_setHeaders();
145
-    }
146
-
147
-    private function _setHeaders()
148
-    {
149
-        $headers = [];
150
-
151
-        foreach ($this->_headers as $k => $v) {
152
-            $headers[] = "$k: $v";
153
-        }
154
-
155
-        curl_setopt($this->_conn, CURLOPT_HTTPHEADER, $headers);
156
-    }
157
-
158
-    private function _login()
159
-    {
160
-        $this->_init();
161
-
162
-        curl_setopt($this->_conn, CURLOPT_CUSTOMREQUEST, 'POST');
163
-        curl_setopt($this->_conn, CURLOPT_URL, $this->_loginUrl);
164
-
165
-        $post = json_encode(['username' => $this->username, 'password' => $this->password]);
166
-
167
-        curl_setopt($this->_conn, CURLOPT_POSTFIELDS, $post);
168
-
169
-        $output = curl_exec($this->_conn);
170
-
171
-        $data = json_decode($output);
172
-
173
-        if (false == $data || !isset($data->SecurityToken)) {
174
-            throw new MyQException("Error processing login request: $output");
175
-        }
176
-
177
-        $this->_headers['SecurityToken'] = $data->SecurityToken;
178
-
179
-        return $this;
180
-    }
181
-
182
-    private function _getDetails()
183
-    {
184
-        $this->_init();
185
-
186
-        curl_setopt($this->_conn, CURLOPT_CUSTOMREQUEST, 'GET');
187
-        curl_setopt($this->_conn, CURLOPT_URL, $this->_getDeviceDetailUrl);
188
-
189
-        $output = curl_exec($this->_conn);
190
-
191
-        $data = json_decode($output);
192
-
193
-        if (false == $data || !isset($data->Devices)) {
194
-            throw new MyQException("Error fetching device details: $output");
195
-        }
196
-
197
-        // Find our door device ID
198
-        foreach ($data->Devices as $device) {
199
-            if (false !== stripos($device->MyQDeviceTypeName, 'Gateway')) {
200
-                // Find location name
201
-                foreach ($device->Attributes as $attr) {
202
-                    if ('desc' == $attr->AttributeDisplayName) {
203
-                        $this->_locationName = $attr->Value;
204
-                    }
205
-                }
206
-            }
207
-
208
-            $this->_deviceId = $device->MyQDeviceId;
209
-
210
-            foreach ($device->Attributes as $attr) {
211
-                switch ($attr->AttributeDisplayName) {
212
-                    case 'desc':
213
-                        $this->_doorName = $attr->Value;
214
-                        break;
215
-                    case 'doorstate':
216
-                        $this->_doorState = $attr->Value;
217
-                        // UpdatedTime is a timestamp in ms, so we truncate
218
-                        $this->_doorStateTime = (int) $attr->UpdatedTime / 1000;
219
-                        break;
220
-                    default:
221
-                        continue;
222
-                }
223
-            }
224
-        }
225
-    }
16
+	/** @var string|null $username contains the username used to authenticate with the MyQ API */
17
+	protected $username = null;
18
+	/** @var string|null $password contains the password used to authenticate with the MyQ API */
19
+	protected $password = null;
20
+	/** @var string|null $appId is the application ID used to register with the MyQ API */
21
+	protected $appId = 'NWknvuBd7LoFHfXmKNMBcgajXtZEgKUh4V7WNzMidrpUUluDpVYVZx+xT4PCM5Kx';
22
+	//protected $appId = 'Vj8pQggXLhLy0WHahglCD4N1nAkkXQtGYpq2HrHD7H1nvmbT55KqtN6RSF4ILB%2fi';
23
+	/** @var string|null $securityToken is the auth token returned after a successful login */
24
+	protected $securityToken = null;
25
+	/** @var string|null $userAgent is the User-Agent header value sent with each API request */
26
+	protected $userAgent = 'Chamberlain/3.4.1';
27
+	/** @var string|null $culture is the API culture code for the API */
28
+	protected $culture = 'en';
29
+	/** @var string|null $contentType is the content type used for all cURL requests */
30
+	protected $contentType = 'application/json';
31
+	/** @var array $headers contain HTTP headers for cURL requests */
32
+	protected $_headers = [];
33
+	protected $_deviceId = null;
34
+	protected $_locationName = null;
35
+	protected $_doorName = null;
36
+	protected $_loginUrl = 'https://myqexternal.myqdevice.com/api/v4/User/Validate';
37
+	protected $_getDeviceDetailUrl = 'https://myqexternal.myqdevice.com/api/v4/userdevicedetails/get?&filterOn=true';
38
+	protected $_putDeviceStateUrl = '/api/v4/DeviceAttribute/PutDeviceAttribute';
39
+	/** @var resource|null $_conn is the web connection to the MyQ API */
40
+	protected $_conn = null;
41
+
42
+	/**
43
+	 * Initializes class. Optionally allows user to override variables.
44
+	 *
45
+	 * @param array $params A associative array for overwriting class variables
46
+	 *
47
+	 * @return MyQ
48
+	 */
49
+	public function __construct($params = [])
50
+	{
51
+		// Overwrite class variables
52
+		foreach ($params as $k => $v) {
53
+			$this->$k = $v;
54
+		}
55
+
56
+		// Initialize cURL request headers
57
+		if (0 == sizeof($this->_headers)) {
58
+			$this->_headers = [
59
+				'MyQApplicationId' => $this->appId,
60
+				'Culture' => $this->culture,
61
+				'Content-Type' => $this->contentType,
62
+				'User-Agent' => $this->userAgent,
63
+			];
64
+		}
65
+
66
+		// Initialize cURL connection
67
+		$this->_init();
68
+
69
+		return $this;
70
+	}
71
+
72
+	/**
73
+	 * Perform a login request.
74
+	 *
75
+	 * @param string|null $username Username to use when logging in
76
+	 * @param string|null $password Password to use for logging in
77
+	 *
78
+	 * @return MyQ
79
+	 */
80
+	public function login($username = null, $password = null)
81
+	{
82
+		// Set username/password if not null
83
+		if (!is_null($username)) {
84
+			$this->username = $username;
85
+		}
86
+
87
+		if (!is_null($password)) {
88
+			$this->password = $password;
89
+		}
90
+
91
+		// confirm that we have a valid username/password
92
+		$error = [];
93
+		if (is_null($this->username)) {
94
+			$error[] = 'username';
95
+		}
96
+
97
+		if (is_null($this->password)) {
98
+			$error[] = 'password';
99
+		}
100
+
101
+		if (sizeof($error) > 0) {
102
+			throw new MyQException('Missing required auth credential: '.implode(',', $error));
103
+		}
104
+
105
+		$this->_login();
106
+	}
107
+
108
+	public function getState()
109
+	{
110
+		$this->_getDetails();
111
+		$timeInState = time() - $this->_doorStateTime;
112
+		echo implode(',', [
113
+			$this->_locationName,
114
+			$this->_doorName,
115
+			$this->_doorState,
116
+			(int) $timeInState,
117
+		]);
118
+	}
119
+
120
+	public function getDetails()
121
+	{
122
+		return $this->_getDetails();
123
+	}
124
+
125
+	private function _init()
126
+	{
127
+		if (!isset($this->_conn)) {
128
+			$this->_conn = curl_init();
129
+
130
+			curl_setopt_array($this->_conn, [
131
+				CURLOPT_RETURNTRANSFER => true,
132
+				CURLOPT_ENCODING => '',
133
+				CURLOPT_MAXREDIRS => 10,
134
+				CURLOPT_TIMEOUT => 30,
135
+				CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
136
+				CURLOPT_FAILONERROR => true,
137
+				CURLOPT_FOLLOWLOCATION => true,
138
+				CURLOPT_FRESH_CONNECT => true,
139
+				CURLOPT_FORBID_REUSE => true,
140
+				CURLOPT_USERAGENT => $this->userAgent,
141
+			]);
142
+		}
143
+
144
+		$this->_setHeaders();
145
+	}
146
+
147
+	private function _setHeaders()
148
+	{
149
+		$headers = [];
150
+
151
+		foreach ($this->_headers as $k => $v) {
152
+			$headers[] = "$k: $v";
153
+		}
154
+
155
+		curl_setopt($this->_conn, CURLOPT_HTTPHEADER, $headers);
156
+	}
157
+
158
+	private function _login()
159
+	{
160
+		$this->_init();
161
+
162
+		curl_setopt($this->_conn, CURLOPT_CUSTOMREQUEST, 'POST');
163
+		curl_setopt($this->_conn, CURLOPT_URL, $this->_loginUrl);
164
+
165
+		$post = json_encode(['username' => $this->username, 'password' => $this->password]);
166
+
167
+		curl_setopt($this->_conn, CURLOPT_POSTFIELDS, $post);
168
+
169
+		$output = curl_exec($this->_conn);
170
+
171
+		$data = json_decode($output);
172
+
173
+		if (false == $data || !isset($data->SecurityToken)) {
174
+			throw new MyQException("Error processing login request: $output");
175
+		}
176
+
177
+		$this->_headers['SecurityToken'] = $data->SecurityToken;
178
+
179
+		return $this;
180
+	}
181
+
182
+	private function _getDetails()
183
+	{
184
+		$this->_init();
185
+
186
+		curl_setopt($this->_conn, CURLOPT_CUSTOMREQUEST, 'GET');
187
+		curl_setopt($this->_conn, CURLOPT_URL, $this->_getDeviceDetailUrl);
188
+
189
+		$output = curl_exec($this->_conn);
190
+
191
+		$data = json_decode($output);
192
+
193
+		if (false == $data || !isset($data->Devices)) {
194
+			throw new MyQException("Error fetching device details: $output");
195
+		}
196
+
197
+		// Find our door device ID
198
+		foreach ($data->Devices as $device) {
199
+			if (false !== stripos($device->MyQDeviceTypeName, 'Gateway')) {
200
+				// Find location name
201
+				foreach ($device->Attributes as $attr) {
202
+					if ('desc' == $attr->AttributeDisplayName) {
203
+						$this->_locationName = $attr->Value;
204
+					}
205
+				}
206
+			}
207
+
208
+			$this->_deviceId = $device->MyQDeviceId;
209
+
210
+			foreach ($device->Attributes as $attr) {
211
+				switch ($attr->AttributeDisplayName) {
212
+					case 'desc':
213
+						$this->_doorName = $attr->Value;
214
+						break;
215
+					case 'doorstate':
216
+						$this->_doorState = $attr->Value;
217
+						// UpdatedTime is a timestamp in ms, so we truncate
218
+						$this->_doorStateTime = (int) $attr->UpdatedTime / 1000;
219
+						break;
220
+					default:
221
+						continue;
222
+				}
223
+			}
224
+		}
225
+	}
226 226
 }
Please login to merge, or discard this patch.
Switch Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -209,16 +209,16 @@
 block discarded – undo
209 209
 
210 210
             foreach ($device->Attributes as $attr) {
211 211
                 switch ($attr->AttributeDisplayName) {
212
-                    case 'desc':
213
-                        $this->_doorName = $attr->Value;
214
-                        break;
215
-                    case 'doorstate':
216
-                        $this->_doorState = $attr->Value;
217
-                        // UpdatedTime is a timestamp in ms, so we truncate
218
-                        $this->_doorStateTime = (int) $attr->UpdatedTime / 1000;
219
-                        break;
220
-                    default:
221
-                        continue;
212
+                case 'desc':
213
+                    $this->_doorName = $attr->Value;
214
+                    break;
215
+                case 'doorstate':
216
+                    $this->_doorState = $attr->Value;
217
+                    // UpdatedTime is a timestamp in ms, so we truncate
218
+                    $this->_doorStateTime = (int) $attr->UpdatedTime / 1000;
219
+                    break;
220
+                default:
221
+                    continue;
222 222
                 }
223 223
             }
224 224
         }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
         }
55 55
 
56 56
         // Initialize cURL request headers
57
-        if (0 == sizeof($this->_headers)) {
57
+        if (0==sizeof($this->_headers)) {
58 58
             $this->_headers = [
59 59
                 'MyQApplicationId' => $this->appId,
60 60
                 'Culture' => $this->culture,
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
             $error[] = 'password';
99 99
         }
100 100
 
101
-        if (sizeof($error) > 0) {
101
+        if (sizeof($error)>0) {
102 102
             throw new MyQException('Missing required auth credential: '.implode(',', $error));
103 103
         }
104 104
 
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
             $this->_locationName,
114 114
             $this->_doorName,
115 115
             $this->_doorState,
116
-            (int) $timeInState,
116
+            (int)$timeInState,
117 117
         ]);
118 118
     }
119 119
 
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
 
171 171
         $data = json_decode($output);
172 172
 
173
-        if (false == $data || !isset($data->SecurityToken)) {
173
+        if (false==$data || !isset($data->SecurityToken)) {
174 174
             throw new MyQException("Error processing login request: $output");
175 175
         }
176 176
 
@@ -190,16 +190,16 @@  discard block
 block discarded – undo
190 190
 
191 191
         $data = json_decode($output);
192 192
 
193
-        if (false == $data || !isset($data->Devices)) {
193
+        if (false==$data || !isset($data->Devices)) {
194 194
             throw new MyQException("Error fetching device details: $output");
195 195
         }
196 196
 
197 197
         // Find our door device ID
198 198
         foreach ($data->Devices as $device) {
199
-            if (false !== stripos($device->MyQDeviceTypeName, 'Gateway')) {
199
+            if (false!==stripos($device->MyQDeviceTypeName, 'Gateway')) {
200 200
                 // Find location name
201 201
                 foreach ($device->Attributes as $attr) {
202
-                    if ('desc' == $attr->AttributeDisplayName) {
202
+                    if ('desc'==$attr->AttributeDisplayName) {
203 203
                         $this->_locationName = $attr->Value;
204 204
                     }
205 205
                 }
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
                     case 'doorstate':
216 216
                         $this->_doorState = $attr->Value;
217 217
                         // UpdatedTime is a timestamp in ms, so we truncate
218
-                        $this->_doorStateTime = (int) $attr->UpdatedTime / 1000;
218
+                        $this->_doorStateTime = (int)$attr->UpdatedTime / 1000;
219 219
                         break;
220 220
                     default:
221 221
                         continue;
Please login to merge, or discard this patch.