1
|
|
|
<?php |
2
|
|
|
namespace Route4Me; |
3
|
|
|
|
4
|
|
|
use Route4Me\Common; |
5
|
|
|
use Route4Me\Enum\Endpoint; |
6
|
|
|
|
7
|
|
|
class Vehicle extends Common |
8
|
|
|
{ |
9
|
|
|
public $vehicle_id; |
10
|
|
|
public $member_id; |
11
|
|
|
public $is_deleted; |
12
|
|
|
public $vehicle_alias; |
13
|
|
|
public $vehicle_vin; |
14
|
|
|
public $vehicle_reg_state_id; |
15
|
|
|
public $vehicle_reg_country_id; |
16
|
|
|
public $vehicle_license_plate; |
17
|
|
|
public $vehicle_type_id; |
18
|
|
|
public $vehicle_make; |
19
|
|
|
public $vehicle_model_year; |
20
|
|
|
public $vehicle_model; |
21
|
|
|
public $vehicle_year_acquired; |
22
|
|
|
public $vehicle_cost_new; |
23
|
|
|
public $purchased_new; |
24
|
|
|
public $license_start_date; |
25
|
|
|
public $license_end_date; |
26
|
|
|
public $vehicle_axle_count; |
27
|
|
|
public $is_operational; |
28
|
|
|
public $mpg_city; |
29
|
|
|
public $mpg_highway; |
30
|
|
|
public $fuel_type; |
31
|
|
|
public $height_inches; |
32
|
|
|
public $weight_lb; |
33
|
|
|
public $external_telematics_vehicle_id; |
34
|
|
|
public $has_trailer; |
35
|
|
|
public $heightInInches; |
36
|
|
|
public $lengthInInches; |
37
|
|
|
public $widthInInches; |
38
|
|
|
public $maxWeightPerAxleGroupInPounds; |
39
|
|
|
public $numAxles; |
40
|
|
|
public $weightInPounds; |
41
|
|
|
public $HazmatType; |
42
|
|
|
public $LowEmissionZonePref; |
43
|
|
|
public $Use53FootTrailerRouting; |
44
|
|
|
public $UseNationalNetwork; |
45
|
|
|
public $UseTruckRestrictions; |
46
|
|
|
public $AvoidFerries; |
47
|
|
|
public $DividedHighwayAvoidPreference; |
48
|
|
|
public $FreewayAvoidPreference; |
49
|
|
|
public $InternationalBordersOpen; |
50
|
|
|
public $TollRoadUsage; |
51
|
|
|
public $hwy_only; |
52
|
|
|
public $long_combination_vehicle; |
53
|
|
|
public $avoid_highways; |
54
|
|
|
public $side_street_adherence; |
55
|
|
|
public $truck_config; |
56
|
|
|
public $height_metric; |
57
|
|
|
public $length_metric; |
58
|
|
|
public $width_metric; |
59
|
|
|
public $weight_metric; |
60
|
|
|
public $max_weight_per_axle_group_metric; |
61
|
|
|
|
62
|
|
|
public function __construct () |
63
|
|
|
{ |
64
|
|
|
Route4Me::setBaseUrl(Endpoint::WH_BASE_URL); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public static function fromArray(array $params) { |
68
|
|
|
$vehicle= new Vehicle(); |
69
|
|
|
foreach($params as $key => $value) { |
70
|
|
|
if (property_exists($vehicle, $key)) { |
71
|
|
|
$vehicle->{$key} = $value; |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
return $vehicle; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
View Code Duplication |
public static function getVehicles($params) |
|
|
|
|
79
|
|
|
{ |
80
|
|
|
$response = Route4Me::makeRequst(array( |
81
|
|
|
'url' => Endpoint::VEHICLE_V4, |
82
|
|
|
'method' => 'GET', |
83
|
|
|
'query' => array( |
84
|
|
|
'with_pagination' => isset($params['with_pagination']) ? $params['with_pagination'] : null, |
85
|
|
|
'page' => isset($params['page']) ? $params['page'] : null, |
86
|
|
|
'perPage' => isset($params['perPage']) ? $params['perPage'] : null, |
87
|
|
|
) |
88
|
|
|
)); |
89
|
|
|
|
90
|
|
|
return $response; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function getRandomVehicleId($page,$perPage) |
94
|
|
|
{ |
95
|
|
|
$query['page'] = isset($page) ? $page : 1; |
|
|
|
|
96
|
|
|
$query['perPage'] = isset($perPage) ? $perPage : 10; |
97
|
|
|
$query['with_pagination'] = true; |
98
|
|
|
|
99
|
|
|
$vehicles = $this->getVehicles($query); |
100
|
|
|
|
101
|
|
|
if (is_null($vehicles)) return null; |
102
|
|
|
if (!isset($vehicles['data'])) return null; |
103
|
|
|
if (sizeof($vehicles['data'])<1) return null; |
104
|
|
|
|
105
|
|
|
$randomIndex = rand(0, sizeof($vehicles['data'])-1); |
106
|
|
|
|
107
|
|
|
return $vehicles['data'][$randomIndex]['vehicle_id']; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
View Code Duplication |
public function getVehicleByID($vehicleID) |
|
|
|
|
111
|
|
|
{ |
112
|
|
|
$response = Route4Me::makeRequst(array( |
113
|
|
|
'url' => Endpoint::VEHICLE_V4 . '/' . $vehicleID, |
114
|
|
|
'method' => 'GET' |
115
|
|
|
)); |
116
|
|
|
|
117
|
|
|
return $response; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
public function updateVehicle($params) |
121
|
|
|
{ |
122
|
|
|
$vehicleID = isset($params->vehicle_id) ? $params->vehicle_id : null; |
123
|
|
|
|
124
|
|
|
$body = array(); |
125
|
|
|
|
126
|
|
|
$vehicle= new Vehicle(); |
127
|
|
|
|
128
|
|
|
foreach($params as $key => $value) { |
129
|
|
|
if ($key=="vehicle_id") continue; |
130
|
|
|
if (property_exists($vehicle, $key)) { |
131
|
|
|
if (isset($params->{$key})) { |
132
|
|
|
$body[$key] = $params->{$key}; |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
$response = Route4Me::makeRequst(array( |
138
|
|
|
'url' => Endpoint::VEHICLE_V4 . '/' . $vehicleID, |
139
|
|
|
'method' => 'PUT', |
140
|
|
|
'body' => $body, |
141
|
|
|
'HTTPHEADER' => 'Content-Type: application/json' |
142
|
|
|
)); |
143
|
|
|
|
144
|
|
|
return $response; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
View Code Duplication |
public function createVehicle($params) |
|
|
|
|
148
|
|
|
{ |
149
|
|
|
$body = array(); |
150
|
|
|
|
151
|
|
|
$vehicle= new Vehicle(); |
152
|
|
|
|
153
|
|
|
foreach($params as $key => $value) { |
154
|
|
|
if ($key=="vehicle_id") continue; |
155
|
|
|
if (property_exists($vehicle, $key)) { |
156
|
|
|
if (isset($params->{$key})) { |
157
|
|
|
$body[$key] = $params->{$key}; |
158
|
|
|
} |
159
|
|
|
} |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
$response = Route4Me::makeRequst(array( |
163
|
|
|
'url' => Endpoint::VEHICLE_V4, |
164
|
|
|
'method' => 'POST', |
165
|
|
|
'body' => $body, |
166
|
|
|
'HTTPHEADER' => 'Content-Type: application/json' |
167
|
|
|
)); |
168
|
|
|
|
169
|
|
|
return $response; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
public function removeVehicle($params) |
173
|
|
|
{ |
174
|
|
|
$vehicleID = isset($params->vehicle_id) ? $params->vehicle_id : null; |
175
|
|
|
|
176
|
|
|
$response = Route4Me::makeRequst(array( |
177
|
|
|
'url' => Endpoint::VEHICLE_V4 . '/' . $vehicleID, |
178
|
|
|
'method' => 'DELETE', |
179
|
|
|
'HTTPHEADER' => 'Content-Type: application/json' |
180
|
|
|
)); |
181
|
|
|
|
182
|
|
|
return $response; |
183
|
|
|
} |
184
|
|
|
} |
185
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.