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
src/Route4Me/V5/AccountProfile.php 1 patch
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -9,46 +9,46 @@
 block discarded – undo
9 9
  */
10 10
 class AccountProfile extends Common
11 11
 {
12
-    /**
13
-     * Account profile email
14
-     * @var type string
15
-     */
16
-    public $email;
12
+	/**
13
+	 * Account profile email
14
+	 * @var type string
15
+	 */
16
+	public $email;
17 17
     
18
-    /**
19
-     * Account member ID
20
-     * @var type integer
21
-     */
22
-    public $member_id;
18
+	/**
19
+	 * Account member ID
20
+	 * @var type integer
21
+	 */
22
+	public $member_id;
23 23
     
24
-    /**
25
-     * Account API key
26
-     * @var type string
27
-     */
28
-    public $api_key;
24
+	/**
25
+	 * Account API key
26
+	 * @var type string
27
+	 */
28
+	public $api_key;
29 29
     
30
-    /**
31
-     * Account root member ID
32
-     * @var type integer
33
-     */
34
-    public $root_member_id;
30
+	/**
31
+	 * Account root member ID
32
+	 * @var type integer
33
+	 */
34
+	public $root_member_id;
35 35
     
36
-    /**
37
-     * Preferred units of the account.
38
-     * @var type string
39
-     */
40
-    public $preferred_units;
36
+	/**
37
+	 * Preferred units of the account.
38
+	 * @var type string
39
+	 */
40
+	public $preferred_units;
41 41
     
42
-    public static function fromArray(array $params)
43
-    {
44
-        $thisParams = new self();
42
+	public static function fromArray(array $params)
43
+	{
44
+		$thisParams = new self();
45 45
 
46
-        foreach ($params as $key => $value) {
47
-            if (property_exists($thisParams, $key)) {
48
-                $thisParams->{$key} = $value;
49
-            }
50
-        }
46
+		foreach ($params as $key => $value) {
47
+			if (property_exists($thisParams, $key)) {
48
+				$thisParams->{$key} = $value;
49
+			}
50
+		}
51 51
 
52
-        return $thisParams;
53
-    }
52
+		return $thisParams;
53
+	}
54 54
 }
Please login to merge, or discard this patch.
src/Route4Me/V5/TelematicsVendorFeature.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -9,10 +9,10 @@  discard block
 block discarded – undo
9 9
  */
10 10
 class TelematicsVendorFeature extends Common
11 11
 {
12
-    /**
13
-     * Feature ID
14
-     * @var type string
15
-     */
12
+	/**
13
+	 * Feature ID
14
+	 * @var type string
15
+	 */
16 16
    public $id;
17 17
    
18 18
    /**
@@ -33,16 +33,16 @@  discard block
 block discarded – undo
33 33
     */
34 34
    public $feature_group;
35 35
 
36
-    public static function fromArray(array $params)
37
-    {
38
-        $thisParams = new self();
36
+	public static function fromArray(array $params)
37
+	{
38
+		$thisParams = new self();
39 39
 
40
-        foreach ($params as $key => $value) {
41
-            if (property_exists($thisParams, $key)) {
42
-                $thisParams->{$key} = $value;
43
-            }
44
-        }
40
+		foreach ($params as $key => $value) {
41
+			if (property_exists($thisParams, $key)) {
42
+				$thisParams->{$key} = $value;
43
+			}
44
+		}
45 45
 
46
-        return $thisParams;
47
-    }
46
+		return $thisParams;
47
+	}
48 48
 }
Please login to merge, or discard this patch.
src/Route4Me/V5/DataObjectBase.php 1 patch
Indentation   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -6,33 +6,33 @@
 block discarded – undo
6 6
 
7 7
 class DataObjectBase extends \Route4Me\Common
8 8
 {
9
-    /** @var string $optimization_problem_id
10
-     * Optimization problem ID
11
-     */
12
-    public $optimization_problem_id;
13
-
14
-    /** @var string $smart_optimization_id
15
-     * Smart Optimization Problem ID
16
-     */
17
-    public $smart_optimization_id;
18
-
19
-    /** @var long $created_timestamp
20
-     * When the optimization problem was created.
21
-     */
22
-    public $created_timestamp;
23
-
24
-    /** @var RouteParameters $parameters
25
-     * Route Parameters.
26
-     */
27
-    public $parameters = [];
28
-
29
-    /** @var Address[] $addresses
30
-     * An array ot the Address type objects.
31
-     */
32
-    public $addresses = [];
33
-
34
-    /** @var string[] $links
35
-     * The links to the GET operations for the optimization problem.
36
-     */
37
-    public $links = [];
9
+	/** @var string $optimization_problem_id
10
+	 * Optimization problem ID
11
+	 */
12
+	public $optimization_problem_id;
13
+
14
+	/** @var string $smart_optimization_id
15
+	 * Smart Optimization Problem ID
16
+	 */
17
+	public $smart_optimization_id;
18
+
19
+	/** @var long $created_timestamp
20
+	 * When the optimization problem was created.
21
+	 */
22
+	public $created_timestamp;
23
+
24
+	/** @var RouteParameters $parameters
25
+	 * Route Parameters.
26
+	 */
27
+	public $parameters = [];
28
+
29
+	/** @var Address[] $addresses
30
+	 * An array ot the Address type objects.
31
+	 */
32
+	public $addresses = [];
33
+
34
+	/** @var string[] $links
35
+	 * The links to the GET operations for the optimization problem.
36
+	 */
37
+	public $links = [];
38 38
 }
39 39
\ No newline at end of file
Please login to merge, or discard this patch.
src/Route4Me/ScheduleCalendarParameters.php 1 patch
Indentation   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -9,101 +9,101 @@
 block discarded – undo
9 9
  */
10 10
 class ScheduleCalendarParameters extends Common
11 11
 {
12
-    /**
13
-     * Start date to filter the schedules in the string format<br>
14
-     * (e.g. 2020-10-27).
15
-     * @var string
16
-     */
17
-    public $date_from_string;
18
-
19
-    /**
20
-     * End date to filter the schedules in the string format<br>
21
-     * (e.g. 2020-10-30).
22
-     * @var string
23
-     */
24
-    public $date_to_string;
25
-
26
-    /**
27
-     * Member ID
28
-     * @var integer
29
-     */
30
-    public $member_id;
31
-
32
-    /**
33
-     * Timezone offset (in minutes)<br>
34
-     * (e.g. NYT: -4*60 = -480, Kiev: 3*60 = 180).
35
-     * @var integer
36
-     */
37
-    public $timezone_offset_minutes;
38
-
39
-    /**
40
-     * If true, the scheduled orders are included in the calendar.
41
-     * @var Boolean
42
-     */
43
-    public $orders;
44
-
45
-    /**
46
-     * If true, the scheduled address book contacts
47
-     * are included in the calendar.
48
-     * @var Boolean
49
-     */
50
-    public $ab;
51
-
52
-    /**
53
-     * If true, the scheduled routes are included in the calendar.
54
-     * @var Boolean
55
-     */
56
-    public $routes_count;
57
-
58
-    /**
59
-     * Class constructor.
60
-     * @var
61
-     */
62
-    public function __construct()
63
-    {
64
-        Route4Me::setBaseUrl(Endpoint::BASE_URL);
65
-    }
66
-
67
-    /**
68
-     * Convert an array to this object
69
-     */
70
-    public static function fromArray(array $params)
71
-    {
72
-        $scheduleCalendarParameters = new self();
73
-
74
-        foreach ($params as $key => $value) {
75
-            if (property_exists($scheduleCalendarParameters, $key)) {
76
-                $scheduleCalendarParameters->{$key} = $value;
77
-            }
78
-        }
79
-
80
-        return $scheduleCalendarParameters;
81
-    }
82
-
83
-    public function setTimezoneOffsetMinutes($tz)
84
-    {
85
-        $this->timezone_offset_minutes = -$tz;
86
-    }
87
-
88
-    public function getTimezoneOffsetMinutes()
89
-    {
90
-        if (is_numeric($this->timezone_offset_minutes)) {
91
-            return -$this->timezone_offset_minutes;
92
-        } else {
93
-            return 0;
94
-        }
95
-    }
96
-
97
-    public function getScheduleCalendar($params)
98
-    {
99
-        $allQueryFields = ['date_from_string', 'date_to_string', 'member_id', 'timezone_offset_minutes', 'orders', 'ab', 'routes_count'];
100
-
101
-        $schedCalendar = Route4Me::makeRequst([
102
-            'url'       => Endpoint::SCHEDULE_CALENDAR,
103
-            'method'    => 'GET',
104
-            'query'     => Route4Me::generateRequestParameters($allQueryFields, $params),
105
-        ]);
106
-
107
-        return $schedCalendar;
108
-    }
12
+	/**
13
+	 * Start date to filter the schedules in the string format<br>
14
+	 * (e.g. 2020-10-27).
15
+	 * @var string
16
+	 */
17
+	public $date_from_string;
18
+
19
+	/**
20
+	 * End date to filter the schedules in the string format<br>
21
+	 * (e.g. 2020-10-30).
22
+	 * @var string
23
+	 */
24
+	public $date_to_string;
25
+
26
+	/**
27
+	 * Member ID
28
+	 * @var integer
29
+	 */
30
+	public $member_id;
31
+
32
+	/**
33
+	 * Timezone offset (in minutes)<br>
34
+	 * (e.g. NYT: -4*60 = -480, Kiev: 3*60 = 180).
35
+	 * @var integer
36
+	 */
37
+	public $timezone_offset_minutes;
38
+
39
+	/**
40
+	 * If true, the scheduled orders are included in the calendar.
41
+	 * @var Boolean
42
+	 */
43
+	public $orders;
44
+
45
+	/**
46
+	 * If true, the scheduled address book contacts
47
+	 * are included in the calendar.
48
+	 * @var Boolean
49
+	 */
50
+	public $ab;
51
+
52
+	/**
53
+	 * If true, the scheduled routes are included in the calendar.
54
+	 * @var Boolean
55
+	 */
56
+	public $routes_count;
57
+
58
+	/**
59
+	 * Class constructor.
60
+	 * @var
61
+	 */
62
+	public function __construct()
63
+	{
64
+		Route4Me::setBaseUrl(Endpoint::BASE_URL);
65
+	}
66
+
67
+	/**
68
+	 * Convert an array to this object
69
+	 */
70
+	public static function fromArray(array $params)
71
+	{
72
+		$scheduleCalendarParameters = new self();
73
+
74
+		foreach ($params as $key => $value) {
75
+			if (property_exists($scheduleCalendarParameters, $key)) {
76
+				$scheduleCalendarParameters->{$key} = $value;
77
+			}
78
+		}
79
+
80
+		return $scheduleCalendarParameters;
81
+	}
82
+
83
+	public function setTimezoneOffsetMinutes($tz)
84
+	{
85
+		$this->timezone_offset_minutes = -$tz;
86
+	}
87
+
88
+	public function getTimezoneOffsetMinutes()
89
+	{
90
+		if (is_numeric($this->timezone_offset_minutes)) {
91
+			return -$this->timezone_offset_minutes;
92
+		} else {
93
+			return 0;
94
+		}
95
+	}
96
+
97
+	public function getScheduleCalendar($params)
98
+	{
99
+		$allQueryFields = ['date_from_string', 'date_to_string', 'member_id', 'timezone_offset_minutes', 'orders', 'ab', 'routes_count'];
100
+
101
+		$schedCalendar = Route4Me::makeRequst([
102
+			'url'       => Endpoint::SCHEDULE_CALENDAR,
103
+			'method'    => 'GET',
104
+			'query'     => Route4Me::generateRequestParameters($allQueryFields, $params),
105
+		]);
106
+
107
+		return $schedCalendar;
108
+	}
109 109
 }
110 110
\ No newline at end of file
Please login to merge, or discard this patch.
src/Route4Me/OptimizationProblemParams.php 2 patches
Indentation   +127 added lines, -127 removed lines patch added patch discarded remove patch
@@ -6,131 +6,131 @@
 block discarded – undo
6 6
 
7 7
 class OptimizationProblemParams extends Common
8 8
 {
9
-    public $optimization_problem_id;
10
-    public $reoptimize;
11
-    public $addresses = [];
12
-    public $depots = [];
13
-    public $parameters;
14
-    public $directions;
15
-    public $format;
16
-    public $route_path_output;
17
-    public $optimized_callback_url;
18
-    public $redirect = true;
19
-
20
-    public static function fromArray($params)
21
-    {
22
-        $param = new self();
23
-        if (!isset($params['addresses'])) {
24
-            throw new BadParam('addresses must be provided.');
25
-        }
26
-
27
-        if (!isset($params['parameters'])) {
28
-            throw new BadParam('parameters must be provided.');
29
-        }
30
-
31
-        if ($params['parameters'] instanceof RouteParameters) {
32
-            $param->setParameters($params['parameters']);
33
-        } else {
34
-            $param->setParameters(RouteParameters::fromArray($params['parameters']));
35
-        }
36
-
37
-        foreach ($params['addresses'] as $address) {
38
-            if (!($address instanceof Address)) {
39
-                $address = Address::fromArray($address);
40
-            }
41
-
42
-            $param->addAddress($address);
43
-        }
44
-
45
-        if (isset($params['depots'] )) {
46
-            foreach ($params['depots'] as $depot) {
47
-                if (!($depot instanceof Address)) {
48
-                    $depot = Address::fromArray($depot);
49
-                }
50
-
51
-                $param->addAddress($address);
52
-            }
53
-        }
54
-
55
-        $param->directions = self::getValue($params, 'directions');
56
-        $param->format = self::getValue($params, 'format');
57
-        $param->route_path_output = self::getValue($params, 'route_path_output');
58
-        $param->optimized_callback_url = self::getValue($params, 'optimized_callback_url');
59
-        $param->optimization_problem_id = self::getValue($params, 'optimization_problem_id');
60
-        $param->reoptimize = self::getValue($params, 'reoptimize');
61
-        $param->redirect = filter_var(self::getValue($params, 'redirect', true), FILTER_VALIDATE_BOOLEAN);
62
-
63
-        return $param;
64
-    }
65
-
66
-    public function __construct()
67
-    {
68
-        $this->parameters = new RouteParameters();
69
-    }
70
-
71
-    public function setParameters(RouteParameters $params)
72
-    {
73
-        $this->parameters = $params;
74
-
75
-        return $this;
76
-    }
77
-
78
-    public function addAddress(Address $address)
79
-    {
80
-        $this->addresses[] = $address;
81
-
82
-        return $this;
83
-    }
84
-
85
-    public function addDepot(Address $depot)
86
-    {
87
-        $this->depots[] = $depot;
88
-
89
-        return $this;
90
-    }
91
-
92
-    public function getAddressesArray()
93
-    {
94
-        $addresses = [];
95
-
96
-        foreach ($this->addresses as $address) {
97
-            $addresses[] = $address->toArray();
98
-        }
99
-
100
-        return $addresses;
101
-    }
102
-
103
-    public function getDepotsArray()
104
-    {
105
-        $depots = [];
106
-
107
-        foreach ($this->depots as $depot) {
108
-            $depots[] = $depot->toArray();
109
-        }
110
-
111
-        return $depots;
112
-    }
113
-
114
-    public function getParametersArray()
115
-    {
116
-        return $this->parameters->toArray();
117
-    }
118
-
119
-    public function setAddresses(array $addresses)
120
-    {
121
-        foreach ($addresses as $address) {
122
-            $this->addAddress($address);
123
-        }
124
-
125
-        return $this;
126
-    }
127
-
128
-    public function setDepots(array $depots)
129
-    {
130
-        foreach ($depots as $depot) {
131
-            $this->addDepot($depot);
132
-        }
133
-
134
-        return $this;
135
-    }
9
+	public $optimization_problem_id;
10
+	public $reoptimize;
11
+	public $addresses = [];
12
+	public $depots = [];
13
+	public $parameters;
14
+	public $directions;
15
+	public $format;
16
+	public $route_path_output;
17
+	public $optimized_callback_url;
18
+	public $redirect = true;
19
+
20
+	public static function fromArray($params)
21
+	{
22
+		$param = new self();
23
+		if (!isset($params['addresses'])) {
24
+			throw new BadParam('addresses must be provided.');
25
+		}
26
+
27
+		if (!isset($params['parameters'])) {
28
+			throw new BadParam('parameters must be provided.');
29
+		}
30
+
31
+		if ($params['parameters'] instanceof RouteParameters) {
32
+			$param->setParameters($params['parameters']);
33
+		} else {
34
+			$param->setParameters(RouteParameters::fromArray($params['parameters']));
35
+		}
36
+
37
+		foreach ($params['addresses'] as $address) {
38
+			if (!($address instanceof Address)) {
39
+				$address = Address::fromArray($address);
40
+			}
41
+
42
+			$param->addAddress($address);
43
+		}
44
+
45
+		if (isset($params['depots'] )) {
46
+			foreach ($params['depots'] as $depot) {
47
+				if (!($depot instanceof Address)) {
48
+					$depot = Address::fromArray($depot);
49
+				}
50
+
51
+				$param->addAddress($address);
52
+			}
53
+		}
54
+
55
+		$param->directions = self::getValue($params, 'directions');
56
+		$param->format = self::getValue($params, 'format');
57
+		$param->route_path_output = self::getValue($params, 'route_path_output');
58
+		$param->optimized_callback_url = self::getValue($params, 'optimized_callback_url');
59
+		$param->optimization_problem_id = self::getValue($params, 'optimization_problem_id');
60
+		$param->reoptimize = self::getValue($params, 'reoptimize');
61
+		$param->redirect = filter_var(self::getValue($params, 'redirect', true), FILTER_VALIDATE_BOOLEAN);
62
+
63
+		return $param;
64
+	}
65
+
66
+	public function __construct()
67
+	{
68
+		$this->parameters = new RouteParameters();
69
+	}
70
+
71
+	public function setParameters(RouteParameters $params)
72
+	{
73
+		$this->parameters = $params;
74
+
75
+		return $this;
76
+	}
77
+
78
+	public function addAddress(Address $address)
79
+	{
80
+		$this->addresses[] = $address;
81
+
82
+		return $this;
83
+	}
84
+
85
+	public function addDepot(Address $depot)
86
+	{
87
+		$this->depots[] = $depot;
88
+
89
+		return $this;
90
+	}
91
+
92
+	public function getAddressesArray()
93
+	{
94
+		$addresses = [];
95
+
96
+		foreach ($this->addresses as $address) {
97
+			$addresses[] = $address->toArray();
98
+		}
99
+
100
+		return $addresses;
101
+	}
102
+
103
+	public function getDepotsArray()
104
+	{
105
+		$depots = [];
106
+
107
+		foreach ($this->depots as $depot) {
108
+			$depots[] = $depot->toArray();
109
+		}
110
+
111
+		return $depots;
112
+	}
113
+
114
+	public function getParametersArray()
115
+	{
116
+		return $this->parameters->toArray();
117
+	}
118
+
119
+	public function setAddresses(array $addresses)
120
+	{
121
+		foreach ($addresses as $address) {
122
+			$this->addAddress($address);
123
+		}
124
+
125
+		return $this;
126
+	}
127
+
128
+	public function setDepots(array $depots)
129
+	{
130
+		foreach ($depots as $depot) {
131
+			$this->addDepot($depot);
132
+		}
133
+
134
+		return $this;
135
+	}
136 136
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@
 block discarded – undo
42 42
             $param->addAddress($address);
43 43
         }
44 44
 
45
-        if (isset($params['depots'] )) {
45
+        if (isset($params['depots'])) {
46 46
             foreach ($params['depots'] as $depot) {
47 47
                 if (!($depot instanceof Address)) {
48 48
                     $depot = Address::fromArray($depot);
Please login to merge, or discard this patch.
src/Route4Me/DirectionLocation.php 1 patch
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -11,58 +11,58 @@
 block discarded – undo
11 11
  */
12 12
 class DirectionLocation extends Common
13 13
 {
14
-    /**
15
-     * Direction name
16
-     * @var string
17
-     */
18
-    public $name;
14
+	/**
15
+	 * Direction name
16
+	 * @var string
17
+	 */
18
+	public $name;
19 19
 
20
-    /**
21
-     * Required time for passing the segment (seconds)
22
-     * @var integer
23
-     */
24
-    public $time;
20
+	/**
21
+	 * Required time for passing the segment (seconds)
22
+	 * @var integer
23
+	 */
24
+	public $time;
25 25
 
26
-    /**
27
-     * Segment distance
28
-     * @var double
29
-     */
30
-    public $segment_distance;
26
+	/**
27
+	 * Segment distance
28
+	 * @var double
29
+	 */
30
+	public $segment_distance;
31 31
 
32
-    /**
33
-     * Start Location
34
-     * @var string
35
-     */
36
-    public $start_location;
32
+	/**
33
+	 * Start Location
34
+	 * @var string
35
+	 */
36
+	public $start_location;
37 37
 
38
-    /**
39
-     * End Location
40
-     * @var string
41
-     */
42
-    public $end_location;
38
+	/**
39
+	 * End Location
40
+	 * @var string
41
+	 */
42
+	public $end_location;
43 43
 
44
-    /**
45
-     * Directions Error
46
-     * @var string
47
-     */
48
-    public $directions_error;
44
+	/**
45
+	 * Directions Error
46
+	 * @var string
47
+	 */
48
+	public $directions_error;
49 49
 
50
-    /**
51
-     * Error Code
52
-     * @var integer
53
-     */
54
-    public $error_code;
50
+	/**
51
+	 * Error Code
52
+	 * @var integer
53
+	 */
54
+	public $error_code;
55 55
 
56
-    public static function fromArray(array $params)
57
-    {
58
-        $thisParams = new self();
56
+	public static function fromArray(array $params)
57
+	{
58
+		$thisParams = new self();
59 59
 
60
-        foreach ($params as $key => $value) {
61
-            if (property_exists($thisParams, $key)) {
62
-                $thisParams->{$key} = $value;
63
-            }
64
-        }
60
+		foreach ($params as $key => $value) {
61
+			if (property_exists($thisParams, $key)) {
62
+				$thisParams->{$key} = $value;
63
+			}
64
+		}
65 65
 
66
-        return $thisParams;
67
-    }
66
+		return $thisParams;
67
+	}
68 68
 }
69 69
\ No newline at end of file
Please login to merge, or discard this patch.
src/Route4Me/Common.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -11,8 +11,8 @@
 block discarded – undo
11 11
 
12 12
     public function toArray()
13 13
     {
14
-        $params = array_filter(get_object_vars($this), function ($item) {
15
-            return (null !== $item) && !(is_array($item) && !count($item));
14
+        $params = array_filter(get_object_vars($this), function($item) {
15
+            return (null!==$item) && !(is_array($item) && !count($item));
16 16
         });
17 17
 
18 18
         return $params;
Please login to merge, or discard this patch.
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -4,26 +4,26 @@
 block discarded – undo
4 4
 
5 5
 class Common
6 6
 {
7
-    public static function getValue($array, $item, $default = null)
8
-    {
9
-        return (isset($array[$item])) ? $array[$item] : $default;
10
-    }
7
+	public static function getValue($array, $item, $default = null)
8
+	{
9
+		return (isset($array[$item])) ? $array[$item] : $default;
10
+	}
11 11
 
12
-    public function toArray()
13
-    {
14
-        $params = array_filter(get_object_vars($this), function ($item) {
15
-            return (null !== $item) && !(is_array($item) && !count($item));
16
-        });
12
+	public function toArray()
13
+	{
14
+		$params = array_filter(get_object_vars($this), function ($item) {
15
+			return (null !== $item) && !(is_array($item) && !count($item));
16
+		});
17 17
 
18
-        return $params;
19
-    }
18
+		return $params;
19
+	}
20 20
 
21
-    protected function fillFromArray(array $params)
22
-    {
23
-        foreach ($this as $key => $value) {
24
-            if (isset($params[$key])) {
25
-                $this->{$key} = $params[$key];
26
-            }
27
-        }
28
-    }
21
+	protected function fillFromArray(array $params)
22
+	{
23
+		foreach ($this as $key => $value) {
24
+			if (isset($params[$key])) {
25
+				$this->{$key} = $params[$key];
26
+			}
27
+		}
28
+	}
29 29
 }
Please login to merge, or discard this patch.
src/Route4Me/Route.php 2 patches
Indentation   +805 added lines, -805 removed lines patch added patch discarded remove patch
@@ -12,809 +12,809 @@
 block discarded – undo
12 12
  */
13 13
 class Route extends Common
14 14
 {
15
-    /**
16
-     * The route ID
17
-     * @var string
18
-     */
19
-    public $route_id;
20
-
21
-    /**
22
-     * Member ID of a route owner
23
-     * @var integer
24
-     */
25
-    public $member_id;
26
-
27
-    /**
28
-     * Optimization problem ID
29
-     * @var string
30
-     */
31
-    public $optimization_problem_id;
32
-
33
-    /**
34
-     * Vehicle alias
35
-     * @var string
36
-     */
37
-    public $vehicle_alias;
38
-
39
-    /**
40
-     * Driver alias
41
-     * @var string
42
-     */
43
-    public $driver_alias;
44
-
45
-    /**
46
-     * Total route's trip distance
47
-     * @var double
48
-     */
49
-    public $trip_distance;
50
-
51
-    /**
52
-     * The UDU distance measurement unit for the route.<br>
53
-     * @note km or mi, the route4me api will convert all distance measurements into these units.
54
-     * @var string
55
-     */
56
-    public $udu_distance_unit;
57
-
58
-    /**
59
-     * Total route's UDU trip distance
60
-     * @var double
61
-     */
62
-    public $udu_trip_distance;
63
-
64
-    /** Miles per gallon
65
-     * @var double
66
-     */
67
-    public $mpg;
68
-
69
-    /**
70
-     * Gas price
71
-     * @var double
72
-     */
73
-    public $gas_price;
74
-
75
-    /**
76
-     * Total route duration (seconds)
77
-     * @var integer
78
-     */
79
-    public $route_duration_sec;
80
-
81
-    /**
82
-     * Number of the destinations in the route.
83
-     * @var integer
84
-     */
85
-    public $destination_count;
86
-
87
-    /**
88
-     * Notes count in the route.
89
-     * @var integer
90
-     */
91
-    public $notes_count;
92
-
93
-    /**
94
-     * Route parameters
95
-     * @var RouteParameters
96
-     */
97
-    public $parameters;
98
-
99
-    /**
100
-     * An array of the route addresses
101
-     * @var Address[]
102
-     */
103
-    public $addresses = [];
104
-
105
-    /**
106
-     * An array of the links
107
-     * @var string[]
108
-     */
109
-    public $links = [];
110
-
111
-    /**
112
-     * Edge by edge turn-by-turn directions.
113
-     * @var Direction[]
114
-     */
115
-    public $directions = [];
116
-
117
-    /**
118
-     * Edge-wise path to be drawn on the map.
119
-     * @var GeoPoint[]
120
-     */
121
-    public $path = [];
122
-
123
-    /**
124
-     * A collection of device tracking data with coordinates, speed, and timestamps.
125
-     * @var Tracking\TrackingHistory[]
126
-     */
127
-    public $tracking_history = [];
128
-
129
-    /**
130
-     * HTTP headers
131
-     * @var string
132
-     */
133
-    public $httpheaders;
134
-
135
-    /**
136
-     * If true, the route is unrouted.
137
-     * @var Boolean
138
-     */
139
-    public $is_unrouted;
140
-
141
-    /**
142
-     * User route rating [0, 5]. A null value means no rating was given.<br>
143
-     * Users can rate routes so that future optimizations take these ratings into account.
144
-     * @var integer
145
-     */
146
-    public $user_route_rating;
147
-
148
-    /**
149
-     * The member's email
150
-     * @var string
151
-     */
152
-    public $member_email;
153
-
154
-    /**
155
-     * URL to a member picture
156
-     * @var string
157
-     */
158
-    public $member_picture;
159
-
160
-    /**
161
-     * Member tracking subheadline.
162
-     * @var string
163
-     */
164
-    public $member_tracking_subheadline;
165
-
166
-    /**
167
-     * If true, the order is approved for execution.
168
-     * @var Boolean
169
-     */
170
-    public $approved_for_execution;
171
-
172
-    /**
173
-     * Counter of the approved revisions.
174
-     * @var integer
175
-     */
176
-    public $approved_revisions_counter;
177
-
178
-    /**
179
-     * The member's first name.
180
-     * @var string
181
-     */
182
-    public $member_first_name;
183
-
184
-    /**
185
-     * The member's last name.
186
-     * @var string
187
-     */
188
-    public $member_last_name;
189
-
190
-    /**
191
-     * Channel name
192
-     * @var string
193
-     */
194
-    public $channel_name;
195
-
196
-    /**
197
-     * Total cost of the route.
198
-     * @var double
199
-     */
200
-    public $route_cost;
201
-
202
-    /**
203
-     * Total route revenue
204
-     * @var double
205
-     */
206
-    public $route_revenue;
207
-
208
-    /**
209
-     * Net revenue per distance unit.
210
-     * @var double
211
-     */
212
-    public $net_revenue_per_distance_unit;
213
-
214
-    /**
215
-     * When route created (UNIX format timestamp).
216
-     * @var integer
217
-     */
218
-    public $created_timestamp;
219
-
220
-    /**
221
-     * Planned total route duration (seconds).
222
-     * @var integer
223
-     */
224
-    public $planned_total_route_duration;
225
-
226
-    /**
227
-     * Total wait time (seconds).
228
-     * @var integer
229
-     */
230
-    public $total_wait_time;
231
-
232
-    /**
233
-     * UDU Actual travel distance.
234
-     * @var double
235
-     */
236
-    public $udu_actual_travel_distance;
237
-
238
-    /**
239
-     * Actual travel distance.
240
-     * @var double
241
-     */
242
-    public $actual_travel_distance;
243
-
244
-    /**
245
-     * Actual travel time (seconds).
246
-     * @var integer
247
-     */
248
-    public $actual_travel_time;
249
-
250
-    /**
251
-     * Actual footsteps.
252
-     * @var integer
253
-     */
254
-    public $actual_footsteps;
255
-
256
-    /**
257
-     * Working time.
258
-     * @var integer
259
-     */
260
-    public $working_time;
261
-
262
-    /**
263
-     * Driving time.
264
-     * @var integer
265
-     */
266
-    public $driving_time;
267
-
268
-    /**
269
-     * Idling time.
270
-     * @var integer
271
-     */
272
-    public $idling_time;
273
-
274
-    /**
275
-     * Paying miles
276
-     * @var double
277
-     */
278
-    public $paying_miles;
279
-
280
-    /**
281
-     * Geofence polygon type.<br>
282
-     * enum: ["circle", "poly", "rect"]
283
-     * @var string
284
-     */
285
-    public $geofence_polygon_type;
286
-
287
-    /**
288
-     * Geofence polygon size.
289
-     * @var integer
290
-     */
291
-    public $geofence_polygon_size;
292
-
293
-    /**
294
-     * Route notes
295
-     * @var AddressNote[]
296
-     */
297
-    public $notes=[];
298
-
299
-    /**
300
-     * A vehicle assigned to the route.
301
-     * @var Vehicles\VehicleResponseV4
302
-     */
303
-    public $vehicle=[];
304
-
305
-    /**
306
-     * Member config key-value pairs.
307
-     * @var array
308
-     */
309
-    public $member_config_storage;
310
-
311
-    /**
312
-     * Original route
313
-     * @var Route
314
-     */
315
-    public $original_route;
316
-
317
-    /**
318
-     * If true, the route will be unlinked from the master optimization.
319
-     * @var Boolean
320
-     */
321
-    public $unlink_from_master_optimization;
322
-
323
-    public function __construct()
324
-    {
325
-        Route4Me::setBaseUrl(Endpoint::BASE_URL);
326
-    }
327
-
328
-    public static function fromArray(array $params)
329
-    {
330
-        $route = new self();
331
-        $route->route_id = Common::getValue($params, 'route_id');
332
-        $route->member_id = Common::getValue($params, 'member_id');
333
-        $route->member_email = Common::getValue($params, 'member_email');
334
-        $route->member_picture = Common::getValue($params, 'member_picture');
335
-        $route->member_tracking_subheadline = Common::getValue($params, 'member_tracking_subheadline');
336
-        $route->approved_for_execution = Common::getValue($params, 'approved_for_execution');
337
-        $route->approved_revisions_counter = Common::getValue($params, 'approved_revisions_counter');
338
-        $route->member_first_name = Common::getValue($params, 'member_first_name');
339
-        $route->member_last_name = Common::getValue($params, 'member_last_name');
340
-        $route->channel_name = Common::getValue($params, 'channel_name');
341
-        $route->optimization_problem_id = Common::getValue($params, 'optimization_problem_id');
342
-        $route->user_route_rating = Common::getValue($params, 'user_route_rating');
343
-        $route->vehicle_alias = Common::getValue($params, 'vehicle_alias');
344
-        $route->driver_alias = Common::getValue($params, 'driver_alias');
345
-        $route->trip_distance = Common::getValue($params, 'trip_distance');
346
-        $route->udu_distance_unit = Common::getValue($params, 'udu_distance_unit');
347
-        $route->udu_trip_distance = Common::getValue($params, 'udu_trip_distance');
348
-        $route->mpg = Common::getValue($params, 'mpg');
349
-        $route->gas_price = Common::getValue($params, 'gas_price');
350
-        $route->route_duration_sec = Common::getvalue($params, 'route_duration_sec');
351
-        $route->planned_total_route_duration = Common::getvalue($params, 'planned_total_route_duration');
352
-        $route->total_wait_time = Common::getvalue($params, 'total_wait_time');
353
-        $route->udu_actual_travel_distance = Common::getvalue($params, 'udu_actual_travel_distance');
354
-        $route->actual_travel_distance = Common::getvalue($params, 'actual_travel_distance');
355
-        $route->actual_travel_time = Common::getvalue($params, 'actual_travel_time');
356
-        $route->actual_footsteps = Common::getvalue($params, 'actual_footsteps');
357
-        $route->working_time = Common::getvalue($params, 'working_time');
358
-        $route->driving_time = Common::getvalue($params, 'driving_time');
359
-        $route->idling_time = Common::getvalue($params, 'idling_time');
360
-        $route->paying_miles = Common::getvalue($params, 'paying_miles');
361
-        $route->geofence_polygon_type = Common::getvalue($params, 'geofence_polygon_type');
362
-        $route->geofence_polygon_size = Common::getvalue($params, 'geofence_polygon_size');
363
-        $route->destination_count = Common::getvalue($params, 'destination_count');
364
-        $route->notes_count = Common::getvalue($params, 'notes_count');
365
-        $route->is_unrouted = Common::getvalue($params, 'is_unrouted');
366
-        $route->route_cost = Common::getvalue($params, 'route_cost');
367
-        $route->route_revenue = Common::getvalue($params, 'route_revenue');
368
-        $route->net_revenue_per_distance_unit = Common::getvalue($params, 'net_revenue_per_distance_unit');
369
-        $route->created_timestamp = Common::getvalue($params, 'created_timestamp');
370
-
371
-        if (isset($params['vehicle'])) {
372
-            $route->vehicle = new Vehicle();
373
-            $route->vehicle = Vehicle::fromArray($params['vehicle']);
374
-            Route4Me::setBaseUrl(Endpoint::BASE_URL);
375
-        };
376
-
377
-        $route->member_config_storage = Common::getvalue($params, 'member_config_storage');
378
-
379
-        // Make RouteParameters
380
-        if (isset($params['parameters'])) {
381
-            $route->parameters = new RouteParameters();
382
-            $route->parameters = RouteParameters::fromArray($params['parameters']);
383
-            Route4Me::setBaseUrl(Endpoint::BASE_URL);
384
-        }
385
-
386
-        if (isset($params['addresses'])) {
387
-            $addresses = [];
388
-
389
-            foreach ($params['addresses'] as $address) {
390
-                $addresses[] = Address::fromArray($address);
391
-            }
392
-
393
-            $route->addresses = $addresses;
394
-        }
395
-
396
-        $route->links = Common::getValue($params, 'links', []);
397
-        $route->notes = Common::getValue($params, 'notes', []);
398
-        $route->directions = Common::getValue($params, 'directions', []);
399
-        $route->path = Common::getValue($params, 'path', []);
400
-        $route->tracking_history = Common::getValue($params, 'tracking_history', []);
401
-
402
-        if (isset($params['original_route'])) {
403
-            $route->original_route = Route::fromArray($params['original_route']);
404
-        };
405
-
406
-        return $route;
407
-    }
408
-
409
-    /**
410
-     * @param RouteParametersQuery $params
411
-     * @return An array of the routes
412
-     * @throws Exception\ApiError
413
-     */
414
-    public static function getRoutes($params = null)
415
-    {
416
-        $allQueryFields = ['route_id', 'original', 'route_path_output', 'query', 'directions', 'device_tracking_history', 'limit', 'offset','start_date','end_date'];
417
-
418
-        $result = Route4Me::makeRequst([
419
-            'url'       => Endpoint::ROUTE_V4,
420
-            'method'    => 'GET',
421
-            'query'     => Route4Me::generateRequestParameters($allQueryFields, $params),
422
-        ]);
423
-
424
-        if (isset($params['route_id'])) {
425
-            if (strlen($params['route_id'])==32) {
426
-                return self::fromArray($result);
427
-            } else {
428
-                return $result;
429
-            }
430
-        } else {
431
-            $routes = [];
432
-            foreach ($result as $route) {
433
-                $routes[] = self::fromArray($route);
434
-            }
435
-
436
-            return $routes;
437
-        }
438
-    }
439
-
440
-    public function getRoutePoints($params)
441
-    {
442
-        $allQueryFields = ['route_id', 'route_path_output', 'compress_path_points', 'directions'];
443
-
444
-        $result = Route4Me::makeRequst([
445
-            'url'    => Endpoint::ROUTE_V4,
446
-            'method' => 'GET',
447
-            'query'  => Route4Me::generateRequestParameters($allQueryFields, $params),
448
-        ]);
449
-
450
-        return $result;
451
-    }
452
-
453
-    public function duplicateRoute($routeIDs)
454
-    {
455
-        $result = Route4Me::makeRequst([
456
-            'url'    => Endpoint::ROUTE_V4,
457
-            'method' => 'POST',
458
-            'body'   => [
459
-                'duplicate_routes_id' => $routeIDs
460
-            ],
461
-        ]);
462
-
463
-        return $result;
464
-    }
465
-
466
-    public function resequenceRoute($params)
467
-    {
468
-        $allQueryFields = ['route_id', 'route_destination_id'];
469
-        $allBodyFields = ['addresses'];
470
-
471
-        $result = Route4Me::makeRequst([
472
-            'url'       => Endpoint::ROUTE_V4,
473
-            'method'    => 'PUT',
474
-            'query'     => Route4Me::generateRequestParameters($allQueryFields, $params),
475
-            'body'      => Route4Me::generateRequestParameters($allBodyFields, $params),
476
-        ]);
477
-
478
-        return $result;
479
-    }
480
-
481
-    /**
482
-     * @deprecated 'The method is obsolete, use the method ReoptimizeRoute instead.'
483
-     * @param $params
484
-     * @return mixed|string
485
-     */
486
-    public function resequenceAllAddresses($params)
487
-    {
488
-        $allQueryFields = ['route_id', 'disable_optimization', 'optimize'];
489
-
490
-        $result = Route4Me::makeRequst([
491
-            'url'       => Endpoint::REOPTIMIZE_V3_2,
492
-            'method'    => 'GET',
493
-            'query'     => Route4Me::generateRequestParameters($allQueryFields, $params),
494
-        ]);
495
-
496
-        return $result;
497
-    }
498
-
499
-    /**
500
-     * Reoptimize a route
501
-     * @param $params type Route
502
-     * @return mixed|string
503
-     * @throws Exception\ApiError
504
-     */
505
-    public function reoptimizeRoute($params)
506
-    {
507
-        $allQueryFields = ['route_id', 'reoptimize', 'remaining', 'device_type'];
508
-
509
-        $result = Route4Me::makeRequst([
510
-            'url'       => Endpoint::ROUTE_V4,
511
-            'method'    => 'PUT',
512
-            'query'     => Route4Me::generateRequestParameters($allQueryFields, $params),
513
-        ]);
514
-
515
-        return $result;
516
-    }
517
-
518
-    /**
519
-     * Merges the routes
520
-     * @param $params array contains:
521
-     * @param route_ids IDs of the routes to be merged.
522
-     * @param depot_address a depot address of the merged route.
523
-     * @param remove_origin if true, the origin routes will be removed.
524
-     * @param depot_lat the depot's latitude
525
-     * @param depot_lng the depot's longitude
526
-     * @return Status response
527
-     * @throws Exception\ApiError
528
-     */
529
-    public function mergeRoutes($params)
530
-    {
531
-        $allBodyFields = ['route_ids', 'depot_address', 'remove_origin', 'depot_lat',  'depot_lng'];
532
-
533
-        $result = Route4Me::makeRequst([
534
-            'url'           => Endpoint::ROUTES_MERGE,
535
-            'method'        => 'POST',
536
-            'body'          => Route4Me::generateRequestParameters($allBodyFields, $params),
537
-            'HTTPHEADER'    => 'Content-Type: multipart/form-data',
538
-        ]);
539
-
540
-        return $result;
541
-    }
542
-
543
-    /**
544
-     * Share a route by an email
545
-     * @param $params RouteParametersQuery contains:
546
-     * @param route_id a route ID to be shared.
547
-     * @param response_format the response format.
548
-     * @param recipient_email Recipient email.
549
-     * @return Status response
550
-     * @throws Exception\ApiError
551
-     */
552
-    public function shareRoute($params)
553
-    {
554
-        $allQueryFields = ['route_id', 'response_format'];
555
-        $allBodyFields = ['recipient_email'];
556
-
557
-        $result = Route4Me::makeRequst([
558
-            'url'           => Endpoint::ROUTE_SHARE,
559
-            'method'        => 'POST',
560
-            'query'         => Route4Me::generateRequestParameters($allQueryFields, $params),
561
-            'body'          => Route4Me::generateRequestParameters($allBodyFields, $params),
562
-            'HTTPHEADER'    => 'Content-Type: multipart/form-data',
563
-        ]);
564
-
565
-        return $result;
566
-    }
567
-
568
-    /**
569
-     * Returns random route_id from existing routes between $offset and $offset+$limit
570
-     * @param $offset integer The page number for route listing pagination.
571
-     * @param $limit integer The maximum number of the returned routes.
572
-     * @return string random route ID
573
-     * @throws Exception\ApiError
574
-     */
575
-    public function getRandomRouteId($offset, $limit)
576
-    {
577
-        $params = [
578
-            'offset'    => !is_null($offset) ? $offset : 0,
579
-            'limit'     => !is_null($limit) ? $limit : 30,
580
-        ];
581
-
582
-        $route = new self();
583
-        $routes = $route->getRoutes($params);
584
-
585
-        if (is_null($routes) || sizeof($routes) < 1) {
586
-            echo '<br> There are no routes in the account. Please, create the routes first. <br>';
587
-
588
-            return null;
589
-        }
590
-
591
-        $randomIndex = rand(0, sizeof($routes) - 1);
592
-
593
-        return $routes[$randomIndex]->route_id;
594
-    }
595
-
596
-    /**
597
-     * Update a route
598
-     * @param $params array contains:
599
-     * @param route_id string : route ID
600
-     * @param reoptimize int : if equal to 1 the route re-optimized.
601
-     * @param route_destination_id int : route destination ID
602
-     * @param addresses Address[] : an array of a route addresses.
603
-     * @param parameters RouteParameters : route parameters.
604
-     * @param unlink_from_master_optimization  Boolean : if true, the route will be unlinked from optimization.
605
-     * @return Route updated route
606
-     * @throws Exception\ApiError
607
-     */
608
-    public function updateRoute($params)
609
-    {
610
-        $allQueryFields = ['route_id', 'reoptimize','route_destination_id'];
611
-        $allBodyFields = ['addresses', 'parameters', 'unlink_from_master_optimization'];
612
-
613
-        $result = Route4Me::makeRequst([
614
-            'url'       => Endpoint::ROUTE_V4,
615
-            'method'    => 'PUT',
616
-            'query'     => Route4Me::generateRequestParameters($allQueryFields, $params),
617
-            'body'      => (isset($params['addresses']) || isset($params['parameters']) || isset($params['unlink_from_master_optimization']))
618
-                            ? Route4Me::generateRequestParameters($allBodyFields, $params)
619
-                            : null,
620
-        ]);
621
-
622
-        return $result;
623
-    }
624
-
625
-    public function update()
626
-    {
627
-        $route = Route4Me::makeRequst([
628
-            'url'    => Endpoint::ROUTE_V4,
629
-            'method' => 'PUT',
630
-            'query'  => [
631
-                'route_id' => isset($this->route_id) ? $this->route_id : null,
632
-            ],
633
-            'body'   => [
634
-                'parameters' => $this->parameters,
635
-                ],
636
-            'HTTPHEADER' => isset($this->httpheaders) ? $this->httpheaders : null,
637
-        ]);
638
-
639
-        return self::fromArray($route);
640
-    }
641
-
642
-    public function updateAddress($address = null)
643
-    {
644
-        $body = sizeof($this->addresses) < 1 ? get_object_vars($this->parameters)
645
-            : (isset($this->addresses[0]) ? $this->addresses[0] : get_object_vars($this->parameters));
646
-
647
-        $result = Route4Me::makeRequst([
648
-            'url'    => Endpoint::ADDRESS_V4,
649
-            'method' => 'PUT',
650
-            'query'  => [
651
-                'route_id' => isset($this->route_id) ? $this->route_id : null,
652
-                'route_destination_id' => isset($this->route_destination_id) ? $this->route_destination_id : null,
653
-            ],
654
-            'body'   => $body,
655
-            'HTTPHEADER' => isset($this->httpheaders) ? $this->httpheaders : null,
656
-        ]);
657
-
658
-        return $result;
659
-    }
660
-
661
-    public function updateRouteAddress()
662
-    {
663
-        $result = Route4Me::makeRequst([
664
-            'url'    => Endpoint::ADDRESS_V4,
665
-            'method' => 'PUT',
666
-            'query'  => [
667
-                'route_id' => isset($this->route_id) ? $this->route_id : null,
668
-                'route_destination_id' => isset($this->route_destination_id) ? $this->route_destination_id : null,
669
-            ],
670
-            'body'   => [
671
-                'parameters' => isset($this->parameters) ? get_object_vars($this->parameters) : null,
672
-                'addresses' => isset($this->addresses) ? $this->addresses : null,
673
-            ],
674
-            'HTTPHEADER' => isset($this->httpheaders) ? $this->httpheaders : null,
675
-        ]);
676
-
677
-        return $result;
678
-    }
679
-
680
-    public function addAddresses($params)
681
-    {
682
-        $allQueryFields = ['route_id'];
683
-        $allBodyFields = ['addresses'];
684
-
685
-        $route = Route4Me::makeRequst([
686
-            'url'           => Endpoint::ROUTE_V4,
687
-            'method'        => 'PUT',
688
-            'query'         => Route4Me::generateRequestParameters($allQueryFields, $params),
689
-            'body'          => Route4Me::generateRequestParameters($allBodyFields, $params),
690
-            'HTTPHEADER'    => isset($this->httpheaders) ? $this->httpheaders : null,
691
-        ]);
692
-
693
-        return self::fromArray($route);
694
-    }
695
-
696
-    public function insertAddressOptimalPosition(array $params)
697
-    {
698
-        $allQueryFields = ['route_id'];
699
-        $allBodyFields = ['addresses', 'optimal_position'];
700
-
701
-        $route = Route4Me::makeRequst([
702
-            'url'    => Endpoint::ROUTE_V4,
703
-            'method' => 'PUT',
704
-            'query'  => Route4Me::generateRequestParameters($allQueryFields, $params),
705
-            'body'   => Route4Me::generateRequestParameters($allBodyFields, $params),
706
-        ]);
707
-
708
-        return self::fromArray($route);
709
-    }
710
-
711
-    public function addNoteFile($params)
712
-    {
713
-        $fname = isset($params['strFilename']) ? $params['strFilename'] : null;
714
-        $rpath = realpath($fname);
715
-
716
-        $allQueryFields = ['route_id', 'address_id', 'dev_lat', 'dev_lng', 'device_type'];
717
-        $allBodyFields = ['strUpdateType', 'strFilename', 'strNoteContents'];
718
-
719
-        $result = Route4Me::makeRequst([
720
-            'url'    => Endpoint::ROUTE_NOTES_ADD,
721
-            'method' => 'POST',
722
-            'query'  => Route4Me::generateRequestParameters($allQueryFields, $params),
723
-            'body'   => Route4Me::generateRequestParameters($allBodyFields, $params),
724
-            'FILE'   => $rpath,
725
-            'HTTPHEADER' => [
726
-                'Content-Type: application/x-www-form-urlencoded',
727
-            ],
728
-        ]);
729
-
730
-        return $result;
731
-    }
732
-
733
-    public function deleteRoutes($route_id)
734
-    {
735
-        $result = Route4Me::makeRequst([
736
-            'url'    => Endpoint::ROUTE_V4,
737
-            'method' => 'DELETE',
738
-            'query'  => [
739
-                'route_id' => $route_id,
740
-            ],
741
-        ]);
742
-
743
-        return $result;
744
-    }
745
-
746
-    public function GetAddressesFromRoute($route_id)
747
-    {
748
-        $route1 = self::getRoutes(['route_id' => $route_id]);
749
-
750
-        if (isset($route1)) {
751
-            return $route1->addresses;
752
-        } else {
753
-            return null;
754
-        }
755
-    }
756
-
757
-    public function GetRandomAddressFromRoute($route_id)
758
-    {
759
-        $route1 = self::getRoutes(['route_id' => $route_id]);
760
-
761
-        if (isset($route1)) {
762
-            $addresses = $route1->addresses;
763
-
764
-            $rnd = rand(0, sizeof($addresses) - 1);
765
-
766
-            return $addresses[$rnd];
767
-        } else {
768
-            return null;
769
-        }
770
-    }
771
-
772
-    public function getRouteId()
773
-    {
774
-        return $this->route_id;
775
-    }
776
-
777
-    public function getOptimizationId()
778
-    {
779
-        return $this->optimization_problem_id;
780
-    }
781
-
782
-    public function GetLastLocation(array $params)
783
-    {
784
-        $allQueryFields = ['route_id', 'device_tracking_history'];
785
-
786
-        $route = Route4Me::makeRequst([
787
-            'url'    => Endpoint::ROUTE_V4,
788
-            'method' => 'GET',
789
-            'query'  => Route4Me::generateRequestParameters($allQueryFields, $params),
790
-        ]);
791
-
792
-        return self::fromArray($route);
793
-    }
794
-
795
-    public function GetTrackingHistoryFromTimeRange(array $params)
796
-    {
797
-        $allQueryFields = ['route_id', 'format', 'time_period', 'start_date', 'end_date'];
798
-
799
-        $route = Route4Me::makeRequst([
800
-            'url'    => Endpoint::GET_DEVICE_LOCATION,
801
-            'method' => 'GET',
802
-            'query'  => Route4Me::generateRequestParameters($allQueryFields, $params),
803
-        ]);
804
-
805
-        return $route;
806
-    }
807
-
808
-    public function GetAssetTracking(array $params)
809
-    {
810
-        $allQueryFields = ['tracking'];
811
-
812
-        $assetResponse = Route4Me::makeRequst([
813
-            'url'    => Endpoint::STATUS_V4,
814
-            'method' => 'GET',
815
-            'query'  => Route4Me::generateRequestParameters($allQueryFields, $params),
816
-        ]);
817
-
818
-        return $assetResponse;
819
-    }
15
+	/**
16
+	 * The route ID
17
+	 * @var string
18
+	 */
19
+	public $route_id;
20
+
21
+	/**
22
+	 * Member ID of a route owner
23
+	 * @var integer
24
+	 */
25
+	public $member_id;
26
+
27
+	/**
28
+	 * Optimization problem ID
29
+	 * @var string
30
+	 */
31
+	public $optimization_problem_id;
32
+
33
+	/**
34
+	 * Vehicle alias
35
+	 * @var string
36
+	 */
37
+	public $vehicle_alias;
38
+
39
+	/**
40
+	 * Driver alias
41
+	 * @var string
42
+	 */
43
+	public $driver_alias;
44
+
45
+	/**
46
+	 * Total route's trip distance
47
+	 * @var double
48
+	 */
49
+	public $trip_distance;
50
+
51
+	/**
52
+	 * The UDU distance measurement unit for the route.<br>
53
+	 * @note km or mi, the route4me api will convert all distance measurements into these units.
54
+	 * @var string
55
+	 */
56
+	public $udu_distance_unit;
57
+
58
+	/**
59
+	 * Total route's UDU trip distance
60
+	 * @var double
61
+	 */
62
+	public $udu_trip_distance;
63
+
64
+	/** Miles per gallon
65
+	 * @var double
66
+	 */
67
+	public $mpg;
68
+
69
+	/**
70
+	 * Gas price
71
+	 * @var double
72
+	 */
73
+	public $gas_price;
74
+
75
+	/**
76
+	 * Total route duration (seconds)
77
+	 * @var integer
78
+	 */
79
+	public $route_duration_sec;
80
+
81
+	/**
82
+	 * Number of the destinations in the route.
83
+	 * @var integer
84
+	 */
85
+	public $destination_count;
86
+
87
+	/**
88
+	 * Notes count in the route.
89
+	 * @var integer
90
+	 */
91
+	public $notes_count;
92
+
93
+	/**
94
+	 * Route parameters
95
+	 * @var RouteParameters
96
+	 */
97
+	public $parameters;
98
+
99
+	/**
100
+	 * An array of the route addresses
101
+	 * @var Address[]
102
+	 */
103
+	public $addresses = [];
104
+
105
+	/**
106
+	 * An array of the links
107
+	 * @var string[]
108
+	 */
109
+	public $links = [];
110
+
111
+	/**
112
+	 * Edge by edge turn-by-turn directions.
113
+	 * @var Direction[]
114
+	 */
115
+	public $directions = [];
116
+
117
+	/**
118
+	 * Edge-wise path to be drawn on the map.
119
+	 * @var GeoPoint[]
120
+	 */
121
+	public $path = [];
122
+
123
+	/**
124
+	 * A collection of device tracking data with coordinates, speed, and timestamps.
125
+	 * @var Tracking\TrackingHistory[]
126
+	 */
127
+	public $tracking_history = [];
128
+
129
+	/**
130
+	 * HTTP headers
131
+	 * @var string
132
+	 */
133
+	public $httpheaders;
134
+
135
+	/**
136
+	 * If true, the route is unrouted.
137
+	 * @var Boolean
138
+	 */
139
+	public $is_unrouted;
140
+
141
+	/**
142
+	 * User route rating [0, 5]. A null value means no rating was given.<br>
143
+	 * Users can rate routes so that future optimizations take these ratings into account.
144
+	 * @var integer
145
+	 */
146
+	public $user_route_rating;
147
+
148
+	/**
149
+	 * The member's email
150
+	 * @var string
151
+	 */
152
+	public $member_email;
153
+
154
+	/**
155
+	 * URL to a member picture
156
+	 * @var string
157
+	 */
158
+	public $member_picture;
159
+
160
+	/**
161
+	 * Member tracking subheadline.
162
+	 * @var string
163
+	 */
164
+	public $member_tracking_subheadline;
165
+
166
+	/**
167
+	 * If true, the order is approved for execution.
168
+	 * @var Boolean
169
+	 */
170
+	public $approved_for_execution;
171
+
172
+	/**
173
+	 * Counter of the approved revisions.
174
+	 * @var integer
175
+	 */
176
+	public $approved_revisions_counter;
177
+
178
+	/**
179
+	 * The member's first name.
180
+	 * @var string
181
+	 */
182
+	public $member_first_name;
183
+
184
+	/**
185
+	 * The member's last name.
186
+	 * @var string
187
+	 */
188
+	public $member_last_name;
189
+
190
+	/**
191
+	 * Channel name
192
+	 * @var string
193
+	 */
194
+	public $channel_name;
195
+
196
+	/**
197
+	 * Total cost of the route.
198
+	 * @var double
199
+	 */
200
+	public $route_cost;
201
+
202
+	/**
203
+	 * Total route revenue
204
+	 * @var double
205
+	 */
206
+	public $route_revenue;
207
+
208
+	/**
209
+	 * Net revenue per distance unit.
210
+	 * @var double
211
+	 */
212
+	public $net_revenue_per_distance_unit;
213
+
214
+	/**
215
+	 * When route created (UNIX format timestamp).
216
+	 * @var integer
217
+	 */
218
+	public $created_timestamp;
219
+
220
+	/**
221
+	 * Planned total route duration (seconds).
222
+	 * @var integer
223
+	 */
224
+	public $planned_total_route_duration;
225
+
226
+	/**
227
+	 * Total wait time (seconds).
228
+	 * @var integer
229
+	 */
230
+	public $total_wait_time;
231
+
232
+	/**
233
+	 * UDU Actual travel distance.
234
+	 * @var double
235
+	 */
236
+	public $udu_actual_travel_distance;
237
+
238
+	/**
239
+	 * Actual travel distance.
240
+	 * @var double
241
+	 */
242
+	public $actual_travel_distance;
243
+
244
+	/**
245
+	 * Actual travel time (seconds).
246
+	 * @var integer
247
+	 */
248
+	public $actual_travel_time;
249
+
250
+	/**
251
+	 * Actual footsteps.
252
+	 * @var integer
253
+	 */
254
+	public $actual_footsteps;
255
+
256
+	/**
257
+	 * Working time.
258
+	 * @var integer
259
+	 */
260
+	public $working_time;
261
+
262
+	/**
263
+	 * Driving time.
264
+	 * @var integer
265
+	 */
266
+	public $driving_time;
267
+
268
+	/**
269
+	 * Idling time.
270
+	 * @var integer
271
+	 */
272
+	public $idling_time;
273
+
274
+	/**
275
+	 * Paying miles
276
+	 * @var double
277
+	 */
278
+	public $paying_miles;
279
+
280
+	/**
281
+	 * Geofence polygon type.<br>
282
+	 * enum: ["circle", "poly", "rect"]
283
+	 * @var string
284
+	 */
285
+	public $geofence_polygon_type;
286
+
287
+	/**
288
+	 * Geofence polygon size.
289
+	 * @var integer
290
+	 */
291
+	public $geofence_polygon_size;
292
+
293
+	/**
294
+	 * Route notes
295
+	 * @var AddressNote[]
296
+	 */
297
+	public $notes=[];
298
+
299
+	/**
300
+	 * A vehicle assigned to the route.
301
+	 * @var Vehicles\VehicleResponseV4
302
+	 */
303
+	public $vehicle=[];
304
+
305
+	/**
306
+	 * Member config key-value pairs.
307
+	 * @var array
308
+	 */
309
+	public $member_config_storage;
310
+
311
+	/**
312
+	 * Original route
313
+	 * @var Route
314
+	 */
315
+	public $original_route;
316
+
317
+	/**
318
+	 * If true, the route will be unlinked from the master optimization.
319
+	 * @var Boolean
320
+	 */
321
+	public $unlink_from_master_optimization;
322
+
323
+	public function __construct()
324
+	{
325
+		Route4Me::setBaseUrl(Endpoint::BASE_URL);
326
+	}
327
+
328
+	public static function fromArray(array $params)
329
+	{
330
+		$route = new self();
331
+		$route->route_id = Common::getValue($params, 'route_id');
332
+		$route->member_id = Common::getValue($params, 'member_id');
333
+		$route->member_email = Common::getValue($params, 'member_email');
334
+		$route->member_picture = Common::getValue($params, 'member_picture');
335
+		$route->member_tracking_subheadline = Common::getValue($params, 'member_tracking_subheadline');
336
+		$route->approved_for_execution = Common::getValue($params, 'approved_for_execution');
337
+		$route->approved_revisions_counter = Common::getValue($params, 'approved_revisions_counter');
338
+		$route->member_first_name = Common::getValue($params, 'member_first_name');
339
+		$route->member_last_name = Common::getValue($params, 'member_last_name');
340
+		$route->channel_name = Common::getValue($params, 'channel_name');
341
+		$route->optimization_problem_id = Common::getValue($params, 'optimization_problem_id');
342
+		$route->user_route_rating = Common::getValue($params, 'user_route_rating');
343
+		$route->vehicle_alias = Common::getValue($params, 'vehicle_alias');
344
+		$route->driver_alias = Common::getValue($params, 'driver_alias');
345
+		$route->trip_distance = Common::getValue($params, 'trip_distance');
346
+		$route->udu_distance_unit = Common::getValue($params, 'udu_distance_unit');
347
+		$route->udu_trip_distance = Common::getValue($params, 'udu_trip_distance');
348
+		$route->mpg = Common::getValue($params, 'mpg');
349
+		$route->gas_price = Common::getValue($params, 'gas_price');
350
+		$route->route_duration_sec = Common::getvalue($params, 'route_duration_sec');
351
+		$route->planned_total_route_duration = Common::getvalue($params, 'planned_total_route_duration');
352
+		$route->total_wait_time = Common::getvalue($params, 'total_wait_time');
353
+		$route->udu_actual_travel_distance = Common::getvalue($params, 'udu_actual_travel_distance');
354
+		$route->actual_travel_distance = Common::getvalue($params, 'actual_travel_distance');
355
+		$route->actual_travel_time = Common::getvalue($params, 'actual_travel_time');
356
+		$route->actual_footsteps = Common::getvalue($params, 'actual_footsteps');
357
+		$route->working_time = Common::getvalue($params, 'working_time');
358
+		$route->driving_time = Common::getvalue($params, 'driving_time');
359
+		$route->idling_time = Common::getvalue($params, 'idling_time');
360
+		$route->paying_miles = Common::getvalue($params, 'paying_miles');
361
+		$route->geofence_polygon_type = Common::getvalue($params, 'geofence_polygon_type');
362
+		$route->geofence_polygon_size = Common::getvalue($params, 'geofence_polygon_size');
363
+		$route->destination_count = Common::getvalue($params, 'destination_count');
364
+		$route->notes_count = Common::getvalue($params, 'notes_count');
365
+		$route->is_unrouted = Common::getvalue($params, 'is_unrouted');
366
+		$route->route_cost = Common::getvalue($params, 'route_cost');
367
+		$route->route_revenue = Common::getvalue($params, 'route_revenue');
368
+		$route->net_revenue_per_distance_unit = Common::getvalue($params, 'net_revenue_per_distance_unit');
369
+		$route->created_timestamp = Common::getvalue($params, 'created_timestamp');
370
+
371
+		if (isset($params['vehicle'])) {
372
+			$route->vehicle = new Vehicle();
373
+			$route->vehicle = Vehicle::fromArray($params['vehicle']);
374
+			Route4Me::setBaseUrl(Endpoint::BASE_URL);
375
+		};
376
+
377
+		$route->member_config_storage = Common::getvalue($params, 'member_config_storage');
378
+
379
+		// Make RouteParameters
380
+		if (isset($params['parameters'])) {
381
+			$route->parameters = new RouteParameters();
382
+			$route->parameters = RouteParameters::fromArray($params['parameters']);
383
+			Route4Me::setBaseUrl(Endpoint::BASE_URL);
384
+		}
385
+
386
+		if (isset($params['addresses'])) {
387
+			$addresses = [];
388
+
389
+			foreach ($params['addresses'] as $address) {
390
+				$addresses[] = Address::fromArray($address);
391
+			}
392
+
393
+			$route->addresses = $addresses;
394
+		}
395
+
396
+		$route->links = Common::getValue($params, 'links', []);
397
+		$route->notes = Common::getValue($params, 'notes', []);
398
+		$route->directions = Common::getValue($params, 'directions', []);
399
+		$route->path = Common::getValue($params, 'path', []);
400
+		$route->tracking_history = Common::getValue($params, 'tracking_history', []);
401
+
402
+		if (isset($params['original_route'])) {
403
+			$route->original_route = Route::fromArray($params['original_route']);
404
+		};
405
+
406
+		return $route;
407
+	}
408
+
409
+	/**
410
+	 * @param RouteParametersQuery $params
411
+	 * @return An array of the routes
412
+	 * @throws Exception\ApiError
413
+	 */
414
+	public static function getRoutes($params = null)
415
+	{
416
+		$allQueryFields = ['route_id', 'original', 'route_path_output', 'query', 'directions', 'device_tracking_history', 'limit', 'offset','start_date','end_date'];
417
+
418
+		$result = Route4Me::makeRequst([
419
+			'url'       => Endpoint::ROUTE_V4,
420
+			'method'    => 'GET',
421
+			'query'     => Route4Me::generateRequestParameters($allQueryFields, $params),
422
+		]);
423
+
424
+		if (isset($params['route_id'])) {
425
+			if (strlen($params['route_id'])==32) {
426
+				return self::fromArray($result);
427
+			} else {
428
+				return $result;
429
+			}
430
+		} else {
431
+			$routes = [];
432
+			foreach ($result as $route) {
433
+				$routes[] = self::fromArray($route);
434
+			}
435
+
436
+			return $routes;
437
+		}
438
+	}
439
+
440
+	public function getRoutePoints($params)
441
+	{
442
+		$allQueryFields = ['route_id', 'route_path_output', 'compress_path_points', 'directions'];
443
+
444
+		$result = Route4Me::makeRequst([
445
+			'url'    => Endpoint::ROUTE_V4,
446
+			'method' => 'GET',
447
+			'query'  => Route4Me::generateRequestParameters($allQueryFields, $params),
448
+		]);
449
+
450
+		return $result;
451
+	}
452
+
453
+	public function duplicateRoute($routeIDs)
454
+	{
455
+		$result = Route4Me::makeRequst([
456
+			'url'    => Endpoint::ROUTE_V4,
457
+			'method' => 'POST',
458
+			'body'   => [
459
+				'duplicate_routes_id' => $routeIDs
460
+			],
461
+		]);
462
+
463
+		return $result;
464
+	}
465
+
466
+	public function resequenceRoute($params)
467
+	{
468
+		$allQueryFields = ['route_id', 'route_destination_id'];
469
+		$allBodyFields = ['addresses'];
470
+
471
+		$result = Route4Me::makeRequst([
472
+			'url'       => Endpoint::ROUTE_V4,
473
+			'method'    => 'PUT',
474
+			'query'     => Route4Me::generateRequestParameters($allQueryFields, $params),
475
+			'body'      => Route4Me::generateRequestParameters($allBodyFields, $params),
476
+		]);
477
+
478
+		return $result;
479
+	}
480
+
481
+	/**
482
+	 * @deprecated 'The method is obsolete, use the method ReoptimizeRoute instead.'
483
+	 * @param $params
484
+	 * @return mixed|string
485
+	 */
486
+	public function resequenceAllAddresses($params)
487
+	{
488
+		$allQueryFields = ['route_id', 'disable_optimization', 'optimize'];
489
+
490
+		$result = Route4Me::makeRequst([
491
+			'url'       => Endpoint::REOPTIMIZE_V3_2,
492
+			'method'    => 'GET',
493
+			'query'     => Route4Me::generateRequestParameters($allQueryFields, $params),
494
+		]);
495
+
496
+		return $result;
497
+	}
498
+
499
+	/**
500
+	 * Reoptimize a route
501
+	 * @param $params type Route
502
+	 * @return mixed|string
503
+	 * @throws Exception\ApiError
504
+	 */
505
+	public function reoptimizeRoute($params)
506
+	{
507
+		$allQueryFields = ['route_id', 'reoptimize', 'remaining', 'device_type'];
508
+
509
+		$result = Route4Me::makeRequst([
510
+			'url'       => Endpoint::ROUTE_V4,
511
+			'method'    => 'PUT',
512
+			'query'     => Route4Me::generateRequestParameters($allQueryFields, $params),
513
+		]);
514
+
515
+		return $result;
516
+	}
517
+
518
+	/**
519
+	 * Merges the routes
520
+	 * @param $params array contains:
521
+	 * @param route_ids IDs of the routes to be merged.
522
+	 * @param depot_address a depot address of the merged route.
523
+	 * @param remove_origin if true, the origin routes will be removed.
524
+	 * @param depot_lat the depot's latitude
525
+	 * @param depot_lng the depot's longitude
526
+	 * @return Status response
527
+	 * @throws Exception\ApiError
528
+	 */
529
+	public function mergeRoutes($params)
530
+	{
531
+		$allBodyFields = ['route_ids', 'depot_address', 'remove_origin', 'depot_lat',  'depot_lng'];
532
+
533
+		$result = Route4Me::makeRequst([
534
+			'url'           => Endpoint::ROUTES_MERGE,
535
+			'method'        => 'POST',
536
+			'body'          => Route4Me::generateRequestParameters($allBodyFields, $params),
537
+			'HTTPHEADER'    => 'Content-Type: multipart/form-data',
538
+		]);
539
+
540
+		return $result;
541
+	}
542
+
543
+	/**
544
+	 * Share a route by an email
545
+	 * @param $params RouteParametersQuery contains:
546
+	 * @param route_id a route ID to be shared.
547
+	 * @param response_format the response format.
548
+	 * @param recipient_email Recipient email.
549
+	 * @return Status response
550
+	 * @throws Exception\ApiError
551
+	 */
552
+	public function shareRoute($params)
553
+	{
554
+		$allQueryFields = ['route_id', 'response_format'];
555
+		$allBodyFields = ['recipient_email'];
556
+
557
+		$result = Route4Me::makeRequst([
558
+			'url'           => Endpoint::ROUTE_SHARE,
559
+			'method'        => 'POST',
560
+			'query'         => Route4Me::generateRequestParameters($allQueryFields, $params),
561
+			'body'          => Route4Me::generateRequestParameters($allBodyFields, $params),
562
+			'HTTPHEADER'    => 'Content-Type: multipart/form-data',
563
+		]);
564
+
565
+		return $result;
566
+	}
567
+
568
+	/**
569
+	 * Returns random route_id from existing routes between $offset and $offset+$limit
570
+	 * @param $offset integer The page number for route listing pagination.
571
+	 * @param $limit integer The maximum number of the returned routes.
572
+	 * @return string random route ID
573
+	 * @throws Exception\ApiError
574
+	 */
575
+	public function getRandomRouteId($offset, $limit)
576
+	{
577
+		$params = [
578
+			'offset'    => !is_null($offset) ? $offset : 0,
579
+			'limit'     => !is_null($limit) ? $limit : 30,
580
+		];
581
+
582
+		$route = new self();
583
+		$routes = $route->getRoutes($params);
584
+
585
+		if (is_null($routes) || sizeof($routes) < 1) {
586
+			echo '<br> There are no routes in the account. Please, create the routes first. <br>';
587
+
588
+			return null;
589
+		}
590
+
591
+		$randomIndex = rand(0, sizeof($routes) - 1);
592
+
593
+		return $routes[$randomIndex]->route_id;
594
+	}
595
+
596
+	/**
597
+	 * Update a route
598
+	 * @param $params array contains:
599
+	 * @param route_id string : route ID
600
+	 * @param reoptimize int : if equal to 1 the route re-optimized.
601
+	 * @param route_destination_id int : route destination ID
602
+	 * @param addresses Address[] : an array of a route addresses.
603
+	 * @param parameters RouteParameters : route parameters.
604
+	 * @param unlink_from_master_optimization  Boolean : if true, the route will be unlinked from optimization.
605
+	 * @return Route updated route
606
+	 * @throws Exception\ApiError
607
+	 */
608
+	public function updateRoute($params)
609
+	{
610
+		$allQueryFields = ['route_id', 'reoptimize','route_destination_id'];
611
+		$allBodyFields = ['addresses', 'parameters', 'unlink_from_master_optimization'];
612
+
613
+		$result = Route4Me::makeRequst([
614
+			'url'       => Endpoint::ROUTE_V4,
615
+			'method'    => 'PUT',
616
+			'query'     => Route4Me::generateRequestParameters($allQueryFields, $params),
617
+			'body'      => (isset($params['addresses']) || isset($params['parameters']) || isset($params['unlink_from_master_optimization']))
618
+							? Route4Me::generateRequestParameters($allBodyFields, $params)
619
+							: null,
620
+		]);
621
+
622
+		return $result;
623
+	}
624
+
625
+	public function update()
626
+	{
627
+		$route = Route4Me::makeRequst([
628
+			'url'    => Endpoint::ROUTE_V4,
629
+			'method' => 'PUT',
630
+			'query'  => [
631
+				'route_id' => isset($this->route_id) ? $this->route_id : null,
632
+			],
633
+			'body'   => [
634
+				'parameters' => $this->parameters,
635
+				],
636
+			'HTTPHEADER' => isset($this->httpheaders) ? $this->httpheaders : null,
637
+		]);
638
+
639
+		return self::fromArray($route);
640
+	}
641
+
642
+	public function updateAddress($address = null)
643
+	{
644
+		$body = sizeof($this->addresses) < 1 ? get_object_vars($this->parameters)
645
+			: (isset($this->addresses[0]) ? $this->addresses[0] : get_object_vars($this->parameters));
646
+
647
+		$result = Route4Me::makeRequst([
648
+			'url'    => Endpoint::ADDRESS_V4,
649
+			'method' => 'PUT',
650
+			'query'  => [
651
+				'route_id' => isset($this->route_id) ? $this->route_id : null,
652
+				'route_destination_id' => isset($this->route_destination_id) ? $this->route_destination_id : null,
653
+			],
654
+			'body'   => $body,
655
+			'HTTPHEADER' => isset($this->httpheaders) ? $this->httpheaders : null,
656
+		]);
657
+
658
+		return $result;
659
+	}
660
+
661
+	public function updateRouteAddress()
662
+	{
663
+		$result = Route4Me::makeRequst([
664
+			'url'    => Endpoint::ADDRESS_V4,
665
+			'method' => 'PUT',
666
+			'query'  => [
667
+				'route_id' => isset($this->route_id) ? $this->route_id : null,
668
+				'route_destination_id' => isset($this->route_destination_id) ? $this->route_destination_id : null,
669
+			],
670
+			'body'   => [
671
+				'parameters' => isset($this->parameters) ? get_object_vars($this->parameters) : null,
672
+				'addresses' => isset($this->addresses) ? $this->addresses : null,
673
+			],
674
+			'HTTPHEADER' => isset($this->httpheaders) ? $this->httpheaders : null,
675
+		]);
676
+
677
+		return $result;
678
+	}
679
+
680
+	public function addAddresses($params)
681
+	{
682
+		$allQueryFields = ['route_id'];
683
+		$allBodyFields = ['addresses'];
684
+
685
+		$route = Route4Me::makeRequst([
686
+			'url'           => Endpoint::ROUTE_V4,
687
+			'method'        => 'PUT',
688
+			'query'         => Route4Me::generateRequestParameters($allQueryFields, $params),
689
+			'body'          => Route4Me::generateRequestParameters($allBodyFields, $params),
690
+			'HTTPHEADER'    => isset($this->httpheaders) ? $this->httpheaders : null,
691
+		]);
692
+
693
+		return self::fromArray($route);
694
+	}
695
+
696
+	public function insertAddressOptimalPosition(array $params)
697
+	{
698
+		$allQueryFields = ['route_id'];
699
+		$allBodyFields = ['addresses', 'optimal_position'];
700
+
701
+		$route = Route4Me::makeRequst([
702
+			'url'    => Endpoint::ROUTE_V4,
703
+			'method' => 'PUT',
704
+			'query'  => Route4Me::generateRequestParameters($allQueryFields, $params),
705
+			'body'   => Route4Me::generateRequestParameters($allBodyFields, $params),
706
+		]);
707
+
708
+		return self::fromArray($route);
709
+	}
710
+
711
+	public function addNoteFile($params)
712
+	{
713
+		$fname = isset($params['strFilename']) ? $params['strFilename'] : null;
714
+		$rpath = realpath($fname);
715
+
716
+		$allQueryFields = ['route_id', 'address_id', 'dev_lat', 'dev_lng', 'device_type'];
717
+		$allBodyFields = ['strUpdateType', 'strFilename', 'strNoteContents'];
718
+
719
+		$result = Route4Me::makeRequst([
720
+			'url'    => Endpoint::ROUTE_NOTES_ADD,
721
+			'method' => 'POST',
722
+			'query'  => Route4Me::generateRequestParameters($allQueryFields, $params),
723
+			'body'   => Route4Me::generateRequestParameters($allBodyFields, $params),
724
+			'FILE'   => $rpath,
725
+			'HTTPHEADER' => [
726
+				'Content-Type: application/x-www-form-urlencoded',
727
+			],
728
+		]);
729
+
730
+		return $result;
731
+	}
732
+
733
+	public function deleteRoutes($route_id)
734
+	{
735
+		$result = Route4Me::makeRequst([
736
+			'url'    => Endpoint::ROUTE_V4,
737
+			'method' => 'DELETE',
738
+			'query'  => [
739
+				'route_id' => $route_id,
740
+			],
741
+		]);
742
+
743
+		return $result;
744
+	}
745
+
746
+	public function GetAddressesFromRoute($route_id)
747
+	{
748
+		$route1 = self::getRoutes(['route_id' => $route_id]);
749
+
750
+		if (isset($route1)) {
751
+			return $route1->addresses;
752
+		} else {
753
+			return null;
754
+		}
755
+	}
756
+
757
+	public function GetRandomAddressFromRoute($route_id)
758
+	{
759
+		$route1 = self::getRoutes(['route_id' => $route_id]);
760
+
761
+		if (isset($route1)) {
762
+			$addresses = $route1->addresses;
763
+
764
+			$rnd = rand(0, sizeof($addresses) - 1);
765
+
766
+			return $addresses[$rnd];
767
+		} else {
768
+			return null;
769
+		}
770
+	}
771
+
772
+	public function getRouteId()
773
+	{
774
+		return $this->route_id;
775
+	}
776
+
777
+	public function getOptimizationId()
778
+	{
779
+		return $this->optimization_problem_id;
780
+	}
781
+
782
+	public function GetLastLocation(array $params)
783
+	{
784
+		$allQueryFields = ['route_id', 'device_tracking_history'];
785
+
786
+		$route = Route4Me::makeRequst([
787
+			'url'    => Endpoint::ROUTE_V4,
788
+			'method' => 'GET',
789
+			'query'  => Route4Me::generateRequestParameters($allQueryFields, $params),
790
+		]);
791
+
792
+		return self::fromArray($route);
793
+	}
794
+
795
+	public function GetTrackingHistoryFromTimeRange(array $params)
796
+	{
797
+		$allQueryFields = ['route_id', 'format', 'time_period', 'start_date', 'end_date'];
798
+
799
+		$route = Route4Me::makeRequst([
800
+			'url'    => Endpoint::GET_DEVICE_LOCATION,
801
+			'method' => 'GET',
802
+			'query'  => Route4Me::generateRequestParameters($allQueryFields, $params),
803
+		]);
804
+
805
+		return $route;
806
+	}
807
+
808
+	public function GetAssetTracking(array $params)
809
+	{
810
+		$allQueryFields = ['tracking'];
811
+
812
+		$assetResponse = Route4Me::makeRequst([
813
+			'url'    => Endpoint::STATUS_V4,
814
+			'method' => 'GET',
815
+			'query'  => Route4Me::generateRequestParameters($allQueryFields, $params),
816
+		]);
817
+
818
+		return $assetResponse;
819
+	}
820 820
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -294,13 +294,13 @@  discard block
 block discarded – undo
294 294
      * Route notes
295 295
      * @var AddressNote[]
296 296
      */
297
-    public $notes=[];
297
+    public $notes = [];
298 298
 
299 299
     /**
300 300
      * A vehicle assigned to the route.
301 301
      * @var Vehicles\VehicleResponseV4
302 302
      */
303
-    public $vehicle=[];
303
+    public $vehicle = [];
304 304
 
305 305
     /**
306 306
      * Member config key-value pairs.
@@ -413,7 +413,7 @@  discard block
 block discarded – undo
413 413
      */
414 414
     public static function getRoutes($params = null)
415 415
     {
416
-        $allQueryFields = ['route_id', 'original', 'route_path_output', 'query', 'directions', 'device_tracking_history', 'limit', 'offset','start_date','end_date'];
416
+        $allQueryFields = ['route_id', 'original', 'route_path_output', 'query', 'directions', 'device_tracking_history', 'limit', 'offset', 'start_date', 'end_date'];
417 417
 
418 418
         $result = Route4Me::makeRequst([
419 419
             'url'       => Endpoint::ROUTE_V4,
@@ -528,7 +528,7 @@  discard block
 block discarded – undo
528 528
      */
529 529
     public function mergeRoutes($params)
530 530
     {
531
-        $allBodyFields = ['route_ids', 'depot_address', 'remove_origin', 'depot_lat',  'depot_lng'];
531
+        $allBodyFields = ['route_ids', 'depot_address', 'remove_origin', 'depot_lat', 'depot_lng'];
532 532
 
533 533
         $result = Route4Me::makeRequst([
534 534
             'url'           => Endpoint::ROUTES_MERGE,
@@ -582,7 +582,7 @@  discard block
 block discarded – undo
582 582
         $route = new self();
583 583
         $routes = $route->getRoutes($params);
584 584
 
585
-        if (is_null($routes) || sizeof($routes) < 1) {
585
+        if (is_null($routes) || sizeof($routes)<1) {
586 586
             echo '<br> There are no routes in the account. Please, create the routes first. <br>';
587 587
 
588 588
             return null;
@@ -607,7 +607,7 @@  discard block
 block discarded – undo
607 607
      */
608 608
     public function updateRoute($params)
609 609
     {
610
-        $allQueryFields = ['route_id', 'reoptimize','route_destination_id'];
610
+        $allQueryFields = ['route_id', 'reoptimize', 'route_destination_id'];
611 611
         $allBodyFields = ['addresses', 'parameters', 'unlink_from_master_optimization'];
612 612
 
613 613
         $result = Route4Me::makeRequst([
@@ -641,7 +641,7 @@  discard block
 block discarded – undo
641 641
 
642 642
     public function updateAddress($address = null)
643 643
     {
644
-        $body = sizeof($this->addresses) < 1 ? get_object_vars($this->parameters)
644
+        $body = sizeof($this->addresses)<1 ? get_object_vars($this->parameters)
645 645
             : (isset($this->addresses[0]) ? $this->addresses[0] : get_object_vars($this->parameters));
646 646
 
647 647
         $result = Route4Me::makeRequst([
Please login to merge, or discard this patch.
src/Route4Me/Order.php 2 patches
Indentation   +320 added lines, -320 removed lines patch added patch discarded remove patch
@@ -6,329 +6,329 @@
 block discarded – undo
6 6
 
7 7
 class Order extends Common
8 8
 {
9
-    public $address_1;
10
-    public $address_2;
11
-    public $cached_lat;
12
-    public $cached_lng;
13
-    public $curbside_lat;
14
-    public $curbside_lng;
15
-    public $address_alias;
16
-    public $address_city;
17
-    public $EXT_FIELD_first_name;
18
-    public $EXT_FIELD_last_name;
19
-    public $EXT_FIELD_email;
20
-    public $EXT_FIELD_phone;
21
-    public $EXT_FIELD_custom_data;
22
-
23
-    public $color;
24
-    public $order_icon;
25
-    public $local_time_window_start;
26
-    public $local_time_window_end;
27
-    public $local_time_window_start_2;
28
-    public $local_time_window_end_2;
29
-    public $service_time;
30
-
31
-    public $day_scheduled_for_YYMMDD;
32
-
33
-    public $route_id;
34
-    public $redirect;
35
-    public $optimization_problem_id;
36
-    public $order_id;
37
-    public $order_ids;
38
-
39
-    public $day_added_YYMMDD;
40
-    public $scheduled_for_YYMMDD;
41
-    public $fields;
42
-    public $offset;
43
-    public $limit;
44
-    public $query;
45
-
46
-    public $created_timestamp;
47
-    public $order_status_id;
48
-    public $member_id;
49
-    public $address_state_id;
50
-    public $address_country_id;
51
-    public $address_zip;
52
-    public $in_route_count;
53
-    public $last_visited_timestamp;
54
-    public $last_routed_timestamp;
55
-    public $local_timezone_string;
56
-    public $is_validated;
57
-    public $is_pending;
58
-    public $is_accepted;
59
-    public $is_started;
60
-    public $is_completed;
61
-    public $custom_user_fields;
62
-
63
-    public $addresses = [];
64
-
65
-    public function __construct()
66
-    {
67
-        Route4Me::setBaseUrl(Endpoint::BASE_URL);
68
-    }
69
-
70
-    public static function fromArray(array $params)
71
-    {
72
-        $order = new self();
73
-        foreach ($params as $key => $value) {
74
-            if (property_exists($order, $key)) {
75
-                $order->{$key} = $value;
76
-            }
77
-        }
78
-
79
-        return $order;
80
-    }
81
-
82
-    /**
83
-     * @param Order $params
84
-     */
85
-    public static function addOrder($params)
86
-    {
87
-        $excludeFields = ['route_id', 'redirect', 'optimization_problem_id', 'order_id',
88
-        'order_ids', 'fields', 'offset', 'limit', 'query', 'created_timestamp', ];
89
-
90
-        $allBodyFields = Route4Me::getObjectProperties(new self(), $excludeFields);
91
-
92
-        $response = Route4Me::makeRequst([
93
-            'url'       => Endpoint::ORDER_V4,
94
-            'method'    => 'POST',
95
-            'body'      => Route4Me::generateRequestParameters($allBodyFields, $params),
96
-        ]);
97
-
98
-        return $response;
99
-    }
100
-
101
-    public static function addOrder2Route($params)
102
-    {
103
-        $allQueryFields = ['route_id', 'redirect'];
104
-        $allBodyFields = ['addresses'];
105
-
106
-        $response = Route4Me::makeRequst([
107
-            'url'       => Endpoint::ROUTE_V4,
108
-            'method'    => 'PUT',
109
-            'query'     => Route4Me::generateRequestParameters($allQueryFields, $params),
110
-            'body'      => Route4Me::generateRequestParameters($allBodyFields, $params),
111
-        ]);
112
-
113
-        return $response;
114
-    }
115
-
116
-    public static function addOrder2Optimization($params)
117
-    {
118
-        $allQueryFields = ['optimization_problem_id', 'redirect', 'device_type'];
119
-        $allBodyFields  = ['addresses'];
120
-
121
-        $response = Route4Me::makeRequst([
122
-            'url'       => Endpoint::OPTIMIZATION_PROBLEM,
123
-            'method'    => 'PUT',
124
-            'query'     => Route4Me::generateRequestParameters($allQueryFields, $params),
125
-            'body'      => Route4Me::generateRequestParameters($allBodyFields, $params),
126
-        ]);
127
-
128
-        return $response;
129
-    }
130
-
131
-    public static function getOrder($params)
132
-    {
133
-        $allQueryFields = ['order_id', 'fields', 'day_added_YYMMDD', 'scheduled_for_YYMMDD', 'query', 'offset', 'limit'];
134
-
135
-        $response = Route4Me::makeRequst([
136
-            'url'       => Endpoint::ORDER_V4,
137
-            'method'    => 'GET',
138
-            'query'     => Route4Me::generateRequestParameters($allQueryFields, $params),
139
-        ]);
140
-
141
-        return $response;
142
-    }
143
-
144
-    public static function getOrders($params)
145
-    {
146
-        $allQueryFields = ['offset', 'limit'];
147
-
148
-        $response = Route4Me::makeRequst([
149
-            'url'       => Endpoint::ORDER_V4,
150
-            'method'    => 'GET',
151
-            'query'     => Route4Me::generateRequestParameters($allQueryFields, $params),
152
-        ]);
153
-
154
-        return $response;
155
-    }
156
-
157
-    public function getRandomOrderId($offset, $limit)
158
-    {
159
-        $randomOrder = $this->getRandomOrder($offset, $limit);
160
-
161
-        if (is_null($randomOrder) || !isset($randomOrder)) {
162
-            return null;
163
-        }
164
-
165
-        return $randomOrder['order_id'];
166
-    }
167
-
168
-    public function getRandomOrder($offset, $limit)
169
-    {
170
-        $params = ['offset' => $offset, 'limit' => $limit];
171
-
172
-        $orders = self::getOrders($params);
173
-
174
-        if (is_null($orders) || !isset($orders['results'])) {
175
-            return null;
176
-        }
177
-
178
-        $randomIndex = rand(0, sizeof($orders['results']) - 1);
179
-
180
-        $order = $orders['results'][$randomIndex];
181
-
182
-        return $order;
183
-    }
184
-
185
-    public static function removeOrder($params)
186
-    {
187
-        $allBodyFields = ['order_ids'];
188
-
189
-        $response = Route4Me::makeRequst([
190
-            'url'       => Endpoint::ORDER_V4,
191
-            'method'    => 'DELETE',
192
-            'body'      => Route4Me::generateRequestParameters($allBodyFields, $params),
193
-        ]);
194
-
195
-        return $response;
196
-    }
197
-
198
-    public static function updateOrder($params)
199
-    {
200
-        $excludeFields = ['route_id', 'redirect', 'optimization_problem_id',
201
-        'order_ids', 'fields', 'offset', 'limit', 'query', 'created_timestamp', ];
202
-
203
-        $allBodyFields = Route4Me::getObjectProperties(new self(), $excludeFields);
204
-
205
-        $response = Route4Me::makeRequst([
206
-            'url'       => Endpoint::ORDER_V4,
207
-            'method'    => 'PUT',
208
-            'body'      => Route4Me::generateRequestParameters($allBodyFields, $params),
209
-        ]);
210
-
211
-        return $response;
212
-    }
213
-
214
-    public static function searchOrder($params)
215
-    {
216
-        $allQueryFields = ['fields', 'day_added_YYMMDD', 'scheduled_for_YYMMDD', 'query', 'offset', 'limit'];
217
-
218
-        $response = Route4Me::makeRequst([
219
-            'url'       => Endpoint::ORDER_V4,
220
-            'method'    => 'GET',
221
-            'query'     => Route4Me::generateRequestParameters($allQueryFields, $params),
222
-        ]);
223
-
224
-        return $response;
225
-    }
9
+	public $address_1;
10
+	public $address_2;
11
+	public $cached_lat;
12
+	public $cached_lng;
13
+	public $curbside_lat;
14
+	public $curbside_lng;
15
+	public $address_alias;
16
+	public $address_city;
17
+	public $EXT_FIELD_first_name;
18
+	public $EXT_FIELD_last_name;
19
+	public $EXT_FIELD_email;
20
+	public $EXT_FIELD_phone;
21
+	public $EXT_FIELD_custom_data;
22
+
23
+	public $color;
24
+	public $order_icon;
25
+	public $local_time_window_start;
26
+	public $local_time_window_end;
27
+	public $local_time_window_start_2;
28
+	public $local_time_window_end_2;
29
+	public $service_time;
30
+
31
+	public $day_scheduled_for_YYMMDD;
32
+
33
+	public $route_id;
34
+	public $redirect;
35
+	public $optimization_problem_id;
36
+	public $order_id;
37
+	public $order_ids;
38
+
39
+	public $day_added_YYMMDD;
40
+	public $scheduled_for_YYMMDD;
41
+	public $fields;
42
+	public $offset;
43
+	public $limit;
44
+	public $query;
45
+
46
+	public $created_timestamp;
47
+	public $order_status_id;
48
+	public $member_id;
49
+	public $address_state_id;
50
+	public $address_country_id;
51
+	public $address_zip;
52
+	public $in_route_count;
53
+	public $last_visited_timestamp;
54
+	public $last_routed_timestamp;
55
+	public $local_timezone_string;
56
+	public $is_validated;
57
+	public $is_pending;
58
+	public $is_accepted;
59
+	public $is_started;
60
+	public $is_completed;
61
+	public $custom_user_fields;
62
+
63
+	public $addresses = [];
64
+
65
+	public function __construct()
66
+	{
67
+		Route4Me::setBaseUrl(Endpoint::BASE_URL);
68
+	}
69
+
70
+	public static function fromArray(array $params)
71
+	{
72
+		$order = new self();
73
+		foreach ($params as $key => $value) {
74
+			if (property_exists($order, $key)) {
75
+				$order->{$key} = $value;
76
+			}
77
+		}
78
+
79
+		return $order;
80
+	}
81
+
82
+	/**
83
+	 * @param Order $params
84
+	 */
85
+	public static function addOrder($params)
86
+	{
87
+		$excludeFields = ['route_id', 'redirect', 'optimization_problem_id', 'order_id',
88
+		'order_ids', 'fields', 'offset', 'limit', 'query', 'created_timestamp', ];
89
+
90
+		$allBodyFields = Route4Me::getObjectProperties(new self(), $excludeFields);
91
+
92
+		$response = Route4Me::makeRequst([
93
+			'url'       => Endpoint::ORDER_V4,
94
+			'method'    => 'POST',
95
+			'body'      => Route4Me::generateRequestParameters($allBodyFields, $params),
96
+		]);
97
+
98
+		return $response;
99
+	}
100
+
101
+	public static function addOrder2Route($params)
102
+	{
103
+		$allQueryFields = ['route_id', 'redirect'];
104
+		$allBodyFields = ['addresses'];
105
+
106
+		$response = Route4Me::makeRequst([
107
+			'url'       => Endpoint::ROUTE_V4,
108
+			'method'    => 'PUT',
109
+			'query'     => Route4Me::generateRequestParameters($allQueryFields, $params),
110
+			'body'      => Route4Me::generateRequestParameters($allBodyFields, $params),
111
+		]);
112
+
113
+		return $response;
114
+	}
115
+
116
+	public static function addOrder2Optimization($params)
117
+	{
118
+		$allQueryFields = ['optimization_problem_id', 'redirect', 'device_type'];
119
+		$allBodyFields  = ['addresses'];
120
+
121
+		$response = Route4Me::makeRequst([
122
+			'url'       => Endpoint::OPTIMIZATION_PROBLEM,
123
+			'method'    => 'PUT',
124
+			'query'     => Route4Me::generateRequestParameters($allQueryFields, $params),
125
+			'body'      => Route4Me::generateRequestParameters($allBodyFields, $params),
126
+		]);
127
+
128
+		return $response;
129
+	}
130
+
131
+	public static function getOrder($params)
132
+	{
133
+		$allQueryFields = ['order_id', 'fields', 'day_added_YYMMDD', 'scheduled_for_YYMMDD', 'query', 'offset', 'limit'];
134
+
135
+		$response = Route4Me::makeRequst([
136
+			'url'       => Endpoint::ORDER_V4,
137
+			'method'    => 'GET',
138
+			'query'     => Route4Me::generateRequestParameters($allQueryFields, $params),
139
+		]);
140
+
141
+		return $response;
142
+	}
143
+
144
+	public static function getOrders($params)
145
+	{
146
+		$allQueryFields = ['offset', 'limit'];
147
+
148
+		$response = Route4Me::makeRequst([
149
+			'url'       => Endpoint::ORDER_V4,
150
+			'method'    => 'GET',
151
+			'query'     => Route4Me::generateRequestParameters($allQueryFields, $params),
152
+		]);
153
+
154
+		return $response;
155
+	}
156
+
157
+	public function getRandomOrderId($offset, $limit)
158
+	{
159
+		$randomOrder = $this->getRandomOrder($offset, $limit);
160
+
161
+		if (is_null($randomOrder) || !isset($randomOrder)) {
162
+			return null;
163
+		}
164
+
165
+		return $randomOrder['order_id'];
166
+	}
167
+
168
+	public function getRandomOrder($offset, $limit)
169
+	{
170
+		$params = ['offset' => $offset, 'limit' => $limit];
171
+
172
+		$orders = self::getOrders($params);
173
+
174
+		if (is_null($orders) || !isset($orders['results'])) {
175
+			return null;
176
+		}
177
+
178
+		$randomIndex = rand(0, sizeof($orders['results']) - 1);
179
+
180
+		$order = $orders['results'][$randomIndex];
181
+
182
+		return $order;
183
+	}
184
+
185
+	public static function removeOrder($params)
186
+	{
187
+		$allBodyFields = ['order_ids'];
188
+
189
+		$response = Route4Me::makeRequst([
190
+			'url'       => Endpoint::ORDER_V4,
191
+			'method'    => 'DELETE',
192
+			'body'      => Route4Me::generateRequestParameters($allBodyFields, $params),
193
+		]);
194
+
195
+		return $response;
196
+	}
197
+
198
+	public static function updateOrder($params)
199
+	{
200
+		$excludeFields = ['route_id', 'redirect', 'optimization_problem_id',
201
+		'order_ids', 'fields', 'offset', 'limit', 'query', 'created_timestamp', ];
202
+
203
+		$allBodyFields = Route4Me::getObjectProperties(new self(), $excludeFields);
204
+
205
+		$response = Route4Me::makeRequst([
206
+			'url'       => Endpoint::ORDER_V4,
207
+			'method'    => 'PUT',
208
+			'body'      => Route4Me::generateRequestParameters($allBodyFields, $params),
209
+		]);
210
+
211
+		return $response;
212
+	}
213
+
214
+	public static function searchOrder($params)
215
+	{
216
+		$allQueryFields = ['fields', 'day_added_YYMMDD', 'scheduled_for_YYMMDD', 'query', 'offset', 'limit'];
217
+
218
+		$response = Route4Me::makeRequst([
219
+			'url'       => Endpoint::ORDER_V4,
220
+			'method'    => 'GET',
221
+			'query'     => Route4Me::generateRequestParameters($allQueryFields, $params),
222
+		]);
223
+
224
+		return $response;
225
+	}
226 226
 
227
-    public static function validateCoordinate($coord)
228
-    {
229
-        $key = key($coord);
227
+	public static function validateCoordinate($coord)
228
+	{
229
+		$key = key($coord);
230 230
 
231
-        if (!is_numeric($coord[$key])) {
232
-            return false;
233
-        }
234
-
235
-        switch ($key) {
236
-        case 'cached_lat':
237
-        case 'curbside_lat':
238
-            if ($coord[$key] > 90 || $coord[$key] < -90) {
239
-                return false;
240
-            }
241
-            break;
242
-        case 'cached_lng':
243
-        case 'curbside_lng':
244
-            if ($coord[$key] > 180 || $coord[$key] < -180) {
245
-                return false;
246
-            }
247
-            break;
248
-        }
249
-
250
-        return true;
251
-    }
231
+		if (!is_numeric($coord[$key])) {
232
+			return false;
233
+		}
234
+
235
+		switch ($key) {
236
+		case 'cached_lat':
237
+		case 'curbside_lat':
238
+			if ($coord[$key] > 90 || $coord[$key] < -90) {
239
+				return false;
240
+			}
241
+			break;
242
+		case 'cached_lng':
243
+		case 'curbside_lng':
244
+			if ($coord[$key] > 180 || $coord[$key] < -180) {
245
+				return false;
246
+			}
247
+			break;
248
+		}
249
+
250
+		return true;
251
+	}
252 252
 
253
-    public function addOrdersFromCsvFile($csvFileHandle, $ordersFieldsMapping)
254
-    {
255
-        $max_line_length = 512;
256
-        $delemietr = ',';
257
-
258
-        $results = [];
259
-        $results['fail'] = [];
260
-        $results['success'] = [];
261
-
262
-        $columns = fgetcsv($csvFileHandle, $max_line_length, $delemietr);
253
+	public function addOrdersFromCsvFile($csvFileHandle, $ordersFieldsMapping)
254
+	{
255
+		$max_line_length = 512;
256
+		$delemietr = ',';
257
+
258
+		$results = [];
259
+		$results['fail'] = [];
260
+		$results['success'] = [];
261
+
262
+		$columns = fgetcsv($csvFileHandle, $max_line_length, $delemietr);
263 263
 
264
-        $excludeFields = ['route_id', 'redirect', 'optimization_problem_id', 'order_id',
265
-        'order_ids', 'fields', 'offset', 'limit', 'query', 'created_timestamp', ];
266
-
267
-        $allOrderFields = Route4Me::getObjectProperties(new self(), $excludeFields);
268
-
269
-        if (!empty($columns)) {
270
-            array_push($results['fail'], 'Empty CSV table');
264
+		$excludeFields = ['route_id', 'redirect', 'optimization_problem_id', 'order_id',
265
+		'order_ids', 'fields', 'offset', 'limit', 'query', 'created_timestamp', ];
266
+
267
+		$allOrderFields = Route4Me::getObjectProperties(new self(), $excludeFields);
268
+
269
+		if (!empty($columns)) {
270
+			array_push($results['fail'], 'Empty CSV table');
271 271
 
272
-            return $results;
273
-        }
274
-
275
-        $iRow = 1;
276
-
277
-        while (false !== ($rows = fgetcsv($csvFileHandle, $max_line_length, $delemietr))) {
278
-            if ($rows[$ordersFieldsMapping['cached_lat']] && $rows[$ordersFieldsMapping['cached_lng']] && $rows[$ordersFieldsMapping['address_1']] && [null] !== $rows) {
279
-                $cached_lat = 0.000;
280
-                $cached_lng = 0.000;
281
-
282
-                foreach (['cached_lat', 'cached_lng', 'curbside_lat', 'curbside_lng'] as $coord) {
283
-                    if (!$this->validateCoordinate([$coord => $rows[$ordersFieldsMapping[$coord]]])) {
284
-                        array_push($results['fail'], "$iRow --> Wrong " + $coord);
285
-                        ++$iRow;
286
-                        continue;
287
-                    } else {
288
-                        switch ($coord) {
289
-                        case 'cached_lat':
290
-                            $cached_lat = doubleval($rows[$ordersFieldsMapping[$coord]]);
291
-                            break;
292
-                        case 'cached_lng':
293
-                            $cached_lng = doubleval($rows[$ordersFieldsMapping[$coord]]);
294
-                            break;
295
-                        }
296
-                    }
297
-                }
298
-
299
-                $address = $rows[$ordersFieldsMapping['address_1']];
300
-
301
-                foreach (['order_city', 'order_state_id', 'order_zip_code', 'order_country_id'] as $addressPart) {
302
-                    if (isset($ordersFieldsMapping[$addressPart])) {
303
-                        $address .= ', '.$rows[$ordersFieldsMapping[$addressPart]];
304
-                    }
305
-                }
306
-
307
-                echo "$iRow --> ".$ordersFieldsMapping['day_scheduled_for_YYMMDD'].', '.$rows[$ordersFieldsMapping['day_scheduled_for_YYMMDD']].'<br>';
308
-
309
-                $parametersArray = [];
310
-
311
-                $parametersArray['cached_lat'] = $cached_lat;
312
-                $parametersArray['cached_lng'] = $cached_lng;
313
-
314
-                foreach ($allOrderFields as $orderField) {
315
-                    if (isset($ordersFieldsMapping[$orderField])) {
316
-                        $parametersArray[$orderField] = $rows[$ordersFieldsMapping[$orderField]];
317
-                    }
318
-                }
319
-
320
-                $orderParameters = self::fromArray($parametersArray);
321
-
322
-                $order = new self();
323
-
324
-                $orderResults = $order->addOrder($orderParameters);
325
-
326
-                array_push($results['success'], 'The order with order_id = '.strval($orderResults['order_id']).' added successfuly.');
327
-            } else {
328
-                array_push($results['fail'], "$iRow --> one of the parameters cached_lat, cached_lng, address_1 is not set");
329
-            }
330
-
331
-            ++$iRow;
332
-        }
333
-    }
272
+			return $results;
273
+		}
274
+
275
+		$iRow = 1;
276
+
277
+		while (false !== ($rows = fgetcsv($csvFileHandle, $max_line_length, $delemietr))) {
278
+			if ($rows[$ordersFieldsMapping['cached_lat']] && $rows[$ordersFieldsMapping['cached_lng']] && $rows[$ordersFieldsMapping['address_1']] && [null] !== $rows) {
279
+				$cached_lat = 0.000;
280
+				$cached_lng = 0.000;
281
+
282
+				foreach (['cached_lat', 'cached_lng', 'curbside_lat', 'curbside_lng'] as $coord) {
283
+					if (!$this->validateCoordinate([$coord => $rows[$ordersFieldsMapping[$coord]]])) {
284
+						array_push($results['fail'], "$iRow --> Wrong " + $coord);
285
+						++$iRow;
286
+						continue;
287
+					} else {
288
+						switch ($coord) {
289
+						case 'cached_lat':
290
+							$cached_lat = doubleval($rows[$ordersFieldsMapping[$coord]]);
291
+							break;
292
+						case 'cached_lng':
293
+							$cached_lng = doubleval($rows[$ordersFieldsMapping[$coord]]);
294
+							break;
295
+						}
296
+					}
297
+				}
298
+
299
+				$address = $rows[$ordersFieldsMapping['address_1']];
300
+
301
+				foreach (['order_city', 'order_state_id', 'order_zip_code', 'order_country_id'] as $addressPart) {
302
+					if (isset($ordersFieldsMapping[$addressPart])) {
303
+						$address .= ', '.$rows[$ordersFieldsMapping[$addressPart]];
304
+					}
305
+				}
306
+
307
+				echo "$iRow --> ".$ordersFieldsMapping['day_scheduled_for_YYMMDD'].', '.$rows[$ordersFieldsMapping['day_scheduled_for_YYMMDD']].'<br>';
308
+
309
+				$parametersArray = [];
310
+
311
+				$parametersArray['cached_lat'] = $cached_lat;
312
+				$parametersArray['cached_lng'] = $cached_lng;
313
+
314
+				foreach ($allOrderFields as $orderField) {
315
+					if (isset($ordersFieldsMapping[$orderField])) {
316
+						$parametersArray[$orderField] = $rows[$ordersFieldsMapping[$orderField]];
317
+					}
318
+				}
319
+
320
+				$orderParameters = self::fromArray($parametersArray);
321
+
322
+				$order = new self();
323
+
324
+				$orderResults = $order->addOrder($orderParameters);
325
+
326
+				array_push($results['success'], 'The order with order_id = '.strval($orderResults['order_id']).' added successfuly.');
327
+			} else {
328
+				array_push($results['fail'], "$iRow --> one of the parameters cached_lat, cached_lng, address_1 is not set");
329
+			}
330
+
331
+			++$iRow;
332
+		}
333
+	}
334 334
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -235,13 +235,13 @@  discard block
 block discarded – undo
235 235
         switch ($key) {
236 236
         case 'cached_lat':
237 237
         case 'curbside_lat':
238
-            if ($coord[$key] > 90 || $coord[$key] < -90) {
238
+            if ($coord[$key]>90 || $coord[$key]<-90) {
239 239
                 return false;
240 240
             }
241 241
             break;
242 242
         case 'cached_lng':
243 243
         case 'curbside_lng':
244
-            if ($coord[$key] > 180 || $coord[$key] < -180) {
244
+            if ($coord[$key]>180 || $coord[$key]<-180) {
245 245
                 return false;
246 246
             }
247 247
             break;
@@ -274,14 +274,14 @@  discard block
 block discarded – undo
274 274
 
275 275
         $iRow = 1;
276 276
 
277
-        while (false !== ($rows = fgetcsv($csvFileHandle, $max_line_length, $delemietr))) {
278
-            if ($rows[$ordersFieldsMapping['cached_lat']] && $rows[$ordersFieldsMapping['cached_lng']] && $rows[$ordersFieldsMapping['address_1']] && [null] !== $rows) {
277
+        while (false!==($rows = fgetcsv($csvFileHandle, $max_line_length, $delemietr))) {
278
+            if ($rows[$ordersFieldsMapping['cached_lat']] && $rows[$ordersFieldsMapping['cached_lng']] && $rows[$ordersFieldsMapping['address_1']] && [null]!==$rows) {
279 279
                 $cached_lat = 0.000;
280 280
                 $cached_lng = 0.000;
281 281
 
282 282
                 foreach (['cached_lat', 'cached_lng', 'curbside_lat', 'curbside_lng'] as $coord) {
283 283
                     if (!$this->validateCoordinate([$coord => $rows[$ordersFieldsMapping[$coord]]])) {
284
-                        array_push($results['fail'], "$iRow --> Wrong " + $coord);
284
+                        array_push($results['fail'], "$iRow --> Wrong " +$coord);
285 285
                         ++$iRow;
286 286
                         continue;
287 287
                     } else {
Please login to merge, or discard this patch.