From 404c65a17e488a68f6db352f52ce523cb4939c03 Mon Sep 17 00:00:00 2001 From: d9it Date: Wed, 1 May 2024 16:36:40 +0530 Subject: [PATCH] Service location and organization service location issue fixed --- .../frontEnd/OrganizationController.php | 519 +++++++------ .../frontEnd/ServiceController.php | 720 +++++++++--------- .../frontEnd/organizations/show.blade.php | 3 +- .../frontEnd/services/services.blade.php | 6 +- 4 files changed, 650 insertions(+), 598 deletions(-) diff --git a/app/Http/Controllers/frontEnd/OrganizationController.php b/app/Http/Controllers/frontEnd/OrganizationController.php index 15870447..cc858af4 100644 --- a/app/Http/Controllers/frontEnd/OrganizationController.php +++ b/app/Http/Controllers/frontEnd/OrganizationController.php @@ -2,61 +2,60 @@ namespace App\Http\Controllers\frontEnd; -use App\Http\Controllers\Controller; -use Illuminate\Http\Request; use App\Functions\Airtable; +use App\Http\Controllers\Controller; use App\Imports\OrganizationImport; use App\Model\Accessibility; use App\Model\Address; -use App\Model\Organization; -use App\Model\OrganizationDetail; -use App\Model\Taxonomy; -use App\Model\Alt_taxonomy; -use App\Model\ServiceOrganization; -use App\Model\Servicetaxonomy; -use App\Model\Service; -use App\Model\Contact; -use App\Model\SessionData; -use App\Model\Comment; -use App\Model\Phone; -use App\Model\Location; +use App\Model\Airtable_v2; use App\Model\Airtablekeyinfo; -use App\Model\Layout; -use App\Model\Map; use App\Model\Airtables; -use App\Model\CSV_Source; -use App\Model\Source_data; -use App\Model\Airtable_v2; +use App\Model\Alt_taxonomy; use App\Model\City; -use App\Model\OrganizationStatus; +use App\Model\Comment; +use App\Model\Contact; +use App\Model\CSV_Source; use App\Model\Detail; use App\Model\Disposition; use App\Model\InteractionMethod; use App\Model\Language; +use App\Model\Layout; +use App\Model\Location; +use App\Model\Map; use App\Model\MetaFilter; +use App\Model\Organization; +use App\Model\OrganizationDetail; use App\Model\OrganizationPhone; +use App\Model\OrganizationStatus; use App\Model\OrganizationTableFilter; -use App\Model\PhoneType; -use App\Model\Schedule; use App\Model\OrganizationTag; +use App\Model\Phone; +use App\Model\PhoneType; use App\Model\Program; use App\Model\Region; +use App\Model\Schedule; +use App\Model\Service; +use App\Model\ServiceOrganization; use App\Model\ServiceTag; +use App\Model\SessionData; use App\Model\SessionInteraction; +use App\Model\Source_data; use App\Model\State; +use App\Model\Taxonomy; use App\Services\OrganizationService; use App\Services\Stringtoint; use App\User; use Carbon\Carbon; +use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Session; +use Illuminate\Support\Facades\Storage; +use Illuminate\Support\Str; use Maatwebsite\Excel\Facades\Excel; -use PDF; use OwenIt\Auditing\Models\Audit; -use Illuminate\Support\Facades\Log; -use Illuminate\Support\Facades\Storage; +use PDF; use Yajra\DataTables\Facades\DataTables; -use Illuminate\Support\Str; class OrganizationController extends Controller { @@ -68,7 +67,7 @@ public function airtable($access_token, $base_url) { $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; @@ -78,19 +77,18 @@ public function airtable($access_token, $base_url) Organization::truncate(); OrganizationDetail::truncate(); - $airtable = new Airtable(array( + $airtable = new Airtable([ 'access_token' => $access_token, 'base' => $base_url, - )); + ]); $request = $airtable->getContent('organizations'); do { - $response = $request->getResponse(); - $airtable_response = json_decode($response, TRUE); + $airtable_response = json_decode($response, true); foreach ($airtable_response['records'] as $record) { @@ -101,7 +99,7 @@ public function airtable($access_token, $base_url) if (isset($record['fields']['logo-x'])) { foreach ($record['fields']['logo-x'] as $key => $image) { try { - $organization->organization_logo_x .= $image["url"]; + $organization->organization_logo_x .= $image['url']; } catch (\Exception $e) { echo 'Caught exception: ', $e->getMessage(), "\n"; } @@ -110,8 +108,8 @@ public function airtable($access_token, $base_url) if (isset($record['fields']['forms-x'])) { foreach ($record['fields']['forms-x'] as $key => $form) { try { - $organization->organization_forms_x_filename .= $form["filename"]; - $organization->organization_forms_x_url .= $form["url"]; + $organization->organization_forms_x_filename .= $form['filename']; + $organization->organization_forms_x_url .= $form['url']; } catch (\Exception $e) { echo 'Caught exception: ', $e->getMessage(), "\n"; } @@ -121,7 +119,7 @@ public function airtable($access_token, $base_url) $organization->organization_x_uid = isset($record['fields']['x-uid']) ? $record['fields']['x-uid'] : null; $organization->organization_description = isset($record['fields']['description']) ? $record['fields']['description'] : null; - $organization->organization_description = mb_convert_encoding($organization->organization_description, "HTML-ENTITIES", "UTF-8"); + $organization->organization_description = mb_convert_encoding($organization->organization_description, 'HTML-ENTITIES', 'UTF-8'); $organization->organization_email = isset($record['fields']['email']) ? $record['fields']['email'] : null; $organization->organization_url = isset($record['fields']['url']) ? $record['fields']['url'] : null; @@ -155,10 +153,11 @@ public function airtable($access_token, $base_url) $organizationservice = $strtointclass->string_to_int($value); - if ($i != 0) - $organization->organization_services = $organization->organization_services . ',' . $organizationservice; - else + if ($i != 0) { + $organization->organization_services = $organization->organization_services.','.$organizationservice; + } else { $organization->organization_services = $organizationservice; + } $i++; } } @@ -169,29 +168,30 @@ public function airtable($access_token, $base_url) $organizationphone = $strtointclass->string_to_int($value); - if ($i != 0) - $organization->organization_phones = $organization->organization_phones . ',' . $organizationphone; - else + if ($i != 0) { + $organization->organization_phones = $organization->organization_phones.','.$organizationphone; + } else { $organization->organization_phones = $organizationphone; + } $i++; } } - if (isset($record['fields']['locations'])) { $i = 0; foreach ($record['fields']['locations'] as $value) { $organizationlocation = $strtointclass->string_to_int($value); - if ($i != 0) - $organization->organization_locations = $organization->organization_locations . ',' . $organizationlocation; - else + if ($i != 0) { + $organization->organization_locations = $organization->organization_locations.','.$organizationlocation; + } else { $organization->organization_locations = $organizationlocation; + } $i++; } } - $organization->organization_contact = isset($record['fields']['contact']) ? implode(",", $record['fields']['contact']) : null; + $organization->organization_contact = isset($record['fields']['contact']) ? implode(',', $record['fields']['contact']) : null; $organization->organization_contact = $strtointclass->string_to_int($organization->organization_contact); if (isset($record['fields']['details'])) { @@ -203,10 +203,11 @@ public function airtable($access_token, $base_url) $organization_detail->save(); $organizationdetail = $strtointclass->string_to_int($value); - if ($i != 0) - $organization->organization_details = $organization->organization_details . ',' . $organizationdetail; - else + if ($i != 0) { + $organization->organization_details = $organization->organization_details.','.$organizationdetail; + } else { $organization->organization_details = $organizationdetail; + } $i++; } } @@ -215,10 +216,11 @@ public function airtable($access_token, $base_url) $i = 0; foreach ($record['fields']['AIRS Taxonomy-x'] as $value) { - if ($i != 0) - $organization->organization_airs_taxonomy_x = $organization->organization_airs_taxonomy_x . ',' . $value; - else + if ($i != 0) { + $organization->organization_airs_taxonomy_x = $organization->organization_airs_taxonomy_x.','.$value; + } else { $organization->organization_airs_taxonomy_x = $value; + } $i++; } } @@ -227,7 +229,7 @@ public function airtable($access_token, $base_url) } } while ($request = $response->next()); - $date = date("Y/m/d H:i:s"); + $date = date('Y/m/d H:i:s'); $airtable = Airtables::where('name', '=', 'Organizations')->first(); $airtable->records = Organization::count(); $airtable->syncdate = $date; @@ -238,7 +240,7 @@ public function airtable_v2($access_token, $base_url, $organization_tag) { 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; @@ -248,19 +250,18 @@ public function airtable_v2($access_token, $base_url, $organization_tag) // Organization::truncate(); // OrganizationDetail::truncate(); - $airtable = new Airtable(array( + $airtable = new Airtable([ 'access_token' => $access_token, 'base' => $base_url, - )); + ]); $request = $airtable->getContent('organizations'); 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(); @@ -274,7 +275,7 @@ public function airtable_v2($access_token, $base_url, $organization_tag) if (isset($record['fields']['x-logo'])) { foreach ($record['fields']['x-logo'] as $key => $image) { try { - $organization->organization_logo_x .= $image["url"]; + $organization->organization_logo_x .= $image['url']; } catch (\Exception $e) { echo 'Caught exception: ', $e->getMessage(), "\n"; } @@ -283,8 +284,8 @@ public function airtable_v2($access_token, $base_url, $organization_tag) if (isset($record['fields']['x-forms'])) { foreach ($record['fields']['x-forms'] as $key => $form) { try { - $organization->organization_forms_x_filename .= $form["filename"]; - $organization->organization_forms_x_url .= $form["url"]; + $organization->organization_forms_x_filename .= $form['filename']; + $organization->organization_forms_x_url .= $form['url']; } catch (\Exception $e) { echo 'Caught exception: ', $e->getMessage(), "\n"; } @@ -295,7 +296,7 @@ public function airtable_v2($access_token, $base_url, $organization_tag) $organization->organization_website_rating = isset($record['fields']['y-website_quality']) ? $record['fields']['y-website_quality'] : null; $organization->organization_description = isset($record['fields']['description']) ? $record['fields']['description'] : null; - $organization->organization_description = mb_convert_encoding($organization->organization_description, "HTML-ENTITIES", "UTF-8"); + $organization->organization_description = mb_convert_encoding($organization->organization_description, 'HTML-ENTITIES', 'UTF-8'); $organization->organization_email = isset($record['fields']['email']) ? $record['fields']['email'] : null; $organization->organization_url = isset($record['fields']['url']) ? $record['fields']['url'] : null; @@ -328,16 +329,16 @@ public function airtable_v2($access_token, $base_url, $organization_tag) $organization->organization_year_incorporated = isset($record['fields']['year_incorporated']) ? $record['fields']['year_incorporated'] : null; // $organization->organization_tag = isset($record['fields']['x-tags']) ? implode(',', $record['fields']['x-tags']) : null; $organization_tags = isset($record['fields']['x-tags']) ? $record['fields']['x-tags'] : []; - if (!empty($organization_tags)) { + if (! empty($organization_tags)) { // $organization->organization_tag = $organization->organization_tag . ',' . $organization_tag; $orgTag = []; foreach ($organization_tags as $key1 => $value1) { - $organization_tag = OrganizationTag::where('tag', 'LIKE', '%' . $value1 . '%')->first(); + $organization_tag = OrganizationTag::where('tag', 'LIKE', '%'.$value1.'%')->first(); if ($organization_tag) { $orgTag[] = $organization_tag->id; } else { $organization_tag = OrganizationTag::create([ - 'tag' => $value1 + 'tag' => $value1, ]); $orgTag[] = $organization_tag->id; } @@ -351,10 +352,11 @@ public function airtable_v2($access_token, $base_url, $organization_tag) $organizationservice = $strtointclass->string_to_int($value); - if ($i != 0) - $organization->organization_services = $organization->organization_services . ',' . $organizationservice; - else + if ($i != 0) { + $organization->organization_services = $organization->organization_services.','.$organizationservice; + } else { $organization->organization_services = $organizationservice; + } $i++; } } @@ -365,29 +367,30 @@ public function airtable_v2($access_token, $base_url, $organization_tag) $organizationphone = $strtointclass->string_to_int($value); - if ($i != 0) - $organization->organization_phones = $organization->organization_phones . ',' . $organizationphone; - else + if ($i != 0) { + $organization->organization_phones = $organization->organization_phones.','.$organizationphone; + } else { $organization->organization_phones = $organizationphone; + } $i++; } } - if (isset($record['fields']['locations'])) { $i = 0; foreach ($record['fields']['locations'] as $value) { $organizationlocation = $strtointclass->string_to_int($value); - if ($i != 0) - $organization->organization_locations = $organization->organization_locations . ',' . $organizationlocation; - else + if ($i != 0) { + $organization->organization_locations = $organization->organization_locations.','.$organizationlocation; + } else { $organization->organization_locations = $organizationlocation; + } $i++; } } - $organization->organization_contact = isset($record['fields']['contacts']) ? implode(",", $record['fields']['contacts']) : null; + $organization->organization_contact = isset($record['fields']['contacts']) ? implode(',', $record['fields']['contacts']) : null; $organization->organization_contact = $strtointclass->string_to_int($organization->organization_contact); if (isset($record['fields']['x-details'])) { @@ -399,10 +402,11 @@ public function airtable_v2($access_token, $base_url, $organization_tag) $organization_detail->save(); $organizationdetail = $strtointclass->string_to_int($value); - if ($i != 0) - $organization->organization_details = $organization->organization_details . ',' . $organizationdetail; - else + if ($i != 0) { + $organization->organization_details = $organization->organization_details.','.$organizationdetail; + } else { $organization->organization_details = $organizationdetail; + } $i++; } } @@ -411,10 +415,11 @@ public function airtable_v2($access_token, $base_url, $organization_tag) $i = 0; foreach ($record['fields']['AIRS Taxonomy-x'] as $value) { - if ($i != 0) - $organization->organization_airs_taxonomy_x = $organization->organization_airs_taxonomy_x . ',' . $value; - else + if ($i != 0) { + $organization->organization_airs_taxonomy_x = $organization->organization_airs_taxonomy_x.','.$value; + } else { $organization->organization_airs_taxonomy_x = $value; + } $i++; } } @@ -424,16 +429,17 @@ public function airtable_v2($access_token, $base_url, $organization_tag) } } 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', '=', 'Organizations')->first(); $airtable->records = Organization::count(); $airtable->syncdate = $date; $airtable->save(); } catch (\Throwable $th) { - Log::error('Error in Organization sync : ' . $th->getMessage()); + Log::error('Error in Organization sync : '.$th->getMessage()); + return response()->json([ 'message' => $th->getMessage(), - 'success' => false + 'success' => false, ], 500); } } @@ -480,16 +486,18 @@ public function csv(Request $request) $csv_source->syncdate = $date; $csv_source->save(); - $response = array( + $response = [ 'status' => 'success', 'result' => 'Organization imported successfully', - ); + ]; + return $response; } catch (\Throwable $th) { - $response = array( + $response = [ 'status' => 'false', 'result' => $th->getMessage(), - ); + ]; + return $response; } } @@ -511,7 +519,7 @@ public function index() if ($layout->meta_filter_activate == 1 && $count_metas > 0 && $filter_label == 'on_label') { $filterServiceRecordId = []; foreach ($metas as $key => $meta) { - $values = explode(",", $meta->values); + $values = explode(',', $meta->values); if (count($values) > 0) { if ($meta->facet == 'organization_status') { $organizations_status_ids = Organization::getOrganizationStatusMeta($values, $meta->operations); @@ -585,7 +593,7 @@ public function index() } 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'] = ''; array_push($parent_taxonomy, $child_data); } } @@ -621,58 +629,64 @@ public function tb_organizations(Request $request) $organizationStatus = OrganizationStatus::orderBy('order')->pluck('status', 'id'); $saved_filters = OrganizationTableFilter::where('user_id', Auth::id())->get(); - if (!$request->ajax()) { + if (! $request->ajax()) { return view('backEnd.tables.tb_organization', compact('organizations', 'organization_tags', 'organizationStatus', 'service_tags', 'saved_filters')); } + return DataTables::of($organizations) ->editColumn('services', function ($row) { $service_name = ''; if (isset($row->services)) { foreach ($row->services as $key => $service) { - $service_name .= ' ' . $service->service_name . ''; + $service_name .= ' '.$service->service_name.''; } } + return $service_name; }) ->editColumn('phones', function ($row) { $phone_number = ''; if (isset($row->phones)) { foreach ($row->phones as $key => $phone) { - $phone_number .= ' ' . $phone->phone_number . ''; + $phone_number .= ' '.$phone->phone_number.''; } } + return $phone_number; }) ->editColumn('location', function ($row) { $location_name = ''; if (isset($row->location)) { foreach ($row->location as $key => $location) { - $location_name .= ' ' . $location->location_name . ''; + $location_name .= ' '.$location->location_name.''; } } + return $location_name; }) ->editColumn('organization_details', function ($row) { $organization_detail = ''; if (isset($row->organization_details)) { foreach ($row->organization_details as $key => $organization_detail) { - $organization_detail .= ' ' . $organization_detail->detail_value . ''; + $organization_detail .= ' '.$organization_detail->detail_value.''; } } + return $organization_detail; }) ->editColumn('contact_name', function ($row) { $location_name = ''; if (isset($row->contact()->first()->contact_name)) { - $location_name .= '' . $row->contact()->first()->contact_name . ''; + $location_name .= ''.$row->contact()->first()->contact_name.''; } + return $location_name; }) ->editColumn('bookmark', function ($row) { if ($row->bookmark && $row->bookmark == 1) { - return ''; + return ''; } else { - return ''; + return ''; } }) ->editColumn('organization_description', function ($row) { @@ -681,17 +695,17 @@ public function tb_organizations(Request $request) return $organization_description; }) ->editColumn('organization_url', function ($row) { - return '' . $row->organization_url . ''; + return ''.$row->organization_url.''; }) ->editColumn('organization_name', function ($row) { - return '' . $row->organization_name . ''; + return ''.$row->organization_name.''; }) ->editColumn('organization_status_x', function ($row) { return $row->status_data ? $row->status_data->status : ''; }) ->editColumn('last_verified_by', function ($row) { // return $row->get_latest_updated($row, 'updated_by'); - return $row->get_last_verified_by ? $row->get_last_verified_by->first_name . ' ' . $row->get_last_verified_by->last_name : ''; + return $row->get_last_verified_by ? $row->get_last_verified_by->first_name.' '.$row->get_last_verified_by->last_name : ''; }) ->editColumn('updated_by', function ($row) { return $row->get_latest_updated($row, 'updated_by'); @@ -707,12 +721,12 @@ public function tb_organizations(Request $request) ->addColumn('last_note_date', function ($row) { $note = SessionData::where('session_organization', $row->organization_recordid)->orderBy('id', 'desc')->first(); - return $note ? ' ' . $note->created_at . '' : ""; + return $note ? ' '.$note->created_at.'' : ''; }) ->addColumn('last_edit_date', function ($row) { $audit = Audit::where('auditable_id', $row->organization_recordid)->orderBy('id', 'desc')->first(); - return $audit ? ' ' . $audit->created_at . '' : ""; + return $audit ? ' '.$audit->created_at.'' : ''; }) ->addColumn('service_tag', function ($row) { $tags = []; @@ -730,6 +744,7 @@ public function tb_organizations(Request $request) } } } + return count($tags) > 0 ? implode(',', $tags) : ''; }) ->editColumn('organization_tag', function ($row) { @@ -739,12 +754,13 @@ public function tb_organizations(Request $request) foreach ($organization_tags as $key => $value) { $tag = OrganizationTag::whereId($value)->first(); if ($tag) { - $organization_tag[] = ' ' . $tag->tag . ''; + $organization_tag[] = ' '.$tag->tag.''; } } + return implode(',', $organization_tag); } else { - return ''; + return ''; } }) ->editColumn('organization_status_x', function ($row) { @@ -755,12 +771,13 @@ public function tb_organizations(Request $request) foreach ($organization_statuses as $key => $value) { $status = OrganizationStatus::whereId($value)->first(); if ($status) { - $organization_status[] = ' ' . $status->status . ''; + $organization_status[] = ' '.$status->status.''; } } + return implode(',', $organization_status); } else { - return ''; + return ''; } }) ->filter(function ($query) use ($request) { @@ -772,11 +789,11 @@ public function tb_organizations(Request $request) $organization_tags = count($extraData['organization_tag']) > 0 ? array_filter($extraData['organization_tag']) : []; $query = $query->where(function ($q) use ($organization_tags) { foreach ($organization_tags as $key => $value) { - $q->orWhere('organization_tag', 'LIKE', '%' . $value . '%'); + $q->orWhere('organization_tag', 'LIKE', '%'.$value.'%'); } }); } - if (isset($extraData['organization_bookmark_only']) && $extraData['organization_bookmark_only'] != null && $extraData['organization_bookmark_only'] == "true") { + if (isset($extraData['organization_bookmark_only']) && $extraData['organization_bookmark_only'] != null && $extraData['organization_bookmark_only'] == 'true') { $query = $query->where('bookmark', 1); } if (isset($extraData['service_tag']) && $extraData['service_tag'] != null) { @@ -784,7 +801,7 @@ public function tb_organizations(Request $request) $organization_recordids = Service::where(function ($q) use ($service_tags) { foreach ($service_tags as $key => $value) { - $q->orWhere('service_tag', 'LIKE', '%' . $value . '%'); + $q->orWhere('service_tag', 'LIKE', '%'.$value.'%'); } })->pluck('service_organization')->toArray(); $query->whereIn('organization_recordid', $organization_recordids); @@ -805,13 +822,15 @@ public function tb_organizations(Request $request) $query->whereIn('organization_status_x', $extraData['status']); } } + return $query; }, true) ->rawColumns(['services', 'phones', 'location', 'organization_details', 'contact_name', 'last_note_date', 'last_edit_date', 'organization_name', 'organization_tag', 'organization_url', 'bookmark', 'organization_status_x']) ->make(true); } catch (\Throwable $th) { dd($th); - Log::error('Error in organization table index : ' . $th); + Log::error('Error in organization table index : '.$th); + return redirect()->back(); } } @@ -863,7 +882,7 @@ public function organizations() } 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'] = ''; array_push($parent_taxonomy, $child_data); } } @@ -892,14 +911,16 @@ public function organization_tag(Request $request, $id) $organization->organization_tag = $request->organization_tag ? implode(',', $request->organization_tag) : ''; $organization->latest_updated_date = Carbon::now(); $organization->updated_by = Auth::id(); - $organization->updated_at = date("Y-m-d H:i:s"); + $organization->updated_at = date('Y-m-d H:i:s'); $organization->save(); Session::flash('message', 'Tag added successfully!'); Session::flash('status', 'success'); + return redirect()->back(); } catch (\Throwable $th) { Session::flash('message', $th->getMessage()); Session::flash('status', 'error'); + return redirect()->back(); } } @@ -940,11 +961,13 @@ public function saveOrganizationFilter(Request $request) ]); Session::flash('message', 'Filter Saved Successfully!'); Session::flash('status', 'success'); + return redirect()->back(); } catch (\Throwable $th) { dd($th); Session::flash('message', $th->getMessage()); Session::flash('status', 'error'); + return redirect()->back(); } } @@ -955,7 +978,7 @@ public function saveOrganizationStatus(Request $request) $id = $request->organization_recordid; $organization = Organization::where('organization_recordid', $id)->first(); $organization->organization_status_x = $request->organisation_status ? $request->organisation_status : ''; - $organization->updated_at = date("Y-m-d H:i:s"); + $organization->updated_at = date('Y-m-d H:i:s'); $organization->latest_updated_date = Carbon::now(); $organization->updated_by = Auth::id(); $organizationStatus = OrganizationStatus::whereId($request->organisation_status)->first(); @@ -966,10 +989,12 @@ public function saveOrganizationStatus(Request $request) $organization->save(); Session::flash('message', 'Organization Status added successfully!'); Session::flash('status', 'success'); + return redirect()->back(); } catch (\Throwable $th) { Session::flash('message', $th->getMessage()); Session::flash('status', 'error'); + return redirect()->back(); } } @@ -983,7 +1008,7 @@ public function download($id) $pdf = PDF::loadView('frontEnd.organization_download', compact('organization', 'layout')); - return $pdf->download($organization_name . '.pdf'); + return $pdf->download($organization_name.'.pdf'); } /** @@ -1009,7 +1034,7 @@ public function create() } $taxonomy_info_list = Taxonomy::whereNull('taxonomy_parent_name')->Where(function ($query) use ($exclude_vocabulary) { for ($i = 0; $i < count($exclude_vocabulary); $i++) { - $query->where('taxonomy_name', 'not like', '%' . $exclude_vocabulary[$i] . '%'); + $query->where('taxonomy_name', 'not like', '%'.$exclude_vocabulary[$i].'%'); } })->get(); $taxonomyArray = []; @@ -1022,6 +1047,7 @@ public function create() } $value->taxonomyArray = $taxonomyArray; } + return true; }); $schedule_info_list = Schedule::select('schedule_recordid', 'opens', 'closes')->whereNotNull('opens')->where('opens', '!=', '')->orderBy('opens')->distinct()->get(); @@ -1071,7 +1097,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) @@ -1089,7 +1114,7 @@ public function store(Request $request) try { $organization = new Organization; - $new_recordid = Organization::max("organization_recordid") + 1; + $new_recordid = Organization::max('organization_recordid') + 1; $organization->organization_recordid = $new_recordid; $organization_recordid = $new_recordid; $layout = Layout::find(1); @@ -1120,7 +1145,7 @@ public function store(Request $request) if ($request->logo_type == 'file' && $request->hasFile('logo')) { $link = $request->file('logo')->store('uploads', 'public'); $link = Storage::url($link); - } else if ($request->logo_type == 'url' && $request->logo) { + } elseif ($request->logo_type == 'url' && $request->logo) { $link = $request->logo; } else { $link = $organization->logo; @@ -1150,7 +1175,6 @@ public function store(Request $request) $contact_phone_languages = $request->contact_phone_languages && count($request->contact_phone_languages) ? json_decode($request->contact_phone_languages[0]) : []; $contact_phone_descriptions = $request->contact_phone_descriptions && count($request->contact_phone_descriptions) ? json_decode($request->contact_phone_descriptions[0]) : []; - if ($request->contactRadio[$i] == 'new_data') { $contact = new Contact(); $contact->contact_recordid = Contact::max('contact_recordid') + 1; @@ -1162,7 +1186,7 @@ public function store(Request $request) $contact->contact_organizations = $new_recordid; // $contact->contact_phones = $request->contact_phone[$i]; if ($contact_service) { - $contact->contact_services = join(',', $contact_service[$i]); + $contact->contact_services = implode(',', $contact_service[$i]); } else { $contact->contact_services = ''; } @@ -1173,7 +1197,7 @@ public function store(Request $request) for ($p = 0; $p < count($contact_phone_numbers[$i]); $p++) { $phone_info = Phone::where('phone_number', '=', $contact_phone_numbers[$i][$p])->first(); if ($phone_info) { - $contact->contact_phones = $contact->contact_phones . $phone_info->phone_recordid . ','; + $contact->contact_phones = $contact->contact_phones.$phone_info->phone_recordid.','; $phone_info->phone_number = $contact_phone_numbers[$i][$p]; $phone_info->phone_extension = $contact_phone_extensions[$i][$p]; $phone_info->phone_type = $contact_phone_types[$i][$p]; @@ -1191,7 +1215,7 @@ public function store(Request $request) $new_phone->phone_language = isset($contact_phone_languages[$i][$p]) && is_array($contact_phone_languages[$i][$p]) && count($contact_phone_languages[$i][$p]) > 0 ? implode(',', $contact_phone_languages[$i][$p]) : ''; $new_phone->phone_description = $contact_phone_descriptions[$i][$p]; $new_phone->save(); - $contact->contact_phones = $contact->contact_phones . $new_phone_recordid . ','; + $contact->contact_phones = $contact->contact_phones.$new_phone_recordid.','; array_push($contact_phone_recordid_list, $new_phone_recordid); } } @@ -1209,7 +1233,7 @@ public function store(Request $request) $updating_contact->visibility = $contact_visibility[$i]; // $contact->contact_phones = $request->contact_phone[$i]; if ($contact_service) { - $updating_contact->contact_services = join(',', $contact_service[$i]); + $updating_contact->contact_services = implode(',', $contact_service[$i]); } else { $updating_contact->contact_services = ''; } @@ -1219,7 +1243,7 @@ public function store(Request $request) for ($p = 0; $p < count($contact_phone_numbers[$i]); $p++) { $phone_info = Phone::where('phone_number', '=', $contact_phone_numbers[$i][$p])->first(); if ($phone_info) { - $updating_contact->contact_phones = $updating_contact->contact_phones . $phone_info->phone_recordid . ','; + $updating_contact->contact_phones = $updating_contact->contact_phones.$phone_info->phone_recordid.','; $phone_info->phone_number = $contact_phone_numbers[$i][$p]; $phone_info->phone_extension = $contact_phone_extensions[$i][$p]; $phone_info->phone_type = $contact_phone_types[$i][$p]; @@ -1237,7 +1261,7 @@ public function store(Request $request) $new_phone->phone_language = isset($contact_phone_languages[$i][$p]) && is_array($contact_phone_languages[$i][$p]) && count($contact_phone_languages[$i][$p]) > 0 ? implode(',', $contact_phone_languages[$i][$p]) : ''; $new_phone->phone_description = $contact_phone_descriptions[$i][$p]; $new_phone->save(); - $updating_contact->contact_phones = $updating_contact->contact_phones . $new_phone_recordid . ','; + $updating_contact->contact_phones = $updating_contact->contact_phones.$new_phone_recordid.','; array_push($contact_phone_recordid_list, $new_phone_recordid); } } @@ -1287,7 +1311,7 @@ public function store(Request $request) $location->location_recordid = $newLocationId; $location->location_name = $request->location_name[$i]; $location->location_organization = $new_recordid; - $organization->organization_locations = $organization->organization_locations . ',' . $newLocationId; + $organization->organization_locations = $organization->organization_locations.','.$newLocationId; $location->location_alternate_name = isset($location_alternate_name[$i]) ? $location_alternate_name[$i] : null; $location->location_transportation = isset($location_transporation[$i]) ? $location_transporation[$i] : null; @@ -1311,7 +1335,7 @@ public function store(Request $request) } if ($location_service) { - $location->location_services = join(',', $location_service[$i]); + $location->location_services = implode(',', $location_service[$i]); } else { $location->location_services = ''; } @@ -1319,7 +1343,7 @@ public function store(Request $request) $location->services()->sync($location_service[$i]); if ($location_schedules[$i]) { - $location->location_schedule = join(',', $location_schedules[$i]); + $location->location_schedule = implode(',', $location_schedules[$i]); } else { $location->location_schedule = ''; } @@ -1415,7 +1439,7 @@ public function store(Request $request) } } $schedule_locations = is_array($schedule_locations) ? array_values(array_filter($schedule_locations)) : []; - $location->location_schedule = join(',', $schedule_locations); + $location->location_schedule = implode(',', $schedule_locations); $location->schedules()->sync($schedule_locations); @@ -1434,16 +1458,15 @@ public function store(Request $request) $location->location_name = $request->location_name[$i]; $location->location_organization = $new_recordid; // location address - $organization->organization_locations = $organization->organization_locations . ',' . $request->location_recordid[$i]; + $organization->organization_locations = $organization->organization_locations.','.$request->location_recordid[$i]; $location->location_alternate_name = $location_alternate_name[$i]; $location->location_transportation = $location_transporation[$i]; $location->location_description = $location_description[$i]; $location->location_details = $location_details[$i]; - // accessesibility - if (!empty($location_accessibility[$i]) && !empty($location_accessibility_details[$i])) { + if (! empty($location_accessibility[$i]) && ! empty($location_accessibility_details[$i])) { // Accessibility::updateOrCreate([ // 'accessibility_location' => $request->location_recordid[$i] // ], [ @@ -1459,7 +1482,7 @@ public function store(Request $request) } if ($location_service) { - $location->location_services = join(',', $location_service[$i]); + $location->location_services = implode(',', $location_service[$i]); } else { $location->location_services = ''; } @@ -1467,7 +1490,7 @@ public function store(Request $request) $location->services()->sync($location_service[$i]); if ($location_schedules[$i]) { - $location->location_schedule = join(',', $location_schedules[$i]); + $location->location_schedule = implode(',', $location_schedules[$i]); } else { $location->location_schedule = ''; } @@ -1595,7 +1618,7 @@ public function store(Request $request) // } } } - $location->location_schedule = join(',', $schedule_locations); + $location->location_schedule = implode(',', $schedule_locations); $location_phone_recordid_list = is_array($location_phone_recordid_list) ? array_values(array_filter($location_phone_recordid_list)) : []; $location_address_recordid_list = is_array($location_address_recordid_list) ? array_values(array_filter($location_address_recordid_list)) : []; $location->phones()->sync($location_phone_recordid_list); @@ -1611,7 +1634,6 @@ public function store(Request $request) } } - $phone_recordids = []; // if ($request->organization_phones) { // foreach ($request->organization_phones as $key => $number) { @@ -1706,12 +1728,14 @@ public function store(Request $request) } Session::flash('message', 'Organization created successfully!'); Session::flash('status', 'success'); + return redirect('organizations'); } catch (\Throwable $th) { dd($th); - Log::error('Error in create organization : ' . $th); + Log::error('Error in create organization : '.$th); Session::flash('message', $th->getMessage()); Session::flash('status', 'error'); + return redirect('organizations'); } } @@ -1719,23 +1743,24 @@ public function store(Request $request) /** * Display the specified resource. * - * @param int $id + * @param int $id * @return \Illuminate\Http\Response */ public function show($id) { $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)) { + 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)) { $layout = Layout::find(1); $orgService = $organization->organization_service_data->with('locations')->get(); $serviceLocationIds = []; foreach ($orgService as $key => $value) { - if ($value->locations) + if ($value->locations) { foreach ($value->locations as $key => $location) { $serviceLocationIds[] = $location->location_recordid; // $locations->push($location->with('services', 'address', 'phones')->first()); } + } } $organization_services = $organization->organization_service_data->paginate(10); @@ -1760,13 +1785,13 @@ public function show($id) // $location_info_list = Location::whereIn('location_recordid', $organization_locations_recordid_list)->orderBy('location_recordid')->paginate(10); // $location_info_list = array_map('intval', explode(',', $organization->organization_locations)); $location_info_list = $organization->location->pluck('location_recordid')->toArray(); - // $locationIds = $organization->location()->pluck('location_recordid')->toArray(); - // if (count($locationIds) > 0) { - // $location_info_list = array_merge($location_info_list, $locationIds); - // } - // if (count($serviceLocationIds) > 0) { - // $location_info_list = array_unique(array_merge($location_info_list, $serviceLocationIds)); - // } + $locationIds = $organization->location()->pluck('location_recordid')->toArray(); + if (count($locationIds) > 0) { + $location_info_list = array_merge($location_info_list, $locationIds); + } + 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(); @@ -1777,6 +1802,7 @@ public function show($id) $value->organization_name = $value->organization ? $value->organization->organization_name : ''; $value->organization_recordid = $value->organization ? $value->organization->organization_recordid : ''; $value->address_name = $value->address && count($value->address) > 0 ? $value->address[0]->address_1 : ''; + return true; }); } @@ -1805,7 +1831,7 @@ public function show($id) } 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'] = ''; array_push($parent_taxonomy, $child_data); } } @@ -1826,10 +1852,10 @@ public function show($id) $existing_tag_element_list = Organization::whereNotNull('organization_tag')->get()->pluck('organization_tag'); $existing_tags = []; foreach ($existing_tag_element_list as $key => $existing_tag_element) { - $existing_tag_list = explode(",", $existing_tag_element); + $existing_tag_list = explode(',', $existing_tag_element); foreach ($existing_tag_list as $key => $existing_tag) { - if (!in_array($existing_tag, $existing_tags, true)) { + if (! in_array($existing_tag, $existing_tags, true)) { array_push($existing_tags, $existing_tag); } } @@ -1855,6 +1881,7 @@ public function show($id) } else { Session::flash('message', 'This record has been deleted.'); Session::flash('status', 'warning'); + return redirect('organizations'); } } @@ -1862,7 +1889,7 @@ public function show($id) /** * Show the form for editing the specified resource. * - * @param int $id + * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) @@ -1891,7 +1918,6 @@ public function edit($id) $organization_locations_data = Location::where('location_organization', $organization->organization_recordid)->get(); - $organizationContacts = Contact::where('contact_organizations', '=', $id)->with('service')->get(); $phone_info_list = explode(',', $organization->organization_phones); @@ -1914,6 +1940,7 @@ public function edit($id) $value->location_state = $address ? $address->address_state_province : ''; $value->location_zipcode = $address ? $address->address_postal_code : ''; $value->location_phone = $phones ? $phones->phone_number : ''; + return true; }); $phone_languages = Language::orderBy('order')->pluck('language', 'language_recordid'); @@ -1929,7 +1956,7 @@ public function edit($id) } $taxonomy_info_list = Taxonomy::whereNull('taxonomy_parent_name')->Where(function ($query) use ($exclude_vocabulary) { for ($i = 0; $i < count($exclude_vocabulary); $i++) { - $query->where('taxonomy_name', 'not like', '%' . $exclude_vocabulary[$i] . '%'); + $query->where('taxonomy_name', 'not like', '%'.$exclude_vocabulary[$i].'%'); } })->get(); $taxonomyArray = []; @@ -1942,6 +1969,7 @@ public function edit($id) } $value->taxonomyArray = $taxonomyArray; } + return true; }); $schedule_info_list = Schedule::select('schedule_recordid', 'opens', 'closes')->whereNotNull('opens')->where('opens', '!=', '')->orderBy('opens')->distinct()->get(); @@ -2148,7 +2176,7 @@ public function edit($id) $j = 0; foreach ($organization_locations_data as $key => $value) { - if ($value->schedules && !empty($value->schedules) && count($value->schedules) > 0) { + if ($value->schedules && ! empty($value->schedules) && count($value->schedules) > 0) { foreach ($value->schedules as $key1 => $schedule) { if ($schedule->schedule_holiday == 1) { $location_holiday_start_dates[$j][] = $schedule->dtstart; @@ -2163,10 +2191,10 @@ public function edit($id) if (str_contains($schedule->weekday, $weekdays[$i])) { if (in_array(($i + 1), $schedule_closed_array)) { - ${'schedule_closed_' . $weekdays[$i] . '_datas'}[$j] = in_array(($i + 1), $schedule_closed_array) ? ($i + 1) : ''; + ${'schedule_closed_'.$weekdays[$i].'_datas'}[$j] = in_array(($i + 1), $schedule_closed_array) ? ($i + 1) : ''; } else { - ${'opens_location_' . $weekdays[$i] . '_datas'}[$j] = $schedule->opens; - ${'closes_location_' . $weekdays[$i] . '_datas'}[$j] = $schedule->closes; + ${'opens_location_'.$weekdays[$i].'_datas'}[$j] = $schedule->opens; + ${'closes_location_'.$weekdays[$i].'_datas'}[$j] = $schedule->closes; } } } @@ -2181,9 +2209,9 @@ public function edit($id) $weekdays = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday']; for ($i = 0; $i < 7; $i++) { // if ($schedule->weekday == $weekdays[$i]) { - ${'opens_location_' . $weekdays[$i] . '_datas'}[$j] = ''; - ${'closes_location_' . $weekdays[$i] . '_datas'}[$j] = ''; - ${'schedule_closed_' . $weekdays[$i] . '_datas'}[$j] = ''; + ${'opens_location_'.$weekdays[$i].'_datas'}[$j] = ''; + ${'closes_location_'.$weekdays[$i].'_datas'}[$j] = ''; + ${'schedule_closed_'.$weekdays[$i].'_datas'}[$j] = ''; // } } } @@ -2247,11 +2275,13 @@ public function edit($id) } else { Session::flash('message', 'Warning! Not enough permissions. Please contact Us for more'); Session::flash('status', 'warning'); + return redirect('/'); } } else { Session::flash('message', 'This record has been deleted.'); Session::flash('status', 'warning'); + return redirect('organizations'); } } @@ -2259,8 +2289,7 @@ public function edit($id) /** * Update the specified resource in storage. * - * @param \Illuminate\Http\Request $request - * @param int $id + * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) @@ -2296,13 +2325,12 @@ public function update(Request $request, $id) $organization->organization_year_incorporated = $request->organization_year_incorporated; - if ($request->has('logo_type')) { $link = ''; if ($request->logo_type == 'file' && $request->hasFile('logo')) { $link = $request->file('logo')->store('uploads', 'public'); $link = Storage::url($link); - } else if ($request->logo_type == 'url' && $request->logo) { + } elseif ($request->logo_type == 'url' && $request->logo) { $link = $request->logo; } else { $link = $organization->logo; @@ -2316,10 +2344,8 @@ public function update(Request $request, $id) $contact->save(); } - $this->saveOrganizationProgram($request, $organization); - $phone_recordids = []; if ($request->organization_phones) { @@ -2396,7 +2422,7 @@ public function update(Request $request, $id) $contact->contact_organizations = $id; // $contact->contact_phones = $request->contact_phone[$i]; if ($contact_service) { - $contact->contact_services = join(',', $contact_service[$i]); + $contact->contact_services = implode(',', $contact_service[$i]); } else { $contact->contact_services = ''; } @@ -2408,7 +2434,7 @@ public function update(Request $request, $id) for ($p = 0; $p < count($contact_phone_numbers[$i]); $p++) { $phone_info = Phone::where('phone_number', '=', $contact_phone_numbers[$i][$p])->first(); if ($phone_info) { - $contact->contact_phones = $contact->contact_phones . $phone_info->phone_recordid . ','; + $contact->contact_phones = $contact->contact_phones.$phone_info->phone_recordid.','; $phone_info->phone_number = $contact_phone_numbers[$i][$p]; $phone_info->phone_extension = $contact_phone_extensions[$i][$p]; $phone_info->phone_type = $contact_phone_types[$i][$p]; @@ -2426,7 +2452,7 @@ public function update(Request $request, $id) $new_phone->phone_language = isset($contact_phone_languages[$i][$p]) && is_array($contact_phone_languages[$i][$p]) && count($contact_phone_languages[$i][$p]) > 0 ? implode(',', $contact_phone_languages[$i][$p]) : ''; $new_phone->phone_description = $contact_phone_descriptions[$i][$p]; $new_phone->save(); - $contact->contact_phones = $contact->contact_phones . $new_phone_recordid . ','; + $contact->contact_phones = $contact->contact_phones.$new_phone_recordid.','; array_push($contact_phone_recordid_list, $new_phone_recordid); } } @@ -2444,7 +2470,7 @@ public function update(Request $request, $id) $updating_contact->contact_organizations = $id; // $contact->contact_phones = $request->contact_phone[$i]; if ($contact_service) { - $updating_contact->contact_services = join(',', $contact_service[$i]); + $updating_contact->contact_services = implode(',', $contact_service[$i]); } else { $updating_contact->contact_services = ''; } @@ -2457,7 +2483,7 @@ public function update(Request $request, $id) $phone_info = Phone::where('phone_number', '=', $contact_phone_numbers[$i][$p])->first(); // $contact_phones = explode(',',$updating_contact->contact_phones); if ($phone_info) { - $updating_contact->contact_phones = $updating_contact->contact_phones . $phone_info->phone_recordid . ','; + $updating_contact->contact_phones = $updating_contact->contact_phones.$phone_info->phone_recordid.','; $phone_info->phone_number = $contact_phone_numbers[$i][$p]; $phone_info->phone_extension = $contact_phone_extensions[$i][$p]; $phone_info->phone_type = $contact_phone_types[$i][$p]; @@ -2475,7 +2501,7 @@ public function update(Request $request, $id) $new_phone->phone_language = isset($contact_phone_languages[$i][$p]) && is_array($contact_phone_languages[$i][$p]) && count($contact_phone_languages[$i][$p]) > 0 ? implode(',', $contact_phone_languages[$i][$p]) : ''; $new_phone->phone_description = $contact_phone_descriptions[$i][$p]; $new_phone->save(); - $contact->contact_phones = $contact->contact_phones . $new_phone_recordid . ','; + $contact->contact_phones = $contact->contact_phones.$new_phone_recordid.','; array_push($contact_phone_recordid_list, $new_phone_recordid); } } @@ -2532,7 +2558,7 @@ public function update(Request $request, $id) $location->location_recordid = $newLocationId; $location->location_name = $request->location_name[$i]; $location->location_organization = $id; - $organization->organization_locations = $organization->organization_locations . ',' . $newLocationId; + $organization->organization_locations = $organization->organization_locations.','.$newLocationId; $location->location_alternate_name = $location_alternate_name[$i] ?? null; $location->location_transportation = $location_transporation[$i] ?? null; @@ -2543,7 +2569,7 @@ public function update(Request $request, $id) $location->accessesibility_url = isset($accessesibility_url[$i]) ? $accessesibility_url[$i] : null; // accessesibility - if (!empty($location_accessibility[$i]) && !empty($location_accessibility_details[$i])) { + if (! empty($location_accessibility[$i]) && ! empty($location_accessibility_details[$i])) { // Accessibility::create([ // 'accessibility_recordid' => Accessibility::max('accessibility_recordid') + 1, // 'accessibility' => $location_accessibility[$i], @@ -2558,7 +2584,7 @@ public function update(Request $request, $id) } if ($location_service) { - $location->location_services = join(',', $location_service[$i]); + $location->location_services = implode(',', $location_service[$i]); } else { $location->location_services = ''; } @@ -2652,7 +2678,7 @@ public function update(Request $request, $id) } } $location_phone_recordid_list = is_array($location_phone_recordid_list) ? array_values(array_filter($location_phone_recordid_list)) : []; - $location->location_schedule = join(',', $schedule_locations); + $location->location_schedule = implode(',', $schedule_locations); $location->schedules()->sync($schedule_locations); $location->phones()->sync($location_phone_recordid_list); @@ -2665,7 +2691,7 @@ public function update(Request $request, $id) $location->location_name = $request->location_name[$i]; $location->location_organization = $id; // location address - $organization->organization_locations = $organization->organization_locations . ',' . $request->location_recordid[$i]; + $organization->organization_locations = $organization->organization_locations.','.$request->location_recordid[$i]; $location->location_alternate_name = $location_alternate_name[$i]; $location->location_transportation = $location_transporation[$i]; @@ -2675,9 +2701,8 @@ public function update(Request $request, $id) $location->external_identifier_type = isset($external_identifier_type[$i]) ? $external_identifier_type[$i] : null; $location->accessesibility_url = isset($accessesibility_url[$i]) ? $accessesibility_url[$i] : null; - // accessesibility - if (!empty($location_accessibility[$i]) && !empty($location_accessibility_details[$i])) { + if (! empty($location_accessibility[$i]) && ! empty($location_accessibility_details[$i])) { // Accessibility::updateOrCreate([ // 'accessibility_location' => $request->location_recordid[$i] // ], [ @@ -2693,7 +2718,7 @@ public function update(Request $request, $id) } if ($location_service) { - $location->location_services = join(',', $location_service[$i]); + $location->location_services = implode(',', $location_service[$i]); } else { $location->location_services = ''; } @@ -2736,7 +2761,7 @@ public function update(Request $request, $id) for ($p = 0; $p < count($location_phone_numbers[$i]); $p++) { $phone_info = Phone::where('phone_number', '=', $request->location_phone[$i])->first(); if ($phone_info) { - $location->location_phones = $location->location_phones . $phone_info->phone_recordid . ','; + $location->location_phones = $location->location_phones.$phone_info->phone_recordid.','; $phone_info->phone_number = $location_phone_numbers[$i][$p]; $phone_info->phone_extension = $location_phone_extensions[$i][$p]; $phone_info->phone_type = $location_phone_types[$i][$p]; @@ -2754,7 +2779,7 @@ public function update(Request $request, $id) $new_phone->phone_language = isset($location_phone_languages[$i][$p]) && is_array($location_phone_languages[$i][$p]) && count($location_phone_languages[$i][$p]) > 0 ? implode(',', $location_phone_languages[$i][$p]) : ''; $new_phone->phone_description = $location_phone_descriptions[$i][$p]; $new_phone->save(); - $location->location_phones = $location->location_phones . $new_phone_recordid . ','; + $location->location_phones = $location->location_phones.$new_phone_recordid.','; array_push($location_phone_recordid_list, $new_phone_recordid); } } @@ -2766,7 +2791,7 @@ public function update(Request $request, $id) if ($location_holiday_start_dates && isset($location_holiday_start_dates[$i]) && $location_holiday_start_dates[$i] != null) { Schedule::where('locations', $location->location_recordid)->where('schedule_holiday', '1')->delete(); - if ($location_holiday_start_dates[$i] != null && !empty($location_holiday_start_dates[$i])) { + if ($location_holiday_start_dates[$i] != null && ! empty($location_holiday_start_dates[$i])) { for ($hs = 0; $hs < count($location_holiday_start_dates[$i]); $hs++) { $schedule_recordid = Schedule::max('schedule_recordid') + 1; $schedules = new Schedule(); @@ -2785,7 +2810,7 @@ public function update(Request $request, $id) } } } - $location->location_schedule = join(',', $schedule_locations); + $location->location_schedule = implode(',', $schedule_locations); $location_phone_recordid_list = is_array($location_phone_recordid_list) ? array_values(array_filter($location_phone_recordid_list)) : []; $schedule_locations = is_array($schedule_locations) ? array_values(array_filter($schedule_locations)) : []; @@ -2821,8 +2846,8 @@ public function update(Request $request, $id) $new_recordid = SessionData::max('session_recordid') + 1; $session->session_recordid = $new_recordid; $user = Auth::user(); - $date_time = date("Y-m-d h:i:sa"); - $session->session_name = 'session' . $new_recordid; + $date_time = date('Y-m-d h:i:sa'); + $session->session_name = 'session'.$new_recordid; $session->session_organization = $id; $session->session_method = $request->interaction_method; $session->session_disposition = $request->interaction_disposition; @@ -2852,7 +2877,7 @@ public function update(Request $request, $id) $interaction->organization_services = $request->organization_services ? implode(',', $request->organization_services) : ''; $interaction->organization_status = $request->organization_status; $interaction->interaction_records_edited = $request->interaction_records_edited; - $date_time = date("Y-m-d h:i:sa"); + $date_time = date('Y-m-d h:i:sa'); $interaction->interaction_timestamp = $date_time; $interaction->save(); @@ -2865,21 +2890,22 @@ public function update(Request $request, $id) $organization->organization_status_x = $request->organization_status; } - $organization->latest_updated_date = Carbon::now(); if ($organization->wasChanged()) { - $organization->updated_at = date("Y-m-d H:i:s"); + $organization->updated_at = date('Y-m-d H:i:s'); } $organization->updated_by = Auth::id(); $organization->save(); Session::flash('message', 'Organization updated successfully!'); Session::flash('status', 'success'); - return redirect('organizations/' . $id); + + return redirect('organizations/'.$id); } catch (\Throwable $th) { dd($th); - Log::error('Error in update organization : ' . $th); + Log::error('Error in update organization : '.$th); Session::flash('message', $th->getMessage()); Session::flash('status', 'error'); + return redirect('organizations'); } } @@ -2887,17 +2913,17 @@ public function update(Request $request, $id) public function add_comment(Request $request, $id) { $this->validate($request, [ - 'comment' => 'required' + 'comment' => 'required', ]); try { $organization = Organization::find($id); $comment_content = $request->comment; $user = Auth::user(); - $date_time = date("Y-m-d H:i:s"); + $date_time = date('Y-m-d H:i:s'); $comment = new Comment(); - $comment_recordids = Comment::select("comments_recordid")->distinct()->get(); - $comment_recordid_list = array(); + $comment_recordids = Comment::select('comments_recordid')->distinct()->get(); + $comment_recordid_list = []; foreach ($comment_recordids as $key => $value) { $comment_recordid = $value->comments_recordid; array_push($comment_recordid_list, $comment_recordid); @@ -2920,10 +2946,12 @@ public function add_comment(Request $request, $id) $comment_list = Comment::where('comments_organization', '=', $id)->get(); Session::flash('message', 'Comment added successfully!'); Session::flash('status', 'success'); - return redirect('organizations/' . $id); + + return redirect('organizations/'.$id); } catch (\Throwable $th) { Session::flash('message', $th->getMessage()); Session::flash('status', 'error'); + return redirect()->back(); } } @@ -2931,7 +2959,7 @@ public function add_comment(Request $request, $id) /** * Remove the specified resource from storage. * - * @param int $id + * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) @@ -2950,6 +2978,7 @@ public function delete_organization(Request $request) } Session::flash('message', 'Organization deleted successfully!'); Session::flash('status', 'success'); + return redirect('organizations'); } else { $organization = Organization::where('organization_recordid', '=', $organization_recordid)->first(); @@ -2964,11 +2993,13 @@ public function delete_organization(Request $request) } Session::flash('message', 'The organization and its services, contacts & facilities have been successfully deleted.'); Session::flash('status', 'success'); + return redirect('organizations'); } } catch (\Throwable $th) { Session::flash('message', $th->getMessage()); Session::flash('status', 'error'); + return redirect()->back(); } } @@ -2984,28 +3015,31 @@ public function organization_history($organization_old, $request) public function createNewTag(Request $request, $id) { try { - if (!$request->tag) { + if (! $request->tag) { Session::flash('message', 'Organization tag can`t be blank!'); Session::flash('status', 'error'); + return redirect()->back(); } $organizationTag = OrganizationTag::create([ 'tag' => $request->tag, - 'created_by' => Auth::id() + 'created_by' => Auth::id(), ]); $organization = Organization::whereId($id)->first(); $orgTag = $organization->organization_tag != null ? explode(',', $organization->organization_tag) : []; $orgTag[] = $organizationTag->id; - if (!empty($orgTag)) { + if (! empty($orgTag)) { $organization->organization_tag = implode(',', $orgTag); $organization->save(); } Session::flash('message', 'Organization tag added successfully!'); Session::flash('status', 'success'); + return redirect()->back(); } catch (\Throwable $th) { Session::flash('message', $th->getMessage()); Session::flash('status', 'success'); + return redirect()->back(); } } @@ -3013,29 +3047,32 @@ public function createNewTag(Request $request, $id) public function createNewOrganizationTag(Request $request) { try { - if (!$request->tag) { + if (! $request->tag) { Session::flash('message', 'Organization tag can`t be blank!'); Session::flash('status', 'error'); + return redirect()->back(); } $organizationTag = OrganizationTag::create([ 'tag' => $request->tag, - 'created_by' => Auth::id() + 'created_by' => Auth::id(), ]); $organization_recordid = $request->organization_recordid; $organization = Organization::where('organization_recordid', $organization_recordid)->first(); $orgTag = $organization->organization_tag != null ? explode(',', $organization->organization_tag) : []; $orgTag[] = $organizationTag->id; - if (!empty($orgTag)) { + if (! empty($orgTag)) { $organization->organization_tag = implode(',', $orgTag); $organization->save(); } Session::flash('message', 'Organization tag added successfully!'); Session::flash('status', 'success'); + return redirect()->back(); } catch (\Throwable $th) { Session::flash('message', $th->getMessage()); Session::flash('status', 'success'); + return redirect()->back(); } } @@ -3050,14 +3087,15 @@ public function addOrganizationTag(Request $request) $organization->updated_by = Auth::id(); $organization->updated_at = Carbon::now(); $organization->save(); + return response()->json([ 'message' => 'tags added successfully!', - 'success' => true + 'success' => true, ], 200); } catch (\Throwable $th) { return response()->json([ 'message' => $th->getMessage(), - 'success' => false + 'success' => false, ], 500); } } @@ -3072,16 +3110,17 @@ public function saveOrganizationBookmark(Request $request) $organization->updated_by = Auth::id(); $organization->updated_at = Carbon::now(); $organization->save(); + // Session::flash('message', 'Organization Bookmarked successfully!'); // Session::flash('status', 'success'); return response()->json([ 'success' => true, - 'message' => 'Organization Bookmarked successfully' + 'message' => 'Organization Bookmarked successfully', ], 200); } catch (\Throwable $th) { return response()->json([ 'message' => $th->getMessage(), - 'success' => false + 'success' => false, ], 500); } } @@ -3099,6 +3138,7 @@ public function delete_manage_filters($id) Session::flash('message', 'Filter Deleted successfully!'); Session::flash('status', 'success'); + return redirect()->back(); } @@ -3111,10 +3151,12 @@ public function saveOrganizationTags(Request $request) $organization->save(); Session::flash('message', 'Organization tag updated successfully!'); Session::flash('status', 'success'); + return redirect()->back(); } catch (\Throwable $th) { Session::flash('message', $th->getMessage()); Session::flash('status', 'success'); + return redirect()->back(); } } @@ -3152,11 +3194,6 @@ public function saveOrganizationProgram($request, $organization) $organization->program()->sync($organizationPrograms); } - /** - * @param $request - * @param $new_recordid - * @return array - */ public function saveOrganizationService($request, $new_recordid): array { $service_recordids = []; @@ -3195,26 +3232,26 @@ public function saveOrganizationService($request, $new_recordid): array } else { $service->service_status = ''; } - $service->service_taxonomy = join(',', $service_taxonomies[$i]); + $service->service_taxonomy = implode(',', $service_taxonomies[$i]); $service->service_application_process = $service_application_process[$i]; $service->service_wait_time = $service_wait_time[$i]; $service->service_fees = $service_fees[$i]; $service->service_accreditations = $service_accreditations[$i]; $service->service_licenses = $service_licenses[$i]; if ($service_schedules[$i]) { - $service->service_schedule = join(',', $service_schedules[$i]); + $service->service_schedule = implode(',', $service_schedules[$i]); } else { $service->service_schedule = ''; } // $service->service_details = $service_details[$i]; if ($service_details[$i]) { - $service->service_details = join(',', $service_details[$i]); + $service->service_details = implode(',', $service_details[$i]); } else { $service->service_details = ''; } // $service->service_address = $service_address[$i]; if ($service_address[$i]) { - $service->service_address = join(',', $service_address[$i]); + $service->service_address = implode(',', $service_address[$i]); } else { $service->service_address = ''; } @@ -3224,7 +3261,7 @@ public function saveOrganizationService($request, $new_recordid): array $phone_info = Phone::where('phone_number', '=', $request->service_phone[$i])->first(); if ($phone_info) { - $service->service_phones = $service->service_phones . $phone_info->phone_recordid . ','; + $service->service_phones = $service->service_phones.$phone_info->phone_recordid.','; $phone_info->phone_number = $request->service_phone[$i]; $phone_info->save(); array_push($service_phone_recordid_list, $phone_info->phone_recordid); @@ -3234,7 +3271,7 @@ public function saveOrganizationService($request, $new_recordid): array $new_phone->phone_recordid = $new_phone_recordid; $new_phone->phone_number = $request->service_phone[$i]; $new_phone->save(); - $service->service_phones = $service->service_phones . $new_phone_recordid . ','; + $service->service_phones = $service->service_phones.$new_phone_recordid.','; array_push($service_phone_recordid_list, $new_phone_recordid); } array_push($service_recordids, Service::max('service_recordid') + 1); @@ -3269,26 +3306,26 @@ public function saveOrganizationService($request, $new_recordid): array } else { $updating_service->service_status = ''; } - $updating_service->service_taxonomy = join(',', $service_taxonomies[$i]); + $updating_service->service_taxonomy = implode(',', $service_taxonomies[$i]); $updating_service->service_application_process = $service_application_process[$i]; $updating_service->service_wait_time = $service_wait_time[$i]; $updating_service->service_fees = $service_fees[$i]; $updating_service->service_accreditations = $service_accreditations[$i]; $updating_service->service_licenses = $service_licenses[$i]; if ($service_schedules[$i]) { - $updating_service->service_schedule = join(',', $service_schedules[$i]); + $updating_service->service_schedule = implode(',', $service_schedules[$i]); } else { $updating_service->service_schedule = ''; } // $updating_service->service_details = $service_details[$i]; if ($service_details[$i]) { - $updating_service->service_details = join(',', $service_details[$i]); + $updating_service->service_details = implode(',', $service_details[$i]); } else { $updating_service->service_details = ''; } // $updating_service->service_address = $service_address[$i]; if ($service_address[$i]) { - $updating_service->service_address = join(',', $service_address[$i]); + $updating_service->service_address = implode(',', $service_address[$i]); } else { $updating_service->service_address = ''; } @@ -3298,7 +3335,7 @@ public function saveOrganizationService($request, $new_recordid): array $phone_info = Phone::where('phone_number', '=', $request->service_phone[$i])->first(); if ($phone_info) { - $updating_service->service_phones = $updating_service->service_phones . $phone_info->phone_recordid . ','; + $updating_service->service_phones = $updating_service->service_phones.$phone_info->phone_recordid.','; $phone_info->phone_number = $request->service_phone[$i]; $phone_info->save(); array_push($service_phone_recordid_list, $phone_info->phone_recordid); @@ -3308,7 +3345,7 @@ public function saveOrganizationService($request, $new_recordid): array $new_phone->phone_recordid = $new_phone_recordid; $new_phone->phone_number = $request->service_phone[$i]; $new_phone->save(); - $updating_service->service_phones = $updating_service->service_phones . $new_phone_recordid . ','; + $updating_service->service_phones = $updating_service->service_phones.$new_phone_recordid.','; array_push($service_phone_recordid_list, $new_phone_recordid); } $service_recordids[] = Service::max('service_recordid') + 1; @@ -3330,15 +3367,10 @@ public function saveOrganizationService($request, $new_recordid): array } } } + return $service_recordids; } - /** - * @param $request - * @param $i - * @param $location_recordid - * @return array - */ public function saveLocationSchedule($request, $i, $location_recordid): array { // location schedule section @@ -3376,20 +3408,20 @@ public function saveLocationSchedule($request, $i, $location_recordid): array $weekdays = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday']; for ($s = 0; $s < 7; $s++) { // dd($request); - if ((isset(${'opens_location_' . $weekdays[$s] . '_datas'}[$i]) && isset(${'closes_location_' . $weekdays[$s] . '_datas'}[$i])) || ((isset(${'schedule_closed_' . $weekdays[$s] . '_datas'}[$i]) && ${'schedule_closed_' . $weekdays[$s] . '_datas'}[$i] == ($s + 1)))) { - if ((isset(${'opens_location_' . $weekdays[$s] . '_datas'}[$i]) && isset(${'closes_location_' . $weekdays[$s] . '_datas'}[$i])) && ${'opens_location_' . $weekdays[$s] . '_datas'}[$i] && ${'closes_location_' . $weekdays[$s] . '_datas'}[$i]) { - $schedules = Schedule::where('locations', $location_recordid)->where('opens', ${'opens_location_' . $weekdays[$s] . '_datas'}[$i])->where('closes', ${'closes_location_' . $weekdays[$s] . '_datas'}[$i])->first(); + if ((isset(${'opens_location_'.$weekdays[$s].'_datas'}[$i]) && isset(${'closes_location_'.$weekdays[$s].'_datas'}[$i])) || ((isset(${'schedule_closed_'.$weekdays[$s].'_datas'}[$i]) && ${'schedule_closed_'.$weekdays[$s].'_datas'}[$i] == ($s + 1)))) { + if ((isset(${'opens_location_'.$weekdays[$s].'_datas'}[$i]) && isset(${'closes_location_'.$weekdays[$s].'_datas'}[$i])) && ${'opens_location_'.$weekdays[$s].'_datas'}[$i] && ${'closes_location_'.$weekdays[$s].'_datas'}[$i]) { + $schedules = Schedule::where('locations', $location_recordid)->where('opens', ${'opens_location_'.$weekdays[$s].'_datas'}[$i])->where('closes', ${'closes_location_'.$weekdays[$s].'_datas'}[$i])->first(); } else { $schedules = Schedule::where('locations', $location_recordid)->whereNotNull('schedule_closed')->first(); } if ($schedules) { $schedules->locations = $location_recordid; - $schedules->weekday = $schedules->weekday ? (str_contains($schedules->weekday, $weekdays[$s]) ? $schedules->weekday : ($schedules->weekday . ',' . $weekdays[$s])) : $weekdays[$s]; - $schedules->opens = isset(${'opens_location_' . $weekdays[$s] . '_datas'}[$i]) && ${'opens_location_' . $weekdays[$s] . '_datas'}[$i] ? ${'opens_location_' . $weekdays[$s] . '_datas'}[$i] : $schedules->opens; - $schedules->closes = isset(${'closes_location_' . $weekdays[$s] . '_datas'}[$i]) && ${'closes_location_' . $weekdays[$s] . '_datas'}[$i] ? ${'closes_location_' . $weekdays[$s] . '_datas'}[$i] : $schedules->closes; - if (isset(${'schedule_closed_' . $weekdays[$s] . '_datas'}[$i]) && ${'schedule_closed_' . $weekdays[$s] . '_datas'}[$i] == ($s + 1)) { + $schedules->weekday = $schedules->weekday ? (str_contains($schedules->weekday, $weekdays[$s]) ? $schedules->weekday : ($schedules->weekday.','.$weekdays[$s])) : $weekdays[$s]; + $schedules->opens = isset(${'opens_location_'.$weekdays[$s].'_datas'}[$i]) && ${'opens_location_'.$weekdays[$s].'_datas'}[$i] ? ${'opens_location_'.$weekdays[$s].'_datas'}[$i] : $schedules->opens; + $schedules->closes = isset(${'closes_location_'.$weekdays[$s].'_datas'}[$i]) && ${'closes_location_'.$weekdays[$s].'_datas'}[$i] ? ${'closes_location_'.$weekdays[$s].'_datas'}[$i] : $schedules->closes; + if (isset(${'schedule_closed_'.$weekdays[$s].'_datas'}[$i]) && ${'schedule_closed_'.$weekdays[$s].'_datas'}[$i] == ($s + 1)) { - $schedules->schedule_closed = $schedules->schedule_closed ? (str_contains($schedules->schedule_closed, ($s + 1)) ? $schedules->schedule_closed : $schedules->schedule_closed . ',' . ($s + 1)) : ($s + 1); + $schedules->schedule_closed = $schedules->schedule_closed ? (str_contains($schedules->schedule_closed, ($s + 1)) ? $schedules->schedule_closed : $schedules->schedule_closed.','.($s + 1)) : ($s + 1); } else { if (str_contains($schedules->schedule_closed, ($s + 1))) { $schedule_closed = explode(',', $schedules->schedule_closed); @@ -3407,9 +3439,9 @@ public function saveLocationSchedule($request, $i, $location_recordid): array $schedules->schedule_recordid = $schedule_recordid; $schedules->locations = $location_recordid; $schedules->weekday = $weekdays[$s]; - $schedules->opens = isset(${'opens_location_' . $weekdays[$s] . '_datas'}[$i]) ? ${'opens_location_' . $weekdays[$s] . '_datas'}[$i] : null; - $schedules->closes = isset(${'closes_location_' . $weekdays[$s] . '_datas'}[$i]) ? ${'closes_location_' . $weekdays[$s] . '_datas'}[$i] : null; - if (isset(${'schedule_closed_' . $weekdays[$s] . '_datas'}[$i]) && ${'schedule_closed_' . $weekdays[$s] . '_datas'}[$i] == ($s + 1)) { + $schedules->opens = isset(${'opens_location_'.$weekdays[$s].'_datas'}[$i]) ? ${'opens_location_'.$weekdays[$s].'_datas'}[$i] : null; + $schedules->closes = isset(${'closes_location_'.$weekdays[$s].'_datas'}[$i]) ? ${'closes_location_'.$weekdays[$s].'_datas'}[$i] : null; + if (isset(${'schedule_closed_'.$weekdays[$s].'_datas'}[$i]) && ${'schedule_closed_'.$weekdays[$s].'_datas'}[$i] == ($s + 1)) { $schedules->schedule_closed = $s + 1; } $schedules->save(); @@ -3417,6 +3449,7 @@ public function saveLocationSchedule($request, $i, $location_recordid): array } } } + // } return $schedule_locations; } diff --git a/app/Http/Controllers/frontEnd/ServiceController.php b/app/Http/Controllers/frontEnd/ServiceController.php index ccddafc7..0d09a5cd 100644 --- a/app/Http/Controllers/frontEnd/ServiceController.php +++ b/app/Http/Controllers/frontEnd/ServiceController.php @@ -2,16 +2,16 @@ namespace App\Http\Controllers\frontEnd; +use App\Exports\ServiceExport; use App\Functions\Airtable; use App\Http\Controllers\Controller; use App\Imports\ServiceLocationImport; use App\Imports\Services; -use App\Exports\ServiceExport; use App\Model\Accessibility; use App\Model\Address; +use App\Model\Airtable_v2; use App\Model\Airtablekeyinfo; use App\Model\Airtables; -use App\Model\Airtable_v2; use App\Model\Alt_taxonomy; use App\Model\City; use App\Model\Code; @@ -19,66 +19,67 @@ use App\Model\CodeLedger; use App\Model\Comment; use App\Model\Contact; +use App\Model\csv; use App\Model\CSV_Source; use App\Model\Detail; +use App\Model\DetailType; +use App\Model\Disposition; +use App\Model\FeeOption; +use App\Model\Helptext; +use App\Model\InteractionMethod; +use App\Model\InterpretationService; +use App\Model\Language; use App\Model\Layout; use App\Model\Location; use App\Model\Map; use App\Model\MetaFilter; use App\Model\Organization; +use App\Model\OrganizationStatus; +use App\Model\OrganizationTag; use App\Model\Phone; +use App\Model\PhoneType; +use App\Model\Program; +use App\Model\Region; +use App\Model\RequiredDocument; use App\Model\Schedule; use App\Model\Service; -use App\Model\OrganizationTag; use App\Model\ServiceAddress; +use App\Model\ServiceArea; use App\Model\ServiceContact; use App\Model\ServiceDetail; use App\Model\ServiceLocation; use App\Model\ServiceOrganization; use App\Model\ServicePhone; use App\Model\ServiceSchedule; -use App\Model\ServiceTaxonomy; -use App\Model\Source_data; -use App\Model\DetailType; -use App\Model\Taxonomy; -use App\Services\Stringtoint; -use Carbon\Carbon; -use App\Model\csv; -use App\Model\Disposition; -use App\Model\FeeOption; -use App\Model\Helptext; -use App\Model\InteractionMethod; -use App\Model\InterpretationService; -use App\Model\TaxonomyType; -use App\Model\Language; -use App\Model\OrganizationStatus; -use App\Model\PhoneType; -use App\Model\Program; -use App\Model\Region; -use App\Model\RequiredDocument; -use App\Model\ServiceArea; use App\Model\ServiceStatus; use App\Model\ServiceTag; +use App\Model\ServiceTaxonomy; use App\Model\SessionData; use App\Model\SessionInteraction; +use App\Model\Source_data; use App\Model\State; +use App\Model\Taxonomy; use App\Model\TaxonomyEmail; +use App\Model\TaxonomyType; use App\Services\ServiceDataService; +use App\Services\Stringtoint; +use Carbon\Carbon; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\DB; +use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Session; use Maatwebsite\Excel\Facades\Excel; +use OwenIt\Auditing\Models\Audit; use PDF; use SendGrid; use SendGrid\Mail\Mail; -use OwenIt\Auditing\Models\Audit; -use Illuminate\Support\Facades\Log; -use Yajra\DataTables\DataTables; class ServiceController extends Controller { - public $commonController, $serviceDataService; + public $commonController; + + public $serviceDataService; public function __construct(CommonController $commonControllerData, ServiceDataService $serviceDataService) { @@ -101,8 +102,6 @@ public function index() // $locations = Location::with('services', 'organization', 'address'); $locations = Location::whereIn('location_recordid', $service_locations)->with('services', 'organization', 'address'); - - $sort_by_distance_clickable = false; $map = Map::find(1); $parent_taxonomy = []; @@ -128,7 +127,7 @@ public function index() $taxonomy_serviceids = []; foreach ($metas as $key => $meta) { - $values = explode(",", $meta->values); + $values = explode(',', $meta->values); if (count($values) > 0) { if ($meta->facet == 'Postal_code') { @@ -172,12 +171,13 @@ public function index() $service_tag_ids = Service::where(function ($query) use ($values, $operations) { foreach ($values as $keyword) { if ($keyword && $operations == 'Include') { - $query = $query->orWhereRaw('find_in_set(' . $keyword . ', service_tag)'); + $query = $query->orWhereRaw('find_in_set('.$keyword.', service_tag)'); } if ($keyword && $operations == 'Exclude') { - $query = $query->orWhereRaw('NOT find_in_set(' . $keyword . ', service_tag)'); + $query = $query->orWhereRaw('NOT find_in_set('.$keyword.', service_tag)'); } } + return $query; })->pluck('service_recordid')->toArray(); $taxonomy_serviceids = array_merge($service_tag_ids, $taxonomy_serviceids); @@ -199,6 +199,7 @@ public function index() $query = $query->orWhere('organization_status_x', 'NOT LIKE', "%$keyword%"); } } + return $query; })->pluck('organization_recordid')->toArray(); } @@ -217,12 +218,13 @@ public function index() foreach ($values as $keyword) { // $organization_status = OrganizationStatus::whereId($keyword)->first(); if ($keyword && $operations == 'Include') { - $query = $query->orWhereRaw('find_in_set(' . $keyword . ', organization_tag)'); + $query = $query->orWhereRaw('find_in_set('.$keyword.', organization_tag)'); } if ($keyword && $operations == 'Exclude') { - $query = $query->orWhereRaw('NOT find_in_set(' . $keyword . ', organization_tag)'); + $query = $query->orWhereRaw('NOT find_in_set('.$keyword.', organization_tag)'); } } + return $query; })->pluck('organization_recordid')->toArray(); } @@ -237,8 +239,8 @@ public function index() $locations_ids = Servicelocation::whereIn('service_recordid', $services_ids)->pluck('location_recordid')->toArray(); $locations = $locations->whereIn('location_recordid', $locations_ids); } - if (!Auth::check()) { - $services = $services->where('access_requirement', '!=', 'yes'); + if (! Auth::check()) { + $services = $services->where('access_requirement', '!=', 'yes'); $locations = $locations->whereHas('services', function ($q) { $q->where('access_requirement', '!=', 'yes'); }); @@ -250,7 +252,7 @@ public function index() foreach ($services as $key => $service) { $service_taxonomy_recordid_list = explode(',', $service->service_taxonomy); 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; @@ -280,7 +282,6 @@ public function index() // } $sdoh_codes_category_Array = json_encode($sdoh_codes_category_Array); - $codesIds = Service::whereNotNull('SDOH_code')->where('SDOH_code', '!=', '')->pluck('SDOH_code')->toArray(); $tempCode = []; foreach ($codesIds as $key => $value) { @@ -323,7 +324,7 @@ public function index() } 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'] = ''; array_push($parent_taxonomy, $child_data); } } @@ -369,22 +370,21 @@ public function create() if (Auth::user()->organization_tags) { $organization_tags = explode(',', Auth::user()->organization_tags); foreach ($organization_tags as $key => $value) { - $organizations = Organization::where('organization_tag', 'LIKE', '%' . $value . '%')->pluck('organization_recordid')->toArray(); + $organizations = Organization::where('organization_tag', 'LIKE', '%'.$value.'%')->pluck('organization_recordid')->toArray(); $organization_recordid = array_unique(array_merge($organization_recordid, $organizations)); } } - $organization_names = Organization::orderBy("organization_name")->select("organization_name")->whereIn('organization_recordid', $organization_recordid)->distinct()->get(); + $organization_names = Organization::orderBy('organization_name')->select('organization_name')->whereIn('organization_recordid', $organization_recordid)->distinct()->get(); } else { - $organization_names = Organization::orderBy("organization_name")->select("organization_name")->distinct()->get(); + $organization_names = Organization::orderBy('organization_name')->select('organization_name')->distinct()->get(); } $organization_name_list = []; foreach ($organization_names as $key => $value) { - $org_names = explode(", ", trim($value->organization_name)); + $org_names = explode(', ', trim($value->organization_name)); $organization_name_list = array_merge($organization_name_list, $org_names); } $organization_name_list = array_unique($organization_name_list); - $facility_info_list = Location::select('location_recordid', 'location_name')->orderBy('location_recordid')->distinct()->get(); $service_status_list = ['Yes' => 'Yes', 'No' => 'No']; @@ -397,7 +397,7 @@ public function create() } $taxonomy_info_list = Taxonomy::whereNull('taxonomy_parent_name')->Where(function ($query) use ($exclude_vocabulary) { for ($i = 0; $i < count($exclude_vocabulary); $i++) { - $query->where('taxonomy_name', 'not like', '%' . $exclude_vocabulary[$i] . '%'); + $query->where('taxonomy_name', 'not like', '%'.$exclude_vocabulary[$i].'%'); } })->get(); $taxonomyArray = []; @@ -410,6 +410,7 @@ public function create() } $value->taxonomyArray = $taxonomyArray; } + return true; }); $schedule_info_list = Schedule::select('schedule_recordid', 'opens', 'closes')->whereNotNull('opens')->where('opens', '!=', '')->orderBy('opens')->distinct()->get(); @@ -419,7 +420,6 @@ public function create() $contact_info_list = Contact::select('contact_recordid', 'contact_name')->orderBy('contact_recordid')->distinct()->get(); - $phone_languages = Language::orderBy('order')->whereNotNull('language_recordid')->pluck('language', 'language_recordid'); $phone_type = PhoneType::orderBy('order')->orderBy('type')->pluck('type', 'id'); @@ -448,7 +448,6 @@ public function create() $goals = Code::where('resource', 'Goal')->get()->groupBy('category'); $activities = Code::where('resource', 'Procedure')->get()->groupBy('category'); - $service_area = ServiceArea::pluck('name', 'id'); $fee_options = FeeOption::pluck('fees', 'id'); @@ -473,7 +472,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) @@ -486,14 +484,14 @@ public function store(Request $request) ]); if ($request->service_email) { $this->validate($request, [ - 'service_email' => 'email' + 'service_email' => 'email', ]); } try { $layout = Layout::find(1); $service = new Service; - $service_recordids = Service::select("service_recordid")->distinct()->get(); - $service_recordid_list = array(); + $service_recordids = Service::select('service_recordid')->distinct()->get(); + $service_recordid_list = []; foreach ($service_recordids as $key => $value) { $service_recordid = $value->service_recordid; $service_recordid_list[] = $service_recordid; @@ -542,15 +540,17 @@ public function store(Request $request) $organization_name = $request->service_organization; $service_organization = Organization::where('organization_name', '=', $organization_name)->first(); - $service_organization_id = $service_organization["organization_recordid"]; + $service_organization_id = $service_organization['organization_recordid']; $service->service_organization = $service_organization_id; // $service->service_area = is_array($request->service_area) ? implode(',', array_values(array_filter($request->service_area))) : ''; // $service->fee_option = is_array($request->fee_option) ? implode(',', array_values(array_filter($request->fee_option))) : ''; - if ($request->service_area) + if ($request->service_area) { $service->areas()->sync($request->service_area); - if ($request->fee_option) + } + if ($request->fee_option) { $service->fees()->sync($request->fee_option); + } $servicePrograms = $this->saveServiceProgram($request, $service_recordid); @@ -688,7 +688,6 @@ public function store(Request $request) $location_phone_types = $request->location_phone_types && count($request->location_phone_types) ? json_decode($request->location_phone_types[0], true) : []; $location_phone_languages = $request->location_phone_languages && count($request->location_phone_languages) ? json_decode($request->location_phone_languages[0], true) : []; - $location_phone_descriptions = $request->location_phone_descriptions && count($request->location_phone_descriptions) ? json_decode($request->location_phone_descriptions[0], true) : []; // location schedule section @@ -726,7 +725,6 @@ public function store(Request $request) $location_holiday_close_ats = $request->location_holiday_close_ats ? json_decode($request->location_holiday_close_ats, true) : []; $location_holiday_closeds = $request->location_holiday_closeds ? json_decode($request->location_holiday_closeds, true) : []; - if ($request->locationRadio[$i] == 'new_data') { $location = new Location(); $location_recordid = Location::max('location_recordid') + 1; @@ -737,10 +735,9 @@ public function store(Request $request) $location->location_description = isset($location_description[$i]) ? $location_description[$i] : null; $location->location_details = isset($location_details[$i]) ? $location_details[$i] : null; - // accessesibility - if (!empty($location_accessibility[$i]) && !empty($location_accessibility_details[$i])) { + if (! empty($location_accessibility[$i]) && ! empty($location_accessibility_details[$i])) { // Accessibility::create([ // 'accessibility_recordid' => Accessibility::max('accessibility_recordid') + 1, // 'accessibility' => $location_accessibility[$i], @@ -831,9 +828,9 @@ public function store(Request $request) $schedules = Schedule::where('locations', $location_recordid)->where('weekday', $weekdays[$s])->first(); if ($schedules) { $schedules->weekday = $weekdays[$s]; - $schedules->opens = isset(${'opens_location_' . $weekdays[$s] . '_datas'}[$i]) ? ${'opens_location_' . $weekdays[$s] . '_datas'}[$i] : ''; - $schedules->closes = isset(${'closes_location_' . $weekdays[$s] . '_datas'}[$i]) ? ${'closes_location_' . $weekdays[$s] . '_datas'}[$i] : ''; - if (isset(${'schedule_closed_' . $weekdays[$s] . '_datas'}[$i]) && ${'schedule_closed_' . $weekdays[$s] . '_datas'}[$i] == ($s + 1)) { + $schedules->opens = isset(${'opens_location_'.$weekdays[$s].'_datas'}[$i]) ? ${'opens_location_'.$weekdays[$s].'_datas'}[$i] : ''; + $schedules->closes = isset(${'closes_location_'.$weekdays[$s].'_datas'}[$i]) ? ${'closes_location_'.$weekdays[$s].'_datas'}[$i] : ''; + if (isset(${'schedule_closed_'.$weekdays[$s].'_datas'}[$i]) && ${'schedule_closed_'.$weekdays[$s].'_datas'}[$i] == ($s + 1)) { $schedules->schedule_closed = $s + 1; } else { $schedules->schedule_closed = null; @@ -846,9 +843,9 @@ public function store(Request $request) $schedules->schedule_recordid = $schedule_recordid; $schedules->locations = $location_recordid; $schedules->weekday = $weekdays[$s]; - $schedules->opens = isset(${'opens_location_' . $weekdays[$s] . '_datas'}[$i]) ? ${'opens_location_' . $weekdays[$s] . '_datas'}[$i] : ''; - $schedules->closes = isset(${'closes_location_' . $weekdays[$s] . '_datas'}[$i]) ? ${'closes_location_' . $weekdays[$s] . '_datas'}[$i] : ''; - if (isset(${'schedule_closed_' . $weekdays[$s] . '_datas'}[$i]) && ${'schedule_closed_' . $weekdays[$s] . '_datas'}[$i] == ($s + 1)) { + $schedules->opens = isset(${'opens_location_'.$weekdays[$s].'_datas'}[$i]) ? ${'opens_location_'.$weekdays[$s].'_datas'}[$i] : ''; + $schedules->closes = isset(${'closes_location_'.$weekdays[$s].'_datas'}[$i]) ? ${'closes_location_'.$weekdays[$s].'_datas'}[$i] : ''; + if (isset(${'schedule_closed_'.$weekdays[$s].'_datas'}[$i]) && ${'schedule_closed_'.$weekdays[$s].'_datas'}[$i] == ($s + 1)) { $schedules->schedule_closed = $s + 1; } else { $schedules->schedule_closed = null; @@ -892,7 +889,7 @@ public function store(Request $request) } } $schedule_locations = is_array($schedule_locations) ? array_values(array_filter($schedule_locations)) : []; - $location->location_schedule = join(',', $schedule_locations); + $location->location_schedule = implode(',', $schedule_locations); $location->schedules()->sync($schedule_locations); @@ -916,7 +913,7 @@ public function store(Request $request) $location->location_details = isset($location_details[$i]) ? $location_details[$i] : null; // accessesibility - if (!empty($location_accessibility[$i]) && !empty($location_accessibility_details[$i])) { + if (! empty($location_accessibility[$i]) && ! empty($location_accessibility_details[$i])) { // Accessibility::updateOrCreate([ // 'accessibility_location' => $request->location_recordid[$i] // ], [ @@ -993,9 +990,9 @@ public function store(Request $request) $schedules = Schedule::where('locations', $location->location_recordid)->where('weekday', $weekdays[$s])->first(); if ($schedules) { $schedules->weekday = $weekdays[$s]; - $schedules->opens = isset(${'opens_location_' . $weekdays[$s] . '_datas'}[$i]) ? ${'opens_location_' . $weekdays[$s] . '_datas'}[$i] : ''; - $schedules->closes = isset(${'closes_location_' . $weekdays[$s] . '_datas'}[$i]) ? ${'closes_location_' . $weekdays[$s] . '_datas'}[$i] : ''; - if (isset(${'schedule_closed_' . $weekdays[$s] . '_datas'}[$i]) && ${'schedule_closed_' . $weekdays[$s] . '_datas'}[$i] == ($s + 1)) { + $schedules->opens = isset(${'opens_location_'.$weekdays[$s].'_datas'}[$i]) ? ${'opens_location_'.$weekdays[$s].'_datas'}[$i] : ''; + $schedules->closes = isset(${'closes_location_'.$weekdays[$s].'_datas'}[$i]) ? ${'closes_location_'.$weekdays[$s].'_datas'}[$i] : ''; + if (isset(${'schedule_closed_'.$weekdays[$s].'_datas'}[$i]) && ${'schedule_closed_'.$weekdays[$s].'_datas'}[$i] == ($s + 1)) { $schedules->schedule_closed = $s + 1; } else { $schedules->schedule_closed = null; @@ -1008,9 +1005,9 @@ public function store(Request $request) $schedules->schedule_recordid = $schedule_recordid; $schedules->locations = $location->location_recordid; $schedules->weekday = $weekdays[$s]; - $schedules->opens = isset(${'opens_location_' . $weekdays[$s] . '_datas'}[$i]) ? ${'opens_location_' . $weekdays[$s] . '_datas'}[$i] : ''; - $schedules->closes = isset(${'closes_location_' . $weekdays[$s] . '_datas'}[$i]) ? ${'closes_location_' . $weekdays[$s] . '_datas'}[$i] : ''; - if (isset(${'schedule_closed_' . $weekdays[$s] . '_datas'}[$i]) && ${'schedule_closed_' . $weekdays[$s] . '_datas'}[$i] == ($s + 1)) { + $schedules->opens = isset(${'opens_location_'.$weekdays[$s].'_datas'}[$i]) ? ${'opens_location_'.$weekdays[$s].'_datas'}[$i] : ''; + $schedules->closes = isset(${'closes_location_'.$weekdays[$s].'_datas'}[$i]) ? ${'closes_location_'.$weekdays[$s].'_datas'}[$i] : ''; + if (isset(${'schedule_closed_'.$weekdays[$s].'_datas'}[$i]) && ${'schedule_closed_'.$weekdays[$s].'_datas'}[$i] == ($s + 1)) { $schedules->schedule_closed = $s + 1; } else { $schedules->schedule_closed = null; @@ -1054,7 +1051,7 @@ public function store(Request $request) } } $schedule_locations = is_array($schedule_locations) ? array_values(array_filter($schedule_locations)) : []; - $location->location_schedule = join(',', $schedule_locations); + $location->location_schedule = implode(',', $schedule_locations); $location->schedules()->sync($schedule_locations); $location_phone_recordid_list = is_array($location_phone_recordid_list) ? array_values(array_filter($location_phone_recordid_list)) : []; @@ -1072,10 +1069,9 @@ public function store(Request $request) } } $service_locations = is_array($service_locations) ? array_values(array_filter($service_locations)) : []; - $service->service_locations = join(',', $service_locations); + $service->service_locations = implode(',', $service_locations); $service->locations()->sync($service_locations); - $service_taxonomies = []; if ($request->service_category_type && $request->service_category_type[0] != null) { $service_category_type = $request->service_category_type; @@ -1128,7 +1124,7 @@ public function store(Request $request) if (count($service_taxonomies) > 0) { $service_taxonomies = is_array($service_taxonomies) ? array_unique(array_values(array_filter($service_taxonomies))) : []; } - $service->service_taxonomy = join(',', $service_taxonomies); + $service->service_taxonomy = implode(',', $service_taxonomies); $service->taxonomy()->sync($service_taxonomies); $service->service_phones = ''; @@ -1150,7 +1146,7 @@ public function store(Request $request) for ($i = 0; $i < count($service_phone_number_list); $i++) { $phone_info = Phone::where('phone_number', '=', $service_phone_number_list[$i])->first(); if ($phone_info) { - $service->service_phones = $service->service_phones . $phone_info->phone_recordid . ','; + $service->service_phones = $service->service_phones.$phone_info->phone_recordid.','; $phone_info->phone_number = $service_phone_number_list[$i]; $phone_info->phone_extension = $service_phone_extension_list[$i]; $phone_info->phone_type = $service_phone_type_list[$i]; @@ -1178,7 +1174,7 @@ public function store(Request $request) $new_phone->main_priority = '0'; } $new_phone->save(); - $service->service_phones = $service->service_phones . $new_phone_recordid . ','; + $service->service_phones = $service->service_phones.$new_phone_recordid.','; array_push($phone_recordid_list, $new_phone_recordid); } // } @@ -1188,11 +1184,9 @@ public function store(Request $request) $phone_recordid_list = is_array($phone_recordid_list) ? array_values(array_filter($phone_recordid_list)) : []; $service->phone()->sync($phone_recordid_list); - $schedule_services = []; $schedule_services = $this->saveServiceSchedule($request, $service); - if ($request->holiday_start_date && $request->holiday_end_date && $request->holiday_open_at && $request->holiday_close_at) { Schedule::where('services', $service->service_recordid)->where('schedule_holiday', '1')->delete(); for ($i = 0; $i < count($request->holiday_start_date); $i++) { @@ -1217,7 +1211,7 @@ public function store(Request $request) } } if (count($schedule_services)) { - $service->service_schedule = join(',', $schedule_services); + $service->service_schedule = implode(',', $schedule_services); } $schedule_services = is_array($schedule_services) ? array_values(array_filter($schedule_services)) : []; $service->schedules()->sync($schedule_services); @@ -1250,7 +1244,7 @@ public function store(Request $request) for ($p = 0; $p < count($contact_phone_numbers[$i]); $p++) { $phone_info = Phone::where('phone_number', '=', $contact_phone_numbers[$i][$p])->first(); if ($phone_info) { - $contact->contact_phones = $contact->contact_phones . $phone_info->phone_recordid . ','; + $contact->contact_phones = $contact->contact_phones.$phone_info->phone_recordid.','; $phone_info->phone_number = $contact_phone_numbers[$i][$p]; $phone_info->phone_extension = $contact_phone_extensions[$i][$p]; $phone_info->phone_type = $contact_phone_types[$i][$p]; @@ -1268,7 +1262,7 @@ public function store(Request $request) $new_phone->phone_language = isset($contact_phone_languages[$i][$p]) ? implode(',', $contact_phone_languages[$i][$p]) : ''; $new_phone->phone_description = $contact_phone_descriptions[$i][$p]; $new_phone->save(); - $contact->contact_phones = $contact->contact_phones . $new_phone_recordid . ','; + $contact->contact_phones = $contact->contact_phones.$new_phone_recordid.','; array_push($contact_phone_recordid_list, $new_phone_recordid); } } @@ -1289,7 +1283,7 @@ public function store(Request $request) for ($p = 0; $p < count($contact_phone_numbers[$i]); $p++) { $phone_info = Phone::where('phone_number', '=', $contact_phone_numbers[$i][$p])->first(); if ($phone_info) { - $contact->contact_phones = $contact->contact_phones . $phone_info->phone_recordid . ','; + $contact->contact_phones = $contact->contact_phones.$phone_info->phone_recordid.','; $phone_info->phone_number = $contact_phone_numbers[$i][$p]; $phone_info->phone_extension = $contact_phone_extensions[$i][$p]; $phone_info->phone_type = $contact_phone_types[$i][$p]; @@ -1307,7 +1301,7 @@ public function store(Request $request) $new_phone->phone_language = isset($contact_phone_languages[$i][$p]) ? implode(',', $contact_phone_languages[$i][$p]) : ''; $new_phone->phone_description = $contact_phone_descriptions[$i][$p]; $new_phone->save(); - $contact->contact_phones = $contact->contact_phones . $new_phone_recordid . ','; + $contact->contact_phones = $contact->contact_phones.$new_phone_recordid.','; array_push($contact_phone_recordid_list, $new_phone_recordid); } } @@ -1320,7 +1314,7 @@ public function store(Request $request) } } $service_contacts = is_array($service_contacts) ? array_values(array_filter($service_contacts)) : []; - $service->service_contacts = join(',', $service_contacts); + $service->service_contacts = implode(',', $service_contacts); $service->contact()->sync($service_contacts); $detail_ids = []; @@ -1347,13 +1341,13 @@ public function store(Request $request) } } $detail_ids = is_array($detail_ids) ? array_values(array_filter($detail_ids)) : []; - $service->service_details = join(',', $detail_ids); + $service->service_details = implode(',', $detail_ids); $service->details()->sync($detail_ids); $service_address = $request->service_address; $service_address = is_array($service_address) ? array_values(array_filter($service_address)) : []; if ($service_address) { - $service->service_address = join(',', $service_address); + $service->service_address = implode(',', $service_address); } else { $service->service_address = ''; } @@ -1370,12 +1364,14 @@ public function store(Request $request) Session::flash('message', 'Service created successfully'); Session::flash('status', 'success'); + return redirect('services'); } catch (\Throwable $th) { dd($th); - Log::error('Error in create service : ' . $th); + Log::error('Error in create service : '.$th); Session::flash('message', $th->getMessage()); Session::flash('status', 'error'); + return redirect('services'); } } @@ -1383,7 +1379,7 @@ public function store(Request $request) /** * Display the specified resource. * - * @param int $id + * @param int $id * @return \Illuminate\Http\Response */ public function show($id) @@ -1394,7 +1390,7 @@ public function show($id) try { $service = Service::where('service_recordid', '=', $id)->with('locations', 'phone', 'locations.address', 'contact', 'schedules')->first(); $organizationStatus = OrganizationStatus::orderBy('order')->pluck('status', 'id'); - if ($service && (Auth::check() || (!Auth::check() && $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')) || !$service->organizations || !$service->organizations->organization_status_x)) { + if ($service && (Auth::check() || (! Auth::check() && $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')) || ! $service->organizations || ! $service->organizations->organization_status_x)) { $organzation_recordid = $service->service_organization; $organization = Organization::where('organization_recordid', '=', $organzation_recordid)->first(); $service_phones_info = $service->service_phones; @@ -1426,14 +1422,13 @@ public function show($id) } $mainPhoneNumber = array_filter(array_merge($mainPhoneNumber, $phone_number_info_array)); - $service_taxonomy_recordid_list = explode(',', $service->service_taxonomy); $service_taxonomy_info_list = []; foreach ($service_taxonomy_recordid_list as $key => $service_taxonomy_recordid) { - $service_taxonomy_info = (object)[]; + $service_taxonomy_info = (object) []; $service_taxonomy_info->taxonomy_recordid = $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->taxonomy_name = $service_taxonomy_name; @@ -1449,7 +1444,7 @@ public function show($id) if ($locations) { $locations->filter(function ($value, $key) use ($service) { - if (!$value->location_latitude || !$value->location_longitude || $value->location_latitude == 0 || $value->location_longitude == 0) { + if (! $value->location_latitude || ! $value->location_longitude || $value->location_latitude == 0 || $value->location_longitude == 0) { app('App\Http\Controllers\frontEnd\CommonController')->apply_geocode($value); } $value->service = $service->service_name; @@ -1470,7 +1465,7 @@ public function show($id) $contact_info_list = Contact::whereIn('contact_recordid', $service_contacts_recordid_list)->get(); $contactCount = 0; foreach ($contact_info_list as $key => $value) { - if ((Auth::user() && Auth::user()->roles && Auth::user()->roles->name == 'System Admin') || (Auth::user() && Auth::user()->roles && Auth::user()->user_organization && $value->organization && str_contains(Auth::user()->user_organization, $value->organization->organization_recordid) && (Auth::user()->roles->name == 'Organization Admin' || Auth::user()->roles->name == 'Section Admin')) || !Auth::check() && $value->visibility != 'private') { + if ((Auth::user() && Auth::user()->roles && Auth::user()->roles->name == 'System Admin') || (Auth::user() && Auth::user()->roles && Auth::user()->user_organization && $value->organization && str_contains(Auth::user()->user_organization, $value->organization->organization_recordid) && (Auth::user()->roles->name == 'Organization Admin' || Auth::user()->roles->name == 'Section Admin')) || ! Auth::check() && $value->visibility != 'private') { $contactCount += 1; } } @@ -1516,7 +1511,7 @@ public function show($id) } 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'] = ''; array_push($parent_taxonomy, $child_data); } } @@ -1550,11 +1545,13 @@ public function show($id) } else { Session::flash('message', 'This record has been deleted.'); Session::flash('status', 'warning'); + return redirect('services'); } } catch (\Throwable $th) { Session::flash('message', $th->getMessage()); Session::flash('status', 'error'); + return redirect('services'); } } @@ -1562,7 +1559,7 @@ public function show($id) /** * Show the form for editing the specified resource. * - * @param int $id + * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) @@ -1571,7 +1568,7 @@ public function edit($id) $service = Service::where('service_recordid', '=', $id)->first(); $organizationStatus = OrganizationStatus::orderBy('order')->pluck('status', 'id'); - if ($service && (Auth::check() || (!Auth::check() && $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')) || !$service->organizations || !$service->organizations->organization_status_x)) { + if ($service && (Auth::check() || (! Auth::check() && $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')) || ! $service->organizations || ! $service->organizations->organization_status_x)) { if (Auth::user() && Auth::user()->roles && Auth::user()->user_organization && str_contains(Auth::user()->user_organization, $service->organizations()->first()->organization_recordid) && (Auth::user()->roles->name == 'Organization Admin' || Auth::user()->roles->name == 'Section Admin') || (Auth::user() && Auth::user()->roles && Auth::user()->roles->name == 'System Admin') || (Auth::user() && Auth::user()->roles && Auth::user()->service_tags && $service->service_tag && count(array_intersect(explode(',', Auth::user()->service_tags), explode(',', $service->service_tag))) > 0) || (Auth::user() && Auth::user()->roles && Auth::user()->roles->name == 'Section Admin' && Auth::user()->organization_tags && $service->organizations()->first()->organization_tag && count(array_intersect(explode(',', Auth::user()->organization_tags), explode(',', $service->organizations()->first()->organization_tag))) > 0)) { @@ -1586,13 +1583,13 @@ public function edit($id) if (Auth::user()->organization_tags) { $organization_tags = explode(',', Auth::user()->organization_tags); foreach ($organization_tags as $key => $value) { - $organizations = Organization::where('organization_tag', 'LIKE', '%' . $value . '%')->pluck('organization_recordid')->toArray(); + $organizations = Organization::where('organization_tag', 'LIKE', '%'.$value.'%')->pluck('organization_recordid')->toArray(); $organization_recordid = array_unique(array_merge($organization_recordid, $organizations)); } } - $organization_names = Organization::orderBy("organization_name")->select("organization_name", "organization_recordid")->whereIn('organization_recordid', $organization_recordid)->distinct()->get(); + $organization_names = Organization::orderBy('organization_name')->select('organization_name', 'organization_recordid')->whereIn('organization_recordid', $organization_recordid)->distinct()->get(); } else { - $organization_names = Organization::orderBy("organization_name")->select("organization_name", "organization_recordid")->distinct()->get(); + $organization_names = Organization::orderBy('organization_name')->select('organization_name', 'organization_recordid')->distinct()->get(); } $service_organization_list = $organization_names; @@ -1606,7 +1603,7 @@ public function edit($id) } $service_taxonomy_list = Taxonomy::whereNull('taxonomy_parent_name')->whereNull('exclude_vocabulary')->Where(function ($query) use ($exclude_vocabulary) { for ($i = 0; $i < count($exclude_vocabulary); $i++) { - $query->where('taxonomy_name', 'not like', '%' . $exclude_vocabulary[$i] . '%'); + $query->where('taxonomy_name', 'not like', '%'.$exclude_vocabulary[$i].'%'); } })->get(); @@ -1620,10 +1617,10 @@ public function edit($id) } $value->taxonomyArray = $taxonomyArray; } + return true; }); - $service_details_list = Detail::select('detail_recordid', 'detail_value')->get(); $location_info_list = explode(',', $service->service_locations); @@ -1645,6 +1642,7 @@ public function edit($id) $value->location_state = $address ? $address->address_state_province : ''; $value->location_zipcode = $address ? $address->address_postal_code : ''; $value->location_phone = $phones ? $phones->phone_number : ''; + return true; }); @@ -1678,7 +1676,7 @@ public function edit($id) $selected_details_value = []; $selected_details_types = []; foreach ($serviceDetailsData as $key => $v) { - if (!in_array($v->detail_type, $selected_details_types)) { + if (! in_array($v->detail_type, $selected_details_types)) { $selected_details_types[] = $v->detail_type; } $selected_details_value[$v->detail_type][] = $v->detail_recordid; @@ -1697,7 +1695,6 @@ public function edit($id) $sunday = Schedule::where('services', $service->service_recordid)->whereRaw('FIND_IN_SET(?, weekday)', ['sunday'])->orderBy('updated_at', 'desc')->first(); $holiday_schedules = Schedule::where('services', $service->service_recordid)->where('schedule_holiday', '1')->get(); - $detail_info_list = Detail::select('detail_recordid', 'detail_value')->orderBy('detail_value')->distinct()->get(); $all_contacts = Contact::orderBy('contact_name')->with('phone', 'service')->distinct()->get(); $all_locations = Location::orderBy('location_name')->with('phones', 'address', 'services', 'schedules')->distinct()->get(); @@ -1832,7 +1829,6 @@ public function edit($id) $location_phone_languages = json_encode($location_phone_languages); $location_phone_descriptions = json_encode($location_phone_descriptions); - // location schedule section $opens_location_monday_datas = []; $closes_location_monday_datas = []; @@ -1863,7 +1859,7 @@ public function edit($id) $j = 0; foreach ($service_locations_data as $key => $value) { $weekdays = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday']; - if ($value->schedules && !empty($value->schedules) && count($value->schedules) > 0) { + if ($value->schedules && ! empty($value->schedules) && count($value->schedules) > 0) { foreach ($value->schedules as $key1 => $schedule) { if ($schedule->schedule_holiday == 1) { $location_holiday_start_dates[$j][] = $schedule->dtstart; @@ -1874,9 +1870,9 @@ public function edit($id) } else { for ($i = 0; $i < 7; $i++) { if ($schedule->weekday == $weekdays[$i]) { - ${'opens_location_' . $weekdays[$i] . '_datas'}[$j] = $schedule->opens; - ${'closes_location_' . $weekdays[$i] . '_datas'}[$j] = $schedule->closes; - ${'schedule_closed_' . $weekdays[$i] . '_datas'}[$j] = $schedule->schedule_closed; + ${'opens_location_'.$weekdays[$i].'_datas'}[$j] = $schedule->opens; + ${'closes_location_'.$weekdays[$i].'_datas'}[$j] = $schedule->closes; + ${'schedule_closed_'.$weekdays[$i].'_datas'}[$j] = $schedule->schedule_closed; } } } @@ -1888,9 +1884,9 @@ public function edit($id) $location_holiday_close_ats[$j][] = ''; $location_holiday_closeds[$j][] = ''; for ($i = 0; $i < 7; $i++) { - ${'opens_location_' . $weekdays[$i] . '_datas'}[$j] = ''; - ${'closes_location_' . $weekdays[$i] . '_datas'}[$j] = ''; - ${'schedule_closed_' . $weekdays[$i] . '_datas'}[$j] = ''; + ${'opens_location_'.$weekdays[$i].'_datas'}[$j] = ''; + ${'closes_location_'.$weekdays[$i].'_datas'}[$j] = ''; + ${'schedule_closed_'.$weekdays[$i].'_datas'}[$j] = ''; } } $j = $j + 1; @@ -1942,7 +1938,6 @@ public function edit($id) $service_category_types = Taxonomy::orderBy('taxonomy_name')->whereNull('taxonomy_parent_name')->where('taxonomy', $serviceCategoryId ? $serviceCategoryId->taxonomy_type_recordid : '')->pluck('taxonomy_name', 'taxonomy_recordid'); $service_eligibility_types = Taxonomy::orderBy('taxonomy_name')->whereNull('taxonomy_parent_name')->where('taxonomy', $serviceEligibilityId ? $serviceEligibilityId->taxonomy_type_recordid : '')->pluck('taxonomy_name', 'taxonomy_recordid'); - $service_category_term_data = $serviceCategoryId ? $service->taxonomy()->where('taxonomy', $serviceCategoryId->taxonomy_type_recordid)->get() : []; // $service_category_term_data = $service->taxonomy()->where('taxonomy', $serviceCategoryId->taxonomy_type_recordid)->get(); // ->whereNotNull('taxonomy_parent_name') @@ -1977,7 +1972,7 @@ public function edit($id) // $service_category_type_data[] = $taxonomyParentData; // dd(!in_array($value->taxonomy_recordid, $parent_ids), $value, $parent_ids); // dd($parent_ids, $taxonomyParentData->taxonomy_recordid); - if (!in_array($taxonomyParentData->taxonomy_recordid, $parent_ids) && $taxonomyParentData->taxonomy_parent_name == null) { + if (! in_array($taxonomyParentData->taxonomy_recordid, $parent_ids) && $taxonomyParentData->taxonomy_parent_name == null) { $parent_ids[] = $taxonomyParentData->taxonomy_recordid; $service_category_type_data[] = $taxonomyParentData; } @@ -2027,7 +2022,7 @@ public function edit($id) if ($taxonomyParentData) { // $taxonomyParentData->selectedTermId = $value->taxonomy_recordid; // $taxonomyParentData->selectedTermName = $value->taxonomy_name; - if (!in_array($taxonomyParentData->taxonomy_recordid, $parent_ids) && $taxonomyParentData->taxonomy_parent_name == null) { + if (! in_array($taxonomyParentData->taxonomy_recordid, $parent_ids) && $taxonomyParentData->taxonomy_parent_name == null) { $parent_ids[] = $taxonomyParentData->taxonomy_recordid; $service_eligibility_type_data[] = $taxonomyParentData; } @@ -2057,10 +2052,8 @@ public function edit($id) $serviceAudits = $this->commonController->serviceSection($service); - $all_programs = Program::with('organization')->distinct()->get(); - $help_text = Helptext::first(); $conditions = Code::where('resource', 'Condition')->get()->groupBy('category'); @@ -2096,11 +2089,13 @@ public function edit($id) } else { Session::flash('message', 'Warning! Not enough permissions. Please contact Us for more'); Session::flash('status', 'warning'); + return redirect('/'); } } else { Session::flash('message', 'This record has been deleted.'); Session::flash('status', 'warning'); + return redirect('services'); } } @@ -2108,8 +2103,7 @@ public function edit($id) /** * Update the specified resource in storage. * - * @param \Illuminate\Http\Request $request - * @param int $id + * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) @@ -2121,7 +2115,7 @@ public function update(Request $request, $id) ]); if ($request->service_email) { $this->validate($request, [ - 'service_email' => 'email' + 'service_email' => 'email', ]); } // dd($request); @@ -2151,14 +2145,16 @@ public function update(Request $request, $id) $service->service_interpretation = $request->service_interpretation; $this->saveRequiredDocument($request, $id); $service_area = []; - if ($request->service_area) + if ($request->service_area) { $service_area = $request->service_area; + } $service_area = is_array($service_area) ? array_values(array_filter($service_area)) : []; $service->areas()->sync($service_area); $fee_option = []; - if ($request->fee_option) + if ($request->fee_option) { $fee_option = $request->fee_option; + } $fee_option = is_array($fee_option) ? array_values(array_filter($fee_option)) : []; $service->fees()->sync($request->fee_option); @@ -2218,8 +2214,9 @@ public function update(Request $request, $id) $code_ids = explode('|', $procedure_grouping); if (count($code_ids) > 0 && isset($code_ids[1])) { $code = Code::where('code_id', $code_ids[1])->first(); - if ($code) + if ($code) { CodeLedger::where('service_recordid', $id)->where('SDOH_code', $code->id)->delete(); + } } } } @@ -2229,8 +2226,9 @@ public function update(Request $request, $id) $code_ids = explode('|', $procedure_grouping); if (count($code_ids) > 0 && isset($code_ids[1])) { $code = Code::where('code_id', $code_ids[1])->first(); - if ($code) + if ($code) { CodeLedger::where('service_recordid', $id)->where('SDOH_code', $code->id)->delete(); + } } } } @@ -2462,7 +2460,7 @@ public function update(Request $request, $id) // accessesibility - if (!empty($location_accessibility[$i]) && !empty($location_accessibility_details[$i])) { + if (! empty($location_accessibility[$i]) && ! empty($location_accessibility_details[$i])) { // Accessibility::create([ // 'accessibility_recordid' => Accessibility::max('accessibility_recordid') + 1, // 'accessibility' => $location_accessibility[$i], @@ -2472,7 +2470,7 @@ public function update(Request $request, $id) $location->accessibility_recordid = $location_accessibility[$i]; $location->accessibility_details = $location_accessibility_details[$i]; } - if (!empty($location_regions[$i])) { + if (! empty($location_regions[$i])) { $location_regions[$i] = is_array($location_regions[$i]) ? array_values(array_filter($location_regions[$i])) : []; $location->regions()->sync($location_regions[$i]); } @@ -2554,9 +2552,9 @@ public function update(Request $request, $id) $schedules = Schedule::where('locations', $location_recordid)->where('weekday', $weekdays[$s])->first(); if ($schedules) { $schedules->weekday = $weekdays[$s]; - $schedules->opens = isset(${'opens_location_' . $weekdays[$s] . '_datas'}[$i]) ? ${'opens_location_' . $weekdays[$s] . '_datas'}[$i] : ''; - $schedules->closes = isset(${'closes_location_' . $weekdays[$s] . '_datas'}[$i]) ? ${'closes_location_' . $weekdays[$s] . '_datas'}[$i] : ''; - if (isset(${'schedule_closed_' . $weekdays[$s] . '_datas'}[$i]) && ${'schedule_closed_' . $weekdays[$s] . '_datas'}[$i] == ($s + 1)) { + $schedules->opens = isset(${'opens_location_'.$weekdays[$s].'_datas'}[$i]) ? ${'opens_location_'.$weekdays[$s].'_datas'}[$i] : ''; + $schedules->closes = isset(${'closes_location_'.$weekdays[$s].'_datas'}[$i]) ? ${'closes_location_'.$weekdays[$s].'_datas'}[$i] : ''; + if (isset(${'schedule_closed_'.$weekdays[$s].'_datas'}[$i]) && ${'schedule_closed_'.$weekdays[$s].'_datas'}[$i] == ($s + 1)) { $schedules->schedule_closed = $s + 1; } else { $schedules->schedule_closed = null; @@ -2569,9 +2567,9 @@ public function update(Request $request, $id) $schedules->schedule_recordid = $schedule_recordid; $schedules->locations = $location_recordid; $schedules->weekday = $weekdays[$s]; - $schedules->opens = ${'opens_location_' . $weekdays[$s] . '_datas'}[$i]; - $schedules->closes = ${'closes_location_' . $weekdays[$s] . '_datas'}[$i]; - if (${'schedule_closed_' . $weekdays[$s] . '_datas'}[$i] == ($s + 1)) { + $schedules->opens = ${'opens_location_'.$weekdays[$s].'_datas'}[$i]; + $schedules->closes = ${'closes_location_'.$weekdays[$s].'_datas'}[$i]; + if (${'schedule_closed_'.$weekdays[$s].'_datas'}[$i] == ($s + 1)) { $schedules->schedule_closed = $s + 1; } else { $schedules->schedule_closed = null; @@ -2614,7 +2612,7 @@ public function update(Request $request, $id) // } } } - $location->location_schedule = join(',', $schedule_locations); + $location->location_schedule = implode(',', $schedule_locations); $schedule_locations = is_array($schedule_locations) ? array_values(array_filter($schedule_locations)) : []; $location->schedules()->sync($schedule_locations); @@ -2643,9 +2641,8 @@ public function update(Request $request, $id) $location->external_identifier_type = isset($external_identifier_type[$i]) ? $external_identifier_type[$i] : null; $location->accessesibility_url = isset($accessesibility_url[$i]) ? $accessesibility_url[$i] : null; - // accessesibility - if (!empty($location_accessibility[$i]) && !empty($location_accessibility_details[$i])) { + if (! empty($location_accessibility[$i]) && ! empty($location_accessibility_details[$i])) { // Accessibility::updateOrCreate([ // 'accessibility_location' => $request->location_recordid[$i] // ], [ @@ -2734,9 +2731,9 @@ public function update(Request $request, $id) $schedules = Schedule::where('locations', $location->location_recordid)->where('weekday', $weekdays[$s])->first(); if ($schedules) { $schedules->weekday = $weekdays[$s]; - $schedules->opens = isset(${'opens_location_' . $weekdays[$s] . '_datas'}[$i]) ? ${'opens_location_' . $weekdays[$s] . '_datas'}[$i] : ''; - $schedules->closes = isset(${'closes_location_' . $weekdays[$s] . '_datas'}[$i]) ? ${'closes_location_' . $weekdays[$s] . '_datas'}[$i] : ''; - if (isset(${'schedule_closed_' . $weekdays[$s] . '_datas'}[$i]) && ${'schedule_closed_' . $weekdays[$s] . '_datas'}[$i] == ($s + 1)) { + $schedules->opens = isset(${'opens_location_'.$weekdays[$s].'_datas'}[$i]) ? ${'opens_location_'.$weekdays[$s].'_datas'}[$i] : ''; + $schedules->closes = isset(${'closes_location_'.$weekdays[$s].'_datas'}[$i]) ? ${'closes_location_'.$weekdays[$s].'_datas'}[$i] : ''; + if (isset(${'schedule_closed_'.$weekdays[$s].'_datas'}[$i]) && ${'schedule_closed_'.$weekdays[$s].'_datas'}[$i] == ($s + 1)) { $schedules->schedule_closed = $s + 1; } else { $schedules->schedule_closed = null; @@ -2749,9 +2746,9 @@ public function update(Request $request, $id) $schedules->schedule_recordid = $schedule_recordid; $schedules->locations = $location->location_recordid; $schedules->weekday = $weekdays[$s]; - $schedules->opens = isset(${'opens_location_' . $weekdays[$s] . '_datas'}[$i]) ? ${'opens_location_' . $weekdays[$s] . '_datas'}[$i] : ''; - $schedules->closes = isset(${'closes_location_' . $weekdays[$s] . '_datas'}[$i]) ? ${'closes_location_' . $weekdays[$s] . '_datas'}[$i] : ''; - if (isset(${'schedule_closed_' . $weekdays[$s] . '_datas'}[$i]) && ${'schedule_closed_' . $weekdays[$s] . '_datas'}[$i] == ($s + 1)) { + $schedules->opens = isset(${'opens_location_'.$weekdays[$s].'_datas'}[$i]) ? ${'opens_location_'.$weekdays[$s].'_datas'}[$i] : ''; + $schedules->closes = isset(${'closes_location_'.$weekdays[$s].'_datas'}[$i]) ? ${'closes_location_'.$weekdays[$s].'_datas'}[$i] : ''; + if (isset(${'schedule_closed_'.$weekdays[$s].'_datas'}[$i]) && ${'schedule_closed_'.$weekdays[$s].'_datas'}[$i] == ($s + 1)) { $schedules->schedule_closed = $s + 1; } else { $schedules->schedule_closed = null; @@ -2795,7 +2792,7 @@ public function update(Request $request, $id) } } $schedule_locations = is_array($schedule_locations) ? array_values(array_filter($schedule_locations)) : []; - $location->location_schedule = join(',', $schedule_locations); + $location->location_schedule = implode(',', $schedule_locations); $location->schedules()->sync($schedule_locations); @@ -2815,7 +2812,7 @@ public function update(Request $request, $id) } } else { if ($service->service_locations) { - $service->service_locations = join(',', $service_locations); + $service->service_locations = implode(',', $service_locations); } } $service_locations = is_array($service_locations) ? array_values(array_filter($service_locations)) : []; @@ -2849,7 +2846,7 @@ public function update(Request $request, $id) for ($p = 0; $p < count($contact_phone_numbers[$i]); $p++) { $phone_info = Phone::where('phone_number', '=', $contact_phone_numbers[$i][$p])->first(); if ($phone_info) { - $contact->contact_phones = $contact->contact_phones . $phone_info->phone_recordid . ','; + $contact->contact_phones = $contact->contact_phones.$phone_info->phone_recordid.','; $phone_info->phone_number = $contact_phone_numbers[$i][$p]; $phone_info->phone_extension = $contact_phone_extensions[$i][$p]; $phone_info->phone_type = $contact_phone_types[$i][$p]; @@ -2867,7 +2864,7 @@ public function update(Request $request, $id) $new_phone->phone_language = isset($contact_phone_languages[$i][$p]) ? implode(',', $contact_phone_languages[$i][$p]) : ''; $new_phone->phone_description = $contact_phone_descriptions[$i][$p]; $new_phone->save(); - $contact->contact_phones = $contact->contact_phones . $new_phone_recordid . ','; + $contact->contact_phones = $contact->contact_phones.$new_phone_recordid.','; array_push($contact_phone_recordid_list, $new_phone_recordid); } } @@ -2889,7 +2886,7 @@ public function update(Request $request, $id) for ($p = 0; $p < count($contact_phone_numbers[$i]); $p++) { $phone_info = Phone::where('phone_number', '=', $contact_phone_numbers[$i][$p])->first(); if ($phone_info) { - $contact->contact_phones = $contact->contact_phones . $phone_info->phone_recordid . ','; + $contact->contact_phones = $contact->contact_phones.$phone_info->phone_recordid.','; $phone_info->phone_number = $contact_phone_numbers[$i][$p]; $phone_info->phone_extension = $contact_phone_extensions[$i][$p]; $phone_info->phone_type = $contact_phone_types[$i][$p]; @@ -2907,7 +2904,7 @@ public function update(Request $request, $id) $new_phone->phone_language = isset($contact_phone_languages[$i][$p]) ? implode(',', $contact_phone_languages[$i][$p]) : ''; $new_phone->phone_description = $contact_phone_descriptions[$i][$p]; $new_phone->save(); - $contact->contact_phones = $contact->contact_phones . $new_phone_recordid . ','; + $contact->contact_phones = $contact->contact_phones.$new_phone_recordid.','; array_push($contact_phone_recordid_list, $new_phone_recordid); } } @@ -2919,7 +2916,7 @@ public function update(Request $request, $id) } } } - $service->service_contacts = join(',', $service_contacts); + $service->service_contacts = implode(',', $service_contacts); $service_contacts = is_array($service_contacts) ? array_values(array_filter($service_contacts)) : []; $service->contact()->sync($service_contacts); @@ -2988,7 +2985,7 @@ public function update(Request $request, $id) } if (count($service_taxonomies) > 0) { $service_taxonomies = is_array($service_taxonomies) ? array_unique(array_values(array_filter($service_taxonomies))) : []; - $service->service_taxonomy = join(',', $service_taxonomies); + $service->service_taxonomy = implode(',', $service_taxonomies); } $service->taxonomy()->sync($service_taxonomies); @@ -3019,7 +3016,7 @@ public function update(Request $request, $id) if (count($detail_ids) > 0) { // $detail_ids = array_filter($detail_ids); $detail_ids = is_array($detail_ids) ? array_values(array_filter($detail_ids)) : []; - $service->service_details = join(',', $detail_ids); + $service->service_details = implode(',', $detail_ids); } $service->details()->sync($detail_ids); @@ -3036,7 +3033,7 @@ public function update(Request $request, $id) for ($i = 0; $i < count($service_phone_number_list); $i++) { $phone_info = Phone::where('phone_number', '=', $service_phone_number_list[$i])->first(); if ($phone_info) { - $service->service_phones = $service->service_phones . $phone_info->phone_recordid . ','; + $service->service_phones = $service->service_phones.$phone_info->phone_recordid.','; $phone_info->phone_number = $service_phone_number_list[$i]; $phone_info->phone_extension = $service_phone_extension_list[$i]; $phone_info->phone_type = $service_phone_type_list[$i]; @@ -3064,7 +3061,7 @@ public function update(Request $request, $id) } $new_phone->phone_description = $service_phone_description_list[$i]; $new_phone->save(); - $service->service_phones = $service->service_phones . $new_phone_recordid . ','; + $service->service_phones = $service->service_phones.$new_phone_recordid.','; array_push($phone_recordid_list, $new_phone_recordid); } } @@ -3086,10 +3083,9 @@ public function update(Request $request, $id) Phone::whereIn('phone_recordid', $deletePhoneDataId)->delete(); } - $service_address_info = $request->service_address; - if (!empty($service_address_info)) { + if (! empty($service_address_info)) { $service_address_info = is_array($service_address_info) ? array_values(array_filter($service_address_info)) : []; $service->service_address = implode(',', $service_address_info); $service->address()->sync($service_address_info); @@ -3138,7 +3134,7 @@ public function update(Request $request, $id) // dd($schedule_services, $service->service_schedule, array_diff($old_service_schedule, $schedule_services), $old_service_schedule); $schedule_services = is_array($schedule_services) ? array_values(array_filter($schedule_services)) : []; if (count($schedule_services)) { - $service->service_schedule = join(',', $schedule_services); + $service->service_schedule = implode(',', $schedule_services); } $service->schedules()->sync($schedule_services); @@ -3148,8 +3144,8 @@ public function update(Request $request, $id) $new_recordid = SessionData::max('session_recordid') + 1; $session->session_recordid = $new_recordid; $user = Auth::user(); - $date_time = date("Y-m-d h:i:sa"); - $session->session_name = 'session' . $new_recordid; + $date_time = date('Y-m-d h:i:sa'); + $session->session_name = 'session'.$new_recordid; $session->session_service = $service->service_recordid; $session->session_method = $request->interaction_method; $session->session_disposition = $request->interaction_disposition; @@ -3176,7 +3172,7 @@ public function update(Request $request, $id) $interaction->interaction_disposition = $request->interaction_disposition; $interaction->interaction_notes = $request->interaction_notes; $interaction->interaction_records_edited = $request->interaction_records_edited; - $date_time = date("Y-m-d h:i:sa"); + $date_time = date('Y-m-d h:i:sa'); $interaction->interaction_timestamp = $date_time; $interaction->save(); @@ -3185,7 +3181,7 @@ public function update(Request $request, $id) } $service->updated_by = Auth::id(); - $service->updated_at = date("Y-m-d H:i:s"); + $service->updated_at = date('Y-m-d H:i:s'); $service->save(); // if ($service->wasChanged()) { @@ -3201,12 +3197,14 @@ public function update(Request $request, $id) // } Session::flash('message', 'Service updated successfully!'); Session::flash('status', 'success'); - return redirect('services/' . $id); + + return redirect('services/'.$id); } catch (\Throwable $th) { dd($th); - Log::error('Error in update service : ' . $th); + Log::error('Error in update service : '.$th); Session::flash('message', $th->getMessage()); Session::flash('status', 'error'); + return redirect()->back(); } } @@ -3214,7 +3212,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) @@ -3229,7 +3227,7 @@ public function test_airtable($api_key, $base_url) // var_dump("this is test function for auto sync"); var_dump($api_key); var_dump($base_url); - $response_text = "this is test function for auto sync"; + $response_text = 'this is test function for auto sync'; echo $response_text; return $response_text; @@ -3239,7 +3237,7 @@ public function airtable($access_token, $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; @@ -3256,10 +3254,10 @@ public function airtable($access_token, $base_url) ServiceTaxonomy::truncate(); ServiceSchedule::truncate(); - $airtable = new Airtable(array( + $airtable = new Airtable([ 'access_token' => $access_token, 'base' => $base_url, - )); + ]); $request = $airtable->getContent('services'); $size = ''; do { @@ -3286,7 +3284,7 @@ public function airtable($access_token, $base_url) $serviceorganization = $strtointclass->string_to_int($value); if ($i != 0) { - $service->service_organization = $service->service_organization . ',' . $serviceorganization; + $service->service_organization = $service->service_organization.','.$serviceorganization; } else { $service->service_organization = $serviceorganization; } @@ -3308,7 +3306,7 @@ public function airtable($access_token, $base_url) $servicelocation = $strtointclass->string_to_int($value); if ($i != 0) { - $service->service_locations = $service->service_locations . ',' . $servicelocation; + $service->service_locations = $service->service_locations.','.$servicelocation; } else { $service->service_locations = $servicelocation; } @@ -3329,7 +3327,6 @@ public function airtable($access_token, $base_url) } // $service->service_status = isset($record['fields']['status']) ? $record['fields']['status'] : null; - if (isset($record['fields']['taxonomy'])) { $i = 0; foreach ($record['fields']['taxonomy'] as $value) { @@ -3340,7 +3337,7 @@ public function airtable($access_token, $base_url) $servicetaxonomy = $strtointclass->string_to_int($value); if ($i != 0) { - $service->service_taxonomy = $service->service_taxonomy . ',' . $servicetaxonomy; + $service->service_taxonomy = $service->service_taxonomy.','.$servicetaxonomy; } else { $service->service_taxonomy = $servicetaxonomy; } @@ -3365,7 +3362,7 @@ public function airtable($access_token, $base_url) $servicephone = $strtointclass->string_to_int($value); if ($i != 0) { - $service->service_phones = $service->service_phones . ',' . $servicephone; + $service->service_phones = $service->service_phones.','.$servicephone; } else { $service->service_phones = $servicephone; } @@ -3384,7 +3381,7 @@ public function airtable($access_token, $base_url) $serviceschedule = $strtointclass->string_to_int($value); if ($i != 0) { - $service->service_schedule = $service->service_schedule . ',' . $serviceschedule; + $service->service_schedule = $service->service_schedule.','.$serviceschedule; } else { $service->service_schedule = $serviceschedule; } @@ -3403,7 +3400,7 @@ public function airtable($access_token, $base_url) $servicecontact = $strtointclass->string_to_int($value); if ($i != 0) { - $service->service_contacts = $service->service_contacts . ',' . $servicecontact; + $service->service_contacts = $service->service_contacts.','.$servicecontact; } else { $service->service_contacts = $servicecontact; } @@ -3422,7 +3419,7 @@ public function airtable($access_token, $base_url) $servicedetail = $strtointclass->string_to_int($value); if ($i != 0) { - $service->service_details = $service->service_details . ',' . $servicedetail; + $service->service_details = $service->service_details.','.$servicedetail; } else { $service->service_details = $servicedetail; } @@ -3441,7 +3438,7 @@ public function airtable($access_token, $base_url) $serviceaddress = $strtointclass->string_to_int($value); if ($i != 0) { - $service->service_address = $service->service_address . ',' . $serviceaddress; + $service->service_address = $service->service_address.','.$serviceaddress; } else { $service->service_address = $serviceaddress; } @@ -3452,19 +3449,19 @@ public function airtable($access_token, $base_url) $service->service_metadata = isset($record['fields']['metadata']) ? $record['fields']['metadata'] : null; - $service->service_airs_taxonomy_x = isset($record['fields']['AIRS Taxonomy-x']) ? implode(",", $record['fields']['AIRS Taxonomy-x']) : null; + $service->service_airs_taxonomy_x = isset($record['fields']['AIRS Taxonomy-x']) ? implode(',', $record['fields']['AIRS Taxonomy-x']) : null; $service->save(); } } while ($request = $response->next()); - $date = date("Y/m/d H:i:s"); + $date = date('Y/m/d H:i:s'); $airtable = Airtables::where('name', '=', 'Services')->first(); $airtable->records = Service::count(); $airtable->syncdate = $date; $airtable->save(); } catch (\Throwable $th) { - Log::error('Error in sync service v1 : ' . $th); + Log::error('Error in sync service v1 : '.$th); } } @@ -3482,10 +3479,10 @@ public function airtable_v2($access_token, $base_url) // ServiceTaxonomy::truncate(); // ServiceSchedule::truncate(); - $airtable = new Airtable(array( + $airtable = new Airtable([ 'access_token' => $access_token, 'base' => $base_url, - )); + ]); $request = $airtable->getContent('services'); $size = ''; do { @@ -3531,7 +3528,7 @@ public function airtable_v2($access_token, $base_url) $servicelocation = $strtointclass->string_to_int($value); if ($i != 0) { - $service->service_locations = $service->service_locations . ',' . $servicelocation; + $service->service_locations = $service->service_locations.','.$servicelocation; } else { $service->service_locations = $servicelocation; } @@ -3543,7 +3540,6 @@ public function airtable_v2($access_token, $base_url) $service->service_url = isset($record['fields']['url']) ? $record['fields']['url'] : null; $service->service_email = isset($record['fields']['email']) ? $record['fields']['email'] : null; - $service->service_status = isset($record['fields']['status']) ? $record['fields']['status'] : null; if (isset($record['fields']['taxonomy'])) { @@ -3556,7 +3552,7 @@ public function airtable_v2($access_token, $base_url) $servicetaxonomy = $strtointclass->string_to_int($value); if ($i != 0) { - $service->service_taxonomy = $service->service_taxonomy . ',' . $servicetaxonomy; + $service->service_taxonomy = $service->service_taxonomy.','.$servicetaxonomy; } else { $service->service_taxonomy = $servicetaxonomy; } @@ -3581,7 +3577,7 @@ public function airtable_v2($access_token, $base_url) $servicephone = $strtointclass->string_to_int($value); if ($i != 0) { - $service->service_phones = $service->service_phones . ',' . $servicephone; + $service->service_phones = $service->service_phones.','.$servicephone; } else { $service->service_phones = $servicephone; } @@ -3600,7 +3596,7 @@ public function airtable_v2($access_token, $base_url) $serviceschedule = $strtointclass->string_to_int($value); if ($i != 0) { - $service->service_schedule = $service->service_schedule . ',' . $serviceschedule; + $service->service_schedule = $service->service_schedule.','.$serviceschedule; } else { $service->service_schedule = $serviceschedule; } @@ -3619,7 +3615,7 @@ public function airtable_v2($access_token, $base_url) $servicecontact = $strtointclass->string_to_int($value); if ($i != 0) { - $service->service_contacts = $service->service_contacts . ',' . $servicecontact; + $service->service_contacts = $service->service_contacts.','.$servicecontact; } else { $service->service_contacts = $servicecontact; } @@ -3638,7 +3634,7 @@ public function airtable_v2($access_token, $base_url) $servicedetail = $strtointclass->string_to_int($value); if ($i != 0) { - $service->service_details = $service->service_details . ',' . $servicedetail; + $service->service_details = $service->service_details.','.$servicedetail; } else { $service->service_details = $servicedetail; } @@ -3657,7 +3653,7 @@ public function airtable_v2($access_token, $base_url) $serviceaddress = $strtointclass->string_to_int($value); if ($i != 0) { - $service->service_address = $service->service_address . ',' . $serviceaddress; + $service->service_address = $service->service_address.','.$serviceaddress; } else { $service->service_address = $serviceaddress; } @@ -3668,23 +3664,24 @@ public function airtable_v2($access_token, $base_url) $service->service_metadata = isset($record['fields']['metadata']) ? $record['fields']['metadata'] : null; - $service->service_airs_taxonomy_x = isset($record['fields']['AIRS Taxonomy-x']) ? implode(",", $record['fields']['AIRS Taxonomy-x']) : null; + $service->service_airs_taxonomy_x = isset($record['fields']['AIRS Taxonomy-x']) ? implode(',', $record['fields']['AIRS Taxonomy-x']) : null; $service->save(); } } } 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', '=', 'Services')->first(); $airtable->records = Service::count(); $airtable->syncdate = $date; $airtable->save(); } catch (\Throwable $th) { - Log::error('Error in Service: ' . $th->getMessage()); + Log::error('Error in Service: '.$th->getMessage()); + return response()->json([ 'message' => $th->getMessage(), - 'success' => false + 'success' => false, ], 500); } } @@ -3721,13 +3718,14 @@ public function csv(Request $request) $csv_source->syncdate = $date; $csv_source->save(); - $response = array( + $response = [ 'status' => 'success', 'result' => 'Services imported successfully', - ); + ]; + return $response; } catch (\Throwable $th) { - Log::error('Error in service csv : ' . $th); + Log::error('Error in service csv : '.$th); } } @@ -3737,7 +3735,8 @@ public function export_services() // return Excel::download(new ServiceExport, 'export.csv'); return; } catch (\Throwable $th) { - Log::error('Error in export service : ' . $th); + Log::error('Error in export service : '.$th); + return redirect('services'); } } @@ -3777,16 +3776,18 @@ public function csv_services_location(Request $request) $csv_source->records = ServiceLocation::count(); $csv_source->syncdate = $date; $csv_source->save(); - $response = array( + $response = [ 'status' => 'success', 'result' => 'Service location imported successfully', - ); + ]; + return $response; } catch (\Throwable $th) { - $response = array( + $response = [ 'status' => 'false', 'result' => $th->getMessage(), - ); + ]; + return $response; } } @@ -3796,7 +3797,7 @@ public function create_in_organization($id) $map = Map::find(1); $layout = Layout::find(1); $organization = Organization::where('organization_recordid', '=', $id)->select('organization_recordid', 'organization_name')->first(); - $all_locations = Location::orderBy('location_name')->with('phones', 'address', 'services', 'schedules')->distinct()->get();; + $all_locations = Location::orderBy('location_name')->with('phones', 'address', 'services', 'schedules')->distinct()->get(); $facility_info_list = Location::select('location_recordid', 'location_name')->orderBy('location_recordid')->distinct()->get(); $service_status_list = ['Yes' => 'Yes', 'No' => 'No']; @@ -3872,7 +3873,6 @@ public function create_in_facility($id) $all_contacts = Contact::orderBy('contact_name')->with('phone')->distinct()->get(); $all_locations = Location::orderBy('location_name')->with('phones', 'address', 'schedules')->distinct()->get(); - $address_city_list = City::orderBy('city')->pluck('city', 'city'); $address_states_list = State::orderBy('state')->pluck('state', 'state'); @@ -3918,13 +3918,13 @@ public function add_new_service_in_organization(Request $request) ]); if ($request->service_email) { $this->validate($request, [ - 'service_email' => 'email' + 'service_email' => 'email', ]); } $service = new Service; - $service_recordids = Service::select("service_recordid")->distinct()->get(); - $service_recordid_list = array(); + $service_recordids = Service::select('service_recordid')->distinct()->get(); + $service_recordid_list = []; foreach ($service_recordids as $key => $value) { $service_recordid = $value->service_recordid; array_push($service_recordid_list, $service_recordid); @@ -3944,7 +3944,7 @@ public function add_new_service_in_organization(Request $request) $service_organization->updated_at = Carbon::now(); $service_organization->save(); } - $service_organization_id = $service_organization["organization_recordid"]; + $service_organization_id = $service_organization['organization_recordid']; $service->service_organization = $service_organization_id; $service->service_name = $request->service_name; @@ -3977,10 +3977,12 @@ public function add_new_service_in_organization(Request $request) $service->service_language = $request->service_language ? implode(',', $request->service_language) : ''; $service->service_interpretation = $request->service_interpretation; - if ($request->service_area) + if ($request->service_area) { $service->areas()->sync($request->service_area); - if ($request->fee_option) + } + if ($request->fee_option) { $service->fees()->sync($request->fee_option); + } $servicePrograms = $this->saveServiceProgram($request, $service_recordid); @@ -4126,7 +4128,6 @@ public function add_new_service_in_organization(Request $request) $location_phone_types = $request->location_phone_types && count($request->location_phone_types) ? json_decode($request->location_phone_types[0], true) : []; $location_phone_languages = $request->location_phone_languages && count($request->location_phone_languages) ? json_decode($request->location_phone_languages[0], true) : []; - $location_phone_descriptions = $request->location_phone_descriptions && count($request->location_phone_descriptions) ? json_decode($request->location_phone_descriptions[0], true) : []; // location schedule section @@ -4164,7 +4165,6 @@ public function add_new_service_in_organization(Request $request) $location_holiday_close_ats = $request->location_holiday_close_ats ? json_decode($request->location_holiday_close_ats, true) : []; $location_holiday_closeds = $request->location_holiday_closeds ? json_decode($request->location_holiday_closeds, true) : []; - if ($request->locationRadio[$i] == 'new_data') { $location = new Location(); $location_recordid = Location::max('location_recordid') + 1; @@ -4175,10 +4175,9 @@ public function add_new_service_in_organization(Request $request) $location->location_description = isset($location_description[$i]) ? $location_description[$i] : null; $location->location_details = isset($location_details[$i]) ? $location_details[$i] : null; - // accessesibility - if (!empty($location_accessibility[$i]) && !empty($location_accessibility_details[$i])) { + if (! empty($location_accessibility[$i]) && ! empty($location_accessibility_details[$i])) { // Accessibility::create([ // 'accessibility_recordid' => Accessibility::max('accessibility_recordid') + 1, // 'accessibility' => $location_accessibility[$i], @@ -4271,9 +4270,9 @@ public function add_new_service_in_organization(Request $request) $schedules = Schedule::where('locations', $location_recordid)->where('weekday', $weekdays[$s])->first(); if ($schedules) { $schedules->weekday = $weekdays[$s]; - $schedules->opens = isset(${'opens_location_' . $weekdays[$s] . '_datas'}[$i]) ? ${'opens_location_' . $weekdays[$s] . '_datas'}[$i] : ''; - $schedules->closes = isset(${'closes_location_' . $weekdays[$s] . '_datas'}[$i]) ? ${'closes_location_' . $weekdays[$s] . '_datas'}[$i] : ''; - if (isset(${'schedule_closed_' . $weekdays[$s] . '_datas'}[$i]) && ${'schedule_closed_' . $weekdays[$s] . '_datas'}[$i] == ($s + 1)) { + $schedules->opens = isset(${'opens_location_'.$weekdays[$s].'_datas'}[$i]) ? ${'opens_location_'.$weekdays[$s].'_datas'}[$i] : ''; + $schedules->closes = isset(${'closes_location_'.$weekdays[$s].'_datas'}[$i]) ? ${'closes_location_'.$weekdays[$s].'_datas'}[$i] : ''; + if (isset(${'schedule_closed_'.$weekdays[$s].'_datas'}[$i]) && ${'schedule_closed_'.$weekdays[$s].'_datas'}[$i] == ($s + 1)) { $schedules->schedule_closed = $s + 1; } else { $schedules->schedule_closed = null; @@ -4286,9 +4285,9 @@ public function add_new_service_in_organization(Request $request) $schedules->schedule_recordid = $schedule_recordid; $schedules->locations = $location_recordid; $schedules->weekday = $weekdays[$s]; - $schedules->opens = isset(${'opens_location_' . $weekdays[$s] . '_datas'}[$i]) ? ${'opens_location_' . $weekdays[$s] . '_datas'}[$i] : ''; - $schedules->closes = isset(${'closes_location_' . $weekdays[$s] . '_datas'}[$i]) ? ${'closes_location_' . $weekdays[$s] . '_datas'}[$i] : ''; - if (isset(${'schedule_closed_' . $weekdays[$s] . '_datas'}[$i]) && ${'schedule_closed_' . $weekdays[$s] . '_datas'}[$i] == ($s + 1)) { + $schedules->opens = isset(${'opens_location_'.$weekdays[$s].'_datas'}[$i]) ? ${'opens_location_'.$weekdays[$s].'_datas'}[$i] : ''; + $schedules->closes = isset(${'closes_location_'.$weekdays[$s].'_datas'}[$i]) ? ${'closes_location_'.$weekdays[$s].'_datas'}[$i] : ''; + if (isset(${'schedule_closed_'.$weekdays[$s].'_datas'}[$i]) && ${'schedule_closed_'.$weekdays[$s].'_datas'}[$i] == ($s + 1)) { $schedules->schedule_closed = $s + 1; } else { $schedules->schedule_closed = null; @@ -4331,7 +4330,7 @@ public function add_new_service_in_organization(Request $request) // } } } - $location->location_schedule = join(',', $schedule_locations); + $location->location_schedule = implode(',', $schedule_locations); $location->schedules()->sync($schedule_locations); @@ -4354,7 +4353,7 @@ public function add_new_service_in_organization(Request $request) $location->location_details = isset($location_details[$i]) ? $location_details[$i] : null; // accessesibility - if (!empty($location_accessibility[$i]) && !empty($location_accessibility_details[$i])) { + if (! empty($location_accessibility[$i]) && ! empty($location_accessibility_details[$i])) { // Accessibility::updateOrCreate([ // 'accessibility_location' => $request->location_recordid[$i] // ], [ @@ -4445,9 +4444,9 @@ public function add_new_service_in_organization(Request $request) $schedules = Schedule::where('locations', $location->location_recordid)->where('weekday', $weekdays[$s])->first(); if ($schedules) { $schedules->weekday = $weekdays[$s]; - $schedules->opens = isset(${'opens_location_' . $weekdays[$s] . '_datas'}[$i]) ? ${'opens_location_' . $weekdays[$s] . '_datas'}[$i] : ''; - $schedules->closes = isset(${'closes_location_' . $weekdays[$s] . '_datas'}[$i]) ? ${'closes_location_' . $weekdays[$s] . '_datas'}[$i] : ''; - if (isset(${'schedule_closed_' . $weekdays[$s] . '_datas'}[$i]) && ${'schedule_closed_' . $weekdays[$s] . '_datas'}[$i] == ($s + 1)) { + $schedules->opens = isset(${'opens_location_'.$weekdays[$s].'_datas'}[$i]) ? ${'opens_location_'.$weekdays[$s].'_datas'}[$i] : ''; + $schedules->closes = isset(${'closes_location_'.$weekdays[$s].'_datas'}[$i]) ? ${'closes_location_'.$weekdays[$s].'_datas'}[$i] : ''; + if (isset(${'schedule_closed_'.$weekdays[$s].'_datas'}[$i]) && ${'schedule_closed_'.$weekdays[$s].'_datas'}[$i] == ($s + 1)) { $schedules->schedule_closed = $s + 1; } else { $schedules->schedule_closed = null; @@ -4460,9 +4459,9 @@ public function add_new_service_in_organization(Request $request) $schedules->schedule_recordid = $schedule_recordid; $schedules->locations = $location->location_recordid; $schedules->weekday = $weekdays[$s]; - $schedules->opens = isset(${'opens_location_' . $weekdays[$s] . '_datas'}[$i]) ? ${'opens_location_' . $weekdays[$s] . '_datas'}[$i] : ''; - $schedules->closes = isset(${'closes_location_' . $weekdays[$s] . '_datas'}[$i]) ? ${'closes_location_' . $weekdays[$s] . '_datas'}[$i] : ''; - if (isset(${'schedule_closed_' . $weekdays[$s] . '_datas'}[$i]) && ${'schedule_closed_' . $weekdays[$s] . '_datas'}[$i] == ($s + 1)) { + $schedules->opens = isset(${'opens_location_'.$weekdays[$s].'_datas'}[$i]) ? ${'opens_location_'.$weekdays[$s].'_datas'}[$i] : ''; + $schedules->closes = isset(${'closes_location_'.$weekdays[$s].'_datas'}[$i]) ? ${'closes_location_'.$weekdays[$s].'_datas'}[$i] : ''; + if (isset(${'schedule_closed_'.$weekdays[$s].'_datas'}[$i]) && ${'schedule_closed_'.$weekdays[$s].'_datas'}[$i] == ($s + 1)) { $schedules->schedule_closed = $s + 1; } else { $schedules->schedule_closed = null; @@ -4505,7 +4504,7 @@ public function add_new_service_in_organization(Request $request) // } } } - $location->location_schedule = join(',', $schedule_locations); + $location->location_schedule = implode(',', $schedule_locations); $location->schedules()->sync($schedule_locations); $location->phones()->sync($location_phone_recordid_list); @@ -4521,7 +4520,7 @@ public function add_new_service_in_organization(Request $request) } } } - $service->service_locations = join(',', $service_locations); + $service->service_locations = implode(',', $service_locations); $service->locations()->sync($service_locations); // if ($request->service_taxonomies) { @@ -4586,7 +4585,7 @@ public function add_new_service_in_organization(Request $request) if (count($service_taxonomies) > 0) { $service_taxonomies = is_array($service_taxonomies) ? array_unique(array_values(array_filter($service_taxonomies))) : []; } - $service->service_taxonomy = join(',', $service_taxonomies); + $service->service_taxonomy = implode(',', $service_taxonomies); $service->taxonomy()->sync($service_taxonomies); // $phone_recordids = Phone::select("phone_recordid")->distinct()->get(); @@ -4660,7 +4659,7 @@ public function add_new_service_in_organization(Request $request) for ($i = 0; $i < count($service_phone_number_list); $i++) { $phone_info = Phone::where('phone_number', '=', $service_phone_number_list[$i])->first(); if ($phone_info) { - $service->service_phones = $service->service_phones . $phone_info->phone_recordid . ','; + $service->service_phones = $service->service_phones.$phone_info->phone_recordid.','; $phone_info->phone_number = $service_phone_number_list[$i]; $phone_info->phone_extension = $service_phone_extension_list[$i]; $phone_info->phone_type = $service_phone_type_list[$i]; @@ -4688,7 +4687,7 @@ public function add_new_service_in_organization(Request $request) $new_phone->main_priority = '0'; } $new_phone->save(); - $service->service_phones = $service->service_phones . $new_phone_recordid . ','; + $service->service_phones = $service->service_phones.$new_phone_recordid.','; array_push($phone_recordid_list, $new_phone_recordid); } // } @@ -4720,7 +4719,7 @@ public function add_new_service_in_organization(Request $request) } } if (count($schedule_services)) { - $service->service_schedule = join(',', $schedule_services); + $service->service_schedule = implode(',', $schedule_services); } $service->schedules()->sync($schedule_services); @@ -4750,7 +4749,7 @@ public function add_new_service_in_organization(Request $request) for ($p = 0; $p < count($contact_phone_numbers[$i]); $p++) { $phone_info = Phone::where('phone_number', '=', $contact_phone_numbers[$i][$p])->first(); if ($phone_info) { - $contact->contact_phones = $contact->contact_phones . $phone_info->phone_recordid . ','; + $contact->contact_phones = $contact->contact_phones.$phone_info->phone_recordid.','; $phone_info->phone_number = $contact_phone_numbers[$i][$p]; $phone_info->phone_extension = $contact_phone_extensions[$i][$p]; $phone_info->phone_type = $contact_phone_types[$i][$p]; @@ -4768,7 +4767,7 @@ public function add_new_service_in_organization(Request $request) $new_phone->phone_language = isset($contact_phone_languages[$i][$p]) ? implode(',', $contact_phone_languages[$i][$p]) : ''; $new_phone->phone_description = $contact_phone_descriptions[$i][$p]; $new_phone->save(); - $contact->contact_phones = $contact->contact_phones . $new_phone_recordid . ','; + $contact->contact_phones = $contact->contact_phones.$new_phone_recordid.','; array_push($contact_phone_recordid_list, $new_phone_recordid); } } @@ -4787,7 +4786,7 @@ public function add_new_service_in_organization(Request $request) for ($p = 0; $p < count($contact_phone_numbers[$i]); $p++) { $phone_info = Phone::where('phone_number', '=', $contact_phone_numbers[$i][$p])->first(); if ($phone_info) { - $contact->contact_phones = $contact->contact_phones . $phone_info->phone_recordid . ','; + $contact->contact_phones = $contact->contact_phones.$phone_info->phone_recordid.','; $phone_info->phone_number = $contact_phone_numbers[$i][$p]; $phone_info->phone_extension = $contact_phone_extensions[$i][$p]; $phone_info->phone_type = $contact_phone_types[$i][$p]; @@ -4805,7 +4804,7 @@ public function add_new_service_in_organization(Request $request) $new_phone->phone_language = isset($contact_phone_languages[$i][$p]) ? implode(',', $contact_phone_languages[$i][$p]) : ''; $new_phone->phone_description = $contact_phone_descriptions[$i][$p]; $new_phone->save(); - $contact->contact_phones = $contact->contact_phones . $new_phone_recordid . ','; + $contact->contact_phones = $contact->contact_phones.$new_phone_recordid.','; array_push($contact_phone_recordid_list, $new_phone_recordid); } } @@ -4816,7 +4815,7 @@ public function add_new_service_in_organization(Request $request) } } } - $service->service_contacts = join(',', $service_contacts); + $service->service_contacts = implode(',', $service_contacts); $service->contact()->sync($service_contacts); // if ($request->service_details) { @@ -4848,11 +4847,11 @@ public function add_new_service_in_organization(Request $request) } } } - $service->service_details = join(',', $detail_ids); + $service->service_details = implode(',', $detail_ids); $service->details()->sync($detail_ids); if ($request->service_address) { - $service->service_address = join(',', $request->service_address); + $service->service_address = implode(',', $request->service_address); } else { $service->service_address = ''; } @@ -4867,11 +4866,12 @@ public function add_new_service_in_organization(Request $request) Session::flash('message', 'Services created successfully!'); Session::flash('status', 'success'); - return redirect('organizations/' . $service_organization_id); + return redirect('organizations/'.$service_organization_id); } catch (\Throwable $th) { - Log::error('Erro from add service from organization :' . $th); + Log::error('Erro from add service from organization :'.$th); Session::flash('message', $th->getMessage()); Session::flash('status', 'error'); + return redirect()->back(); } } @@ -4883,14 +4883,14 @@ public function add_new_service_in_facility(Request $request) ]); if ($request->service_email) { $this->validate($request, [ - 'service_email' => 'email' + 'service_email' => 'email', ]); } try { $service = new Service; - $service_recordids = Service::select("service_recordid")->distinct()->get(); - $service_recordid_list = array(); + $service_recordids = Service::select('service_recordid')->distinct()->get(); + $service_recordid_list = []; foreach ($service_recordids as $key => $value) { $service_recordid = $value->service_recordid; array_push($service_recordid_list, $service_recordid); @@ -4946,10 +4946,12 @@ public function add_new_service_in_facility(Request $request) $service->service_language = $request->service_language ? implode(',', $request->service_language) : ''; $service->service_interpretation = $request->service_interpretation; - if ($request->service_area) + if ($request->service_area) { $service->areas()->sync($request->service_area); - if ($request->fee_option) + } + if ($request->fee_option) { $service->fees()->sync($request->fee_option); + } $servicePrograms = $this->saveServiceProgram($request, $service_recordid); @@ -5123,7 +5125,7 @@ public function add_new_service_in_facility(Request $request) if (count($service_taxonomies) > 0) { $service_taxonomies = is_array($service_taxonomies) ? array_unique(array_values(array_filter($service_taxonomies))) : []; } - $service->service_taxonomy = join(',', $service_taxonomies); + $service->service_taxonomy = implode(',', $service_taxonomies); $service->taxonomy()->sync($service_taxonomies); // $service->service_phones = ''; @@ -5167,7 +5169,7 @@ public function add_new_service_in_facility(Request $request) for ($i = 0; $i < count($service_phone_number_list); $i++) { $phone_info = Phone::where('phone_number', '=', $service_phone_number_list[$i])->first(); if ($phone_info) { - $service->service_phones = $service->service_phones . $phone_info->phone_recordid . ','; + $service->service_phones = $service->service_phones.$phone_info->phone_recordid.','; $phone_info->phone_number = $service_phone_number_list[$i]; $phone_info->phone_extension = $service_phone_extension_list[$i]; $phone_info->phone_type = $service_phone_type_list[$i]; @@ -5195,7 +5197,7 @@ public function add_new_service_in_facility(Request $request) $new_phone->main_priority = '0'; } $new_phone->save(); - $service->service_phones = $service->service_phones . $new_phone_recordid . ','; + $service->service_phones = $service->service_phones.$new_phone_recordid.','; array_push($phone_recordid_list, $new_phone_recordid); } // } @@ -5239,7 +5241,7 @@ public function add_new_service_in_facility(Request $request) } } if (count($schedule_services)) { - $service->service_schedule = join(',', $schedule_services); + $service->service_schedule = implode(',', $schedule_services); } $service->schedules()->sync($schedule_services); @@ -5275,7 +5277,7 @@ public function add_new_service_in_facility(Request $request) for ($p = 0; $p < count($contact_phone_numbers[$i]); $p++) { $phone_info = Phone::where('phone_number', '=', $contact_phone_numbers[$i][$p])->first(); if ($phone_info) { - $contact->contact_phones = $contact->contact_phones . $phone_info->phone_recordid . ','; + $contact->contact_phones = $contact->contact_phones.$phone_info->phone_recordid.','; $phone_info->phone_number = $contact_phone_numbers[$i][$p]; $phone_info->phone_extension = $contact_phone_extensions[$i][$p]; $phone_info->phone_type = $contact_phone_types[$i][$p]; @@ -5293,7 +5295,7 @@ public function add_new_service_in_facility(Request $request) $new_phone->phone_language = isset($contact_phone_languages[$i][$p]) ? implode(',', $contact_phone_languages[$i][$p]) : ''; $new_phone->phone_description = $contact_phone_descriptions[$i][$p]; $new_phone->save(); - $contact->contact_phones = $contact->contact_phones . $new_phone_recordid . ','; + $contact->contact_phones = $contact->contact_phones.$new_phone_recordid.','; array_push($contact_phone_recordid_list, $new_phone_recordid); } } @@ -5312,7 +5314,7 @@ public function add_new_service_in_facility(Request $request) for ($p = 0; $p < count($contact_phone_numbers[$i]); $p++) { $phone_info = Phone::where('phone_number', '=', $contact_phone_numbers[$i][$p])->first(); if ($phone_info) { - $contact->contact_phones = $contact->contact_phones . $phone_info->phone_recordid . ','; + $contact->contact_phones = $contact->contact_phones.$phone_info->phone_recordid.','; $phone_info->phone_number = $contact_phone_numbers[$i][$p]; $phone_info->phone_extension = $contact_phone_extensions[$i][$p]; $phone_info->phone_type = $contact_phone_types[$i][$p]; @@ -5330,7 +5332,7 @@ public function add_new_service_in_facility(Request $request) $new_phone->phone_language = isset($contact_phone_languages[$i][$p]) ? implode(',', $contact_phone_languages[$i][$p]) : ''; $new_phone->phone_description = $contact_phone_descriptions[$i][$p]; $new_phone->save(); - $contact->contact_phones = $contact->contact_phones . $new_phone_recordid . ','; + $contact->contact_phones = $contact->contact_phones.$new_phone_recordid.','; array_push($contact_phone_recordid_list, $new_phone_recordid); } } @@ -5341,7 +5343,7 @@ public function add_new_service_in_facility(Request $request) } } } - $service->service_contacts = join(',', $service_contacts); + $service->service_contacts = implode(',', $service_contacts); $service->contact()->sync($service_contacts); // if ($request->service_details) { @@ -5373,11 +5375,11 @@ public function add_new_service_in_facility(Request $request) } } } - $service->service_details = join(',', $detail_ids); + $service->service_details = implode(',', $detail_ids); $service->details()->sync($detail_ids); if ($request->service_address) { - $service->service_address = join(',', $request->service_address); + $service->service_address = implode(',', $request->service_address); } else { $service->service_address = ''; } @@ -5392,10 +5394,12 @@ public function add_new_service_in_facility(Request $request) Session::flash('message', 'Service created successfully!'); Session::flash('status', 'success'); - return redirect('facilities/' . $service_location_recordid); + + return redirect('facilities/'.$service_location_recordid); } catch (\Throwable $th) { Session::flash('message', $th->getMessage()); Session::flash('status', 'error'); + return redirect()->back(); } } @@ -5444,10 +5448,11 @@ public function download($id) $pdf = PDF::loadView('frontEnd.services.service_download', compact('service', 'layout')); $service_name = str_replace('"', '', $service_name); - return $pdf->download($service_name . '_' . time() . '.pdf'); + return $pdf->download($service_name.'_'.time().'.pdf'); } else { Session::flash('message', 'Something went wrong, Please try again later.'); Session::flash('status', 'error'); + return redirect()->back(); } } @@ -5469,14 +5474,14 @@ public function download_csv($id) $details = ''; foreach ($service->taxonomy as $key => $taxonomy) { - $taxonomies = $taxonomies . $taxonomy->taxonomy_name . ','; + $taxonomies = $taxonomies.$taxonomy->taxonomy_name.','; } $service['taxonomies'] = $taxonomies; if (isset($service->service_organization)) { if ($service->service_organization != 0) { foreach ($service->organizations as $organization) { - $organizations = $organizations . $organization->organization_name; + $organizations = $organizations.$organization->organization_name; } } } @@ -5484,17 +5489,17 @@ public function download_csv($id) $service['organizations'] = $organizations; foreach ($service->phone as $phone1) { - $phones = $phones . $phone1->phone_number; + $phones = $phones.$phone1->phone_number; } $service['phones'] = $phones; foreach ($service->address as $address) { - $address1 = $address1 . $address->address_1 . ' ' . $address->address_city . ' ' . $address->address_state_province . ' ' . $address->address_postal_code; + $address1 = $address1.$address->address_1.' '.$address->address_city.' '.$address->address_state_province.' '.$address->address_postal_code; } $service['address1'] = $address1; foreach ($service->contact as $contact) { - $contacts = $contacts . $contact->contact_name; + $contacts = $contacts.$contact->contact_name; } $service['contacts'] = $contacts; @@ -5507,13 +5512,13 @@ public function download_csv($id) } } if ($i == count($show_details)) { - $show_details[$i] = array('detail_type' => $detail->detail_type, 'detail_value' => $detail->detail_value); + $show_details[$i] = ['detail_type' => $detail->detail_type, 'detail_value' => $detail->detail_value]; } else { - $show_details[$i]['detail_value'] = $show_details[$i]['detail_value'] . ', ' . $detail->detail_value; + $show_details[$i]['detail_value'] = $show_details[$i]['detail_value'].', '.$detail->detail_value; } } foreach ($show_details as $detail) { - $details = $details . $detail['detail_type'] . ':' . $detail['detail_value'] . '; '; + $details = $details.$detail['detail_type'].':'.$detail['detail_value'].'; '; } $service['details'] = $details; } @@ -5527,100 +5532,100 @@ public function download_csv($id) $csv = csv::find(2); $description = ''; if (isset($child_taxonomy_names)) { - if ($child_taxonomy_names != "") { + if ($child_taxonomy_names != '') { $filter_category = ''; foreach ($child_taxonomy_names as $child_taxonomy_name) { - $filter_category = $filter_category . $child_taxonomy_name . ','; + $filter_category = $filter_category.$child_taxonomy_name.','; } - $description = $description . "Category: " . $filter_category; + $description = $description.'Category: '.$filter_category; } } if (isset($checked_organization_names)) { - if ($checked_organization_names != "") { + if ($checked_organization_names != '') { $filter_organization = ''; foreach ($checked_organization_names as $checked_organization_name) { - $filter_organization = $filter_organization . $checked_organization_name . ','; + $filter_organization = $filter_organization.$checked_organization_name.','; } - $description = $description . "Organization: " . $filter_organization; + $description = $description.'Organization: '.$filter_organization; } } if (isset($checked_insurance_names)) { - if ($checked_insurance_names != "") { + if ($checked_insurance_names != '') { $filter_insurance = ''; foreach ($checked_insurance_names as $checked_insurance_name) { - $filter_insurance = $filter_insurance . $checked_insurance_name . ','; + $filter_insurance = $filter_insurance.$checked_insurance_name.','; } - $description = $description . "Insurance: " . $filter_insurance; + $description = $description.'Insurance: '.$filter_insurance; } } if (isset($checked_age_names)) { - if ($checked_age_names != "") { + if ($checked_age_names != '') { $filter_age = ''; foreach ($checked_age_names as $checked_age_name) { - $filter_age = $filter_age . $checked_age_name . ','; + $filter_age = $filter_age.$checked_age_name.','; } - $description = $description . "Age: " . $filter_age; + $description = $description.'Age: '.$filter_age; } } if (isset($checked_language_names)) { - if ($checked_language_names != "") { + if ($checked_language_names != '') { $filter_language = ''; foreach ($checked_language_names as $checked_language_name) { - $filter_language = $filter_language . $checked_language_name . ','; + $filter_language = $filter_language.$checked_language_name.','; } - $description = $description . "Language: " . $filter_language; + $description = $description.'Language: '.$filter_language; } } if (isset($checked_setting_names)) { - if ($checked_setting_names != "") { + if ($checked_setting_names != '') { $filter_setting = ''; foreach ($checked_setting_names as $checked_setting_name) { - $filter_setting = $filter_setting . $checked_setting_name . ','; + $filter_setting = $filter_setting.$checked_setting_name.','; } - $description = $description . "Setting: " . $filter_setting; + $description = $description.'Setting: '.$filter_setting; } } if (isset($checked_cultural_names)) { - if ($checked_cultural_names != "") { + if ($checked_cultural_names != '') { $filter_cultural = ''; foreach ($checked_cultural_names as $checked_cultural_name) { - $filter_cultural = $filter_cultural . $checked_cultural_name . ','; + $filter_cultural = $filter_cultural.$checked_cultural_name.','; } - $description = $description . "Cultural: " . $filter_cultural; + $description = $description.'Cultural: '.$filter_cultural; } } if (isset($checked_transportation_names)) { - if ($checked_transportation_names != "") { + if ($checked_transportation_names != '') { $filter_transportation = ''; foreach ($checked_transportation_names as $checked_transportation_name) { - $filter_transportation = $filter_cultural . $checked_transportation_name . ','; + $filter_transportation = $filter_cultural.$checked_transportation_name.','; } - $description = $description . "Transportation: " . $filter_transportation; + $description = $description.'Transportation: '.$filter_transportation; } } if (isset($checked_hour_names)) { - if ($checked_hour_names != "") { + if ($checked_hour_names != '') { $filter_hour = ''; foreach ($checked_hour_names as $checked_hour_name) { - $filter_hour = $filter_hour . $checked_hour_name . ','; + $filter_hour = $filter_hour.$checked_hour_name.','; } - $description = $description . "Additional Hour: " . $filter_hour; + $description = $description.'Additional Hour: '.$filter_hour; } } @@ -5652,9 +5657,11 @@ public function delete_service(Request $request) Session::flash('message', 'Service deleted successfully!'); Session::flash('status', 'success'); + return redirect('/services'); } catch (\Throwable $th) { - Log::error('Error in delete service : ' . $th); + Log::error('Error in delete service : '.$th); + return redirect('/services'); } } @@ -5671,7 +5678,8 @@ public function getDetailTerm(Request $request) 'data' => $detail_info_list, ], 200); } catch (\Throwable $th) { - Log::error('Error in get detai term service : ' . $th); + Log::error('Error in get detai term service : '.$th); + return response()->json([ 'success' => false, 'message' => $th->getMessage(), @@ -5696,7 +5704,8 @@ public function addDetailTerm(Request $request) 'data' => $detail_recordid, ], 200); } catch (\Throwable $th) { - Log::error('Error in get detai term service : ' . $th); + Log::error('Error in get detai term service : '.$th); + return response()->json([ 'success' => false, 'message' => $th->getMessage(), @@ -5709,7 +5718,7 @@ public function getTaxonomyTerm(Request $request) try { $taxonomy_recordid = $request->value; $taxonomy_parent_name = Taxonomy::orderBy('taxonomy_name')->where('taxonomy_recordid', $taxonomy_recordid)->first(); - $taxonomy_info_list = Taxonomy::orderBy('taxonomy_name')->where('taxonomy_parent_name', 'LIKE', '%' . $taxonomy_recordid . '%')->where('status', 'Published')->get(); + $taxonomy_info_list = Taxonomy::orderBy('taxonomy_name')->where('taxonomy_parent_name', 'LIKE', '%'.$taxonomy_recordid.'%')->where('status', 'Published')->get(); // $taxonomy_info_list = $this->parent()->get(); // while ($taxonomy_info_list->last() && $taxonomy_info_list->last()->taxonomy_parent_name !== null) { @@ -5718,26 +5727,28 @@ public function getTaxonomyTerm(Request $request) // } $taxonomy_array = []; foreach ($taxonomy_info_list as $value) { - $taxonomy_array[$value->taxonomy_recordid] = '- ' . $value->taxonomy_name; - $taxonomy_child_list = Taxonomy::orderBy('taxonomy_name')->where('taxonomy_parent_name', 'LIKE', '%' . $value->taxonomy_recordid . '%')->where('status', 'Published')->get(); + $taxonomy_array[$value->taxonomy_recordid] = '- '.$value->taxonomy_name; + $taxonomy_child_list = Taxonomy::orderBy('taxonomy_name')->where('taxonomy_parent_name', 'LIKE', '%'.$value->taxonomy_recordid.'%')->where('status', 'Published')->get(); if ($taxonomy_child_list) { foreach ($taxonomy_child_list as $value1) { - $taxonomy_array[$value1->taxonomy_recordid] = '-- ' . $value1->taxonomy_name; - $taxonomy_child_list1 = Taxonomy::orderBy('taxonomy_name')->where('taxonomy_parent_name', 'LIKE', '%' . $value1->taxonomy_recordid . '%')->where('status', 'Published')->get(); + $taxonomy_array[$value1->taxonomy_recordid] = '-- '.$value1->taxonomy_name; + $taxonomy_child_list1 = Taxonomy::orderBy('taxonomy_name')->where('taxonomy_parent_name', 'LIKE', '%'.$value1->taxonomy_recordid.'%')->where('status', 'Published')->get(); if ($taxonomy_child_list1) { foreach ($taxonomy_child_list1 as $value2) { - $taxonomy_array[$value2->taxonomy_recordid] = '--- ' . $value2->taxonomy_name; + $taxonomy_array[$value2->taxonomy_recordid] = '--- '.$value2->taxonomy_name; } } } } } + return response()->json([ 'success' => true, 'data' => $taxonomy_array, ], 200); } catch (\Throwable $th) { - Log::error('Error in get taxonomy term service : ' . $th); + Log::error('Error in get taxonomy term service : '.$th); + return response()->json([ 'success' => false, 'message' => $th->getMessage(), @@ -5760,7 +5771,7 @@ public function saveTaxonomyTerm(Request $request) 'status' => 'Unpublished', 'added_term' => '1', 'created_by' => Auth::id(), - 'taxonomy' => $taxonomyType->taxonomy_type_recordid ?? '' + 'taxonomy' => $taxonomyType->taxonomy_type_recordid ?? '', ]); $lastInsetedTaxonomy = Taxonomy::where('taxonomy_recordid', $latestTaxonomyId)->first(); @@ -5794,23 +5805,22 @@ public function saveTaxonomyTerm(Request $request) $message = ''; $message .= '

New Taxonomy Term Added to ORServices

'; // $message .= '

The following change was suggested at ' . $site_name . ' website.

'; - $message .= '

User: ' . $user->first_name . ' ' . $user->last_name . '

'; - $message .= '

Term: ' . $request->get('service_category_term') . '

'; - $message .= '

Parent term: ' . $taxonomy->taxonomy_name . '

'; - $message .= '

Service: ' . $service_name . '

'; - $message .= '

Organization: ' . $organization_name . '

'; - $message .= '

Timestamp: ' . Carbon::now() . '

'; + $message .= '

User: '.$user->first_name.' '.$user->last_name.'

'; + $message .= '

Term: '.$request->get('service_category_term').'

'; + $message .= '

Parent term: '.$taxonomy->taxonomy_name.'

'; + $message .= '

Service: '.$service_name.'

'; + $message .= '

Organization: '.$organization_name.'

'; + $message .= '

Timestamp: '.Carbon::now().'

'; // $message .= '

Phone: '. $from_phone .'

'; $message .= ''; - $email->addContent("text/html", $message); + $email->addContent('text/html', $message); $sendgrid = new SendGrid(getenv('SENDGRID_API_KEY')); $error = ''; $username = ''; - foreach ($contact_email_list as $key => $contact_email) { $email->addTo($contact_email, $username); } @@ -5819,14 +5829,16 @@ public function saveTaxonomyTerm(Request $request) $error = json_decode($response->body()); } } + return response()->json([ - 'success' => true + 'success' => true, ], 200); } catch (\Throwable $th) { - Log::error('Error in save taxonomy term servie : ' . $th); + Log::error('Error in save taxonomy term servie : '.$th); + return response()->json([ 'message' => $th->getMessage(), - 'success' => false + 'success' => false, ], 500); } } @@ -5846,7 +5858,7 @@ public function saveEligibilityTaxonomyTerm(Request $request) 'status' => 'Unpublished', 'added_term' => '1', 'created_by' => Auth::id(), - 'taxonomy' => $taxonomyType->taxonomy_type_recordid ?? '' + 'taxonomy' => $taxonomyType->taxonomy_type_recordid ?? '', ]); $lastInsetedTaxonomy = Taxonomy::where('taxonomy_recordid', $latestTaxonomyId)->first(); @@ -5880,23 +5892,22 @@ public function saveEligibilityTaxonomyTerm(Request $request) $message = ''; $message .= '

New Taxonomy Term Added to ORServices

'; // $message .= '

The following change was suggested at ' . $site_name . ' website.

'; - $message .= '

User: ' . $user->first_name . ' ' . $user->last_name . '

'; - $message .= '

Term: ' . $request->get('service_eligibility_term') . '

'; - $message .= '

Parent term: ' . $taxonomy->taxonomy_name . '

'; - $message .= '

Service: ' . $service_name . '

'; - $message .= '

Organization: ' . $organization_name . '

'; - $message .= '

Timestamp: ' . Carbon::now() . '

'; + $message .= '

User: '.$user->first_name.' '.$user->last_name.'

'; + $message .= '

Term: '.$request->get('service_eligibility_term').'

'; + $message .= '

Parent term: '.$taxonomy->taxonomy_name.'

'; + $message .= '

Service: '.$service_name.'

'; + $message .= '

Organization: '.$organization_name.'

'; + $message .= '

Timestamp: '.Carbon::now().'

'; // $message .= '

Phone: '. $from_phone .'

'; $message .= ''; - $email->addContent("text/html", $message); + $email->addContent('text/html', $message); $sendgrid = new SendGrid(getenv('SENDGRID_API_KEY')); $error = ''; $username = ''; - foreach ($contact_email_list as $key => $contact_email) { $email->addTo($contact_email, $username); } @@ -5905,15 +5916,17 @@ public function saveEligibilityTaxonomyTerm(Request $request) $error = json_decode($response->body()); } } + return response()->json([ 'success' => true, - 'taxonomy_recordid' => $latestTaxonomyId + 'taxonomy_recordid' => $latestTaxonomyId, ], 200); } catch (\Throwable $th) { - Log::error('Error in save taxonomy term servie : ' . $th); + Log::error('Error in save taxonomy term servie : '.$th); + return response()->json([ 'message' => $th->getMessage(), - 'success' => false + 'success' => false, ], 500); } } @@ -5921,16 +5934,16 @@ public function saveEligibilityTaxonomyTerm(Request $request) public function add_comment(Request $request, $id) { $this->validate($request, [ - 'comment' => 'required' + 'comment' => 'required', ]); try { $comment_content = $request->comment; $user = Auth::user(); - $date_time = date("Y-m-d H:i:s"); + $date_time = date('Y-m-d H:i:s'); $comment = new Comment(); - $comment_recordids = Comment::select("comments_recordid")->distinct()->get(); - $comment_recordid_list = array(); + $comment_recordids = Comment::select('comments_recordid')->distinct()->get(); + $comment_recordid_list = []; foreach ($comment_recordids as $key => $value) { $comment_recordid = $value->comments_recordid; array_push($comment_recordid_list, $comment_recordid); @@ -5952,10 +5965,12 @@ public function add_comment(Request $request, $id) Session::flash('message', 'Comment added successfully!'); Session::flash('status', 'success'); - return redirect('services/' . $id); + + return redirect('services/'.$id); } catch (\Throwable $th) { Session::flash('message', $th->getMessage()); Session::flash('status', 'error'); + return redirect()->back(); } } @@ -5969,14 +5984,15 @@ public function addServiceTag(Request $request) $service->updated_at = Carbon::now(); $service->updated_by = Auth::id(); $service->save(); + return response()->json([ 'message' => 'tags added successfully!', - 'success' => true + 'success' => true, ], 200); } catch (\Throwable $th) { return response()->json([ 'message' => $th->getMessage(), - 'success' => false + 'success' => false, ], 500); } } @@ -5984,28 +6000,31 @@ public function addServiceTag(Request $request) public function createNewServiceTag(Request $request, $id) { try { - if (!$request->tag) { + if (! $request->tag) { Session::flash('message', 'Service tag can`t be blank!'); Session::flash('status', 'error'); + return redirect()->back(); } $serviceTag = ServiceTag::create([ 'tag' => $request->tag, - 'created_by' => Auth::id() + 'created_by' => Auth::id(), ]); $service = Service::whereId($id)->first(); $serTag = $service->service_tag != null ? explode(',', $service->service_tag) : []; $serTag[] = $serviceTag->id; - if (!empty($serTag)) { + if (! empty($serTag)) { $service->service_tag = implode(',', $serTag); $service->save(); } Session::flash('message', 'Service tag added successfully!'); Session::flash('status', 'success'); + return redirect()->back(); } catch (\Throwable $th) { Session::flash('message', $th->getMessage()); Session::flash('status', 'success'); + return redirect()->back(); } } @@ -6035,19 +6054,15 @@ public function saveRequiredDocument($request, $id) 'document_type' => isset($requiredDocumentTypes[$value]) ? $requiredDocumentTypes[$value] : null, 'document_link' => is_array($request->document_url) && isset($request->document_url[$key]) ? $request->document_url[$key] : null, 'document_title' => is_array($request->document_title) && isset($request->document_title[$key]) ? $request->document_title[$key] : null, - 'created_by' => Auth::id() + 'created_by' => Auth::id(), ]); } } } + return true; } - /** - * @param $request - * @param $service - * @return array - */ public function saveServiceSchedule($request, $service): array { $schedule_services = []; @@ -6056,11 +6071,11 @@ public function saveServiceSchedule($request, $service): array $schedules = Schedule::where('services', $service->service_recordid)->where('opens', $request->opens[$i])->where('closes', $request->closes[$i])->first(); if ($request->weekday[$i] && (((is_array($request->schedule_closed) && in_array(($i + 1), $request->schedule_closed)) || (is_array($request->open_24_hours) && in_array(($i + 1), $request->open_24_hours))) || $request->opens[$i])) { if ($schedules) { - $schedules->weekday = $schedules->weekday ? (str_contains($schedules->weekday, $request->weekday[$i]) ? $schedules->weekday : ($schedules->weekday . ',' . $request->weekday[$i])) : $request->weekday[$i]; + $schedules->weekday = $schedules->weekday ? (str_contains($schedules->weekday, $request->weekday[$i]) ? $schedules->weekday : ($schedules->weekday.','.$request->weekday[$i])) : $request->weekday[$i]; $schedules->opens = $request->opens[$i]; $schedules->closes = $request->closes[$i]; if ($request->schedule_closed && in_array(($i + 1), $request->schedule_closed)) { - $schedules->schedule_closed = $schedules->schedule_closed ? (str_contains($schedules->schedule_closed, ($i + 1)) ? $schedules->schedule_closed : $schedules->schedule_closed . ',' . ($i + 1)) : ($i + 1); + $schedules->schedule_closed = $schedules->schedule_closed ? (str_contains($schedules->schedule_closed, ($i + 1)) ? $schedules->schedule_closed : $schedules->schedule_closed.','.($i + 1)) : ($i + 1); // $schedules->open_24_hours = null; } else { if (str_contains($schedules->schedule_closed, ($i + 1))) { @@ -6074,7 +6089,7 @@ public function saveServiceSchedule($request, $service): array if ($request->open_24_hours && in_array(($i + 1), $request->open_24_hours)) { // $schedules->open_24_hours = $i + 1; - $schedules->open_24_hours = $schedules->open_24_hours ? (str_contains($schedules->open_24_hours, ($i + 1)) ? $schedules->open_24_hours : $schedules->open_24_hours . ',' . ($i + 1)) : ($i + 1); + $schedules->open_24_hours = $schedules->open_24_hours ? (str_contains($schedules->open_24_hours, ($i + 1)) ? $schedules->open_24_hours : $schedules->open_24_hours.','.($i + 1)) : ($i + 1); // $schedules->schedule_closed = null; } else { if (str_contains($schedules->open_24_hours, ($i + 1))) { @@ -6098,7 +6113,7 @@ public function saveServiceSchedule($request, $service): array $schedules->opens = $request->opens[$i]; $schedules->closes = $request->closes[$i]; if ($request->schedule_closed && in_array(($i + 1), $request->schedule_closed)) { - $schedules->schedule_closed = $schedules->schedule_closed ? (str_contains($schedules->schedule_closed, ($i + 1)) ? $schedules->schedule_closed : $schedules->schedule_closed . ',' . ($i + 1)) : ($i + 1); + $schedules->schedule_closed = $schedules->schedule_closed ? (str_contains($schedules->schedule_closed, ($i + 1)) ? $schedules->schedule_closed : $schedules->schedule_closed.','.($i + 1)) : ($i + 1); // $schedules->open_24_hours = null; } else { if (str_contains($schedules->schedule_closed, ($i + 1))) { @@ -6111,7 +6126,7 @@ public function saveServiceSchedule($request, $service): array } if ($request->open_24_hours && in_array(($i + 1), $request->open_24_hours)) { // $schedules->open_24_hours = $i + 1; - $schedules->open_24_hours = $schedules->open_24_hours ? (str_contains($schedules->open_24_hours, ($i + 1)) ? $schedules->open_24_hours : $schedules->open_24_hours . ',' . ($i + 1)) : ($i + 1); + $schedules->open_24_hours = $schedules->open_24_hours ? (str_contains($schedules->open_24_hours, ($i + 1)) ? $schedules->open_24_hours : $schedules->open_24_hours.','.($i + 1)) : ($i + 1); // $schedules->schedule_closed = null; } else { if (str_contains($schedules->open_24_hours, ($i + 1))) { @@ -6130,8 +6145,10 @@ public function saveServiceSchedule($request, $service): array } } } + return $schedule_services; } + public function saveServiceProgram($request, $service_recordid) { $servicePrograms = []; @@ -6162,6 +6179,7 @@ public function saveServiceProgram($request, $service_recordid) $program->save(); } } + return $servicePrograms; } } diff --git a/resources/views/frontEnd/organizations/show.blade.php b/resources/views/frontEnd/organizations/show.blade.php index c9adc6b0..20e865c0 100644 --- a/resources/views/frontEnd/organizations/show.blade.php +++ b/resources/views/frontEnd/organizations/show.blade.php @@ -320,7 +320,7 @@ class="float-right"> @endforeach @endif --}} @foreach ($service->getAddresses() as $address) -
  • {{ $address }} {{ $address }}
  • @endforeach @@ -1065,6 +1065,7 @@ class="btn btn-danger btn-lg btn_delete red_btn organizationTagCloseButton">Clos $(document).ready(function() { var locations = ; + console.log(locations,'locations') var organization = organization_name)); ?>; var maplocation = ; diff --git a/resources/views/frontEnd/services/services.blade.php b/resources/views/frontEnd/services/services.blade.php index eb04b6a3..0add70fb 100644 --- a/resources/views/frontEnd/services/services.blade.php +++ b/resources/views/frontEnd/services/services.blade.php @@ -240,13 +240,13 @@ @endif - @if (count($locations) > 0) + @if ($service->locations->count() > 0)
    - @if(isset($locations)) + @if(isset($service->locations))