public function run() { DB::table('routes')->delete(); $faker = Faker\Factory::create(); $data = \Rome2RioData::call('cebu', 'manila'); foreach ($data->routes as $route) { $new_route = new App\Route(); $new_route->name = $route->name; $new_route->distance = $route->distance; $new_route->duration = $route->duration; $new_route->price = \Rome2RioData::getRome2RioPrice($route); //ctrl + p and look for rome2riodata in facades folder $new_route->save(); $i = 1; foreach ($route->stops as $stop) { $stopObj = new Stop(); $stopObj->name = $stop->name; $stopObj->kind = $stop->kind; $stopObj->pos = $stop->pos; $stopObj->tips = $faker->text(20); $stopObj->timezone = property_exists($stop, "timeZone") ? $stop->timeZone : ""; $stopObj->region_code = property_exists($stop, "regionCode") ? $stop->regionCode : ""; $stopObj->save(); unset($stopObj); } /** * Loop here kay each routes naay segments * */ foreach ($route->segments as $segment) { //check if the segment is flight then passes it to the //converting function //the function then returns a generic segment object if ($segment->kind == "flight") { $segment = \Rome2RioData::convertToFlightSegment($route, $segment); } $new_segment = new App\Segment(); $new_segment->mode = $segment->kind; $new_segment->route_id = $new_route->id; $new_segment->sequence = $i; $new_segment->origin_name = $segment->sName; $new_segment->destination_name = $segment->tName; $new_segment->origin_pos = $segment->sPos; $new_segment->destination_pos = $segment->tPos; $new_segment->price = \Rome2RioData::getRome2RioPrice($segment); //ctrl + p and look for rome2riodata in facades folder $new_segment->path = property_exists($segment, 'path') ? $segment->path : ''; $new_segment->distance = $segment->distance; $new_segment->duration = $segment->duration; $new_segment->save(); $new_segment->route()->associate($new_segment); // $new_segment->save() sad diay $fi = new FlightIterinary(); $fi->days = $new_segment->itineraties; unset($new_segment); $i++; } //unset variables kada human loop unset($new_route, $i); } }
/** * Display a listing of the resource. * * @return Response */ public function get_recommend($origin = "cebu", $destination = "paris") { // $data = \Input::all(); /** * $origin and $destination pwede ra e static * tang tanga lang ang parameter na $request */ // $origin = \Input::get('origin'); // $destination = \Input::get('destination'); // $origin = "cebu"; // $destination = "manila"; $origin = urlencode($origin); $destination = urlencode($destination); /** * $url = API url * kani ray ilisi earl */ $url = "http://free.rome2rio.com/api/1.2/json/Search?key=nKYL3BZS&oName=" . $origin . "&dName=" . $destination; $ch = curl_init($url); curl_setopt($ch, CURLOPT_TIMEOUT, 5); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $data = curl_exec($ch); $data = json_decode($data); // dd($data); $airports = []; if (isset($data->airports)) { foreach ($data->airports as $airport) { $airports[$airport->code] = $airport->pos; } } // dd($data); // start debug $routes = \Rome2RioData::getRoutes($data, 0); // dd($routes); $segments = \Rome2RioData::getSegments($routes); foreach ($segments as $value) { if ($value->kind == "flight") { $value = Rome2Rio::convertToFlightSegment($value, $data); $flightpath = Rome2Rio::getFlightPath($airports[$value->sCode], $airports[$value->tCode]); $value->{"path"} = $flightpath; } } foreach ($segments as &$segment) { $segment->mode = $segment->kind; unset($segment->kind); $segment->origin_name = $segment->sName; unset($segment->sName); $segment->destination_name = $segment->tName; unset($segment->tName); $segment->origin_pos = $segment->sPos; unset($segment->sPos); $segment->destination_pos = $segment->tPos; unset($segment->tPos); } curl_close($ch); return $segments; // dd($segments); // dd($segments); //end debug // dd($data,$ch); // return response()->json([$request->all(),$data],'200'); }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function get() { dd(\Rome2RioData::getData()); }
// End Recommendation // SPOTS Route::get('api/spots', 'SpotController@getSpots'); Route::post('api/spots/add', 'SpotController@newSpot'); Route::post('api/spots/end', 'SpotController@endSpot'); // END SPOTS //Route::get('api/hotels','') // -- GEOLOCATION ROUTES -- // Route::get('geolocationhelper', function () { $longlat = "12.4221,38.9888"; $path = 'a}pwAwgraVcAZgDvD?V|BvG?bBm@z@sPrKuCrCiBvCyCfH~RjFnBZzGbBxB?vDgBnB?f@^dA?tEgBZk@]_DcB_BgACsEfCi@fD}BbB{Br@aAC{^kJwGrP[rAql@v@eAVoPvECbATnLSKgI?gSnAk^kW]OE{B'; //$data = App\Classes\Geolocationhelper::parseLongLat($longlat); // $data = App\Classes\Geolocationhelper::decode($path); // $asd = App\Classes\Geolocationhelper::pair($data); // $newpath = App\Classes\GeolocationHelper::encode($asd); $rome2riodata = \Rome2RioData::call(); $airports = App\Classes\GeolocationHelper::getAirportLongLat($rome2riodata); dd($airports); }); // -- END GEOLOCATION ROUTES -- // // -- FOURSQUARE ROUTES -- //` Route::get('testcache', function () { $data = \App\Classes\Rome2rioHelper::call(); //Cache::add('cebu,manila',$data,20); dd($data); }); // // -- SEGMENT ROUTES -- // Route::get('api/iterinary/segments/all', ['middleware' => 'cors', 'uses' => 'SegmentController@getAll']); Route::get('api/iterinary/segments/show', ['middleware' => 'cors', 'uses' => 'SegmentController@showSegment']); Route::post('api/iterinary/segments/add', ['middleware' => 'cors', 'uses' => 'SegmentController@addNew']);