diff --git a/config/config.default.php b/config/config.default.php
index b1aff882..b066a611 100644
--- a/config/config.default.php
+++ b/config/config.default.php
@@ -275,14 +275,11 @@ return [
// Enables the planned arrival/leave date
'enable_planned_arrival' => (bool) env('ENABLE_PLANNED_ARRIVAL', true),
- // Enables the T-Shirt configuration on signup and profile
- 'enable_tshirt_size' => (bool) env('ENABLE_TSHIRT_SIZE', true),
-
- // When true changes everything from shirts to goodies and disables shirt size
- 'other_goodie' => (bool) env('OTHER_GOODIE', false),
-
- // Enables the goody configuration on signup and profile
- 'enable_goody' => (bool) env('ENABLE_GOODY', false),
+ // Resembles the Goodie Type. There are three options:
+ // 'none' => no goodie at all
+ // 'goodie' => a goodie which has no sizing options
+ // 'tshirt' => goodie that is called tshirt and has sizing options
+ 'goodie_type' => env('GOODIE_TYPE', 'goodie'),
// Enables the food voucher in the user profile
'enable_voucher' => (bool) env('ENABLE_VOUCHER', true),
diff --git a/config/routes.php b/config/routes.php
index 771509dc..96d32c9f 100644
--- a/config/routes.php
+++ b/config/routes.php
@@ -174,7 +174,7 @@ $route->addGroup(
function (RouteCollector $route): void {
// Shirts
$route->addGroup(
- '/shirt',
+ '/goodie',
function (RouteCollector $route): void {
$route->get('', 'Admin\\UserShirtController@editShirt');
$route->post('', 'Admin\\UserShirtController@saveShirt');
diff --git a/db/migrations/2023_02_28_000000_rename_shirt_manager.php b/db/migrations/2023_02_28_000000_rename_shirt_manager.php
new file mode 100644
index 00000000..d5ef7dee
--- /dev/null
+++ b/db/migrations/2023_02_28_000000_rename_shirt_manager.php
@@ -0,0 +1,32 @@
+schema->getConnection();
+ $db->table('groups')
+ ->where('name', 'Shirt Manager')
+ ->update(['name' => 'Goodie Manager']);
+ }
+
+ /**
+ * Reverse the migration
+ */
+ public function down(): void
+ {
+ $db = $this->schema->getConnection();
+ $db->table('groups')
+ ->where('name', 'Goodie Manager')
+ ->update(['name' => 'Shirt Manager']);
+ }
+}
diff --git a/includes/pages/admin_active.php b/includes/pages/admin_active.php
index 2eb6d1de..8e387496 100644
--- a/includes/pages/admin_active.php
+++ b/includes/pages/admin_active.php
@@ -5,6 +5,7 @@ use Engelsystem\Models\User\State;
use Engelsystem\Models\User\User;
use Illuminate\Database\Query\Builder;
use Illuminate\Database\Query\JoinClause;
+use Engelsystem\Config\GoodieType;
/**
* @return string
@@ -22,7 +23,9 @@ function admin_active()
$tshirt_sizes = config('tshirt_sizes');
$shift_sum_formula = User_get_shifts_sum_query();
$request = request();
- $other_goodie = config('other_goodie');
+ $goodie = GoodieType::from(config('goodie_type'));
+ $goodie_enabled = $goodie !== GoodieType::None;
+ $goodie_tshirt = $goodie === GoodieType::Tshirt;
$msg = '';
$search = '';
@@ -130,7 +133,7 @@ function admin_active()
$user_source->state->got_shirt = true;
$user_source->state->save();
engelsystem_log('User ' . User_Nick_render($user_source, true) . ' has tshirt now.');
- $msg = success(($other_goodie ? __('Angel has got a goodie.') : __('Angel has got a t-shirt.')), true);
+ $msg = success(($goodie_tshirt ? __('Angel has got a t-shirt.') : __('Angel has got a goodie.')), true);
} else {
$msg = error('Angel not found.', true);
}
@@ -141,7 +144,7 @@ function admin_active()
$user_source->state->got_shirt = false;
$user_source->state->save();
engelsystem_log('User ' . User_Nick_render($user_source, true) . ' has NO tshirt.');
- $msg = success(($other_goodie ? __('Angel has got no goodie.') : __('Angel has got no t-shirt.')), true);
+ $msg = success(($goodie_tshirt ? __('Angel has got no t-shirt.') : __('Angel has got no goodie.')), true);
} else {
$msg = error(__('Angel not found.'), true);
}
@@ -213,7 +216,7 @@ function admin_active()
$userData = [];
$userData['no'] = count($matched_users) + 1;
$userData['nick'] = User_Nick_render($usr) . User_Pronoun_render($usr);
- if (!$other_goodie) {
+ if ($goodie_tshirt) {
$userData['shirt_size'] = (isset($tshirt_sizes[$shirtSize]) ? $tshirt_sizes[$shirtSize] : '');
}
$userData['work_time'] = round($usr['shift_length'] / 60)
@@ -262,12 +265,15 @@ function admin_active()
if ($show_all_shifts) {
$parametersShirt['show_all_shifts'] = 1;
}
- $actions[] = form(
- [form_submit('submit', ($other_goodie ? __('got goodie') : __('got t-shirt')), 'btn-sm', false, 'secondary')],
- page_link_to('admin_active', $parametersShirt),
- false,
- true
- );
+
+ if ($goodie_enabled) {
+ $actions[] = form(
+ [form_submit('submit', ($goodie_tshirt ? __('got t-shirt') : __('got goodie')), 'btn-sm', false, 'secondary')],
+ page_link_to('admin_active', $parametersShirt),
+ false,
+ true
+ );
+ }
}
if ($usr->state->got_shirt) {
$parameters = [
@@ -277,16 +283,19 @@ function admin_active()
if ($show_all_shifts) {
$parameters['show_all_shifts'] = 1;
}
- $actions[] = form(
- [form_submit('submit', ($other_goodie ? __('remove goodie') : __('remove t-shirt')), 'btn-sm', false, 'secondary')],
- page_link_to('admin_active', $parameters),
- false,
- true
- );
+
+ if ($goodie_enabled) {
+ $actions[] = form(
+ [form_submit('submit', ($goodie_tshirt ? __('remove t-shirt') : __('remove goodie')), 'btn-sm', false, 'secondary')],
+ page_link_to('admin_active', $parameters),
+ false,
+ true
+ );
+ }
}
- if (!$other_goodie) {
- $actions[] = button(url('/admin/user/' . $usr->id . '/shirt'), __('form.edit'), 'btn-secondary btn-sm');
+ if ($goodie_tshirt) {
+ $actions[] = button(url('/admin/user/' . $usr->id . '/goodie'), __('form.edit'), 'btn-secondary btn-sm');
}
$userData['actions'] = buttons($actions);
@@ -294,8 +303,8 @@ function admin_active()
$matched_users[] = $userData;
}
- $shirt_statistics = [];
- if (!$other_goodie) {
+ $goodie_statistics = [];
+ if ($goodie_tshirt) {
foreach (array_keys($tshirt_sizes) as $size) {
$gc = State::query()
->leftJoin('users_settings', 'users_state.user_id', '=', 'users_settings.user_id')
@@ -303,15 +312,15 @@ function admin_active()
->where('users_state.got_shirt', '=', true)
->where('users_personal_data.shirt_size', '=', $size)
->count();
- $shirt_statistics[] = [
+ $goodie_statistics[] = [
'size' => $size,
'given' => $gc,
];
}
}
- $shirt_statistics[] = array_merge(
- (!$other_goodie ? ['size' => '' . __('Sum') . ' '] : []),
+ $goodie_statistics[] = array_merge(
+ ($goodie_tshirt ? ['size' => '' . __('Sum') . ' '] : []),
['given' => '' . State::whereGotShirt(true)->count() . ' ']
);
@@ -332,22 +341,24 @@ function admin_active()
'no' => __('No.'),
'nick' => __('Nickname'),
],
- (!$other_goodie ? ['shirt_size' => __('Size')] : []),
+ ($goodie_tshirt ? ['shirt_size' => __('Size')] : []),
[
'shift_count' => __('Shifts'),
'work_time' => __('Length'),
'active' => __('Active?'),
'force_active' => __('Forced'),
- 'tshirt' => ($other_goodie ? __('Goodie?') : __('T-shirt?')),
+ ],
+ ($goodie_enabled ? ['tshirt' => ($goodie_tshirt ? __('T-shirt?') : __('Goodie?'))] : []),
+ [
'actions' => '',
]
),
$matched_users
),
- '
' . ($other_goodie ? __('Goodie statistic') : __('Shirt statistic')) . ' ',
- table(array_merge(
- (!$other_goodie ? ['size' => __('Size')] : []),
- ['given' => $other_goodie ? __('Given goodies') : __('Given shirts') ]
- ), $shirt_statistics),
+ $goodie_enabled ? '' . ($goodie_tshirt ? __('Shirt statistic') : __('Goodie statistic')) . ' ' : '',
+ $goodie_enabled ? table(array_merge(
+ ($goodie_tshirt ? ['size' => __('Size')] : []),
+ ['given' => $goodie_tshirt ? __('Given shirts') : __('Given goodies') ]
+ ), $goodie_statistics) : '',
]);
}
diff --git a/includes/pages/admin_user.php b/includes/pages/admin_user.php
index b30115e4..c1eff2f8 100644
--- a/includes/pages/admin_user.php
+++ b/includes/pages/admin_user.php
@@ -1,5 +1,6 @@
has('id')) {
throw_redirect(users_link());
@@ -36,11 +40,11 @@ function admin_user()
}
$html .= __('Here you can change the user entry. Under the item \'Arrived\' the angel is marked as present, a yes at Active means that the angel was active.');
- if (config('enable_tshirt_size')) {
- if (config('other_goodie')) {
- $html .= ' ' . __('If the angel is active, it can claim a goodie. If goodie is set to \'Yes\', the angel already got their goodie.');
- } else {
+ if ($goodie_enabled) {
+ if ($goodie_tshirt) {
$html .= ' ' . __('If the angel is active, it can claim a T-shirt. If T-shirt is set to \'Yes\', the angel already got their T-shirt.');
+ } else {
+ $html .= ' ' . __('If the angel is active, it can claim a goodie. If goodie is set to \'Yes\', the angel already got their goodie.');
}
}
$html .= ' ';
@@ -67,7 +71,7 @@ function admin_user()
if ($user_source->settings->email_human) {
$html .= ' ' . __('settings.profile.email') . ' ' . ' ' . "\n";
}
- if (config('enable_tshirt_size') && !config('other_goodie')) {
+ if ($goodie_tshirt) {
$html .= ' ' . __('user.shirt_size') . ' '
. html_select_key(
'size',
@@ -103,12 +107,12 @@ function admin_user()
$html .= html_options('force_active', $options, $user_source->state->force_active) . ' ' . "\n";
}
- if (config('enable_tshirt_size')) {
+ if ($goodie_enabled) {
// T-Shirt bekommen?
- if (config('other_goodie')) {
- $html .= ' ' . __('Goodie') . ' ' . "\n";
- } else {
+ if ($goodie_tshirt) {
$html .= ' ' . __('T-Shirt') . ' ' . "\n";
+ } else {
+ $html .= ' ' . __('Goodie') . ' ' . "\n";
}
$html .= html_options('eTshirt', $options, $user_source->state->got_shirt) . ' ' . "\n";
}
@@ -250,7 +254,7 @@ function admin_user()
$user_source->personalData->first_name = $request->postData('eVorname');
$user_source->personalData->last_name = $request->postData('eName');
}
- if (config('enable_tshirt_size') && !config('other_goodie')) {
+ if ($goodie_tshirt) {
$user_source->personalData->shirt_size = $request->postData('eSize');
}
$user_source->personalData->save();
@@ -259,7 +263,7 @@ function admin_user()
$user_source->contact->dect = $request->postData('eDECT');
$user_source->contact->save();
- if (config('enable_tshirt_size')) {
+ if ($goodie_enabled) {
$user_source->state->got_shirt = $request->postData('eTshirt');
}
$user_source->state->active = $request->postData('eAktiv');
@@ -268,10 +272,10 @@ function admin_user()
engelsystem_log(
'Updated user: ' . $user_source->name . ' (' . $user_source->id . ')'
- . (config('other_goodie') ? '' : ', t-shirt: ' . $user_source->personalData->shirt_size)
+ . ($goodie_tshirt ? ', t-shirt: ' : '' . $user_source->personalData->shirt_size)
. ', active: ' . $user_source->state->active
. ', force-active: ' . $user_source->state->force_active
- . (config('other_goodie') ? ', goodie: ' : ', tshirt: ' . $user_source->state->got_shirt)
+ . ($goodie_tshirt ? ', tshirt: ' : ', goodie: ' . $user_source->state->got_shirt)
);
$html .= success(__('Changes where saved.') . "\n", true);
break;
diff --git a/includes/pages/guest_login.php b/includes/pages/guest_login.php
index 5fe470ea..a798f427 100644
--- a/includes/pages/guest_login.php
+++ b/includes/pages/guest_login.php
@@ -3,6 +3,7 @@
use Carbon\Carbon;
use Engelsystem\Database\Database;
use Engelsystem\Events\Listener\OAuth2;
+use Engelsystem\Config\GoodieType;
use Engelsystem\Models\AngelType;
use Engelsystem\Models\Group;
use Engelsystem\Models\OAuth;
@@ -30,8 +31,9 @@ function guest_register()
{
$authUser = auth()->user();
$tshirt_sizes = config('tshirt_sizes');
- $enable_tshirt_size = config('enable_tshirt_size');
- $other_goodie = config('other_goodie');
+ $goodie = GoodieType::from(config('goodie_type'));
+ $goodie_enabled = $goodie !== GoodieType::None;
+ $goodie_tshirt = $goodie === GoodieType::Tshirt;
$enable_user_name = config('enable_user_name');
$enable_dect = config('enable_dect');
$enable_planned_arrival = config('enable_planned_arrival');
@@ -168,7 +170,7 @@ function guest_register()
$email_goody = true;
}
- if ($enable_tshirt_size && !$other_goodie) {
+ if ($goodie_tshirt) {
if ($request->has('tshirt_size') && isset($tshirt_sizes[$request->input('tshirt_size')])) {
$tshirt_size = $request->input('tshirt_size');
} else {
@@ -450,7 +452,7 @@ function guest_register()
__('Allow heaven angels to contact you by e-mail.'),
$email_by_human_allowed
),
- config('enable_goody') ?
+ $goodie_enabled ?
form_checkbox(
'email_goody',
__('To receive vouchers, give consent that nick, email address, worked hours and shirt size will be stored until the next similar event.')
@@ -495,7 +497,7 @@ function guest_register()
]) : '',
div('col', [
- $enable_tshirt_size && !$other_goodie ? form_select(
+ $goodie_tshirt ? form_select(
'tshirt_size',
__('Shirt size') . ' ' . entry_required(),
$tshirt_sizes,
diff --git a/includes/view/User_view.php b/includes/view/User_view.php
index 64d67b8e..ad286612 100644
--- a/includes/view/User_view.php
+++ b/includes/view/User_view.php
@@ -1,6 +1,7 @@
getAttribute('freeloads');
$u['active'] = icon_bool($user->state->active);
$u['force_active'] = icon_bool($user->state->force_active);
- if (config('enable_tshirt_size')) {
+ if ($goodie_enabled) {
$u['got_shirt'] = icon_bool($user->state->got_shirt);
- if (!config('other_goodie')) {
+ if ($goodie_tshirt) {
$u['shirt_size'] = $user->personalData->shirt_size;
}
}
@@ -142,16 +146,14 @@ function Users_view(
$user_table_headers['freeloads'] = Users_table_header_link('freeloads', __('Freeloads'), $order_by);
$user_table_headers['active'] = Users_table_header_link('active', __('Active'), $order_by);
$user_table_headers['force_active'] = Users_table_header_link('force_active', __('Forced'), $order_by);
- if (config('enable_tshirt_size')) {
- if (config('other_goodie')) {
- $user_table_headers['got_shirt'] = Users_table_header_link('got_shirt', __('Goodie'), $order_by);
- } else {
+ if ($goodie_enabled) {
+ if ($goodie_tshirt) {
$user_table_headers['got_shirt'] = Users_table_header_link('got_shirt', __('T-Shirt'), $order_by);
+ $user_table_headers['shirt_size'] = Users_table_header_link('shirt_size', __('Size'), $order_by);
+ } else {
+ $user_table_headers['got_shirt'] = Users_table_header_link('got_shirt', __('Goodie'), $order_by);
}
}
- if (config('enable_tshirt_size') && !config('other_goodie')) {
- $user_table_headers['shirt_size'] = Users_table_header_link('shirt_size', __('Size'), $order_by);
- }
$user_table_headers['arrival_date'] = Users_table_header_link(
'planned_arrival_date',
__('Planned arrival'),
@@ -376,6 +378,9 @@ function User_view_myshifts(
$user_worklogs,
$admin_user_worklog_privilege
) {
+ $goodie = GoodieType::from(config('goodie_type'));
+ $goodie_enabled = $goodie !== GoodieType::None;
+ $goodie_tshirt = $goodie === GoodieType::Tshirt;
$myshifts_table = [];
$timeSum = 0;
foreach ($shifts as $shift) {
@@ -405,9 +410,9 @@ function User_view_myshifts(
'comment' => '',
'actions' => '',
];
- if (config('enable_tshirt_size', false) && ($its_me || $tshirt_admin)) {
+ if ($goodie_enabled && ($its_me || $tshirt_admin)) {
$myshifts_table[] = [
- 'date' => '' . (config('other_goodie') ? __('Your goodie score') : __('Your t-shirt score')) . '™: ',
+ 'date' => '' . ($goodie_tshirt ? __('Your t-shirt score') : __('Your goodie score')) . '™: ',
'duration' => '' . $tshirt_score . ' ',
'room' => '',
'shift_info' => '',
@@ -489,6 +494,9 @@ function User_view(
$admin_user_worklog_privilege,
$user_worklogs
) {
+ $goodie = GoodieType::from(config('goodie_type'));
+ $goodie_enabled = $goodie !== GoodieType::None;
+ $goodie_tshirt = $goodie === GoodieType::Tshirt;
$auth = auth();
$nightShiftsConfig = config('night_shifts');
$user_name = htmlspecialchars(
@@ -538,9 +546,9 @@ function User_view(
div('row', [
div('col-md-12', [
buttons([
- $auth->can('user.edit.shirt') && (config('enable_tshirt_size')) ? button(
- url('/admin/user/' . $user_source->id . '/shirt'),
- icon('person') . (config('other_goodie') ? __('Goodie') : __('Shirt'))
+ $auth->can('user.edit.shirt') && $goodie_enabled ? button(
+ url('/admin/user/' . $user_source->id . '/goodie'),
+ icon('person') . ($goodie_tshirt ? __('Shirt') : __('Goodie'))
) : '',
$admin_user_privilege ? button(
page_link_to('admin_user', ['id' => $user_source->id]),
@@ -627,7 +635,7 @@ function User_view(
]),
($its_me || $admin_user_privilege) ? '' . __('Shifts') . ' ' : '',
$myshifts_table,
- ($its_me && $nightShiftsConfig['enabled'] && config('enable_tshirt_size')) ? info(
+ ($its_me && $nightShiftsConfig['enabled'] && $goodie_enabled) ? info(
icon('info-circle') . sprintf(
__('Your night shifts between %d and %d am count twice.'),
$nightShiftsConfig['start'],
@@ -700,6 +708,9 @@ function User_view_state_user($user_source)
function User_view_state_admin($freeloader, $user_source)
{
$state = [];
+ $goodie = GoodieType::from(config('goodie_type'));
+ $goodie_enabled = $goodie !== GoodieType::None;
+ $goodie_tshirt = $goodie === GoodieType::Tshirt;
if ($freeloader) {
$state[] = '' . icon('exclamation-circle') . __('Freeloader') . ' ';
@@ -720,8 +731,8 @@ function User_view_state_admin($freeloader, $user_source)
} elseif ($user_source->state->active) {
$state[] = '' . __('Active') . ' ';
}
- if ($user_source->state->got_shirt) {
- $state[] = '' . __('T-Shirt') . ' ';
+ if ($user_source->state->got_shirt && $goodie_enabled) {
+ $state[] = '' . ($goodie_tshirt ? __('T-Shirt') : __('Goodie')) . ' ';
}
} else {
$arrivalDate = $user_source->personalData->planned_arrival_date;
@@ -930,7 +941,9 @@ function render_user_arrived_hint()
*/
function render_user_tshirt_hint()
{
- if ((config('enable_tshirt_size') && !config('other_goodie')) && !auth()->user()->personalData->shirt_size) {
+ $goodie = GoodieType::from(config('goodie_type'));
+ $goodie_tshirt = $goodie === GoodieType::Tshirt;
+ if ($goodie_tshirt && !auth()->user()->personalData->shirt_size) {
$text = __('You need to specify a tshirt size in your settings!');
return render_profile_link($text, null, 'text-danger');
}
diff --git a/resources/lang/en_US/default.po b/resources/lang/en_US/default.po
index 1109ff2c..1683b2d2 100644
--- a/resources/lang/en_US/default.po
+++ b/resources/lang/en_US/default.po
@@ -380,6 +380,9 @@ msgstr "Answer"
msgid "user.edit.shirt"
msgstr "Edit shirt"
+msgid "user.edit.goodie"
+msgstr "Edit goodie"
+
msgid "form.shirt"
msgstr "Shirt"
@@ -398,6 +401,9 @@ msgstr "Arrived"
msgid "user.got_shirt"
msgstr "Got shirt"
+msgid "user.got_goodie"
+msgstr "Got goodie"
+
msgid "message.title"
msgstr "Messages"
diff --git a/resources/views/admin/user/edit-shirt.twig b/resources/views/admin/user/edit-shirt.twig
index 885f56ad..85ced8d3 100644
--- a/resources/views/admin/user/edit-shirt.twig
+++ b/resources/views/admin/user/edit-shirt.twig
@@ -3,11 +3,7 @@
{% import 'macros/form.twig' as f %}
{% block title %}
- {% if config('other_goodie') %}
- {{ __('user.edit.goodie') }}
- {% else %}
- {{ __('user.edit.shirt') }}
- {% endif %}
+ {{ is_tshirt ? __('user.edit.shirt') : __('user.edit.goodie') }}
{% endblock %}
{% block content %}
@@ -20,7 +16,7 @@
{{ csrf() }}
- {% if not config('other_goodie') %}
+ {% if is_tshirt %}
{{ f.select('shirt_size', config('tshirt_sizes'), __('user.shirt_size'), userdata.personalData.shirt_size) }}
@@ -34,11 +30,7 @@
{{ f.switch('active', __('user.active'), userdata.state.active) }}
- {% if config('other_goodie') %}
- {{ f.switch('got_shirt', __('user.got_goodie'), userdata.state.got_shirt) }}
- {% else %}
- {{ f.switch('got_shirt', __('user.got_shirt'), userdata.state.got_shirt) }}
- {% endif %}
+ {{ f.switch('got_shirt', is_tshirt ? __('user.got_shirt') : __('user.got_goodie'), userdata.state.got_shirt) }}
{{ f.submit(__('form.save')) }}
diff --git a/resources/views/pages/settings/profile.twig b/resources/views/pages/settings/profile.twig
index 4f63cac2..60c7c032 100644
--- a/resources/views/pages/settings/profile.twig
+++ b/resources/views/pages/settings/profile.twig
@@ -127,7 +127,7 @@
__('settings.profile.email_by_human_allowed'),
user.settings.email_human
) }}
- {% if config('enable_goody') %}
+ {% if goodie_enabled %}
{% set privacy_email = config('privacy_email') %}
{% set email_goody_label = __('settings.profile.email_goody') ~
(privacy_email ? ' ' ~ __('settings.profile.privacy', [privacy_email]) : '')
@@ -143,7 +143,7 @@
{% endif %}
- {% if config('enable_tshirt_size') and not config('other_goodie') %}
+ {% if goodie_tshirt %}
{{ f.select(
'shirt_size',
diff --git a/src/Config/GoodieType.php b/src/Config/GoodieType.php
new file mode 100644
index 00000000..b7098ef1
--- /dev/null
+++ b/src/Config/GoodieType.php
@@ -0,0 +1,12 @@
+response->withView(
'admin/user/edit-shirt.twig',
- ['userdata' => $user]
+ [
+ 'userdata' => $user,
+ 'is_tshirt' => $this->config->get('goodie_type') === GoodieType::Tshirt->value,
+ ]
);
}
public function saveShirt(Request $request): Response
{
$userId = (int) $request->getAttribute('user_id');
- $shirtEnabled = !$this->config->get('other_goodie');
-
+ $shirtEnabled = $this->config->get('goodie_type') === GoodieType::Tshirt->value;
/** @var User $user */
$user = $this->user->findOrFail($userId);
diff --git a/src/Controllers/SettingsController.php b/src/Controllers/SettingsController.php
index 6e605591..646f18b2 100644
--- a/src/Controllers/SettingsController.php
+++ b/src/Controllers/SettingsController.php
@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace Engelsystem\Controllers;
use Engelsystem\Config\Config;
+use Engelsystem\Config\GoodieType;
use Engelsystem\Http\Exceptions\HttpNotFound;
use Engelsystem\Http\Response;
use Engelsystem\Http\Redirector;
@@ -40,6 +41,8 @@ class SettingsController extends BaseController
[
'settings_menu' => $this->settingsMenu(),
'user' => $user,
+ 'goodie_tshirt' => $this->config->get('goodie_type') === GoodieType::Tshirt->value,
+ 'goodie_enabled' => $this->config->get('goodie_type') !== GoodieType::None->value,
]
);
}
@@ -48,6 +51,9 @@ class SettingsController extends BaseController
{
$user = $this->auth->user();
$data = $this->validate($request, $this->getSaveProfileRules());
+ $goodie = GoodieType::from(config('goodie_type'));
+ $goodie_enabled = $goodie !== GoodieType::None;
+ $goodie_tshirt = $goodie === GoodieType::Tshirt;
if (config('enable_pronoun')) {
$user->personalData->pronoun = $data['pronoun'];
@@ -87,13 +93,12 @@ class SettingsController extends BaseController
$user->settings->email_human = $data['email_human'] ?: false;
$user->settings->email_messages = $data['email_messages'] ?: false;
- if (config('enable_goody')) {
+ if ($goodie_enabled) {
$user->settings->email_goody = $data['email_goody'] ?: false;
}
if (
- (config('enable_tshirt_size')
- && !config('other_goodie'))
+ $goodie_tshirt
&& isset(config('tshirt_sizes')[$data['shirt_size']])
) {
$user->personalData->shirt_size = $data['shirt_size'];
@@ -265,6 +270,7 @@ class SettingsController extends BaseController
*/
private function getSaveProfileRules(): array
{
+ $goodie_tshirt = $this->config->get('goodie_type') === GoodieType::Tshirt->value;
$rules = [
'pronoun' => 'optional|max:15',
'first_name' => 'optional|max:64',
@@ -283,7 +289,7 @@ class SettingsController extends BaseController
$rules['planned_arrival_date'] = 'required|date:Y-m-d';
$rules['planned_departure_date'] = 'optional|date:Y-m-d';
}
- if (config('enable_tshirt_size') && !config('other_goodie')) {
+ if ($goodie_tshirt) {
$rules['shirt_size'] = 'required';
}
return $rules;
diff --git a/tests/Unit/Controllers/Admin/UserShirtControllerTest.php b/tests/Unit/Controllers/Admin/UserShirtControllerTest.php
index a91aacf0..38a217ae 100644
--- a/tests/Unit/Controllers/Admin/UserShirtControllerTest.php
+++ b/tests/Unit/Controllers/Admin/UserShirtControllerTest.php
@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Engelsystem\Test\Unit\Controllers\Admin;
+use Engelsystem\Config\GoodieType;
use Engelsystem\Controllers\Admin\UserShirtController;
use Engelsystem\Helpers\Authenticator;
use Engelsystem\Http\Redirector;
@@ -63,6 +64,7 @@ class UserShirtControllerTest extends ControllerTest
*/
public function testSaveShirt(): void
{
+ $this->config->set('goodie_type', GoodieType::Tshirt->value);
$request = $this->request
->withAttribute('user_id', 1)
->withParsedBody([
@@ -79,11 +81,11 @@ class UserShirtControllerTest extends ControllerTest
->create();
$auth
- ->expects($this->exactly(5))
+ ->expects($this->exactly(6))
->method('can')
->with('admin_arrive')
- ->willReturnOnConsecutiveCalls(true, true, true, false, true);
- $this->setExpects($redirector, 'back', null, $this->response, $this->exactly(5));
+ ->willReturnOnConsecutiveCalls(true, true, true, false, false, true);
+ $this->setExpects($redirector, 'back', null, $this->response, $this->exactly(6));
$controller = new UserShirtController(
$auth,
@@ -146,7 +148,18 @@ class UserShirtControllerTest extends ControllerTest
$this->assertFalse($user->state->arrived);
// Shirt disabled
- $this->config->set('other_goodie');
+ $this->config->set('goodie_type', GoodieType::None->value);
+ $request = $request
+ ->withParsedBody([
+ 'shirt_size' => 'XS',
+ ]);
+
+ $controller->saveShirt($request);
+ $user = User::find(1);
+ $this->assertEquals('S', $user->personalData->shirt_size);
+
+ // Shirt enabled
+ $this->config->set('goodie_type', GoodieType::Tshirt->value);
$request = $request
->withParsedBody([
'shirt_size' => 'XS',
diff --git a/tests/Unit/Controllers/SettingsControllerTest.php b/tests/Unit/Controllers/SettingsControllerTest.php
index 8d835da6..847e170a 100644
--- a/tests/Unit/Controllers/SettingsControllerTest.php
+++ b/tests/Unit/Controllers/SettingsControllerTest.php
@@ -6,6 +6,7 @@ namespace Engelsystem\Test\Unit\Controllers;
use Carbon\Carbon;
use Engelsystem\Config\Config;
+use Engelsystem\Config\GoodieType;
use Engelsystem\Controllers\NotificationType;
use Engelsystem\Controllers\SettingsController;
use Engelsystem\Http\Exceptions\HttpNotFound;
@@ -64,8 +65,7 @@ class SettingsControllerTest extends ControllerTest
'enable_planned_arrival' => true,
'enable_dect' => true,
'enable_mobile_show' => true,
- 'enable_goody' => true,
- 'enable_tshirt_size' => true,
+ 'goodie_type' => GoodieType::Tshirt->value,
]);
$this->setExpects($this->auth, 'user', null, $this->user, $this->atLeastOnce());
@@ -213,7 +213,7 @@ class SettingsControllerTest extends ControllerTest
public function testSaveProfileIgnoresEmailGoodyIfDisabled(): void
{
$this->setUpProfileTest();
- config(['enable_goody' => false]);
+ $this->config->set('goodie_type', GoodieType::None->value);
$this->controller->saveProfile($this->request);
$this->assertFalse($this->user->settings->email_goody);
}
@@ -224,7 +224,7 @@ class SettingsControllerTest extends ControllerTest
public function testSaveProfileIgnoresTShirtSizeIfDisabled(): void
{
$this->setUpProfileTest();
- config(['enable_tshirt_size' => false]);
+ $this->config->set('goodie_type', GoodieType::None->value);
$this->controller->saveProfile($this->request);
$this->assertEquals('', $this->user->personalData->shirt_size);
}
@@ -639,6 +639,7 @@ class SettingsControllerTest extends ControllerTest
'themes' => $themes,
'locales' => $languages,
'tshirt_sizes' => $tshirt_sizes,
+ 'goodie_type' => GoodieType::Goodie->value,
]);
$this->app->instance('config', $this->config);
$this->app->instance(Config::class, $this->config);