diff --git a/config/config.default.php b/config/config.default.php index df2c225c..55982230 100644 --- a/config/config.default.php +++ b/config/config.default.php @@ -323,6 +323,9 @@ return [ 'voucher_start' => env('VOUCHER_START', null) ?: null, ], + # Instruction in accordance with § 43 Para. 1 of the German Infection Protection Act (IfSG) + 'ifsg_enabled' => (bool) env('IFSG_ENABLED', false), + // Available locales in /resources/lang/ 'locales' => [ 'de_DE' => 'Deutsch', diff --git a/config/routes.php b/config/routes.php index 96d32c9f..831c137a 100644 --- a/config/routes.php +++ b/config/routes.php @@ -38,6 +38,8 @@ $route->addGroup( $route->post('/theme', 'SettingsController@saveTheme'); $route->get('/language', 'SettingsController@language'); $route->post('/language', 'SettingsController@saveLanguage'); + $route->get('/certificates', 'SettingsController@ifsgCertificate'); + $route->post('/certificates', 'SettingsController@saveIfsgCertificate'); $route->get('/oauth', 'SettingsController@oauth'); } ); diff --git a/db/migrations/2023_08_07_000000_add_ifsg_cerificates_to_users_licenses.php b/db/migrations/2023_08_07_000000_add_ifsg_cerificates_to_users_licenses.php new file mode 100644 index 00000000..067c51c8 --- /dev/null +++ b/db/migrations/2023_08_07_000000_add_ifsg_cerificates_to_users_licenses.php @@ -0,0 +1,35 @@ +schema->table('users_licenses', function (Blueprint $table): void { + $table->boolean('ifsg_certificate')->default(false)->after('drive_12t'); + $table->boolean('ifsg_certificate_full')->default(false)->after('ifsg_certificate'); + }); + } + + /** + * Reverse the migration + */ + public function down(): void + { + $this->schema->table('users_licenses', function (Blueprint $table): void { + $table->dropColumn('ifsg_certificate'); + $table->dropColumn('ifsg_certificate_full'); + }); + } +} diff --git a/resources/lang/de_DE/default.po b/resources/lang/de_DE/default.po index 0090e7d4..96c0aa79 100644 --- a/resources/lang/de_DE/default.po +++ b/resources/lang/de_DE/default.po @@ -2207,6 +2207,21 @@ msgstr "Hier kannst Du Dein Theme ändern." msgid "settings.theme.success" msgstr "Theme wurde erfolgreich geändert." +msgid settings.certificates +msgstr "Zertifikate" + +msgid settings.certificates.info +msgstr "Hier kannst du deine gemachte Gesundheitsbelehrung eintragen" + +msgid settings.ifsg +msgstr "Kleines Frikadellendiplom ()" + +msgid settings.ifsg_full +msgstr "Großes Frikadellendiplom ()" + +msgid settings.certificates.success +msgstr "Gesundheitsbelehrung wurde erfolgreich geändert." + msgid "settings.language" msgstr "Sprache" diff --git a/resources/lang/en_US/default.po b/resources/lang/en_US/default.po index 0858f159..c18ba7ca 100644 --- a/resources/lang/en_US/default.po +++ b/resources/lang/en_US/default.po @@ -308,6 +308,18 @@ msgstr "Here you can change your theme." msgid "settings.theme.success" msgstr "Theme was changed successfully." +msgid settings.certificates +msgstr "Certificates" + +msgid settings.certificates.info + +msgid settings.ifsg + +msgid settings.ifsg_full + +msgid settings.certificates.success +msgstr "IfSG certificate was changed successfully." + msgid "settings.language" msgstr "Language" diff --git a/resources/views/pages/settings/certificates.twig b/resources/views/pages/settings/certificates.twig new file mode 100644 index 00000000..c7075361 --- /dev/null +++ b/resources/views/pages/settings/certificates.twig @@ -0,0 +1,24 @@ +{% extends 'pages/settings/settings.twig' %} +{% import 'macros/form.twig' as f %} +{% import 'macros/base.twig' as m %} + +{% block title %}{{ __('settings.certificates') }}{% endblock %} + +{% block row_content %} +
+{% endblock %} \ No newline at end of file diff --git a/src/Controllers/Metrics/Controller.php b/src/Controllers/Metrics/Controller.php index 78a86fb5..4962d12f 100644 --- a/src/Controllers/Metrics/Controller.php +++ b/src/Controllers/Metrics/Controller.php @@ -83,6 +83,8 @@ class Controller extends BaseController ['labels' => ['type' => '3.5t'], 'value' => $this->stats->licenses('3.5t')], ['labels' => ['type' => '7.5t'], 'value' => $this->stats->licenses('7.5t')], ['labels' => ['type' => '12t'], 'value' => $this->stats->licenses('12t')], + ['labels' => ['type' => 'ifsg'], 'value' => $this->stats->licenses('ifsg')], + ['labels' => ['type' => 'ifsg_full'], 'value' => $this->stats->licenses('ifsg_full')], ], 'users_email' => [ 'type' => 'gauge', diff --git a/src/Controllers/Metrics/Stats.php b/src/Controllers/Metrics/Stats.php index e412c28e..7343f37b 100644 --- a/src/Controllers/Metrics/Stats.php +++ b/src/Controllers/Metrics/Stats.php @@ -174,20 +174,22 @@ class Stats ->get(); } - public function licenses(string $vehicle): int + public function licenses(string $lisence): int { $mapping = [ - 'has_car' => 'has_car', - 'forklift' => 'drive_forklift', - 'car' => 'drive_car', - '3.5t' => 'drive_3_5t', - '7.5t' => 'drive_7_5t', - '12t' => 'drive_12t', + 'has_car' => 'has_car', + 'forklift' => 'drive_forklift', + 'car' => 'drive_car', + '3.5t' => 'drive_3_5t', + '7.5t' => 'drive_7_5t', + '12t' => 'drive_12t', + 'ifsg' => 'ifsg_certificate', + 'ifsg_full' => 'ifsg_certificate_full', ]; $query = (new License()) ->getQuery() - ->where($mapping[$vehicle], true); + ->where($mapping[$lisence], true); return $query->count(); } diff --git a/src/Controllers/SettingsController.php b/src/Controllers/SettingsController.php index 3c9dd5bb..33de0f28 100644 --- a/src/Controllers/SettingsController.php +++ b/src/Controllers/SettingsController.php @@ -222,6 +222,43 @@ class SettingsController extends BaseController return $this->redirect->to('/settings/language'); } + public function ifsgCertificate(): Response + { + $user = $this->auth->user(); + if (config('ifsg_enabled')) { + throw new HttpNotFound('ifsg.disabled'); + } + return $this->response->withView( + 'pages/settings/certificates', + [ + 'settings_menu' => $this->settingsMenu(), + 'ifsg_certificate' => $user->license->ifsg_certificate, + 'ifsg_certificate_full' => $user->license->ifsg_certificate_full, + ] + ); + } + + public function saveIfsgCertificate(Request $request): Response + { + $user = $this->auth->user(); + $data = $this->validate($request, [ + 'ifsg_certificate' => 'optional|checked', + 'ifsg_certificate_full' => 'optional|checked' + ]); + + if (config('ifsg_enabled')) { + throw new HttpNotFound('ifsg.disabled'); + } + + $user->license->ifsg_certificate = $data['ifsg_certificate'] || $data['ifsg_certificate_full']; + $user->license->ifsg_certificate_full = (bool)$data['ifsg_certificate_full']; + $user->license->save(); + + $this->addNotification('settings.certificates.success'); + + return $this->redirect->to('/settings/certificates'); + } + public function oauth(): Response { $providers = $this->config->get('oauth'); @@ -253,6 +290,10 @@ class SettingsController extends BaseController $menu[url('/settings/theme')] = 'settings.theme'; } + if (!config('ifsg_disable')) { + $menu[url('/settings/certificates')] = 'settings.certificates'; + } + if (!empty(config('oauth'))) { $menu[url('/settings/oauth')] = ['title' => 'settings.oauth', 'hidden' => $this->checkOauthHidden()]; } diff --git a/src/Models/User/License.php b/src/Models/User/License.php index c628dca2..6c77a602 100644 --- a/src/Models/User/License.php +++ b/src/Models/User/License.php @@ -31,12 +31,14 @@ class License extends HasUserModel /** @var array Default attributes */ protected $attributes = [ // phpcs:ignore - 'has_car' => false, - 'drive_forklift' => false, - 'drive_car' => false, - 'drive_3_5t' => false, - 'drive_7_5t' => false, - 'drive_12t' => false, + 'has_car' => false, + 'drive_forklift' => false, + 'drive_car' => false, + 'drive_3_5t' => false, + 'drive_7_5t' => false, + 'drive_12t' => false, + 'ifsg_certificate' => false, + 'ifsg_certificate_full' => false, ]; /** @@ -52,16 +54,20 @@ class License extends HasUserModel 'drive_3_5t', 'drive_7_5t', 'drive_12t', + 'ifsg_certificate', + 'ifsg_certificate_full', ]; /** @var array