コード例 #1
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     $data = Segment::all();
     return response()->json(json_encode($data));
 }
コード例 #2
0
 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);
     }
 }
コード例 #3
0
 public function getRecommendation(Request $request)
 {
     $origin = $request->origin;
     $destination = $request->destination;
     $userbudget = $request->budget;
     // dd($origin,$destination);
     // $origin = "cebu city";
     // $destination = "manila";
     //get closest budget
     $budget = $this->getBudgetRecommendation($userbudget, $origin, $destination);
     if ($budget == 0) {
         // dd("in");
         $segments = $this->get_recommend($origin, $destination);
         // dd($segments);
         return response()->json($segments);
     } else {
         //get iterinaries that falls under the budget
         $iterinary_choices = Iterinary::whereRaw("price <= ?", [$budget])->where("origin", $origin)->where("destination", $destination)->lists("id");
         // dd($iterinary_choices);
         //get the iterinary_id that falls under the budget and is the best in terms of rating
         $suggested_iterinary = WeightedAverage::whereIn("ratingable_id", $iterinary_choices)->where("ratingable_type", "Iterinary")->max("average");
         $suggested_iterinary = WeightedAverage::where("average", $suggested_iterinary)->where("ratingable_type", "Iterinary")->lists("ratingable_id");
         //refers to points if there are iterinaries with the same rate
         // dd($suggested_iterinary);
         if (count($suggested_iterinary) > 1) {
             $suggested_iterinary = $this->getSuggestedIterinary($suggested_iterinary);
         }
         // dd($suggested_iterinary);
         $route_id = Iterinary::where("id", $suggested_iterinary)->lists("route_id");
         $segments = Segment::where("route_id", $route_id)->get();
         return response()->json($segments);
         // dd($segments);
         // dd($route_id);
         // dd($iterinary_choices);
     }
 }