From 891b1039de669d6d9f1334b86254a623db102c7e Mon Sep 17 00:00:00 2001 From: d9it Date: Tue, 26 Mar 2024 18:03:48 +0530 Subject: [PATCH] timezone and default distance unit --- app/Console/Commands/AutoSync.php | 2 +- app/Http/Controllers/HomeController.php | 19 +- .../Controllers/backend/DataController.php | 97 ++-- .../Controllers/backend/ImportController.php | 296 +++++----- .../Controllers/backend/MapController.php | 12 +- .../Controllers/frontEnd/CommonController.php | 2 +- .../frontEnd/ExploreController.php | 42 +- .../frontEnd/LocationController.php | 54 +- app/Http/Middleware/TimeZoneMiddleware.php | 15 +- app/Model/Layout.php | 2 +- app/Model/Map.php | 4 +- app/Services/DistanceServices.php | 2 +- config/app.php | 2 +- ...8_add_javascript_map_key_to_maps_table.php | 34 ++ ...6_070558_add_timezone_to_layouts_table.php | 33 ++ resources/views/backEnd/pages/map.blade.php | 524 ++++++++++-------- .../backEnd/settings/add_country.blade.php | 11 +- .../views/frontEnd/locations/show.blade.php | 2 +- .../frontEnd/services/services.blade.php | 2 +- resources/views/layouts/style.blade.php | 9 +- 20 files changed, 663 insertions(+), 501 deletions(-) create mode 100644 database/migrations/2024_03_22_062948_add_javascript_map_key_to_maps_table.php create mode 100644 database/migrations/2024_03_26_070558_add_timezone_to_layouts_table.php diff --git a/app/Console/Commands/AutoSync.php b/app/Console/Commands/AutoSync.php index 0723cb61..27f204f9 100644 --- a/app/Console/Commands/AutoSync.php +++ b/app/Console/Commands/AutoSync.php @@ -221,7 +221,7 @@ public function apply_geocode() $client = new \GuzzleHttp\Client(); $geocoder = new Geocoder($client); $map = Map::find(1); - $geocode_api_key = $map && $map->api_key ? $map->api_key : null; + $geocode_api_key = $map && $map->geocode_map_key ? $map->geocode_map_key : null; $geocoder->setApiKey($geocode_api_key); if ($ungeocoded_location_info_list) { diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 845f4cad..25159c5b 100755 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -5,12 +5,7 @@ use App\Model\Alt_taxonomy; use App\Model\Layout; use App\Model\Map; -use App\Model\MetaFilter; -use App\Model\Organization; use App\Model\Page; -use App\Model\Service; -use App\Model\ServiceOrganization; -use App\Model\ServiceTaxonomy; use App\Model\Taxonomy; use App\Model\TaxonomyType; use Illuminate\Http\Request; @@ -38,6 +33,7 @@ public function index() { return view('home'); } + public function home($value = '') { $home = Layout::find(1); @@ -73,7 +69,7 @@ public function home($value = '') } else { foreach ($grandparent->terms()->where('taxonomy_parent_name', '=', $taxonomy_parent_name)->get() as $child_key => $child_term) { $child_data['parent_taxonomy'] = $child_term; - $child_data['child_taxonomies'] = ""; + $child_data['child_taxonomies'] = ''; $parent_taxonomy[] = $child_data; } } @@ -83,7 +79,7 @@ public function home($value = '') } } else { $serviceCategoryId = TaxonomyType::orderBy('order')->where('name', 'Service Category')->first(); - $parent_taxonomies = Taxonomy::whereNull('taxonomy_parent_name')->whereNotNull('taxonomy_name')->where('taxonomy', 'LIKE', '%' . ($serviceCategoryId ? $serviceCategoryId->taxonomy_type_recordid : '') . '%'); + $parent_taxonomies = Taxonomy::whereNull('taxonomy_parent_name')->whereNotNull('taxonomy_name')->where('taxonomy', 'LIKE', '%'.($serviceCategoryId ? $serviceCategoryId->taxonomy_type_recordid : '').'%'); $taxonomy_recordids = Taxonomy::getTaxonomyRecordids(); if (count($taxonomy_recordids) > 0) { @@ -93,12 +89,13 @@ public function home($value = '') $taxonomy_tree['parent_taxonomies'] = $parent_taxonomies->get(); } - if ($layout && $layout->activate_login_home == 1 && !Auth::check()) { + if ($layout && $layout->activate_login_home == 1 && ! Auth::check()) { return redirect('/login'); } else { return view('frontEnd.home', compact('home', 'map', 'grandparent_taxonomies', 'layout'))->with('taxonomy_tree', $taxonomy_tree); } } + public function dashboard($value = '') { $layout = Layout::first(); @@ -106,6 +103,7 @@ public function dashboard($value = '') return view('backEnd.dashboard', compact('layout', 'page')); } + public function checkTwillio(Request $request) { try { @@ -113,8 +111,9 @@ public function checkTwillio(Request $request) $token = $request->get('twillioKey'); $twilio = new Client($sid, $token); - $account = $twilio->api->v2010->accounts("ACd991aaec2fba11620c174e9148e04d7a") + $account = $twilio->api->v2010->accounts('ACd991aaec2fba11620c174e9148e04d7a') ->fetch(); + return response()->json([ 'message' => 'Your twillio key is verified!', 'success' => true, @@ -137,7 +136,7 @@ public function checkSendgrid(Request $request) $email->setFrom(env('MAIL_FROM_ADDRESS'), 'test'); $email->setSubject('test'); $email->addTo('example@example.com', 'test'); - $email->addContent("text/plain", 'test'); + $email->addContent('text/plain', 'test'); $sendgrid = new \SendGrid($key); $response = $sendgrid->send($email); diff --git a/app/Http/Controllers/backend/DataController.php b/app/Http/Controllers/backend/DataController.php index 72e61d3d..bcdb1cc6 100644 --- a/app/Http/Controllers/backend/DataController.php +++ b/app/Http/Controllers/backend/DataController.php @@ -3,14 +3,16 @@ namespace App\Http\Controllers\backend; use App\Http\Controllers\Controller; -use App\Model\Map; -use App\Model\Source_data; use App\Model\Address; use App\Model\Airtablekeyinfo; +use App\Model\Layout; +use App\Model\Map; +use App\Model\Source_data; use DateTime; use DateTimeZone; use Illuminate\Http\Request; use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Redirect; use Illuminate\Support\Facades\Session; @@ -117,10 +119,8 @@ public function update($id, Request $request) // exit(); $source_data->active = $request->input('source_data'); - $source_data->save(); - return redirect('import'); } catch (\Throwable $th) { return redirect('import'); @@ -139,11 +139,13 @@ public function destroy($id) return Redirect::route('admin.posts.index'); } + public function add_country() { $countries = DB::table('countries')->pluck('name', 'sortname'); + $layout = Layout::find(1); - $zones_array = array(); + $zones_array = []; $timestamp = time(); // $dummy_datetime_object = new DateTime(); foreach (timezone_identifiers_list() as $key => $zone) { @@ -153,8 +155,9 @@ public function add_country() // $tz = new DateTimeZone($zone); // $zones_array[$key]['offset'] = $tz->getOffset($dummy_datetime_object); - $zones_array[$zone] = ('UTC/GMT ' . date('P', $timestamp)) . ' ' . $zone; + $zones_array[$zone] = ('UTC/GMT '.date('P', $timestamp)).' '.$zone; } + date_default_timezone_set(($layout->timezone ?? 'UTC')); // $zones_array = array(); // $timestamp = time(); @@ -165,55 +168,74 @@ public function add_country() // // $zones_array[$key]['diff_from_GMT'] = 'UTC/GMT ' . date('P', $timestamp); // $zones_array[$zone] = ('UTC/GMT ' . date('P', $timestamp)) . ' ' . $zone; // } - return view('backEnd.settings.add_country', compact('countries', 'zones_array')); + return view('backEnd.settings.add_country', compact('countries', 'zones_array', 'layout')); } + public function save_country(Request $request) { try { Address::whereNULL('address_country')->update([ - 'address_country' => $request->country + 'address_country' => $request->country, ]); DB::commit(); - $envFile = app()->environmentFilePath(); - $str = file_get_contents($envFile); - $values = [ - "TIME_ZONE" => $request->get('timezone') ? $request->get('timezone') : 'UTC', - "LOCALIZATION" => $request->get('country') ? $request->get('country') : 'US', - ]; - - if (count($values) > 0) { - foreach ($values as $envKey => $envValue) { - - $str .= "\n"; // In case the searched variable is in the last line without \n - $keyPosition = strpos($str, "{$envKey}="); - $endOfLinePosition = strpos($str, "\n", $keyPosition); - $oldLine = substr($str, $keyPosition, $endOfLinePosition - $keyPosition); - - // If key does not exist, add it - if (!$keyPosition || !$endOfLinePosition || !$oldLine) { - $str .= "{$envKey}={$envValue}\n"; - } else { - $str = str_replace($oldLine, "{$envKey}={$envValue}", $str); - } + $layout = Layout::find(1); + if ($layout) { + $layout->timezone = $request->get('timezone'); + $layout->localization = $request->get('country'); + $layout->save(); + + date_default_timezone_set(($layout->timezone ?? 'UTC')); + if ($layout && $layout->timezone) { + Config::set('app.timezone', $layout->timezone); + + Artisan::call('cache:clear'); + Artisan::call('config:clear'); } } - $str = substr($str, 0, -1); - if (!file_put_contents($envFile, $str)) { - return false; - } - Artisan::call('config:cache'); - Artisan::call('config:clear'); + // $envFile = app()->environmentFilePath(); + // $str = file_get_contents($envFile); + // $values = [ + // "TIME_ZONE" => $request->get('timezone') ? $request->get('timezone') : 'UTC', + // "LOCALIZATION" => $request->get('country') ? $request->get('country') : 'US', + // ]; + + // if (count($values) > 0) { + // foreach ($values as $envKey => $envValue) { + + // $str .= "\n"; // In case the searched variable is in the last line without \n + // $keyPosition = strpos($str, "{$envKey}="); + // $endOfLinePosition = strpos($str, "\n", $keyPosition); + // $oldLine = substr($str, $keyPosition, $endOfLinePosition - $keyPosition); + + // // If key does not exist, add it + // if (!$keyPosition || !$endOfLinePosition || !$oldLine) { + // $str .= "{$envKey}={$envValue}\n"; + // } else { + // $str = str_replace($oldLine, "{$envKey}={$envValue}", $str); + // } + // } + // } + + // $str = substr($str, 0, -1); + // if (!file_put_contents($envFile, $str)) { + // return false; + // } + // Artisan::call('config:cache'); + // Artisan::call('config:clear'); Session::flash('message', 'Data saved successfully!'); Session::flash('status', 'success'); + return redirect()->back(); } catch (\Throwable $th) { Session::flash('message', $th->getMessage()); Session::flash('status', 'error'); + return redirect()->back(); } } + public function save_source_data(Request $request) { try { @@ -222,6 +244,7 @@ public function save_source_data(Request $request) $source_data->save(); $airtable_api_key_input = $request->airtable_api_key_input; $airtable_base_url_input = $request->airtable_base_url_input; + // if ($request->source_data == 1) { // Airtablekeyinfo::whereid(1)->update([ // 'api_key' => $airtable_api_key_input, @@ -234,12 +257,12 @@ public function save_source_data(Request $request) // ]); // } return response()->json([ - 'success' => true + 'success' => true, ], 200); } catch (\Throwable $th) { return response()->json([ 'message' => $th->getMessage(), - 'success' => false + 'success' => false, ], 500); } } diff --git a/app/Http/Controllers/backend/ImportController.php b/app/Http/Controllers/backend/ImportController.php index 77fd85e8..346e3855 100644 --- a/app/Http/Controllers/backend/ImportController.php +++ b/app/Http/Controllers/backend/ImportController.php @@ -67,7 +67,6 @@ use App\Model\TaxonomyTerm; use App\Model\TaxonomyType; use Carbon\Carbon; -use Illuminate\Auth\Events\Failed; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\DB; @@ -75,10 +74,10 @@ use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Session; -use Yajra\DataTables\Facades\DataTables; use Maatwebsite\Excel\Facades\Excel; use OwenIt\Auditing\Models\Audit; use Spatie\Geocoder\Geocoder; +use Yajra\DataTables\Facades\DataTables; use ZanySoft\Zip\Zip; use ZipArchive; @@ -90,6 +89,7 @@ public function __construct(MapController $mapController) { $this->mapController = $mapController; } + /** * Display a listing of the resource. * @@ -113,7 +113,6 @@ public function create() /** * Store a newly created resource in storage. * - * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) @@ -128,7 +127,7 @@ public function store(Request $request) ]); if ($request->import_type == 'zipfile') { $this->validate($request, [ - 'zipfile' => 'required' + 'zipfile' => 'required', ]); } elseif ($request->import_type == 'zipfile_api') { $this->validate($request, [ @@ -145,22 +144,22 @@ public function store(Request $request) $airtable_access_token = ''; $airtable_base_id = ''; $zipfile_path = ''; - if ($request->has('airtable_access_token') && $request->has('airtable_base_id') && ($request->import_type == 'airtable' || $request->import_type == 'airtable_v3')) { + if ($request->has('airtable_access_token') && $request->has('airtable_base_id') && ($request->import_type == 'airtable' || $request->import_type == 'airtable_v3')) { $response = Http::withHeaders([ - 'Authorization' => 'Bearer ' . $request->airtable_access_token - ])->get('https://api.airtable.com/v0/' . $request->airtable_base_id . '/organizations'); + 'Authorization' => 'Bearer '.$request->airtable_access_token, + ])->get('https://api.airtable.com/v0/'.$request->airtable_base_id.'/organizations'); if ($response->status() != 200) { Session::flash('message', 'Airtable key or base id is invalid. Please enter valid information.'); Session::flash('status', 'error'); + return redirect()->back()->withInput(); } - $Airtablekeyinfo = Airtablekeyinfo::create([ 'access_token' => $request->airtable_access_token, - 'base_url' => $request->airtable_base_id + 'base_url' => $request->airtable_base_id, ]); $airtable_access_token = $Airtablekeyinfo->id; $airtable_base_id = $Airtablekeyinfo->id; @@ -171,25 +170,26 @@ public function store(Request $request) $type = $file->getClientOriginalExtension(); $path = public_path('import_source_file'); $file->move($path, $name); - $zipfile_path = '/import_source_file/' . $name; - } else if ($request->import_type == 'zipfile_api') { - $path = public_path('import_source_file/' . $request->key . '.zip'); + $zipfile_path = '/import_source_file/'.$name; + } elseif ($request->import_type == 'zipfile_api') { + $path = public_path('import_source_file/'.$request->key.'.zip'); $ch = curl_init(); - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_URL, $request->endpoint); curl_setopt($ch, CURLOPT_REFERER, $request->endpoint); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $result = curl_exec($ch); curl_close($ch); - if (json_decode($result) == "Failed") { + if (json_decode($result) == 'Failed') { Session::flash('message', 'Error! : api response error please check api endpoint!'); Session::flash('status', 'error'); + return redirect('import'); } // if($result == ) - $ifp = fopen($path, "wb"); + $ifp = fopen($path, 'wb'); // if ($decode) { // fwrite($ifp, base64_decode($result)); // } else { @@ -198,13 +198,14 @@ public function store(Request $request) fclose($ifp); // $zipfile_path = $path . $name; - $zipfile_path = '/import_source_file/' . $request->key . '.zip'; + $zipfile_path = '/import_source_file/'.$request->key.'.zip'; } if ($request->has('auto_sync') && $request->auto_sync == 1) { $syncData = ImportDataSource::where('auto_sync', '1')->get(); if (count($syncData) > 0) { Session::flash('message', 'You can only have one auto-synced Airtable and you already have one.'); Session::flash('status', 'error'); + return redirect()->back()->withInput(); } } @@ -224,10 +225,12 @@ public function store(Request $request) ]); Session::flash('message', 'Success! Data Source added successfully.'); Session::flash('status', 'success'); + return redirect('import'); } catch (\Throwable $th) { - Session::flash('message', 'Error! :' . $th->getMessage()); + Session::flash('message', 'Error! :'.$th->getMessage()); Session::flash('status', 'error'); + return redirect('import'); } } @@ -252,13 +255,13 @@ public function show($id) public function edit($id) { $dataSource = ImportDataSource::whereId($id)->first(); + return view('backEnd.import.edit', compact('dataSource')); } /** * Update the specified resource in storage. * - * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ @@ -274,7 +277,7 @@ public function update(Request $request, $id) ]); if ($request->import_type == 'zipfile') { $this->validate($request, [ - 'zipfile' => 'required' + 'zipfile' => 'required', ]); } elseif ($request->import_type == 'zipfile_api') { $this->validate($request, [ @@ -297,21 +300,22 @@ public function update(Request $request, $id) if ($Airtablekeyinfo) { Airtablekeyinfo::where('access_token', $request->airtable_access_token)->update([ 'access_token' => $request->airtable_access_token, - 'base_url' => $request->airtable_base_id + 'base_url' => $request->airtable_base_id, ]); } else { $Airtablekeyinfo = Airtablekeyinfo::create([ 'access_token' => $request->airtable_access_token, - 'base_url' => $request->airtable_base_id + 'base_url' => $request->airtable_base_id, ]); } $response = Http::withHeaders([ - 'Authorization' => 'Bearer ' . $request->airtable_access_token - ])->get('https://api.airtable.com/v0/' . $request->airtable_base_id . '/organizations'); + 'Authorization' => 'Bearer '.$request->airtable_access_token, + ])->get('https://api.airtable.com/v0/'.$request->airtable_base_id.'/organizations'); if ($response->status() != 200) { Session::flash('message', 'Airtable key or base id is invalid. Please enter valid information.'); Session::flash('status', 'error'); + return redirect()->back()->withInput(); } $airtable_access_token = $Airtablekeyinfo->id; @@ -323,25 +327,26 @@ public function update(Request $request, $id) $type = $file->getClientOriginalExtension(); $path = public_path('import_source_file'); $file->move($path, $name); - $zipfile_path = '/import_source_file/' . $name; - } else if ($request->import_type == 'zipfile_api') { - $path = public_path('import_source_file/' . $request->key . '.zip'); + $zipfile_path = '/import_source_file/'.$name; + } elseif ($request->import_type == 'zipfile_api') { + $path = public_path('import_source_file/'.$request->key.'.zip'); $ch = curl_init(); - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_URL, $request->endpoint); curl_setopt($ch, CURLOPT_REFERER, $request->endpoint); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $result = curl_exec($ch); curl_close($ch); - if (json_decode($result) == "Failed") { + if (json_decode($result) == 'Failed') { Session::flash('message', 'Error! : api response error please check api endpoint!'); Session::flash('status', 'error'); + return redirect('import'); } // if($result == ) - $ifp = fopen($path, "wb"); + $ifp = fopen($path, 'wb'); // if ($decode) { // fwrite($ifp, base64_decode($result)); // } else { @@ -350,7 +355,7 @@ public function update(Request $request, $id) fclose($ifp); // $zipfile_path = $path . $name; - $zipfile_path = '/import_source_file/' . $request->key . '.zip'; + $zipfile_path = '/import_source_file/'.$request->key.'.zip'; } if ($request->has('auto_sync') && $request->auto_sync == 1) { $syncData = ImportDataSource::where('auto_sync', '1')->first(); @@ -358,6 +363,7 @@ public function update(Request $request, $id) if ($syncData && $syncData->id != $id) { Session::flash('message', 'You can only have one auto-synced Airtable and you already have one.'); Session::flash('status', 'error'); + return redirect()->back()->withInput(); } } @@ -378,10 +384,12 @@ public function update(Request $request, $id) ]); Session::flash('message', 'Success! Data Source updated successfully.'); Session::flash('status', 'success'); + return redirect('import'); } catch (\Throwable $th) { - Session::flash('message', 'Error! :' . $th->getMessage()); + Session::flash('message', 'Error! :'.$th->getMessage()); Session::flash('status', 'error'); + return redirect('import'); } } @@ -398,38 +406,44 @@ public function destroy($id) ImportDataSource::whereId($id)->delete(); Session::flash('message', 'Success! Data Source deleted successfully.'); Session::flash('status', 'success'); + return redirect('import'); } catch (\Throwable $th) { - Session::flash('message', 'Error! :' . $th->getMessage()); + Session::flash('message', 'Error! :'.$th->getMessage()); Session::flash('status', 'error'); + return redirect('import'); } } + public function getDataSource(Request $request) { try { $ImportDataSource = ImportDataSource::select('*'); - if (!$request->ajax()) { + if (! $request->ajax()) { return view('backEnd.import.import', compact('ImportDataSource')); } + return DataTables::of($ImportDataSource) ->editColumn('auto_sync', function ($row) { // $link = 'Off  auto_sync == 1 ? "checked" : "") . ' />  On'; // return $link; - $link = $row->auto_sync == 1 ? "On" : "Off"; + $link = $row->auto_sync == 1 ? 'On' : 'Off'; + return $link; }) ->addColumn('action', function ($row) { $links = ''; if ($row) { - $links .= 'id) . '" class="btn btn-info btn-sm " style="margin-right:10px;">Import Now'; - $links .= 'id) . '" style="margin-right:10px;">'; + $links .= 'Import Now'; + $links .= ''; $id = $row->id; $route = 'import'; - $links .= view('backEnd.delete', compact('id', 'route'))->render(); + $links .= view('backEnd.delete', compact('id', 'route'))->render(); } + return $links; }) // ->filter(function ($query) use ($request) { @@ -448,25 +462,29 @@ public function getDataSource(Request $request) //throw $th; } } + public function getImportHistory(Request $request) { try { $importHistory = ImportHistory::select('*'); - if (!$request->ajax()) { + if (! $request->ajax()) { return view('backEnd.import.import', compact('importHistory')); } + return DataTables::of($importHistory) ->editColumn('created_at', function ($row) { return date('d-m-Y H:i:s A', strtotime($row->created_at)); }) ->editColumn('auto_sync', function ($row) { - $link = $row->auto_sync == 1 ? "Auto" : "Manual"; + $link = $row->auto_sync == 1 ? 'Auto' : 'Manual'; + return $link; }) ->editColumn('import_type', function ($row) { - $link = $row->import_type == 'airtable' ? "Airtable 2.2" : ($row->import_type == 'airtable_v3' ? "Airtable 3.0" : "Zipfile"); + $link = $row->import_type == 'airtable' ? 'Airtable 2.2' : ($row->import_type == 'airtable_v3' ? 'Airtable 3.0' : 'Zipfile'); + return $link; }) // ->filter(function ($query) use ($request) { @@ -485,6 +503,7 @@ public function getImportHistory(Request $request) //throw $th; } } + public function importData($id) { try { @@ -536,12 +555,13 @@ public function importData($id) $airtableKeyInfo = Airtablekeyinfo::whereId($importData->airtable_api_key)->first(); $response = Http::withHeaders([ - 'Authorization' => 'Bearer ' . $airtableKeyInfo->access_token - ])->get('https://api.airtable.com/v0/' . $airtableKeyInfo->base_url . '/organizations'); + 'Authorization' => 'Bearer '.$airtableKeyInfo->access_token, + ])->get('https://api.airtable.com/v0/'.$airtableKeyInfo->base_url.'/organizations'); if ($response->status() != 200) { Session::flash('message', 'Airtable key or base id is invalid. Please enter valid information and try again.'); Session::flash('status', 'error'); + return redirect()->back()->withInput(); } app(\App\Http\Controllers\frontEnd\ServiceController::class)->airtable_v3($airtableKeyInfo->access_token, $airtableKeyInfo->base_url); @@ -569,17 +589,18 @@ public function importData($id) $importHistory->status = 'Completed'; $importHistory->sync_by = Auth::id(); $importHistory->save(); - } else if ($importData && $importData->import_type == 'airtable_v2') { + } elseif ($importData && $importData->import_type == 'airtable_v2') { $organization_tag = $importData->organization_tags; $airtableKeyInfo = Airtablekeyinfo::whereId($importData->airtable_api_key)->first(); $response = Http::withHeaders([ - 'Authorization' => 'Bearer ' . $airtableKeyInfo->access_token - ])->get('https://api.airtable.com/v0/' . $airtableKeyInfo->base_url . '/organizations'); + 'Authorization' => 'Bearer '.$airtableKeyInfo->access_token, + ])->get('https://api.airtable.com/v0/'.$airtableKeyInfo->base_url.'/organizations'); if ($response->status() != 200) { Session::flash('message', 'Airtable key or base id is invalid. Please enter valid information and try again.'); Session::flash('status', 'error'); + return redirect()->back()->withInput(); } app(\App\Http\Controllers\frontEnd\ServiceController::class)->airtable_v2($airtableKeyInfo->access_token, $airtableKeyInfo->base_url); @@ -603,25 +624,26 @@ public function importData($id) $importHistory->status = 'Completed'; $importHistory->sync_by = Auth::id(); $importHistory->save(); - } else if ($importData && $importData->import_type == 'zipfile' || $importData && $importData->import_type == 'zipfile_api') { + } elseif ($importData && $importData->import_type == 'zipfile' || $importData && $importData->import_type == 'zipfile_api') { if ($importData && $importData->import_type == 'zipfile_api') { - $path = public_path('import_source_file/' . $importData->key . '.zip'); + $path = public_path('import_source_file/'.$importData->key.'.zip'); $ch = curl_init(); - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_URL, $importData->endpoint); curl_setopt($ch, CURLOPT_REFERER, $importData->endpoint); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $result = curl_exec($ch); curl_close($ch); - if (json_decode($result) == "Failed") { + if (json_decode($result) == 'Failed') { Session::flash('message', 'Error! : api response error please check api endpoint!'); Session::flash('status', 'error'); + return redirect('import'); } // if($result == ) - $ifp = fopen($path, "wb"); + $ifp = fopen($path, 'wb'); // if ($decode) { // fwrite($ifp, base64_decode($result)); // } else { @@ -645,9 +667,10 @@ public function importData($id) $this->apply_geocode(); Session::flash('message', 'Success! Data Source Imported successfully.'); Session::flash('status', 'success'); + return redirect('import'); } catch (\Throwable $th) { - Log::error('Error from importData : ' . $th); + Log::error('Error from importData : '.$th); $importHistory = new ImportHistory(); $importHistory->status = 'Error'; $importHistory->error_message = $th->getMessage(); @@ -655,9 +678,11 @@ public function importData($id) $importHistory->save(); Session::flash('message', $th->getMessage()); Session::flash('status', 'error'); + return redirect('import'); } } + public function changeAutoImport(Request $request) { try { @@ -672,23 +697,25 @@ public function changeAutoImport(Request $request) if (count($syncData) > 0) { return response()->json([ 'message' => 'You can only have one auto-synced Airtable and you already have one.', - 'success' => false + 'success' => false, ], 500); } $importData = ImportDataSource::whereId($id)->first(); $importData->auto_sync = '1'; $importData->save(); + return response()->json([ 'message' => 'Auto sync changed successfully!', - 'success' => true + 'success' => true, ], 200); } else { $importData = ImportDataSource::whereId($id)->first(); $importData->auto_sync = '0'; $importData->save(); + return response()->json([ 'message' => 'Auto sync changed successfully!', - 'success' => true + 'success' => true, ], 200); } // } else { @@ -700,10 +727,11 @@ public function changeAutoImport(Request $request) } catch (\Throwable $th) { return response()->json([ 'message' => $th->getMessage(), - 'success' => false + 'success' => false, ], 500); } } + public function zip($importData) { try { @@ -732,16 +760,15 @@ public function zip($importData) $path = public_path('/HSDS/data/services.csv'); - - if (!file_exists($path)) { - $response = array( + if (! file_exists($path)) { + $response = [ 'status' => 'error', 'result' => 'services.csv does not exist.', - ); + ]; + return $response; } - // Excel::import(new Services, $path); @@ -754,11 +781,12 @@ public function zip($importData) //locations.csv $path = public_path('/HSDS/data/locations.csv'); - if (!file_exists($path)) { - $response = array( + if (! file_exists($path)) { + $response = [ 'status' => 'error', 'result' => 'locations.csv does not exist.', - ); + ]; + return $response; } @@ -775,11 +803,12 @@ public function zip($importData) //organizations.csv $path = public_path('/HSDS/data/organizations.csv'); - if (!file_exists($path)) { - $response = array( + if (! file_exists($path)) { + $response = [ 'status' => 'error', 'result' => 'organizations.csv does not exist.', - ); + ]; + return $response; } @@ -795,11 +824,12 @@ public function zip($importData) //contacts.csv $path = public_path('/HSDS/data/contacts.csv'); - if (!file_exists($path)) { - $response = array( + if (! file_exists($path)) { + $response = [ 'status' => 'error', 'result' => 'contacts.csv does not exist.', - ); + ]; + return $response; } // @@ -814,11 +844,12 @@ public function zip($importData) //phones.csv $path = public_path('/HSDS/data/phones.csv'); - if (!file_exists($path)) { - $response = array( + if (! file_exists($path)) { + $response = [ 'status' => 'error', 'result' => 'phones.csv does not exist.', - ); + ]; + return $response; } // @@ -833,11 +864,12 @@ public function zip($importData) //physical_addresses.csv $path = public_path('/HSDS/data/physical_addresses.csv'); - if (!file_exists($path)) { - $response = array( + if (! file_exists($path)) { + $response = [ 'status' => 'error', 'result' => 'physical_addresses.csv does not exist.', - ); + ]; + return $response; } // @@ -851,11 +883,12 @@ public function zip($importData) // //languages.csv $path = public_path('/HSDS/data/languages.csv'); - if (!file_exists($path)) { - $response = array( + if (! file_exists($path)) { + $response = [ 'status' => 'error', 'result' => 'languages.csv does not exist.', - ); + ]; + return $response; } // @@ -870,11 +903,12 @@ public function zip($importData) //taxonomy.csv $path = public_path('/HSDS/data/taxonomy_terms.csv'); - if (!file_exists($path)) { - $response = array( + if (! file_exists($path)) { + $response = [ 'status' => 'error', 'result' => 'taxonomy_terms.csv does not exist.', - ); + ]; + return $response; } // @@ -889,11 +923,12 @@ public function zip($importData) //taxonomy_types.csv $path = public_path('/HSDS/data/taxonomy_types.csv'); - if (!file_exists($path)) { - $response = array( + if (! file_exists($path)) { + $response = [ 'status' => 'error', 'result' => 'taxonomy_types.csv does not exist.', - ); + ]; + return $response; } // @@ -909,11 +944,12 @@ public function zip($importData) //taxonomy_terms_types.csv $path = public_path('/HSDS/data/taxonomy_terms_types.csv'); - if (!file_exists($path)) { - $response = array( + if (! file_exists($path)) { + $response = [ 'status' => 'error', 'result' => 'taxonomy_terms_types.csv does not exist.', - ); + ]; + return $response; } // @@ -928,11 +964,12 @@ public function zip($importData) //services_taxonomy.csv $path = public_path('/HSDS/data/service_attributes.csv'); - if (!file_exists($path)) { - $response = array( + if (! file_exists($path)) { + $response = [ 'status' => 'error', 'result' => 'service_attributes.csv does not exist.', - ); + ]; + return $response; } @@ -940,7 +977,7 @@ public function zip($importData) // Excel::import(new ServiceTaxonomyImport, $path); - $date = date("Y/m/d H:i:s"); + $date = date('Y/m/d H:i:s'); $csv_source = CSV_Source::where('name', '=', 'Services_taxonomy')->first(); $csv_source->records = ServiceTaxonomy::count(); $csv_source->syncdate = $date; @@ -949,11 +986,12 @@ public function zip($importData) //services_at_location.csv $path = public_path('/HSDS/data/services_at_location.csv'); - if (!file_exists($path)) { - $response = array( + if (! file_exists($path)) { + $response = [ 'status' => 'error', 'result' => 'services_at_location.csv does not exist.', - ); + ]; + return $response; } @@ -970,11 +1008,12 @@ public function zip($importData) //accessibility_for_disabilities.csv $path = public_path('/HSDS/data/accessibility_for_disabilities.csv'); - if (!file_exists($path)) { - $response = array( + if (! file_exists($path)) { + $response = [ 'status' => 'error', 'result' => 'accessibility_for_disabilities.csv does not exist.', - ); + ]; + return $response; } // Accessibility::truncate(); @@ -990,11 +1029,12 @@ public function zip($importData) //regular_schedules.csv $path = public_path('/HSDS/data/schedules.csv'); - if (!file_exists($path)) { - $response = array( + if (! file_exists($path)) { + $response = [ 'status' => 'error', 'result' => 'schedules.csv does not exist.', - ); + ]; + return $response; } @@ -1009,11 +1049,12 @@ public function zip($importData) //service tag.csv $path = public_path('/HSDS/data/service_tags.csv'); - if (!file_exists($path)) { - $response = array( + if (! file_exists($path)) { + $response = [ 'status' => 'error', 'result' => 'service_tags.csv does not exist.', - ); + ]; + return $response; } Excel::import(new ServiceTagImport, $path); @@ -1021,11 +1062,12 @@ public function zip($importData) //organization tag.csv $path = public_path('/HSDS/data/organization_tags.csv'); - if (!file_exists($path)) { - $response = array( + if (! file_exists($path)) { + $response = [ 'status' => 'error', 'result' => 'organization_tags.csv does not exist.', - ); + ]; + return $response; } Excel::import(new OrganizationTagImport, $path); @@ -1033,11 +1075,12 @@ public function zip($importData) //LocationAddress $path = public_path('/HSDS/data/location_addresses.csv'); - if (!file_exists($path)) { - $response = array( + if (! file_exists($path)) { + $response = [ 'status' => 'error', 'result' => 'location_addresses.csv does not exist.', - ); + ]; + return $response; } Excel::import(new LocationAddressImport, $path); @@ -1045,11 +1088,12 @@ public function zip($importData) //LocationPhone $path = public_path('/HSDS/data/location_phones.csv'); - if (!file_exists($path)) { - $response = array( + if (! file_exists($path)) { + $response = [ 'status' => 'error', 'result' => 'location_phones.csv does not exist.', - ); + ]; + return $response; } Excel::import(new LocationPhoneImport, $path); @@ -1057,16 +1101,16 @@ public function zip($importData) //ServicePhone $path = public_path('/HSDS/data/service_phones.csv'); - if (!file_exists($path)) { - $response = array( + if (! file_exists($path)) { + $response = [ 'status' => 'error', 'result' => 'service_phones.csv does not exist.', - ); + ]; + return $response; } Excel::import(new ServicePhoneImport, $path); - rename(public_path('/HSDS/data/services.csv'), public_path('/csv/services.csv')); rename(public_path('/HSDS/data/locations.csv'), public_path('/csv/locations.csv')); rename(public_path('/HSDS/data/organizations.csv'), public_path('/csv/organizations.csv')); @@ -1079,12 +1123,14 @@ public function zip($importData) rename(public_path('/HSDS/data/services_at_location.csv'), public_path('/csv/services_at_location.csv')); rename(public_path('/HSDS/data/accessibility_for_disabilities.csv'), public_path('/csv/accessibility_for_disabilities.csv')); rename(public_path('/HSDS/data/schedules.csv'), public_path('/csv/schedules.csv')); - return "import completed"; + + return 'import completed'; } catch (\Throwable $th) { dd($th); - Log::error('Error in import controller import : ' . $th); + Log::error('Error in import controller import : '.$th); } } + public function apply_geocode() { try { @@ -1093,7 +1139,7 @@ public function apply_geocode() $client = new \GuzzleHttp\Client(); $geocoder = new Geocoder($client); $map = Map::find(1); - $geocode_api_key = $map && $map->api_key ? $map->api_key : null; + $geocode_api_key = $map && $map->geocode_map_key ? $map->geocode_map_key : null; $geocoder->setApiKey($geocode_api_key); if ($ungeocoded_location_info_list) { @@ -1103,10 +1149,10 @@ public function apply_geocode() $address_info = $location_info->location_name; if ($location_info->address && count($location_info->address) > 0 && isset($location_info->address[0])) { $add = $location_info->address[0]; - $address_info = $add->address_1 . ($add->address_city ? ', ' . $add->address_city : '') . ($add->address_state_province ? ', ' . $add->address_state_province : '') . ($add->address_postal_code ? ', ' . $add->address_postal_code : ''); + $address_info = $add->address_1.($add->address_city ? ', '.$add->address_city : '').($add->address_state_province ? ', '.$add->address_state_province : '').($add->address_postal_code ? ', '.$add->address_postal_code : ''); } // $response = $geocoder->getCoordinatesForAddress('30-61 87th Street, Queens, NY, 11369'); - $response = $geocoder->getCoordinatesForAddress($address_info . ', ' . (env('LOCALIZATION') ? env('LOCALIZATION') : 'US')); + $response = $geocoder->getCoordinatesForAddress($address_info.', '.(env('LOCALIZATION') ? env('LOCALIZATION') : 'US')); // if (($response['lat'] > 40.5) && ($response['lat'] < 42.0)) { // $latitude = $response['lat']; // $longitude = $response['lng']; @@ -1142,7 +1188,7 @@ public function apply_geocode() return; } catch (\Throwable $th) { - Log::error('Error in applying geocode in import : ' . $th); + Log::error('Error in applying geocode in import : '.$th); } } } diff --git a/app/Http/Controllers/backend/MapController.php b/app/Http/Controllers/backend/MapController.php index e36245bf..f9155da7 100644 --- a/app/Http/Controllers/backend/MapController.php +++ b/app/Http/Controllers/backend/MapController.php @@ -115,7 +115,9 @@ public function store(Request $request) { $map = Map::find(1); $map->active = $request->active; - $map->api_key = $request->api_key; + $map->geocode_map_key = $request->geocode_map_key; + $map->javascript_map_key = $request->javascript_map_key; + $map->distance_unit = $request->distance_unit; $map->state = $request->state; $map->lat = $request->lat; $map->long = $request->long; @@ -174,7 +176,9 @@ public function update($id, Request $request) // exit(); if ($request->input('active') == 'checked') { $map->active = 1; - $map->api_key = $request->input('api_key'); + $map->geocode_map_key = $request->input('geocode_map_key'); + $map->javascript_map_key = $request->input('javascript_map_key'); + $map->distance_unit = $request->input('distance_unit'); $map->state = $request->input('state'); $map->lat = $request->input('lat'); $map->long = $request->input('long'); @@ -239,7 +243,7 @@ public function apply_geocode(Request $request) $client = new \GuzzleHttp\Client(); $geocoder = new Geocoder($client); $map = Map::find(1); - $geocode_api_key = $map && $map->api_key ? $map->api_key : null; + $geocode_api_key = $map && $map->geocode_map_key ? $map->geocode_map_key : null; $geocoder->setApiKey($geocode_api_key); @@ -296,7 +300,7 @@ public function apply_geocode_again(Request $request) $client = new \GuzzleHttp\Client(); $geocoder = new Geocoder($client); $map = Map::find(1); - $geocode_api_key = $map && $map->api_key ? $map->api_key : null; + $geocode_api_key = $map && $map->geocode_map_key ? $map->geocode_map_key : null; $geocoder->setApiKey($geocode_api_key); diff --git a/app/Http/Controllers/frontEnd/CommonController.php b/app/Http/Controllers/frontEnd/CommonController.php index 9d437034..9a4a53e6 100644 --- a/app/Http/Controllers/frontEnd/CommonController.php +++ b/app/Http/Controllers/frontEnd/CommonController.php @@ -1188,7 +1188,7 @@ public function apply_geocode($location) $client = new \GuzzleHttp\Client(); $geocoder = new Geocoder($client); $map = Map::find(1); - $geocode_api_key = $map && $map->api_key ? $map->api_key : null; + $geocode_api_key = $map && $map->geocode_map_key ? $map->geocode_map_key : null; $geocoder->setApiKey($geocode_api_key); if ($location->location_name) { diff --git a/app/Http/Controllers/frontEnd/ExploreController.php b/app/Http/Controllers/frontEnd/ExploreController.php index 7c2ded78..b70d2b39 100644 --- a/app/Http/Controllers/frontEnd/ExploreController.php +++ b/app/Http/Controllers/frontEnd/ExploreController.php @@ -39,8 +39,18 @@ class ExploreController extends Controller { + public ?Map $map; + public int $radius; + public function __construct(public Geocoder $geocoder, public DistanceServices $distanceServices) { + $this->map = Map::find(1); + $this->radius = 3959; + + if ($this->map->distance_unit === 'km') { + $this->radius = 6371; + } + $this->geocoder->setApiKey($this->map->geocode_map_key); } public function geolocation(Request $request) @@ -107,7 +117,7 @@ public function geolocation(Request $request) foreach ($service_taxonomy_recordid_list as $key => $service_taxonomy_recordid) { - $taxonomy = Taxonomy::where('taxonomy_recordid', '=', (int) ($service_taxonomy_recordid))->first(); + $taxonomy = Taxonomy::where('taxonomy_recordid', '=', (int)($service_taxonomy_recordid))->first(); if (isset($taxonomy)) { $service_taxonomy_name = $taxonomy->taxonomy_name; $service_taxonomy_info_list[$service_taxonomy_recordid] = $service_taxonomy_name; @@ -202,8 +212,14 @@ public function geocode(Request $request) if ($response) { $lat = $response['lat']; $lng = $response['lng']; + $radius = '3959'; + + if ($this->map->distance_unit === 'km') { + $radius = '6,371'; + } + - $locations = Location::with('services', 'organization')->select(DB::raw('*, ( 3959 * acos( cos( radians(' . $lat . ') ) * cos( radians( location_latitude ) ) * cos( radians( location_longitude ) - radians(' . $lng . ') ) + sin( radians(' . $lat . ') ) * sin( radians( location_latitude ) ) ) ) AS distance')) + $locations = Location::with('services', 'organization')->select(DB::raw('*, ( ' . $radius . ' * acos( cos( radians(' . $lat . ') ) * cos( radians( location_latitude ) ) * cos( radians( location_longitude ) - radians(' . $lng . ') ) + sin( radians(' . $lat . ') ) * sin( radians( location_latitude ) ) ) ) AS distance')) ->having('distance', '<', 2) ->orderBy('distance'); @@ -385,11 +401,11 @@ public function filter(Request $request) $locations = Location::select('*') ->selectRaw( - '(3963 * acos(cos(radians(?)) * cos(radians(location_latitude)) * cos(radians(location_longitude) - radians(?)) + sin(radians(?)) * sin(radians(location_latitude)))) AS distance', + '(' . $this->radius . ' * acos(cos(radians(?)) * cos(radians(location_latitude)) * cos(radians(location_longitude) - radians(?)) + sin(radians(?)) * sin(radians(location_latitude)))) AS distance', [$lat, $lng, $lat] ) - // ->select(DB::raw('* , (((acos(sin((' . $lat . ' * pi()/180)) * sin((location_latitude*pi()/180))+cos((' . $lat . ' * pi()/180)) * cos((location_latitude*pi()/180)) * cos(((' . $lng . '- location_longitude)* pi()/180))))*180/pi())*60*1.1515*5280) AS distance')) - // ->select(DB::raw('*, ( 3959 * acos( cos( radians(' . $lat . ') ) * cos( radians( location_latitude ) ) * cos( radians( location_longitude ) - radians(' . $lng . ') ) + sin( radians(' . $lat . ') ) * sin( radians( location_latitude ) ) ) ) AS distance')) +// ->select(DB::raw('* , (((acos(sin((' . $lat . ' * pi()/180)) * sin((location_latitude*pi()/180))+cos((' . $lat . ' * pi()/180)) * cos((location_latitude*pi()/180)) * cos(((' . $lng . '- location_longitude)* pi()/180))))*180/pi())*60*1.1515*5280) AS distance')) +// ->select(DB::raw('*, ( 3959 * acos( cos( radians(' . $lat . ') ) * cos( radians( location_latitude ) ) * cos( radians( location_longitude ) - radians(' . $lng . ') ) + sin( radians(' . $lat . ') ) * sin( radians( location_latitude ) ) ) ) AS distance')) ->having('distance', '<', 50) ->orderBy('distance'); @@ -874,7 +890,7 @@ public function filter(Request $request) // $dist = acos($dist); // $dist = rad2deg($dist); - $miles = $this->distanceServices->getDistance($lat1, $lon1, $lat2, $lon2, 'mi'); + $miles = $this->distanceServices->getDistance($lat1, $lon1, $lat2, $lon2, $this->map?->distance_unit); } $value->miles = $miles; @@ -899,7 +915,7 @@ public function filter(Request $request) foreach ($service_taxonomy_recordid_list as $key => $service_taxonomy_recordid) { - $taxonomy = Taxonomy::where('taxonomy_recordid', '=', (int) ($service_taxonomy_recordid))->first(); + $taxonomy = Taxonomy::where('taxonomy_recordid', '=', (int)($service_taxonomy_recordid))->first(); if (isset($taxonomy)) { $service_taxonomy_name = $taxonomy->taxonomy_name; $service_taxonomy_info_list[$service_taxonomy_recordid] = $service_taxonomy_name; @@ -912,7 +928,7 @@ public function filter(Request $request) foreach ($services as $key => $service) { $service_details_recordid_list = explode(',', $service->service_details); foreach ($service_details_recordid_list as $key => $service_details_recordid) { - $detail = Detail::where('detail_recordid', '=', (int) ($service_details_recordid))->first(); + $detail = Detail::where('detail_recordid', '=', (int)($service_details_recordid))->first(); if (isset($detail)) { $service_detail_type = $detail->detail_type; $service_details_info_list[$service_details_recordid] = $service_detail_type; @@ -1211,7 +1227,7 @@ public function filter_organization(Request $request) foreach ($service_taxonomy_recordid_list as $key => $service_taxonomy_recordid) { - $taxonomy = Taxonomy::where('taxonomy_recordid', '=', (int) ($service_taxonomy_recordid))->first(); + $taxonomy = Taxonomy::where('taxonomy_recordid', '=', (int)($service_taxonomy_recordid))->first(); if (isset($taxonomy)) { $service_taxonomy_name = $taxonomy->taxonomy_name; $service_taxonomy_info_list[$service_taxonomy_recordid] = $service_taxonomy_name; @@ -1242,7 +1258,7 @@ public function filter_organization(Request $request) /** * Show the form for editing the specified resource. * - * @param int $id + * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) @@ -1253,7 +1269,7 @@ public function edit($id) /** * Update the specified resource in storage. * - * @param int $id + * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) @@ -1263,7 +1279,7 @@ public function update(Request $request, $id) /** * Remove the specified resource from storage. * - * @param int $id + * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) @@ -1456,7 +1472,7 @@ public function fetchOrganization(Request $request) echo $output; } } catch (\Throwable $th) { - Log::error('Error in fetchOrganization : ', $th); + Log::error('Error in fetchOrganization : ' . $th); } } } diff --git a/app/Http/Controllers/frontEnd/LocationController.php b/app/Http/Controllers/frontEnd/LocationController.php index 030036fe..e4ed5a9b 100644 --- a/app/Http/Controllers/frontEnd/LocationController.php +++ b/app/Http/Controllers/frontEnd/LocationController.php @@ -918,7 +918,7 @@ public function add_new_facility_in_organization(Request $request) // $client = new \GuzzleHttp\Client(); // $geocoder = new Geocoder($client); // $map = Map::find(1); - // $geocode_api_key = $map && $map->api_key ? $map->api_key : null; + // $geocode_api_key = $map && $map->geocode_map_key ? $map->geocode_map_key : null; // $geocoder->setApiKey($geocode_api_key); // if ($facility->location_address) { @@ -1250,33 +1250,6 @@ public function store(Request $request) $address_recordid_list = array_values(array_filter($address_recordid_list)); $facility->address()->sync($address_recordid_list); - // $client = new \GuzzleHttp\Client(); - // $geocoder = new Geocoder($client); - // $map = Map::find(1); - // $geocode_api_key = $map && $map->api_key ? $map->api_key : null; - // $geocoder->setApiKey($geocode_api_key); - - // if ($facility->location_address) { - // $address_recordid = $facility->location_address; - // $address_info = Address::where('address_recordid', '=', $address_recordid)->select('address_1', 'address_city', 'address_state_province', 'address_postal_code')->first(); - // $full_address_info = $address_info->address_1 . ', ' . $address_info->address_city . ', ' . $address_info->address_state_province . ', ' . $address_info->address_postal_code; - - // $response = $geocoder->getCoordinatesForAddress($full_address_info); - - // if ($response['lat']) { - // $latitude = $response['lat']; - // $longitude = $response['lng']; - // $facility->location_latitude = $latitude; - // $facility->location_longitude = $longitude; - // } else { - // Session::flash('message', 'Address info is not valid. We can not get longitude and latitude for this address'); - // Session::flash('status', 'error'); - // return redirect()->back()->withInput(); - // } - // } - - - $facility->location_phones = ''; $phone_recordid_list = []; if ($request->facility_phones) { @@ -2220,31 +2193,6 @@ public function add_new_facility_in_service(Request $request) $address_recordid_list = array_values(array_filter($address_recordid_list)); $facility->address()->sync($address_recordid_list); - // $client = new \GuzzleHttp\Client(); - // $geocoder = new Geocoder($client); - // $map = Map::find(1); - // $geocode_api_key = $map && $map->api_key ? $map->api_key : null; - // $geocoder->setApiKey($geocode_api_key); - - // if ($facility->location_address) { - // $address_recordid = $facility->location_address; - // $address_info = Address::where('address_recordid', '=', $address_recordid)->select('address_1', 'address_city', 'address_state_province', 'address_postal_code')->first(); - // $full_address_info = $address_info->address_1 . ', ' . $address_info->address_city . ', ' . $address_info->address_state_province . ', ' . $address_info->address_postal_code; - - // $response = $geocoder->getCoordinatesForAddress($full_address_info); - - // if ($response['lat']) { - // $latitude = $response['lat']; - // $longitude = $response['lng']; - // $facility->location_latitude = $latitude; - // $facility->location_longitude = $longitude; - // } else { - // Session::flash('message', 'Address info is not valid. We can not get longitude and latitude for this address'); - // Session::flash('status', 'error'); - // return redirect()->back()->withInput(); - // } - // } - $facility->location_phones = ''; $phone_recordid_list = []; if ($request->facility_phones) { diff --git a/app/Http/Middleware/TimeZoneMiddleware.php b/app/Http/Middleware/TimeZoneMiddleware.php index 6d989b95..3f6ff8b0 100644 --- a/app/Http/Middleware/TimeZoneMiddleware.php +++ b/app/Http/Middleware/TimeZoneMiddleware.php @@ -2,7 +2,10 @@ namespace App\Http\Middleware; +use App\Model\Layout; use Closure; +use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Config; class TimeZoneMiddleware { @@ -10,17 +13,21 @@ class TimeZoneMiddleware * Handle an incoming request. * * @param \Illuminate\Http\Request $request - * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { - if (env('TIME_ZONE')) { - // \Config::set('app.timezone', env('TIME_ZONE')); - date_default_timezone_set(env('TIME_ZONE')); + $layout = Layout::find(1); + if ($layout && $layout->timezone) { + date_default_timezone_set($layout->timezone); + Config::set('app.timezone', $layout->timezone); + + Artisan::call('cache:clear'); + Artisan::call('config:clear'); } else { date_default_timezone_set('UTC'); } + return $next($request); } } diff --git a/app/Model/Layout.php b/app/Model/Layout.php index 63358f20..0c337984 100644 --- a/app/Model/Layout.php +++ b/app/Model/Layout.php @@ -7,6 +7,6 @@ class Layout extends Model { protected $fillable = [ - 'logo', 'site_name', 'tagline', 'sidebar_content', 'contact_text', 'contact_btn_label', 'contact_btn_link', 'footer', 'header_pdf', 'footer_pdf', 'footer_csv', 'logo_active', 'title_active', 'about_active', 'primary_color', 'secondary_color', 'button_color', 'button_hover_color', 'meta_filter_activate', 'meta_filter_on_label', 'meta_filter_off_label', 'top_background', 'bottom_background', 'bottom_section_active', 'login_content', 'register_content', 'activate_login_home', 'home_page_style', 'activate_religions', 'activate_languages', 'activate_organization_types', 'activate_contact_types', 'activate_facility_types', 'homepage_background', 'banner_text1', 'banner_text2', 'sidebar_content_part_1', 'sidebar_content_part_2', 'sidebar_content_part_3', 'part_1_image', 'part_2_image', 'part_3_image', 'title_link_color', 'top_menu_color', 'activate_about_home', 'display_download_menu', 'display_download_pdf', 'display_download_csv', 'show_suggest_menu', 'show_registration_message', 'user_metafilter_option', 'hide_organizations_with_no_filtered_services', 'top_menu_link_hover_background_color', 'default_service_status', 'default_organization_status', 'taxonomy_icon_hover', 'hide_service_category_with_no_filter_service' + 'logo', 'site_name', 'tagline', 'sidebar_content', 'contact_text', 'contact_btn_label', 'contact_btn_link', 'footer', 'header_pdf', 'footer_pdf', 'footer_csv', 'logo_active', 'title_active', 'about_active', 'primary_color', 'secondary_color', 'button_color', 'button_hover_color', 'meta_filter_activate', 'meta_filter_on_label', 'meta_filter_off_label', 'top_background', 'bottom_background', 'bottom_section_active', 'login_content', 'register_content', 'activate_login_home', 'home_page_style', 'activate_religions', 'activate_languages', 'activate_organization_types', 'activate_contact_types', 'activate_facility_types', 'homepage_background', 'banner_text1', 'banner_text2', 'sidebar_content_part_1', 'sidebar_content_part_2', 'sidebar_content_part_3', 'part_1_image', 'part_2_image', 'part_3_image', 'title_link_color', 'top_menu_color', 'activate_about_home', 'display_download_menu', 'display_download_pdf', 'display_download_csv', 'show_suggest_menu', 'show_registration_message', 'user_metafilter_option', 'hide_organizations_with_no_filtered_services', 'top_menu_link_hover_background_color', 'default_service_status', 'default_organization_status', 'taxonomy_icon_hover', 'hide_service_category_with_no_filter_service', 'timezone', 'localization', ]; } diff --git a/app/Model/Map.php b/app/Model/Map.php index be1e2e09..39dbf921 100644 --- a/app/Model/Map.php +++ b/app/Model/Map.php @@ -6,5 +6,7 @@ class Map extends Model { - // + protected $fillable = [ + 'name', 'sku', 'geocode_map_key', 'state', 'lat', 'long', 'active', 'zoom', 'zoom_profile', 'javascript_map_key', + ]; } diff --git a/app/Services/DistanceServices.php b/app/Services/DistanceServices.php index c914a958..b84e204a 100644 --- a/app/Services/DistanceServices.php +++ b/app/Services/DistanceServices.php @@ -8,7 +8,7 @@ public function getDistance($lat1, $lon1, $lat2, $lon2, $unit = 'km'): float|int { $earthRadius = [ 'km' => 6371, // kilometers - 'mi' => 3959, // miles + 'miles' => 3959, // miles 'nm' => 3440, // nautical miles ]; diff --git a/config/app.php b/config/app.php index ed6cda61..1abf401a 100755 --- a/config/app.php +++ b/config/app.php @@ -67,7 +67,7 @@ | */ - 'timezone' => env('TIME_ZONE', 'UTC'), + 'timezone' => 'UTC', /* |-------------------------------------------------------------------------- diff --git a/database/migrations/2024_03_22_062948_add_javascript_map_key_to_maps_table.php b/database/migrations/2024_03_22_062948_add_javascript_map_key_to_maps_table.php new file mode 100644 index 00000000..417384fe --- /dev/null +++ b/database/migrations/2024_03_22_062948_add_javascript_map_key_to_maps_table.php @@ -0,0 +1,34 @@ +string('javascript_map_key')->nullable(); + $table->renameColumn('api_key', 'geocode_map_key'); + $table->enum('distance_unit',['km','miles'])->default('miles'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('maps', function (Blueprint $table) { + $table->dropColumn('javascript_map_key'); + }); + } +}; diff --git a/database/migrations/2024_03_26_070558_add_timezone_to_layouts_table.php b/database/migrations/2024_03_26_070558_add_timezone_to_layouts_table.php new file mode 100644 index 00000000..5ef50bab --- /dev/null +++ b/database/migrations/2024_03_26_070558_add_timezone_to_layouts_table.php @@ -0,0 +1,33 @@ +string('timezone')->default('UTC')->nullable(); + $table->string('localization')->default('US')->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('layouts', function (Blueprint $table) { + $table->dropColumn(['timezone', 'localization']); + }); + } +}; diff --git a/resources/views/backEnd/pages/map.blade.php b/resources/views/backEnd/pages/map.blade.php index 0280dfe1..5932fad8 100644 --- a/resources/views/backEnd/pages/map.blade.php +++ b/resources/views/backEnd/pages/map.blade.php @@ -1,179 +1,221 @@ @extends('backLayout.app') @section('title') -Map Settings + Map Settings @stop @section('content')
-
-
-
-

Map

- -
-
-
+
+
+
+

Map

+ +
+
+
- {{ Form::open(array('url' => ['map', 1], 'class' => 'form-horizontal form-label-left', 'method' => 'put', 'enctype'=> 'multipart/form-data')) }} -
-
-
- -
- -
-
+ {{ Form::open(array('url' => ['map', 1], 'class' => 'form-horizontal form-label-left', 'method' => 'put', 'enctype'=> 'multipart/form-data')) }} +
+
+
+ +
+ +
+
-
- -
- {{-- active==0) disabled="disabled" @endif> --}} - - - - @if ($errors->first('api_key')) -
{{ $errors->first('api_key') }}
- @endif -
-
+
+ +
+ + + + @if ($errors->first('javascript_map_key')) +
{{ $errors->first('javascript_map_key') }}
+ @endif +
+
-
- -
- active==0) disabled="disabled" @endif> -
-
- active==0) disabled="disabled" @endif> -
-
+
+ +
+ + + + @if ($errors->first('geocode_map_key')) +
{{ $errors->first('geocode_map_key') }}
+ @endif +
+
+
+ +
+
+ {!! Form::select('distance_unit',['miles' => 'miles', 'km' => 'km'],$map->distance_unit,['class' => 'form-control']) !!} + {!! $errors->first('distance_unit', '

:message

') !!} +
+
+
-
- -
- active==0) disabled="disabled" @endif> -
-
+
+ +
+ active==0) disabled="disabled" @endif> +
+
+ active==0) disabled="disabled" @endif> +
+
-
- -
- active==0) disabled="disabled" @endif> -
-
+
+ +
+ active==0) disabled="disabled" @endif> +
+
-
-
-
-
-
-
-
-
- -
-
+
+ +
+ active==0) disabled="disabled" @endif> +
+
- {!! Form::close() !!} +
+
+
+
+
+
+
+
+ +
+
+ {!! Form::close() !!} -
+ +
+
-
-
-
-
-

Geocode

- -
-
-
-
-
-
- -
- Scan -
+
+
+
+

Geocode

+ +
-
+
+
+
+
+ +
+ Scan +
+
+
-
-
- -
-
- {{$invalid_location_info_count}} locations are invalid. -
- @if ($invalid_location_info_count == $ungeocoded_location_numbers) -
- All valid locations have already been geocoded. -
- @else -
- {{$ungeocoded_location_numbers}} locations have not been geocoded. -
- @endif -
-
-
+
+
+ +
+
+ {{$invalid_location_info_count}} locations are invalid. +
+ @if ($invalid_location_info_count == $ungeocoded_location_numbers) +
+ All valid locations have already been geocoded. +
+ @else +
+ {{$ungeocoded_location_numbers}} locations have not been geocoded. +
+ @endif +
+
+
-
-
- -
- Geocode -
- -
-
+
+
+ +
+ Geocode +
+ +
+
-
-
- -
-
- {{$geocode_status_text}} -
-
-
-
+
+
+ +
+
+ {{$geocode_status_text}} +
+
+
+
+
+
-
-
+
+
+
+
+ --> @endsection @section('scripts') - - - - - + + + + - + + }); + @endsection diff --git a/resources/views/backEnd/settings/add_country.blade.php b/resources/views/backEnd/settings/add_country.blade.php index 1988e45b..3e51f048 100644 --- a/resources/views/backEnd/settings/add_country.blade.php +++ b/resources/views/backEnd/settings/add_country.blade.php @@ -32,7 +32,7 @@
- {!! Form::select('country',$countries,env('LOCALIZATION') ? env('LOCALIZATION') : 'US',['class' => 'form-control']) !!} + {!! Form::select('country', $countries, ($layout->localization ?? 'US'),['class' => 'form-control']) !!} {!! $errors->first('country', '

:message

') !!}
@@ -43,7 +43,7 @@
- {!! Form::select('timezone',$zones_array,env('TIME_ZONE') ? env('TIME_ZONE') : 'UTC' ,['class' => 'form-control selectpicker','data-live-search' => 'true']) !!} + {!! Form::select('timezone',$zones_array, ($layout->timezone ?? 'UTC') ,['class' => 'form-control selectpicker','data-live-search' => 'true']) !!} {!! $errors->first('country', '

:message

') !!}
@@ -78,16 +78,21 @@ @section('scripts') +{{-- + --}} @endsection diff --git a/resources/views/frontEnd/locations/show.blade.php b/resources/views/frontEnd/locations/show.blade.php index 64bcfbc3..7a4b4504 100644 --- a/resources/views/frontEnd/locations/show.blade.php +++ b/resources/views/frontEnd/locations/show.blade.php @@ -696,7 +696,7 @@ class="btn btn-raised btn-lg btn_darkblack waves-effect waves-classic">Close - diff --git a/resources/views/frontEnd/services/services.blade.php b/resources/views/frontEnd/services/services.blade.php index 855c6a4a..fdf32c44 100644 --- a/resources/views/frontEnd/services/services.blade.php +++ b/resources/views/frontEnd/services/services.blade.php @@ -218,7 +218,7 @@

{{$service->service_name}}

- {{ isset($service->miles) ? floatval(number_format($service->miles,2)) .' miles' : '' }} + {{ isset($service->miles) ? floatval(number_format($service->miles,2)) .' '. ucfirst($map?->distance_unit) : '' }}

@if ($service->organizations && $service->organizations->organization_status_x && isset($organizationStatus[$service->organizations->organization_status_x]) && ($organizationStatus[$service->organizations->organization_status_x] == 'Out of Business' || $organizationStatus[$service->organizations->organization_status_x] == 'Inactive')) Inactive diff --git a/resources/views/layouts/style.blade.php b/resources/views/layouts/style.blade.php index 0ff48024..e4f26a80 100644 --- a/resources/views/layouts/style.blade.php +++ b/resources/views/layouts/style.blade.php @@ -12,10 +12,9 @@ - + - + @yield('title')| {{ $layout->site_name }} @@ -366,7 +365,7 @@ function initMap() { @endif - \ No newline at end of file +