public function post_rome2rio(Request $request)
 {
     /**
      * $origin and $destination pwede ra e static
      * tang tanga lang ang parameter na $request
      */
     $origin = $request['origin'];
     $destination = $request['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 = Rome2rio::call($origin, $destination);
     //$data = json_decode($data)
     dd($data);
     return response()->json($data, 200);
     curl_close($ch);
 }
 /**
  * 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');
 }
 /**
  * Show the form for creating a new resource.
  *
  * @return Response
  */
 public function populateRoutes()
 {
     $inputs = ['origin' => rawurlencode(Input::get('origin')), 'destination' => rawurlencode(Input::get('destination')), 'pax' => Input::get('pax')];
     $airports = [];
     $user_id = Input::get('user_id');
     $contributor = User::find($user_id);
     $now = Carbon::now();
     if ($contributor == null) {
         return response()->json('user not found.', 404);
     }
     $data = Rome2Rio::call($inputs['origin'], $inputs['destination']);
     if (isset($data->airports)) {
         foreach ($data->airports as $airport) {
             $airports[$airport->code] = $airport->pos;
         }
     }
     foreach ($data->routes as $route) {
         $iterinary = new Iterinary();
         $iterinary->origin = $data->places[0]->name;
         $iterinary->destination = $data->places[1]->name;
         $iterinary->creator_id = $contributor->id;
         $iterinary->duration = $route->duration;
         $iterinary->distance = $route->distance;
         $iterinary->price = Rome2Rio::getRome2RioPrice($route);
         $new_route = new Route();
         $new_route->name = $route->name;
         $new_route->distance = $route->distance;
         $new_route->duration = $route->duration;
         $new_route->price = Rome2Rio::getRome2RioPrice($route);
         $new_route->save();
         $iterinary->route()->associate($new_route);
         $iterinary->save();
         $contributor->iterinaries()->attach($iterinary->id, ['date_start' => $now]);
         $i = 1;
         foreach ($route->segments as $segment) {
             $new_segment = new Segment();
             if ($segment->kind == "flight") {
                 $segment = Rome2Rio::convertToFlightSegment($segment, $data);
             }
             $new_segment->mode = !isset($segment->subkind) ? $segment->kind : $segment->subkind;
             $new_segment->sequence = $i;
             $new_segment->origin_name = !isset($segment->sName) ? "" : $segment->sName;
             $new_segment->destination_name = !isset($segment->tName) ? "" : $segment->tName;
             $new_segment->origin_pos = $segment->sPos;
             $new_segment->destination_pos = $segment->tPos;
             $new_segment->price = Rome2Rio::getRome2RioPrice($segment);
             $new_segment->path = $segment->kind == "flight" ? Rome2Rio::getFlightPath($airports[$segment->sCode], $airports[$segment->tCode]) : $segment->path;
             $new_segment->distance = $segment->distance;
             $new_segment->duration = $segment->duration;
             $new_route->segments()->save($new_segment);
             $activity = new Activity();
             $activity->iterinary_id = $iterinary->id;
             $activity->day = 1;
             $activity->start_time = Carbon::now()->toTimeString();
             $activity->end_time = Carbon::now()->addMinute($segment->duration)->toTimeString();
             $new_segment->activity()->save($activity);
             $i++;
         }
         unset($i);
         // unset index for segments sequence
     }
     //dd($data);
 }
Esempio n. 4
0
// --   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']);
Route::post('api/iterinary/segments/end', ['middleware' => 'cors', 'uses' => 'SegmentController@endSegment']);
//  -- END SEGMENT ROUTES -- //
//  -- STOPS ROUTES -- //
Route::get('api/iterinary/stops/get', ['middleware' => 'cors', 'uses' => 'IterinaryController@getStops']);
Route::post('api/iterinary/stops/add', ['middleware' => 'cors', 'uses' => 'SegmentController@addStop']);
//  -- END STOP ROUTES -- //
//  -- POPULATE TABLES -- //