Esempio n. 1
0
 public function update_city($city_id, Request $request)
 {
     $city = City::find($city_id);
     $city->name = $request->name;
     $city->save();
     return redirect('cities');
 }
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index(Request $request)
 {
     $country = Country::find($request->country_id);
     $city = City::find($request->city_id);
     $state = State::find($request->state_id);
     return ['country' => $country->name, 'city' => $city->name, 'state' => $state->name];
 }
 public function remove(Request $request)
 {
     $oCity = City::find($request->id);
     $oCity->delete();
     $request->session()->flash('notify', ['type' => 'Success', 'text' => 'Данные успешно удалены!']);
     return redirect('city');
 }
Esempio n. 4
0
 public function leave_feedback($city_id, $location_id, Request $request)
 {
     $checkin = new Checkin($request->all());
     $checkin->user_id = Auth::id();
     $city = City::find($city_id);
     $location = $city->locations()->find($location_id);
     $location->checkins()->save($checkin);
     return back();
 }
Esempio n. 5
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     if ($this->option('all')) {
         foreach (City::all() as $city) {
             $city->import();
             sleep(5);
         }
     } elseif ($this->argument('city')) {
         $city = City::find($this->argument('city'));
         if (count($city)) {
             $city->import();
         }
     }
 }
Esempio n. 6
0
 public function gmapsPost()
 {
     $data = $this->request->all();
     if ($data['city_id']) {
         $city_id = City::getCityFromAutoComplete($data['city_id']);
         $city = City::find($city_id);
         $long = $city->long;
         $lat = $city->lat;
     } else {
         $long = $data['long'];
         $lat = $data['lat'];
     }
     isset($data['marker']) ? $marker = 1 : ($marker = 0);
     return redirect()->route('gmaps.get.coords', [$lat, $long, $marker]);
 }
Esempio n. 7
0
 public function checkin($city_id, $location_id, $user_id, Request $request)
 {
     $checkin = new Checkin($request->all());
     $user = User::find($user_id);
     if (!$user) {
         return response()->json(['message' => ['type' => 'error', 'body' => 'There are no user with this ID']]);
     }
     $checkin->user_id = $user_id;
     $city = City::find($city_id);
     if (!$city) {
         return response()->json(['message' => ['type' => 'error', 'body' => 'There are no city with this ID']]);
     }
     $location = $city->locations()->find($location_id);
     if (!$location) {
         return response()->json(['message' => ['type' => 'error', 'body' => 'There is no location with this ID']]);
     }
     $location->checkins()->save($checkin);
     return response()->json(['message' => ['type' => 'success', 'body' => ['new_rating' => $location->checkins()->avg('rating'), 'checkin' => 'User successfuly was cheked-in']]]);
 }
 /**
  * creates the unit training task based on the submitted POST request.
  *
  * @param Request $request
  * @param $city_id
  * @param $slot_num
  * @param $building_id
  * @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
  */
 public function getTrainUnit($city_id, $slot_num, $building_id, $type)
 {
     $city = City::find($city_id);
     if (!$this->validateOwner($city)) {
         return redirect('/home')->withErrors('Nem a te városod');
     }
     if ($building = $this->buildingCompleted($building_id)) {
         // check if the building is completed
         TaskController::checkTasks();
         // check if there any pending tasks and complete the finished ones
         if ($building->workers > 0) {
             // check if there's at least one worker in the building
             if ($building->type == 5) {
                 // check if the type of the building is 'barrack'
                 $lack_resource = $city->hasEnoughResources(Army::$unit_prices[$city->nation][$type]);
                 if (empty($lack_resource)) {
                     // check if the city has enough resources to train the unit
                     if ($city->human_resources->population > 0) {
                         // check if the city has enough population (i.e. at least 1)
                         $city->human_resources->population -= 1;
                         $city->human_resources->save();
                         // if everything is set, remove one from the population of the city and save the new population
                         $city->resources->subtract(Army::$unit_prices[$city->nation][$type]);
                         // remove the amount of resources needed by the training of the unit
                         TaskController::createTask($building, $type + 10, Army::$unit_times[$city->nation][$type]);
                         // create the task
                         return redirect("/city/{$city_id}/slot/{$slot_num}/building/{$building_id}");
                     }
                     return redirect("/city/{$city_id}/slot/{$slot_num}/building/{$building_id}")->withErrors(['not_enough_population' => 'Nincs elég népesség']);
                 }
                 $messages = [];
                 $resources = ['stone' => 'kő', 'lumber' => 'fa', 'food' => 'élelmiszer', 'iron' => 'vas'];
                 foreach ($lack_resource as $key => $value) {
                     $messages["not_enough_{$key}"] = "Még {$value} {$resources[$key]} hiányzik";
                 }
                 return redirect("/city/{$city_id}/slot/{$slot_num}/building/{$building_id}")->withErrors($messages);
             }
             return redirect("/city/{$city_id}/slot/{$slot_num}/building/{$building_id}")->withErrors(['not_a_forum' => 'Az épület nem tud munkást képezni']);
         }
         return redirect("/city/{$city_id}/slot/{$slot_num}/building/{$building_id}")->withErrors(['not_enough_worker' => 'Az épületben nem dolgozik munkás']);
     }
     return redirect("/city/{$city_id}");
 }
Esempio n. 9
0
 /**
  * @param $city_id
  * @param $slot_num
  */
 public function getMakeSettler($city_id, $slot_num, $building_id)
 {
     $city = City::find($city_id);
     if (!$this->validateOwner($city)) {
         return redirect('/home')->withErrors('Nem a te városod');
     }
     if ($building = $this->buildingCompleted($building_id)) {
         TaskController::checkTasks();
         if ($building->task->where('building_id', $building->id)->first()) {
             return redirect("/city/{$city_id}/slot/{$slot_num}/building/{$building_id}")->withErrors(['already_training' => 'Az épület használatban van']);
         }
         if ($building->workers > 0) {
             if ($building->type == 7) {
                 $lack_resource = $city->hasEnoughResources(HumanResource::$settler_price[$city->nation]);
                 if (empty($lack_resource)) {
                     if ($city->resources->workers >= 5) {
                         if ($city->resources->population >= 10) {
                             $city->resources->workers -= 5;
                             $city->resources->population -= 10;
                             $city->resources->save();
                             $city->resources->subtract(HumanResource::$settler_price[$city->nation]);
                             TaskController::createTask($building, 2, HumanResource::$settler_time[$city->nation]);
                             return redirect("/city/{$city_id}/slot/{$slot_num}/building/{$building_id}");
                         }
                         return redirect("/city/{$city_id}/slot/{$slot_num}/building/{$building_id}")->withErrors(['not_enough_population' => 'Nincs elég népesség']);
                     }
                     return redirect("/city/{$city_id}/slot/{$slot_num}/building/{$building_id}")->withErrors(['not_enough_worker' => 'Nincs elég munkás']);
                 } else {
                     $messages = [];
                     $resources = ['stone' => 'kő', 'lumber' => 'fa', 'food' => 'élelmiszer', 'iron' => 'vas'];
                     foreach ($lack_resource as $key => $value) {
                         $messages["not_enough_{$key}"] = "Még {$value} {$resources[$key]} hiányzik";
                     }
                     return redirect("/city/{$city_id}/slot/{$slot_num}/building/{$building_id}")->withErrors($messages);
                 }
             }
             return redirect("/city/{$city_id}/slot/{$slot_num}/building/{$building_id}")->withErrors(['not_a_forum' => 'Az épület nem tud telepest képezni']);
         }
         return redirect("/city/{$city_id}/slot/{$slot_num}/building/{$building_id}")->withErrors(['not_enough_worker' => 'Az épületben nem dolgozik munkás']);
     }
     return redirect("/city/{$city_id}");
 }
Esempio n. 10
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index(Request $request)
 {
     $this->validate($request, ['city_id' => 'integer|exists:city,id', 'tag_id' => 'integer|exists:tag,id', 'type' => 'string|in:' . implode(',', Place::types())]);
     if ($request->has('city_id')) {
         $city = City::find($request->input('city_id'));
     } else {
         $city = City::where('geoname_id', 658225)->first();
         if (!count($city)) {
             $city = City::first();
         }
     }
     $query = Place::where('city_id', $city->id);
     if ($request->has('search')) {
         $words = explode(" ", $request->input('search'));
         $query->whereHas('translations', function ($sub_query) use($words) {
             foreach ($words as $word) {
                 // If it is Chinese, use LIKE. Else, use full text index.
                 // http://www.regular-expressions.info/unicode.html#script
                 if (preg_match('/\\p{Han}+/u', $word)) {
                     $sub_query->where(function ($q) use($word) {
                         $q->where('name', 'like', '%' . $word . '%')->orWhere('content', 'like', '%' . $word . '%');
                     });
                 } else {
                     $sub_query->whereRaw('MATCH(name,content) AGAINST(? IN BOOLEAN MODE)', [$word . '*']);
                 }
             }
         });
     }
     if ($request->has('type')) {
         $query = $query->where('type', $request->input('type'));
     }
     if ($request->has('tag_id')) {
         $query = $query->whereHas('tags', function ($sub_query) use($request) {
             $sub_query->where('id', $request->input('tag_id'));
         });
     }
     $query->with('image');
     $places = $query->orderBy('like_count', 'desc')->paginate(24);
     return view('pages.place.index', ['places' => $places, 'city' => $city, 'type' => $request->input('type')]);
 }
Esempio n. 11
0
 /**
  * Search
  */
 public function search(Request $request)
 {
     $properties = Property::orderBy('created_at', 'DESC');
     if ($request->get('property_type') != 0) {
         $properties = $properties->where('property_type_id', $request->get('property_type'));
     }
     if ($request->get('property_status') != 0) {
         $properties = $properties->where('property_status_id', $request->get('property_status'));
     }
     if ($request->get('town_id') != 0) {
         $town = \App\Town::find($request->get('town_id'));
         $ids = [];
         foreach ($town->streets as $street) {
             $ids[] = $street->id;
         }
         $properties = $properties->whereIn('street_id', $ids);
     } elseif ($request->get('city_id') != 0) {
         $city = \App\City::find($request->get('city_id'));
         $ids = [];
         foreach ($city->towns->streets as $street) {
             $ids[] = $street->id;
         }
         $properties = $properties->whereIn('street_id', $ids);
     }
     if ($request->get("is_credit") != 0) {
         $properties = $properties->where('is_credit', $request->get('is_credit') == 1 ? true : false);
     }
     if ($request->get("is_site") != 0) {
         $properties = $properties->where('is_site', $request->get('is_site') == 1 ? true : false);
     }
     if ($request->get("min")) {
         $properties = $properties->where('price', '>=', $request->get('min'));
     }
     if ($request->get('max')) {
         $properties = $properties->where('price', '<=', $request->get('max'));
     }
     $properties = $properties->paginate(20);
     return view('property.index', ['properties' => $properties, "title" => trans('search.result')]);
 }
Esempio n. 12
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     // Start Check Authorization
     $invalid_auth = 1;
     $authRole = Auth::user()->UserRoles->role;
     if ($authRole == 1 or $authRole == 3) {
         $invalid_auth = 0;
     }
     if ($invalid_auth == 1) {
         Alert::error('Anda tidak memilik akses ini')->persistent('close');
         return redirect('dashboard');
     }
     // End Check Authorization
     $validation = Validator::make($request->all(), City::rules($id));
     // Check if it fails //
     if ($validation->fails()) {
         return redirect()->back()->withInput()->with('errors', $validation->errors());
     }
     // Process valid data & go to success page //
     $city = City::find($id);
     // replace old data with new data from the submitted form //
     // save city data into database //
     $city->name = $request->input('name');
     $city->id_provinces = $request->input('id_provinces');
     $city->save();
     Alert::success($request->input('name') . ' Saved!')->persistent("Close");
     return redirect('city/list')->with('message', 'You just updated an cateogry!');
 }
Esempio n. 13
0
         return redirect(url('/admin'))->withInput()->withErrors($validator);
     }
     $user = Property::find($data['property_id'])->delete();
     return redirect(url('/admin'));
 });
 Route::delete('/property/photo/{picture}', function (Picture $picture) {
     \Cloudinary\Uploader::destroy($picture->cloudinary_public_id);
     $property_id = PropertyPictureBridge::where('picture_id', $picture->id)->get()[0]->property_id;
     $picture->delete();
     return redirect(url('/property/edit/photos/' . $property_id));
 });
 Route::get('/property/edit/{property_id}', function ($property_id) {
     $cities = City::orderBy('name', 'asc')->get();
     $property = Property::find($property_id);
     $property->district_name = District::find($property->district_id)->name;
     $property->city_name = City::find($property->city_id)->name;
     $amenities = PropertyFeatures::where('property_id', $property->id)->get()[0];
     return view('edit_property', ['property' => $property, 'cities' => $cities, 'amenities' => $amenities]);
 });
 Route::get('/property/edit/photos/{property_id}', function ($property_id) {
     $property = Property::find($property_id);
     $images = get_all_images_from_property_id_without_placeholder($property_id);
     return view('edit_images', ['property' => $property, 'images' => $images]);
 });
 Route::post('/property/edit', function (Request $request) {
     $data = $request->all();
     $validator = Validator::make($request->all(), ['title' => 'required|max:255', 'city' => 'required', 'district' => 'required', 'address' => 'required|max:255', 'type' => 'required|in:private_room,shared_room,entire_place', 'max_occupancy' => 'required|numeric|min:0|integer', 'price_per_night' => 'required|numeric|min:0|max:9999.99', 'description' => 'required', 'property_id' => 'required|numeric|integer|min:0']);
     if ($validator->fails()) {
         return redirect(url('/property/edit/' . $data['property_id']))->withInput()->withErrors($validator);
     }
     $myErrorArr = array();
Esempio n. 14
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id, Request $request)
 {
     $city = City::find($id);
     $city->update($request->all());
     return redirect('admin/cities');
 }
Esempio n. 15
0
 public function getArmyData(Request $request)
 {
     TaskController::checkTasks();
     $army = Army::where('id', $request->input('army_id'))->first()->toArray();
     $hex = Grid::find($army['current_hex_id']);
     // if there's a city on the current hex
     if ($hex->city > 0) {
         $city = City::find($hex->city);
         $army['city_nation'] = intval($city->nation);
         $army['city_name'] = $city->name;
     }
     $army['hex_type'] = $hex->type;
     $army['hex_owner'] = User::find($hex->owner)->name;
     if (Auth::user()->id === $army['user_id']) {
         return $army;
     } else {
         $units = ['unit1' => 0, 'unit2' => 0, 'unit3' => 0, 'unit4' => 0, 'unit5' => 0, 'unit6' => 0, 'unit7' => 0];
         $army = array_diff_key($army, $units);
         $user = User::find($army['user_id']);
         $army['army_owner'] = $user->name;
         $army['nation'] = intval($user->nation);
         return $army;
     }
 }
Esempio n. 16
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     //
     $data = City::find($id);
     Session::flash('message', 'City name "' . $data->name . '" successfully deleted');
     $data->delete();
     return redirect('/city');
 }
Esempio n. 17
0
 public function towns(TownsRequest $request)
 {
     $city = City::find($request->get("city_id"));
     $towns = $city->towns;
     return Response::json($towns);
 }
Esempio n. 18
0
 /**
  * @param $city_id
  * @param $slot_num
  * @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
  */
 public function getLevelUpBuilding($city_id, $slot_num, $building_id)
 {
     $city = City::find($city_id);
     if (!$this->validateOwner($city)) {
         return redirect('/home')->withErrors('Nem a te városod');
     }
     $building = $this->buildingCompleted($building_id);
     if ($building == !false) {
         //            if (($building->level + 1) > ($city->level * 5)) {
         //                return redirect("/city/$city_id/slot/$slot_num/building/$building_id")->withErrors(['low_city_level' => 'A város nem elég fejlett egy ilyen szintű épülethez']);
         //            }
         $price = Building::$building_prices[$city->nation][$building->type];
         foreach ($price as $key => &$value) {
             $value *= $building->level + 1;
         }
         $time = Building::$building_times[$city->nation][$building->type] * ($building->level + 1) / $building->workers;
         $this->levelUp($city, $building, $price, $time);
         return redirect("/city/{$city_id}");
     }
     return redirect("/city/{$city_id}");
 }
Esempio n. 19
0
 public function getBuildingsForCity($id)
 {
     $city = City::find($id);
     $buildings = \App\Building::all();
     $modifiedPrices = ResourceController::getPricesForBuildings($buildings, $city);
     return $modifiedPrices;
     for ($i = 0; $i < count($buildings); $i++) {
         $buildings[$i]->resource = $modifiedPrices[$i];
     }
     return $buildings;
 }
Esempio n. 20
0
 public function searchPlaces(Request $request)
 {
     $data = $request->all();
     $properties = DB::table('properties')->where('owner_id', '!=', Auth::id());
     if ($request->has('city')) {
         $city = City::where('name', $data['city'])->first();
         $properties = $properties->where('city_id', '=', $city->id);
     }
     if ($request->has('district')) {
         $district = District::where('name', $data['district'])->first();
         $properties = $properties->where('district_id', '=', $district->id);
     }
     if ($request->has('type')) {
         $properties = $properties->where('type', '=', $data['type']);
     }
     if ($request->has('min_occupancy')) {
         $properties = $properties->where('max_occupancy', '>=', $data['min_occupancy']);
     }
     if ($request->has('max_occupancy')) {
         $properties = $properties->where('max_occupancy', '<=', $data['max_occupancy']);
     }
     if ($request->has('min_price_per_night')) {
         $properties = $properties->where('price_per_night', '>=', $data['min_price_per_night']);
     }
     if ($request->has('max_price_per_night')) {
         $properties = $properties->where('price_per_night', '<=', $data['max_price_per_night']);
     }
     $properties = $properties->join('property_features', 'properties.id', '=', 'property_features.property_id');
     if ($request->has('kitchen')) {
         $properties = $properties->where('kitchen', '=', on2true($data['kitchen']));
     }
     if ($request->has('internet')) {
         $properties = $properties->where('internet', '=', on2true($data['internet']));
     }
     if ($request->has('tv')) {
         $properties = $properties->where('tv', '=', on2true($data['tv']));
     }
     if ($request->has('essentials')) {
         $properties = $properties->where('essentials', '=', on2true($data['essentials']));
     }
     if ($request->has('shampoo')) {
         $properties = $properties->where('shampoo', '=', on2true($data['shampoo']));
     }
     if ($request->has('heating')) {
         $properties = $properties->where('heating', '=', on2true($data['heating']));
     }
     if ($request->has('air_conditioning')) {
         $properties = $properties->where('air_conditioning', '=', on2true($data['air_conditioning']));
     }
     if ($request->has('washer')) {
         $properties = $properties->where('washer', '=', on2true($data['washer']));
     }
     if ($request->has('dryer')) {
         $properties = $properties->where('dryer', '=', on2true($data['dryer']));
     }
     if ($request->has('free_parking_on_premises')) {
         $properties = $properties->where('free_parking_on_premises', '=', on2true($data['free_parking_on_premises']));
     }
     if ($request->has('wireless_internet')) {
         $properties = $properties->where('wireless_internet', '=', on2true($data['wireless_internet']));
     }
     if ($request->has('cable_tv')) {
         $properties = $properties->where('cable_tv', '=', on2true($data['cable_tv']));
     }
     if ($request->has('breakfast')) {
         $properties = $properties->where('breakfast', '=', on2true($data['breakfast']));
     }
     if ($request->has('pets_allowed')) {
         $properties = $properties->where('pets_allowed', '=', on2true($data['pets_allowed']));
     }
     if ($request->has('family_kid_friendly')) {
         $properties = $properties->where('family_kid_friendly', '=', on2true($data['family_kid_friendly']));
     }
     if ($request->has('suitable_for_events')) {
         $properties = $properties->where('suitable_for_events', '=', on2true($data['suitable_for_events']));
     }
     if ($request->has('smoking_allowed')) {
         $properties = $properties->where('smoking_allowed', '=', on2true($data['smoking_allowed']));
     }
     if ($request->has('wheelchair_accessible')) {
         $properties = $properties->where('wheelchair_accessible', '=', on2true($data['wheelchair_accessible']));
     }
     if ($request->has('elevator_in_building')) {
         $properties = $properties->where('elevator_in_building', '=', on2true($data['elevator_in_building']));
     }
     if ($request->has('indoor_fireplace')) {
         $properties = $properties->where('indoor_fireplace', '=', on2true($data['indoor_fireplace']));
     }
     if ($request->has('buzzer_wireless_intercom')) {
         $properties = $properties->where('buzzer_wireless_intercom', '=', on2true($data['buzzer_wireless_intercom']));
     }
     if ($request->has('doorman')) {
         $properties = $properties->where('doorman', '=', on2true($data['doorman']));
     }
     if ($request->has('pool')) {
         $properties = $properties->where('pool', '=', on2true($data['pool']));
     }
     if ($request->has('hot_tub')) {
         $properties = $properties->where('hot_tub', '=', on2true($data['hot_tub']));
     }
     if ($request->has('gym')) {
         $properties = $properties->where('gym', '=', on2true($data['gym']));
     }
     if ($request->has('feature_24_hour_check_in')) {
         $properties = $properties->where('feature_24_hour_check_in', '=', on2true($data['feature_24_hour_check_in']));
     }
     if ($request->has('hangers')) {
         $properties = $properties->where('hangers', '=', on2true($data['hangers']));
     }
     if ($request->has('iron')) {
         $properties = $properties->where('iron', '=', on2true($data['iron']));
     }
     if ($request->has('hair_dryer')) {
         $properties = $properties->where('hair_dryer', '=', on2true($data['hair_dryer']));
     }
     if ($request->has('laptop_friendly_workspace')) {
         $properties = $properties->where('laptop_friendly_workspace', '=', on2true($data['laptop_friendly_workspace']));
     }
     $properties = $properties->get();
     foreach ($properties as $property) {
         $property->id = $property->property_id;
         $property->city_name = City::find($property->city_id)->name;
         $photo_ids = PropertyPictureBridge::where('property_id', $property->id)->get();
         if (count($photo_ids) < 1) {
             $property->image_url = env('PLACEHOLDER_IMAGE_URL');
         } else {
             $property->image_url = Picture::find($photo_ids[0]->picture_id)->url;
         }
     }
     $cities = City::all();
     return redirect(url('/places/searchresult'))->with(['properties' => $properties, 'cities' => $cities]);
 }
Esempio n. 21
0
 public function editProfil($id)
 {
     $cities = City::all();
     $user = $this->userRepository->getById($id);
     $selected_city = City::find($user->city_id);
     return view('manager.users.editProfil', compact('user', 'cities', 'selected_city'));
 }
Esempio n. 22
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     $validation = Validator::make($request->all(), City::rules($id));
     // Check if it fails //
     if ($validation->fails()) {
         return redirect()->back()->withInput()->with('errors', $validation->errors());
     }
     // Process valid data & go to success page //
     $city = City::find($id);
     // replace old data with new data from the submitted form //
     // save city data into database //
     $city->name = $request->input('name');
     $city->id_provinces = $request->input('id_provinces');
     $city->save();
     Alert::success($request->input('name') . ' Saved!')->persistent("Close");
     return redirect('city/list')->with('message', 'You just updated an cateogry!');
 }