public function getAll() { //add a compiled polyline of all activities $iterinary_id = Input::get('iterinary'); // return response()->json($iterinary_id); $token = Input::get('token'); if (isset($iterinary_id) || $iterinary_id) { $iterinary = Iterinary::find($iterinary_id); if (!isset($iterinary) || $iterinary == null) { $message = ['err' => '404', 'message' => ' iterinary not found']; return response()->json($message); } $activities = $iterinary->activities()->with('typable')->get(); return response()->json($activities, 200); } else { $iterinary = UserSessionHandler::getUserCurrentIterinary($token); if ($iterinary['err'] == 'err') { return response()->json($iterinary, 403); } if (!isset($iterinary) || $iterinary == null) { $message = ['err' => '403', 'message' => 'no current iterinary']; return response()->json($message); } $activities = $iterinary->activities()->with('typable')->get(); return response()->json($activities, 200); } }
public static function addOtherActivity($token, $other_data, $transpo) { $response = UserSessionHandler::resolveNewSegmentFromActivity($token, $transpo, $other_data); // return response()->json($response); $current_iterinary = UserSessionHandler::getUserCurrentIterinary($token); $day = UserSessionHandler::getDiffInDays($token, $current_iterinary->id); $activity = new Activity(); $activity->start_time = Carbon::now()->toTimeString(); $activity->iterinary_id = $current_iterinary->id; $activity->day = $day; $other_activity = new OtherActivity(); $other_activity->name = $other_data['place_name']; $other_activity->lng = $other_data['lng']; $other_activity->lat = $other_data['lat']; $other_activity->review = $other_data['review']; $other_activity->expense = $other_data['expense']; // return response()->json($eat); $other_activity->save(); $other_activity->activity()->save($activity); $iterinary = Iterinary::findOrFail($current_iterinary->id)->with('activities.typable')->first(); return response()->json($iterinary, 200); }
public function getByDay($iterinary, $day) { $iterinary = Iterinary::find($iterinary); $activities = $iterinary->activities()->day($day)->with('typable')->get(); $data = collect([]); $data->offsetSet('iterinary', $iterinary); $data->offsetSet('activities', $activities); return response()->json($data, 200); }
public function addHotelTest(Request $request) { $request = $request->all(); $food_data = $request['hotel']; $token = $request['token']; $transpo = $request['transpo']; $response = UserSessionHandler::resolveNewSegmentFromActivity($token, $transpo, $food_data); // return response()->json($response); $current_iterinary = UserSessionHandler::getUserCurrentIterinary($token); $day = UserSessionHandler::getDiffInDays($token, $current_iterinary->id); $activity = new Activity(); $activity->start_time = Carbon::now()->toTimeString(); $activity->iterinary_id = $current_iterinary->id; $activity->day = $day; $hotel = new Hotel(); $hotel->hotel_name = $food_data['place_name']; $hotel->lng = $food_data['lng']; $hotel->lat = $food_data['lat']; $hotel->tips = $food_data['review']; $hotel->price = $food_data['price']; $hotel->pic_url = ''; // return response()->json($eat); $hotel->save(); $hotel->activity()->save($activity); $iterinary = Iterinary::findOrFail($current_iterinary->id)->with('activities.typable')->first(); return response()->json($iterinary, 200); }
public function findrecommendations(Request $request) { $title = $request->title; $origin = $request->origin; $destination = $request->destination; $budget = $request->budget; $pax = $request->pax; $orderbyrate; $sortedSuggestions; // return $origin; //get iterinaries base from the origin destination $iterinaries = Iterinary::where("origin", $origin)->where("destination", $destination)->lists("id"); // dd($iterinaries); //get iterinaries that is sorted based on their avg ratings 5-1 if (count($orderbyrate = $this->sortByRating($iterinaries)) == 0) { $orderbyrate = $iterinaries; } else { $orderbyrate = $this->sortByRating($iterinaries); } // dd($orderbyrate); $acceptedBudget = $budget + $budget * 0.5; // dd($acceptedBudget); //iterinaries what fits the budget $iterinaries_accepted = Iterinary::whereIn("id", $orderbyrate)->where("price", "<=", $acceptedBudget)->lists("id"); // dd($iterinaries_accepted); if (count($sortedSuggestions = $this->sortByRating($iterinaries_accepted)) == 0) { $sortedSuggestions = $iterinaries_accepted; } else { $sortedSuggestions = $this->sortByRating($iterinaries_accepted); } // return $sortedSuggestions[0]; $finalrecommendations = []; for ($i = 0; $i < count($sortedSuggestions); $i++) { $listactivity = []; $data = Iterinary::where("id", $sortedSuggestions[$i])->get(); $creator = User::where("id", $data[0]->creator_id)->lists("name"); $rate = Rating::where("ratingable_type", "Iterinary")->where("ratingable_id", $sortedSuggestions[$i])->selectRaw("avg(value)")->lists("avg(value)"); // return round($rate[0],2); $arrayvalue = ["id" => $data[0]->id, "destination" => $data[0]->destination, "origin" => $data[0]->origin, "pax" => $data[0]->pax, "days" => $data[0]->days, "distance" => $data[0]->distance, "duration" => $data[0]->duration, "price" => $data[0]->price, "creator_id" => $data[0]->creator_id, "route_id" => $data[0]->route_id, "created_at" => $data[0]->created_at, "updated_at" => $data[0]->updated_at, "rating" => round($rate[0], 2), "creator" => $creator[0]]; // return $arrayvalue; array_push($finalrecommendations, $arrayvalue); } // dd($finalrecommendations); return $finalrecommendations; }