Skip to content

Commit

Permalink
Merge pull request #159 from sarapis/feedback-changes
Browse files Browse the repository at this point in the history
Update organization location
  • Loading branch information
d9it committed Apr 3, 2024
2 parents 1a1e3e3 + 3461c29 commit 97f0d49
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 32 deletions.
14 changes: 4 additions & 10 deletions app/Http/Controllers/frontEnd/OrganizationController.php
Expand Up @@ -60,12 +60,8 @@

class OrganizationController extends Controller
{
public $commonController, $organizationService;

public function __construct(CommonController $commonController, OrganizationService $organizationService)
public function __construct(public CommonController $commonController, public OrganizationService $organizationService)
{
$this->commonController = $commonController;
$this->organizationService = $organizationService;
}

public function airtable($access_token, $base_url)
Expand Down Expand Up @@ -1728,8 +1724,6 @@ public function store(Request $request)
*/
public function show($id)
{
// $organization= Organization::find($id);
// return response()->json($organization);
$organization = Organization::where('organization_recordid', '=', $id)->first();
$organizationStatus = OrganizationStatus::orderBy('order')->pluck('status', 'id');
if ($organization && (Auth::check() || (!Auth::check() && $organization->organization_status_x && isset($organizationStatus[$organization->organization_status_x]) && ($organizationStatus[$organization->organization_status_x] != 'Out of Business' && $organizationStatus[$organization->organization_status_x] != 'Inactive')) || !$organization->organization_status_x)) {
Expand Down Expand Up @@ -1770,9 +1764,9 @@ public function show($id)
// if (count($locationIds) > 0) {
// $location_info_list = array_merge($location_info_list, $locationIds);
// }
if (count($serviceLocationIds) > 0) {
$location_info_list = array_merge($location_info_list, $serviceLocationIds);
}
// if (count($serviceLocationIds) > 0) {
// $location_info_list = array_unique(array_merge($location_info_list, $serviceLocationIds));
// }
$locations = Location::whereIn('location_recordid', $location_info_list)->with('phones', 'address', 'services', 'schedules')->get();
$location_info_list = Location::whereIn('location_recordid', $location_info_list)->with('phones', 'address', 'services', 'schedules')->get();

Expand Down
37 changes: 18 additions & 19 deletions app/Services/LocationService.php
Expand Up @@ -10,30 +10,29 @@

class LocationService
{
function import_airtable_v3(string $access_token, string $base_url)
public function import_airtable_v3(string $access_token, string $base_url)
{
try {
$airtable_key_info = Airtablekeyinfo::find(1);
if (!$airtable_key_info) {
if (! $airtable_key_info) {
$airtable_key_info = new Airtablekeyinfo;
}
$airtable_key_info->access_token = $access_token;
$airtable_key_info->base_url = $base_url;
$airtable_key_info->save();

$airtable = new Airtable(array(
'access_token' => $access_token,
'base' => $base_url,
));
$airtable = new Airtable([
'access_token' => $access_token,
'base' => $base_url,
]);

$request = $airtable->getContent('locations');

do {


$response = $request->getResponse();

$airtable_response = json_decode($response, TRUE);
$airtable_response = json_decode($response, true);

foreach ($airtable_response['records'] as $record) {
$strtointclass = new Stringtoint();
Expand Down Expand Up @@ -64,56 +63,55 @@ function import_airtable_v3(string $access_token, string $base_url)

if (isset($record['fields']['services'])) {
$serviceRecordIds = [];
foreach ($record['fields']['services'] as $value) {
foreach ($record['fields']['services'] as $value) {
$serviceRecordIds[] = $strtointclass->string_to_int($value);
}
$location->location_services = implode(', ', $serviceRecordIds);
}

if (isset($record['fields']['phones'])) {
$phoneRecordIds = [];
foreach ($record['fields']['phones'] as $value) {
foreach ($record['fields']['phones'] as $value) {
$phoneRecordIds[] = $strtointclass->string_to_int($value);
}
$location->phones()->sync($phoneRecordIds);
}

if (isset($record['fields']['schedules'])) {
$scheduleRecordIds = [];
foreach ($record['fields']['schedules'] as $value) {
foreach ($record['fields']['schedules'] as $value) {
$scheduleRecordIds[] = $strtointclass->string_to_int($value);
}
$location->schedules()->sync($scheduleRecordIds);
}


if (isset($record['fields']['addresses'])) {
$addressRecordIds = [];
foreach ($record['fields']['addresses'] as $value) {
foreach ($record['fields']['addresses'] as $value) {
$addressRecordIds[] = $strtointclass->string_to_int($value);
}
$location->address()->sync($addressRecordIds);
}

if (isset($record['fields']['languages'])) {
$languageRecordIds = [];
foreach ($record['fields']['languages'] as $value) {
foreach ($record['fields']['languages'] as $value) {
$languageRecordIds[] = $strtointclass->string_to_int($value);
}
$location->languages()->sync($languageRecordIds);
}

if (isset($record['fields']['accessibility'])) {
$accessebilityRecordIds = [];
foreach ($record['fields']['accessibility'] as $value) {
foreach ($record['fields']['accessibility'] as $value) {
$accessebilityRecordIds[] = $strtointclass->string_to_int($value);
}
$location->accessibilities()->sync($accessebilityRecordIds);
}

if (isset($record['fields']['location_type'])) {
$locationTypes = [];
foreach ($record['fields']['location_type'] as $value) {
foreach ($record['fields']['location_type'] as $value) {
$locationTypes[] = $strtointclass->string_to_int($value);
}
$location->location_type = implode(', ', $locationTypes);
Expand All @@ -124,17 +122,18 @@ function import_airtable_v3(string $access_token, string $base_url)
}
} while ($request = $response->next());

$date = date("Y/m/d H:i:s");
$date = date('Y/m/d H:i:s');
$airtable = Airtable_v2::where('name', '=', 'Locations')->first();
$airtable->records = Location::count();
$airtable->syncdate = $date;
$airtable->save();
} catch (\Throwable $th) {
dd($th);
Log::error('Error in location: ' . $th->getMessage());
Log::error('Error in location: '.$th->getMessage());

return response()->json([
'message' => $th->getMessage(),
'success' => false
'success' => false,
], 500);
}
}
Expand Down
4 changes: 1 addition & 3 deletions resources/views/frontEnd/organizations/show.blade.php
Expand Up @@ -1113,11 +1113,9 @@ class="btn btn-danger btn-lg btn_delete red_btn organizationTagCloseButton">Clos
var content = '<div id="iw-container">';
for (i = 0; i < location.services.length; i++) {
content += '<div class="iw-title"> <a href="/services/' + location.services[i]
.service_recordid + '">' + location.services[i].service_name + '</a></div>';
content += '<div class="iw-title"> <a href="/services/' + location.services[i].service_recordid + '">' + location.services[i].service_name + '</a></div>';
}
// '<div class="iw-title"> <a href="/services/'+ location.service_recordid +'">' + location.service_name + '</a> </div>' +
content += '<div class="iw-content">' +
'<div class="iw-subTitle">Organization Name</div>' +
'<a href="/organizations/' + location.organization_recordid + '">' + location
Expand Down

0 comments on commit 97f0d49

Please sign in to comment.