From 3461c2926521296312c81d716979b5e3a5c6d05b Mon Sep 17 00:00:00 2001 From: d9it Date: Wed, 3 Apr 2024 11:57:29 +0530 Subject: [PATCH] Update organization location --- .../frontEnd/OrganizationController.php | 14 ++----- app/Services/LocationService.php | 37 +++++++++---------- .../frontEnd/organizations/show.blade.php | 4 +- 3 files changed, 23 insertions(+), 32 deletions(-) diff --git a/app/Http/Controllers/frontEnd/OrganizationController.php b/app/Http/Controllers/frontEnd/OrganizationController.php index 5d08c08b..15870447 100644 --- a/app/Http/Controllers/frontEnd/OrganizationController.php +++ b/app/Http/Controllers/frontEnd/OrganizationController.php @@ -60,12 +60,8 @@ class OrganizationController extends Controller { - public $commonController, $organizationService; - - public function __construct(CommonController $commonController, OrganizationService $organizationService) + public function __construct(public CommonController $commonController, public OrganizationService $organizationService) { - $this->commonController = $commonController; - $this->organizationService = $organizationService; } public function airtable($access_token, $base_url) @@ -1728,8 +1724,6 @@ public function store(Request $request) */ public function show($id) { - // $organization= Organization::find($id); - // return response()->json($organization); $organization = Organization::where('organization_recordid', '=', $id)->first(); $organizationStatus = OrganizationStatus::orderBy('order')->pluck('status', 'id'); if ($organization && (Auth::check() || (!Auth::check() && $organization->organization_status_x && isset($organizationStatus[$organization->organization_status_x]) && ($organizationStatus[$organization->organization_status_x] != 'Out of Business' && $organizationStatus[$organization->organization_status_x] != 'Inactive')) || !$organization->organization_status_x)) { @@ -1770,9 +1764,9 @@ public function show($id) // if (count($locationIds) > 0) { // $location_info_list = array_merge($location_info_list, $locationIds); // } - if (count($serviceLocationIds) > 0) { - $location_info_list = array_merge($location_info_list, $serviceLocationIds); - } + // if (count($serviceLocationIds) > 0) { + // $location_info_list = array_unique(array_merge($location_info_list, $serviceLocationIds)); + // } $locations = Location::whereIn('location_recordid', $location_info_list)->with('phones', 'address', 'services', 'schedules')->get(); $location_info_list = Location::whereIn('location_recordid', $location_info_list)->with('phones', 'address', 'services', 'schedules')->get(); diff --git a/app/Services/LocationService.php b/app/Services/LocationService.php index e9a662d1..42964c25 100644 --- a/app/Services/LocationService.php +++ b/app/Services/LocationService.php @@ -10,30 +10,29 @@ class LocationService { - function import_airtable_v3(string $access_token, string $base_url) + public function import_airtable_v3(string $access_token, string $base_url) { try { $airtable_key_info = Airtablekeyinfo::find(1); - if (!$airtable_key_info) { + if (! $airtable_key_info) { $airtable_key_info = new Airtablekeyinfo; } $airtable_key_info->access_token = $access_token; $airtable_key_info->base_url = $base_url; $airtable_key_info->save(); - $airtable = new Airtable(array( - 'access_token' => $access_token, - 'base' => $base_url, - )); + $airtable = new Airtable([ + 'access_token' => $access_token, + 'base' => $base_url, + ]); $request = $airtable->getContent('locations'); do { - $response = $request->getResponse(); - $airtable_response = json_decode($response, TRUE); + $airtable_response = json_decode($response, true); foreach ($airtable_response['records'] as $record) { $strtointclass = new Stringtoint(); @@ -64,7 +63,7 @@ function import_airtable_v3(string $access_token, string $base_url) if (isset($record['fields']['services'])) { $serviceRecordIds = []; - foreach ($record['fields']['services'] as $value) { + foreach ($record['fields']['services'] as $value) { $serviceRecordIds[] = $strtointclass->string_to_int($value); } $location->location_services = implode(', ', $serviceRecordIds); @@ -72,7 +71,7 @@ function import_airtable_v3(string $access_token, string $base_url) if (isset($record['fields']['phones'])) { $phoneRecordIds = []; - foreach ($record['fields']['phones'] as $value) { + foreach ($record['fields']['phones'] as $value) { $phoneRecordIds[] = $strtointclass->string_to_int($value); } $location->phones()->sync($phoneRecordIds); @@ -80,16 +79,15 @@ function import_airtable_v3(string $access_token, string $base_url) if (isset($record['fields']['schedules'])) { $scheduleRecordIds = []; - foreach ($record['fields']['schedules'] as $value) { + foreach ($record['fields']['schedules'] as $value) { $scheduleRecordIds[] = $strtointclass->string_to_int($value); } $location->schedules()->sync($scheduleRecordIds); } - if (isset($record['fields']['addresses'])) { $addressRecordIds = []; - foreach ($record['fields']['addresses'] as $value) { + foreach ($record['fields']['addresses'] as $value) { $addressRecordIds[] = $strtointclass->string_to_int($value); } $location->address()->sync($addressRecordIds); @@ -97,7 +95,7 @@ function import_airtable_v3(string $access_token, string $base_url) if (isset($record['fields']['languages'])) { $languageRecordIds = []; - foreach ($record['fields']['languages'] as $value) { + foreach ($record['fields']['languages'] as $value) { $languageRecordIds[] = $strtointclass->string_to_int($value); } $location->languages()->sync($languageRecordIds); @@ -105,7 +103,7 @@ function import_airtable_v3(string $access_token, string $base_url) if (isset($record['fields']['accessibility'])) { $accessebilityRecordIds = []; - foreach ($record['fields']['accessibility'] as $value) { + foreach ($record['fields']['accessibility'] as $value) { $accessebilityRecordIds[] = $strtointclass->string_to_int($value); } $location->accessibilities()->sync($accessebilityRecordIds); @@ -113,7 +111,7 @@ function import_airtable_v3(string $access_token, string $base_url) if (isset($record['fields']['location_type'])) { $locationTypes = []; - foreach ($record['fields']['location_type'] as $value) { + foreach ($record['fields']['location_type'] as $value) { $locationTypes[] = $strtointclass->string_to_int($value); } $location->location_type = implode(', ', $locationTypes); @@ -124,17 +122,18 @@ function import_airtable_v3(string $access_token, string $base_url) } } while ($request = $response->next()); - $date = date("Y/m/d H:i:s"); + $date = date('Y/m/d H:i:s'); $airtable = Airtable_v2::where('name', '=', 'Locations')->first(); $airtable->records = Location::count(); $airtable->syncdate = $date; $airtable->save(); } catch (\Throwable $th) { dd($th); - Log::error('Error in location: ' . $th->getMessage()); + Log::error('Error in location: '.$th->getMessage()); + return response()->json([ 'message' => $th->getMessage(), - 'success' => false + 'success' => false, ], 500); } } diff --git a/resources/views/frontEnd/organizations/show.blade.php b/resources/views/frontEnd/organizations/show.blade.php index 5629abe3..c9adc6b0 100644 --- a/resources/views/frontEnd/organizations/show.blade.php +++ b/resources/views/frontEnd/organizations/show.blade.php @@ -1113,11 +1113,9 @@ class="btn btn-danger btn-lg btn_delete red_btn organizationTagCloseButton">Clos var content = '
'; for (i = 0; i < location.services.length; i++) { - content += ''; + content += ''; } // '' + - content += '
' + '
Organization Name
' + '' + location