miscellaneous updates

This commit is contained in:
2025-01-26 23:14:28 -06:00
parent 493413ec97
commit cff8101088
28 changed files with 734 additions and 474 deletions

View File

@ -3,6 +3,7 @@
namespace App\Services;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Schema;
use Modules\Admin\App\Models\Setting;
class WebsiteTemplateService
@ -25,9 +26,14 @@ class WebsiteTemplateService
/**
* Obtiene las variables del sitio web desde el caché o la base de datos.
*/
public function getWebsiteVars(String $setting = ''): array
public function getWebsiteVars(string $setting = ''): array
{
try {
// Verifica si la base de datos está inicializada
if (!Schema::hasTable('migrations')) {
return $this->getDefaultWebsiteVars($setting);
}
$webVars = Cache::remember('website_settings', $this->cacheTTL, function () {
$settings = Setting::global()
->where(function ($query) {
@ -38,31 +44,58 @@ class WebsiteTemplateService
->pluck('value', 'key')
->toArray();
return [
'title' => $settings['website_title'] ?? config('_var.appTitle'),
'author' => config('_var.author'),
'description' => $settings['website_description'] ?? config('_var.appDescription'),
'favicon' => $this->getFaviconPaths($settings),
'app_name' => $settings['website_app_name'] ?? config('_var.appName'),
'image_logo' => $this->getImageLogoPaths($settings),
'template' => $this->getTemplateVars($settings),
'google' => $this->getGoogleVars($settings),
'chat' => $this->getChatVars($settings),
'contact' => $this->getContactVars(),
'social' => $this->getSocialVars(),
];
return $this->buildWebsiteVars($settings);
});
return $setting
? $webVars[$setting]
: $webVars;
return $setting ? ($webVars[$setting] ?? []) : $webVars;
} catch (\Exception $e) {
echo __METHOD__;
echo "<br>" . $e->getMessage() . "<br><br>";
die('You must configure the database.');
// Manejo de excepciones: devolver valores predeterminados
return $this->getDefaultWebsiteVars($setting);
}
}
/**
* Construye las variables del sitio web.
*/
private function buildWebsiteVars(array $settings): array
{
return [
'title' => $settings['website_title'] ?? config('_var.appTitle'),
'author' => config('_var.author'),
'description' => $settings['website_description'] ?? config('_var.appDescription'),
'favicon' => $this->getFaviconPaths($settings),
'app_name' => $settings['website_app_name'] ?? config('_var.appName'),
'image_logo' => $this->getImageLogoPaths($settings),
'template' => $this->getTemplateVars($settings),
'google' => $this->getGoogleVars($settings),
'chat' => $this->getChatVars($settings),
'contact' => $this->getContactVars(),
'social' => $this->getSocialVars(),
];
}
/**
* Devuelve las variables predeterminadas del sitio web.
*/
private function getDefaultWebsiteVars(string $setting = ''): array
{
$defaultVars = [
'title' => config('_var.appTitle', 'Default Title'),
'author' => config('_var.author', 'Default Author'),
'description' => config('_var.appDescription', 'Default Description'),
'favicon' => $this->getFaviconPaths([]),
'app_name' => config('_var.appName', 'Default App Name'),
'image_logo' => $this->getImageLogoPaths([]),
'template' => $this->getTemplateVars([]),
'google' => $this->getGoogleVars([]),
'chat' => $this->getChatVars([]),
'contact' => [],
'social' => [],
];
return $setting ? ($defaultVars[$setting] ?? []) : $defaultVars;
}
/**
* Obtiene los paths de favicon en distintos tamaños.
*/
@ -269,4 +302,4 @@ class WebsiteTemplateService
? $legalDocuments[$legalDocument]
: $legalDocuments;
}
}
}