@@ -203,15 +203,15 @@ private function import_choose()
203203 "dep " => $ segments [2 ],
204204 "arr " => $ segments [3 ],
205205 "duration " => Time::strToSecs (str_replace ('. ' , ': ' , $ segments [10 ])),
206- "aircraftid " => $ segments [5 ]
206+ "aircraftids " => array_map ( ' trim ' , explode ( ' , ' , $ segments [5 ])),
207207 );
208208 }, array_filter ($ routelines [0 ], function ($ l ) {
209209 return strlen (trim ($ l )) > 0 ;
210210 }));
211211
212212 foreach ($ data ->routes as $ r ) {
213213 foreach ($ r as $ k => $ v ) {
214- if (strlen ($ v ) < 1 ) {
214+ if (gettype ( $ v ) === ' string ' && strlen ($ v ) < 1 ) {
215215 Session::flash ('error ' , 'Invalid CSV File ' );
216216 $ this ->get_import ();
217217 }
@@ -231,11 +231,13 @@ private function import_import()
231231 $ db ->query ("DELETE FROM route_aircraft WHERE NOT routeid IN (SELECT id FROM routes) " );
232232
233233 $ allaircraft = Aircraft::fetchActiveAircraft ()->results ();
234+ $ acdict = [];
234235 $ firstRank = $ db ->query ("SELECT * FROM ranks ORDER BY timereq ASC LIMIT 1 " )->first ()->id ;
235236
236237 for ($ i = 0 ; $ i < $ count ; $ i ++) {
237238 $ item = Input::get ('livery ' . $ i );
238239 if (empty ($ item )) continue ;
240+
239241 $ aircraft = false ;
240242 foreach ($ allaircraft as $ a ) {
241243 if ($ a ->ifliveryid == $ item ) $ aircraft = $ a ;
@@ -247,15 +249,7 @@ private function import_import()
247249 array_push ($ allaircraft , $ aircraft );
248250 }
249251
250-
251-
252- $ routes = array_map (function ($ r ) use ($ i , $ aircraft ) {
253- if ($ r ['aircraftid ' ] == Input::get ('rego ' . $ i )) {
254- $ r ['aircraftid ' ] = $ aircraft ->id ;
255- }
256-
257- return $ r ;
258- }, $ routes );
252+ $ acdict [Input::get ('rego ' . $ i )] = $ aircraft ;
259253 }
260254
261255 $ nextId = intval (Route::nextId ());
@@ -270,7 +264,19 @@ private function import_import()
270264 array_push ($ params , $ item ["dep " ]);
271265 array_push ($ params , $ item ["arr " ]);
272266 array_push ($ params , $ item ["duration " ]);
273- Route::addAircraft ($ nextId + $ j , $ item ["aircraftid " ]);
267+
268+ $ aircraft = array_map (function ($ a ) use ($ acdict ) {
269+ if (isset ($ acdict [$ a ])) return $ acdict [$ a ]->id ;
270+
271+ return null ;
272+ }, $ item ["aircraftids " ]);
273+ $ aircraft = array_filter ($ aircraft , function ($ a ) {
274+ return $ a !== null ;
275+ });
276+
277+ foreach ($ aircraft as $ a ) {
278+ Route::addAircraft ($ nextId + $ j , $ a );
279+ }
274280
275281 $ j ++;
276282 }
0 commit comments