Skip to content

Commit

Permalink
Merge pull request #156 from sarapis/feedback-changes
Browse files Browse the repository at this point in the history
timezone and default distance unit
  • Loading branch information
d9it authored Mar 26, 2024
2 parents 454b2c7 + 891b103 commit 6a81468
Show file tree
Hide file tree
Showing 20 changed files with 663 additions and 501 deletions.
2 changes: 1 addition & 1 deletion app/Console/Commands/AutoSync.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public function apply_geocode()
$client = new \GuzzleHttp\Client();
$geocoder = new Geocoder($client);
$map = Map::find(1);
$geocode_api_key = $map && $map->api_key ? $map->api_key : null;
$geocode_api_key = $map && $map->geocode_map_key ? $map->geocode_map_key : null;
$geocoder->setApiKey($geocode_api_key);

if ($ungeocoded_location_info_list) {
Expand Down
19 changes: 9 additions & 10 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@
use App\Model\Alt_taxonomy;
use App\Model\Layout;
use App\Model\Map;
use App\Model\MetaFilter;
use App\Model\Organization;
use App\Model\Page;
use App\Model\Service;
use App\Model\ServiceOrganization;
use App\Model\ServiceTaxonomy;
use App\Model\Taxonomy;
use App\Model\TaxonomyType;
use Illuminate\Http\Request;
Expand Down Expand Up @@ -38,6 +33,7 @@ public function index()
{
return view('home');
}

public function home($value = '')
{
$home = Layout::find(1);
Expand Down Expand Up @@ -73,7 +69,7 @@ public function home($value = '')
} else {
foreach ($grandparent->terms()->where('taxonomy_parent_name', '=', $taxonomy_parent_name)->get() as $child_key => $child_term) {
$child_data['parent_taxonomy'] = $child_term;
$child_data['child_taxonomies'] = "";
$child_data['child_taxonomies'] = '';
$parent_taxonomy[] = $child_data;
}
}
Expand All @@ -83,7 +79,7 @@ public function home($value = '')
}
} else {
$serviceCategoryId = TaxonomyType::orderBy('order')->where('name', 'Service Category')->first();
$parent_taxonomies = Taxonomy::whereNull('taxonomy_parent_name')->whereNotNull('taxonomy_name')->where('taxonomy', 'LIKE', '%' . ($serviceCategoryId ? $serviceCategoryId->taxonomy_type_recordid : '') . '%');
$parent_taxonomies = Taxonomy::whereNull('taxonomy_parent_name')->whereNotNull('taxonomy_name')->where('taxonomy', 'LIKE', '%'.($serviceCategoryId ? $serviceCategoryId->taxonomy_type_recordid : '').'%');
$taxonomy_recordids = Taxonomy::getTaxonomyRecordids();

if (count($taxonomy_recordids) > 0) {
Expand All @@ -93,28 +89,31 @@ public function home($value = '')
$taxonomy_tree['parent_taxonomies'] = $parent_taxonomies->get();
}

if ($layout && $layout->activate_login_home == 1 && !Auth::check()) {
if ($layout && $layout->activate_login_home == 1 && ! Auth::check()) {
return redirect('/login');
} else {
return view('frontEnd.home', compact('home', 'map', 'grandparent_taxonomies', 'layout'))->with('taxonomy_tree', $taxonomy_tree);
}
}

public function dashboard($value = '')
{
$layout = Layout::first();
$page = Page::whereId(6)->first();

return view('backEnd.dashboard', compact('layout', 'page'));
}

public function checkTwillio(Request $request)
{
try {
$sid = $request->get('twillioSid');
$token = $request->get('twillioKey');
$twilio = new Client($sid, $token);

$account = $twilio->api->v2010->accounts("ACd991aaec2fba11620c174e9148e04d7a")
$account = $twilio->api->v2010->accounts('ACd991aaec2fba11620c174e9148e04d7a')
->fetch();

return response()->json([
'message' => 'Your twillio key is verified!',
'success' => true,
Expand All @@ -137,7 +136,7 @@ public function checkSendgrid(Request $request)
$email->setFrom(env('MAIL_FROM_ADDRESS'), 'test');
$email->setSubject('test');
$email->addTo('[email protected]', 'test');
$email->addContent("text/plain", 'test');
$email->addContent('text/plain', 'test');

$sendgrid = new \SendGrid($key);
$response = $sendgrid->send($email);
Expand Down
97 changes: 60 additions & 37 deletions app/Http/Controllers/backend/DataController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
namespace App\Http\Controllers\backend;

use App\Http\Controllers\Controller;
use App\Model\Map;
use App\Model\Source_data;
use App\Model\Address;
use App\Model\Airtablekeyinfo;
use App\Model\Layout;
use App\Model\Map;
use App\Model\Source_data;
use DateTime;
use DateTimeZone;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Session;
Expand Down Expand Up @@ -117,10 +119,8 @@ public function update($id, Request $request)
// exit();
$source_data->active = $request->input('source_data');


$source_data->save();


return redirect('import');
} catch (\Throwable $th) {
return redirect('import');
Expand All @@ -139,11 +139,13 @@ public function destroy($id)

return Redirect::route('admin.posts.index');
}

public function add_country()
{
$countries = DB::table('countries')->pluck('name', 'sortname');
$layout = Layout::find(1);

$zones_array = array();
$zones_array = [];
$timestamp = time();
// $dummy_datetime_object = new DateTime();
foreach (timezone_identifiers_list() as $key => $zone) {
Expand All @@ -153,8 +155,9 @@ public function add_country()

// $tz = new DateTimeZone($zone);
// $zones_array[$key]['offset'] = $tz->getOffset($dummy_datetime_object);
$zones_array[$zone] = ('UTC/GMT ' . date('P', $timestamp)) . ' ' . $zone;
$zones_array[$zone] = ('UTC/GMT '.date('P', $timestamp)).' '.$zone;
}
date_default_timezone_set(($layout->timezone ?? 'UTC'));

// $zones_array = array();
// $timestamp = time();
Expand All @@ -165,55 +168,74 @@ public function add_country()
// // $zones_array[$key]['diff_from_GMT'] = 'UTC/GMT ' . date('P', $timestamp);
// $zones_array[$zone] = ('UTC/GMT ' . date('P', $timestamp)) . ' ' . $zone;
// }
return view('backEnd.settings.add_country', compact('countries', 'zones_array'));
return view('backEnd.settings.add_country', compact('countries', 'zones_array', 'layout'));
}

public function save_country(Request $request)
{
try {
Address::whereNULL('address_country')->update([
'address_country' => $request->country
'address_country' => $request->country,
]);
DB::commit();

$envFile = app()->environmentFilePath();
$str = file_get_contents($envFile);
$values = [
"TIME_ZONE" => $request->get('timezone') ? $request->get('timezone') : 'UTC',
"LOCALIZATION" => $request->get('country') ? $request->get('country') : 'US',
];

if (count($values) > 0) {
foreach ($values as $envKey => $envValue) {

$str .= "\n"; // In case the searched variable is in the last line without \n
$keyPosition = strpos($str, "{$envKey}=");
$endOfLinePosition = strpos($str, "\n", $keyPosition);
$oldLine = substr($str, $keyPosition, $endOfLinePosition - $keyPosition);

// If key does not exist, add it
if (!$keyPosition || !$endOfLinePosition || !$oldLine) {
$str .= "{$envKey}={$envValue}\n";
} else {
$str = str_replace($oldLine, "{$envKey}={$envValue}", $str);
}
$layout = Layout::find(1);
if ($layout) {
$layout->timezone = $request->get('timezone');
$layout->localization = $request->get('country');
$layout->save();

date_default_timezone_set(($layout->timezone ?? 'UTC'));
if ($layout && $layout->timezone) {
Config::set('app.timezone', $layout->timezone);

Artisan::call('cache:clear');
Artisan::call('config:clear');
}
}

$str = substr($str, 0, -1);
if (!file_put_contents($envFile, $str)) {
return false;
}
Artisan::call('config:cache');
Artisan::call('config:clear');
// $envFile = app()->environmentFilePath();
// $str = file_get_contents($envFile);
// $values = [
// "TIME_ZONE" => $request->get('timezone') ? $request->get('timezone') : 'UTC',
// "LOCALIZATION" => $request->get('country') ? $request->get('country') : 'US',
// ];

// if (count($values) > 0) {
// foreach ($values as $envKey => $envValue) {

// $str .= "\n"; // In case the searched variable is in the last line without \n
// $keyPosition = strpos($str, "{$envKey}=");
// $endOfLinePosition = strpos($str, "\n", $keyPosition);
// $oldLine = substr($str, $keyPosition, $endOfLinePosition - $keyPosition);

// // If key does not exist, add it
// if (!$keyPosition || !$endOfLinePosition || !$oldLine) {
// $str .= "{$envKey}={$envValue}\n";
// } else {
// $str = str_replace($oldLine, "{$envKey}={$envValue}", $str);
// }
// }
// }

// $str = substr($str, 0, -1);
// if (!file_put_contents($envFile, $str)) {
// return false;
// }
// Artisan::call('config:cache');
// Artisan::call('config:clear');
Session::flash('message', 'Data saved successfully!');
Session::flash('status', 'success');

return redirect()->back();
} catch (\Throwable $th) {
Session::flash('message', $th->getMessage());
Session::flash('status', 'error');

return redirect()->back();
}
}

public function save_source_data(Request $request)
{
try {
Expand All @@ -222,6 +244,7 @@ public function save_source_data(Request $request)
$source_data->save();
$airtable_api_key_input = $request->airtable_api_key_input;
$airtable_base_url_input = $request->airtable_base_url_input;

// if ($request->source_data == 1) {
// Airtablekeyinfo::whereid(1)->update([
// 'api_key' => $airtable_api_key_input,
Expand All @@ -234,12 +257,12 @@ public function save_source_data(Request $request)
// ]);
// }
return response()->json([
'success' => true
'success' => true,
], 200);
} catch (\Throwable $th) {
return response()->json([
'message' => $th->getMessage(),
'success' => false
'success' => false,
], 500);
}
}
Expand Down
Loading

0 comments on commit 6a81468

Please sign in to comment.