Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

ConfigureCompanyDefault.php 3.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. namespace App\Listeners;
  3. use App\Enums\Setting\DateFormat;
  4. use App\Enums\Setting\Font;
  5. use App\Enums\Setting\PrimaryColor;
  6. use App\Enums\Setting\RecordsPerPage;
  7. use App\Enums\Setting\TableSortDirection;
  8. use App\Enums\Setting\WeekStart;
  9. use App\Events\CompanyConfigured;
  10. use App\Utilities\Currency\ConfigureCurrencies;
  11. use Filament\Facades\Filament;
  12. use Filament\Forms\Components\DatePicker;
  13. use Filament\Forms\Components\Section;
  14. use Filament\Forms\Components\Tabs\Tab;
  15. use Filament\Resources\Components\Tab as ResourcesTab;
  16. use Filament\Support\Facades\FilamentColor;
  17. use Filament\Tables\Table;
  18. class ConfigureCompanyDefault
  19. {
  20. /**
  21. * Handle the event.
  22. */
  23. public function handle(CompanyConfigured $event): void
  24. {
  25. $company = $event->company;
  26. $paginationPageOptions = RecordsPerPage::caseValues();
  27. $defaultPaginationPageOption = $company->appearance->records_per_page->value ?? RecordsPerPage::DEFAULT;
  28. $defaultSort = $company->appearance->table_sort_direction->value ?? TableSortDirection::DEFAULT;
  29. $defaultPrimaryColor = $company->appearance->primary_color ?? PrimaryColor::from(PrimaryColor::DEFAULT);
  30. $defaultFont = $company->appearance->font->value ?? Font::DEFAULT;
  31. $default_language = $company->locale->language ?? config('transmatic.source_locale');
  32. $defaultTimezone = $company->locale->timezone ?? config('app.timezone');
  33. $dateFormat = $company->locale->date_format->value ?? DateFormat::DEFAULT;
  34. $weekStart = $company->locale->week_start->value ?? WeekStart::DEFAULT;
  35. app()->setLocale($default_language);
  36. locale_set_default($default_language);
  37. config(['app.timezone' => $defaultTimezone]);
  38. date_default_timezone_set($defaultTimezone);
  39. Table::configureUsing(static function (Table $table) use ($paginationPageOptions, $defaultSort, $defaultPaginationPageOption): void {
  40. $table
  41. ->paginationPageOptions($paginationPageOptions)
  42. ->defaultSort(column: 'id', direction: $defaultSort)
  43. ->defaultPaginationPageOption($defaultPaginationPageOption);
  44. }, isImportant: true);
  45. FilamentColor::register([
  46. 'primary' => $defaultPrimaryColor->getColor(),
  47. ]);
  48. Filament::getPanel('company')
  49. ->font($defaultFont)
  50. ->brandName($company->name);
  51. DatePicker::configureUsing(static function (DatePicker $component) use ($dateFormat, $weekStart) {
  52. $component
  53. ->displayFormat($dateFormat)
  54. ->firstDayOfWeek($weekStart);
  55. });
  56. Tab::configureUsing(static function (Tab $tab) {
  57. $label = $tab->getLabel();
  58. $translatedLabel = translate($label);
  59. $tab->label(ucwords($translatedLabel));
  60. }, isImportant: true);
  61. Section::configureUsing(static function (Section $section): void {
  62. $heading = $section->getHeading();
  63. $translatedHeading = translate($heading);
  64. $section->heading(ucfirst($translatedHeading));
  65. }, isImportant: true);
  66. ResourcesTab::configureUsing(static function (ResourcesTab $tab): void {
  67. $tab->localizeLabel();
  68. }, isImportant: true);
  69. ConfigureCurrencies::syncCurrencies();
  70. }
  71. }