add config option for other goodies

This commit is contained in:
Xu 2023-01-27 21:01:23 +01:00 committed by Igor Scheller
parent 3ca39dc8e1
commit ccdf1aa8d5
11 changed files with 169 additions and 72 deletions

View File

@ -276,6 +276,9 @@ return [
// 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),

View File

@ -22,6 +22,7 @@ function admin_active()
$tshirt_sizes = config('tshirt_sizes');
$shift_sum_formula = User_get_shifts_sum_query();
$request = request();
$other_goodie = config('other_goodie');
$msg = '';
$search = '';
@ -129,7 +130,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(__('Angel has got a t-shirt.'), true);
$msg = success(($other_goodie ? __('Angel has got a goodie.') : __('Angel has got a t-shirt.')), true);
} else {
$msg = error('Angel not found.', true);
}
@ -140,7 +141,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(__('Angel has got no t-shirt.'), true);
$msg = success(($other_goodie ? __('Angel has got no goodie.') : __('Angel has got no t-shirt.')), true);
} else {
$msg = error(__('Angel not found.'), true);
}
@ -212,7 +213,9 @@ function admin_active()
$userData = [];
$userData['no'] = count($matched_users) + 1;
$userData['nick'] = User_Nick_render($usr) . User_Pronoun_render($usr);
$userData['shirt_size'] = (isset($tshirt_sizes[$shirtSize]) ? $tshirt_sizes[$shirtSize] : '');
if (!$other_goodie) {
$userData['shirt_size'] = (isset($tshirt_sizes[$shirtSize]) ? $tshirt_sizes[$shirtSize] : '');
}
$userData['work_time'] = round($usr['shift_length'] / 60)
. ' min (' . sprintf('%.2f', $usr['shift_length'] / 3600) . ' h)';
$userData['active'] = icon_bool($usr->state->active == 1);
@ -260,7 +263,7 @@ function admin_active()
$parametersShirt['show_all_shifts'] = 1;
}
$actions[] = form(
[form_submit('submit', __('got t-shirt'), 'btn-sm', false, 'secondary')],
[form_submit('submit', ($other_goodie ? __('got goodie') : __('got t-shirt')), 'btn-sm', false, 'secondary')],
page_link_to('admin_active', $parametersShirt),
false,
true
@ -275,14 +278,16 @@ function admin_active()
$parameters['show_all_shifts'] = 1;
}
$actions[] = form(
[form_submit('submit', __('remove t-shirt'), 'btn-sm', false, 'secondary')],
[form_submit('submit', ($other_goodie ? __('remove goodie') : __('remove t-shirt')), 'btn-sm', false, 'secondary')],
page_link_to('admin_active', $parameters),
false,
true
);
}
$actions[] = button(url('/admin/user/' . $usr->id . '/shirt'), __('form.edit'), 'btn-secondary btn-sm');
if (!$other_goodie) {
$actions[] = button(url('/admin/user/' . $usr->id . '/shirt'), __('form.edit'), 'btn-secondary btn-sm');
}
$userData['actions'] = buttons($actions);
@ -290,23 +295,25 @@ function admin_active()
}
$shirt_statistics = [];
foreach (array_keys($tshirt_sizes) as $size) {
$gc = State::query()
->leftJoin('users_settings', 'users_state.user_id', '=', 'users_settings.user_id')
->leftJoin('users_personal_data', 'users_state.user_id', '=', 'users_personal_data.user_id')
->where('users_state.got_shirt', '=', true)
->where('users_personal_data.shirt_size', '=', $size)
->count();
$shirt_statistics[] = [
'size' => $size,
'given' => $gc
];
if (!$other_goodie) {
foreach (array_keys($tshirt_sizes) as $size) {
$gc = State::query()
->leftJoin('users_settings', 'users_state.user_id', '=', 'users_settings.user_id')
->leftJoin('users_personal_data', 'users_state.user_id', '=', 'users_personal_data.user_id')
->where('users_state.got_shirt', '=', true)
->where('users_personal_data.shirt_size', '=', $size)
->count();
$shirt_statistics[] = [
'size' => $size,
'given' => $gc
];
}
}
$shirt_statistics[] = [
'size' => '<b>' . __('Sum') . '</b>',
'given' => '<b>' . State::whereGotShirt(true)->count() . '</b>'
];
$shirt_statistics[] = array_merge(
(!$other_goodie ? ['size' => '<b>' . __('Sum') . '</b>'] : []),
['given' => '<b>' . State::whereGotShirt(true)->count() . '</b>']
);
return page_with_title(admin_active_title(), [
form([
@ -319,21 +326,28 @@ function admin_active()
form_submit('set_active', __('Preview'))
]) : $set_active,
$msg . msg(),
table([
'no' => __('No.'),
'nick' => __('Nickname'),
'shirt_size' => __('Size'),
'shift_count' => __('Shifts'),
'work_time' => __('Length'),
'active' => __('Active?'),
'force_active' => __('Forced'),
'tshirt' => __('T-shirt?'),
'actions' => ''
], $matched_users),
'<h2>' . __('Shirt statistics') . '</h2>',
table([
'size' => __('Size'),
'given' => __('Given shirts')
], $shirt_statistics)
table(
array_merge(
[
'no' => __('No.'),
'nick' => __('Nickname'),
],
(!$other_goodie ? ['shirt_size' => __('Size')] : []),
[
'shift_count' => __('Shifts'),
'work_time' => __('Length'),
'active' => __('Active?'),
'force_active' => __('Forced'),
'tshirt' => ($other_goodie ? __('Goodie?') : __('T-shirt?')),
'actions' => ''
]
),
$matched_users
),
'<h2>' . ($other_goodie ? __('Goodie statistic') : __('Shirt statistic')) . '</h2>',
table(array_merge(
(!$other_goodie ? ['size' => __('Size')] : []),
['given' => $other_goodie ? __('Given goodies') : __('Given shirts') ]
), $shirt_statistics)
]);
}

View File

@ -37,7 +37,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')) {
$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.');
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 {
$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.');
}
}
$html .= '<br /><br />';
$html .= '<form action="'
@ -63,7 +67,7 @@ function admin_user()
if ($user_source->settings->email_human) {
$html .= " <tr><td>" . __('settings.profile.email') . "</td><td>" . '<input type="email" size="40" name="eemail" value="' . $user_source->email . '" class="form-control" maxlength="254"></td></tr>' . "\n";
}
if (config('enable_tshirt_size')) {
if (config('enable_tshirt_size') && !config('other_goodie')) {
$html .= ' <tr><td>' . __('user.shirt_size') . '</td><td>'
. html_select_key(
'size',
@ -101,7 +105,11 @@ function admin_user()
if (config('enable_tshirt_size')) {
// T-Shirt bekommen?
$html .= ' <tr><td>' . __('T-Shirt') . '</td><td>' . "\n";
if (config('other_goodie')) {
$html .= ' <tr><td>' . __('Goodie') . '</td><td>' . "\n";
} else {
$html .= ' <tr><td>' . __('T-Shirt') . '</td><td>' . "\n";
}
$html .= html_options('eTshirt', $options, $user_source->state->got_shirt) . '</td></tr>' . "\n";
}
$html .= '</table>' . "\n" . '</td><td></td></tr>';
@ -242,7 +250,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')) {
if (config('enable_tshirt_size') && !config('other_goodie')) {
$user_source->personalData->shirt_size = $request->postData('eSize');
}
$user_source->personalData->save();
@ -260,10 +268,10 @@ function admin_user()
engelsystem_log(
'Updated user: ' . $user_source->name . ' (' . $user_source->id . ')'
. ', t-shirt: ' . $user_source->personalData->shirt_size
. (config('other_goodie') ? '' : ', t-shirt: ' . $user_source->personalData->shirt_size)
. ', active: ' . $user_source->state->active
. ', force-active: ' . $user_source->state->force_active
. ', tshirt: ' . $user_source->state->got_shirt
. (config('other_goodie') ? ', goodie: ' : ', tshirt: ' . $user_source->state->got_shirt)
);
$html .= success(__('Changes where saved.') . "\n", true);
break;

View File

@ -31,6 +31,7 @@ function guest_register()
$authUser = auth()->user();
$tshirt_sizes = config('tshirt_sizes');
$enable_tshirt_size = config('enable_tshirt_size');
$other_goodie = config('other_goodie');
$enable_user_name = config('enable_user_name');
$enable_dect = config('enable_dect');
$enable_planned_arrival = config('enable_planned_arrival');
@ -162,7 +163,7 @@ function guest_register()
$email_goody = true;
}
if ($enable_tshirt_size) {
if ($enable_tshirt_size && !$other_goodie) {
if ($request->has('tshirt_size') && isset($tshirt_sizes[$request->input('tshirt_size')])) {
$tshirt_size = $request->input('tshirt_size');
} else {
@ -483,7 +484,7 @@ function guest_register()
]) : '',
div('col', [
$enable_tshirt_size ? form_select(
$enable_tshirt_size && !$other_goodie ? form_select(
'tshirt_size',
__('Shirt size') . ' ' . entry_required(),
$tshirt_sizes,

View File

@ -100,7 +100,9 @@ function Users_view(
$u['force_active'] = icon_bool($user->state->force_active);
if (config('enable_tshirt_size')) {
$u['got_shirt'] = icon_bool($user->state->got_shirt);
$u['shirt_size'] = $user->personalData->shirt_size;
if (!config('other_goodie')) {
$u['shirt_size'] = $user->personalData->shirt_size;
}
}
$u['arrival_date'] = $user->personalData->planned_arrival_date
? $user->personalData->planned_arrival_date->format(__('Y-m-d')) : '';
@ -141,9 +143,13 @@ function Users_view(
$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')) {
$user_table_headers['got_shirt'] = Users_table_header_link('got_shirt', __('T-Shirt'), $order_by);
if (config('other_goodie')) {
$user_table_headers['got_shirt'] = Users_table_header_link('got_shirt', __('Goodie'), $order_by);
} else {
$user_table_headers['got_shirt'] = Users_table_header_link('got_shirt', __('T-Shirt'), $order_by);
}
}
if (config('enable_tshirt_size')) {
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(
@ -401,7 +407,7 @@ function User_view_myshifts(
];
if (config('enable_tshirt_size', false) && ($its_me || $tshirt_admin)) {
$myshifts_table[] = [
'date' => '<b>' . __('Your t-shirt score') . '&trade;:</b>',
'date' => '<b>' . (config('other_goodie') ? __('Your goodie score') : __('Your t-shirt score')) . '&trade;:</b>',
'duration' => '<b>' . $tshirt_score . '</b>',
'room' => '',
'shift_info' => '',
@ -532,9 +538,9 @@ function User_view(
div('row', [
div('col-md-12', [
buttons([
$auth->can('user.edit.shirt') && config('enable_tshirt_size') ? button(
$auth->can('user.edit.shirt') && (config('enable_tshirt_size')) ? button(
url('/admin/user/' . $user_source->id . '/shirt'),
icon('person') . __('Shirt')
icon('person') . (config('other_goodie') ? __('Goodie') : __('Shirt'))
) : '',
$admin_user_privilege ? button(
page_link_to('admin_user', ['id' => $user_source->id]),
@ -924,7 +930,7 @@ function render_user_arrived_hint()
*/
function render_user_tshirt_hint()
{
if (config('enable_tshirt_size') && !auth()->user()->personalData->shirt_size) {
if ((config('enable_tshirt_size') && !config('other_goodie')) && !auth()->user()->personalData->shirt_size) {
$text = __('You need to specify a tshirt size in your settings!');
return render_profile_link($text, null, 'text-danger');
}

View File

@ -961,11 +961,11 @@ msgstr "entferne aktiv"
#: includes/pages/admin_active.php:261
msgid "got t-shirt"
msgstr "hat t-shirt"
msgstr "T-Shirt bekommen"
#: includes/pages/admin_active.php:274
msgid "remove t-shirt"
msgstr "entferne t-shirt"
msgstr "entferne T-Shirt"
#: includes/pages/admin_active.php:299 includes/pages/admin_arrive.php:202
#: includes/pages/admin_arrive.php:217 includes/pages/admin_arrive.php:232
@ -1031,7 +1031,7 @@ msgid "T-shirt?"
msgstr "T-Shirt?"
#: includes/pages/admin_active.php:324
msgid "Shirt statistics"
msgid "Shirt statistic"
msgstr "T-Shirt Statistik"
#: includes/pages/admin_active.php:327
@ -2753,6 +2753,40 @@ msgstr "Passwort zurückgesetzt."
msgid "The entries must match and must not be empty!"
msgstr "Die Einträge müssen übereinstimmen und dürfen nicht leer sein!"
msgid "Number of shifts: %s"
msgstr "Anzahl an Schichten: %s"
msgid "If the angel is active, it can claim a goodie. If goodie is set to 'Yes', the angel already got their goodie."
msgstr "Ist der Engel Aktiv, hat er damit Anspruch auf ein Goodie. Wenn Goodie ein 'Ja' enthält, bedeutet dies, "
"dass der Engel bereits sein Goodie erhalten hat."
msgid "Goodie"
msgstr "Goodie"
msgid "Your goodie score"
msgstr "Dein Goodie Score"
msgid "Given goodies"
msgstr "Ausgegebene Goodies"
msgid "Goodie statistic"
msgstr "Goodie Statistik"
msgid "remove goodie"
msgstr "entferne Goodie"
msgid "got goodie"
msgstr "Goodie bekommen"
msgid "Goodie?"
msgstr "Goodie?"
msgid "Angel has got a goodie."
msgstr "Engel hat ein Goodie bekommen."
msgid "Angel has got no goodie."
msgstr "Engel hat kein Goodie bekommen."
#: src/Middleware/LegacyMiddleware.php:83
msgid "page.404.text"
msgstr ""
@ -3091,6 +3125,9 @@ msgstr "Antwort"
msgid "user.edit.shirt"
msgstr "Shirt bearbeiten"
msgid "user.edit.goodie"
msgstr "Goodie bearbeiten"
msgid "form.shirt"
msgstr "Shirt"
@ -3109,6 +3146,9 @@ msgstr "Angekommen"
msgid "user.got_shirt"
msgstr "Shirt bekommen"
msgid "user.got_goodie"
msgstr "Goodie bekommen"
msgid "message.title"
msgstr "Nachrichten"
@ -3147,6 +3187,3 @@ msgstr "Arbeitseinsatz löschen"
msgid "worklog.delete.info"
msgstr "Möchtest du den Arbeitseinsatz von %s wirklich löschen?"
msgid "Number of shifts: %s"
msgstr "Anzahl an Schichten: %s"

View File

@ -2,7 +2,13 @@
{% import 'macros/base.twig' as m %}
{% import 'macros/form.twig' as f %}
{% block title %}{{ __('user.edit.shirt') }}{% endblock %}
{% block title %}
{% if config('other_goodie') %}
{{ __('user.edit.goodie') }}
{% else %}
{{ __('user.edit.shirt') }}
{% endif %}
{% endblock %}
{% block content %}
<div class="container">
@ -14,9 +20,11 @@
{{ csrf() }}
<div class="row">
<div class="col-md-6">
{{ f.select('shirt_size', config('tshirt_sizes'), __('user.shirt_size'), userdata.personalData.shirt_size) }}
</div>
{% if not config('other_goodie') %}
<div class="col-md-6">
{{ f.select('shirt_size', config('tshirt_sizes'), __('user.shirt_size'), userdata.personalData.shirt_size) }}
</div>
{% endif %}
<div class="col-md-6">
{{ f.switch('arrived', __('user.arrived'), userdata.state.arrived, {'disabled': not has_permission_to('admin_arrive')}) }}
@ -26,7 +34,11 @@
{{ f.switch('active', __('user.active'), userdata.state.active) }}
{{ f.switch('got_shirt', __('user.got_shirt'), userdata.state.got_shirt) }}
{% 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 %}
</div>
<div class="col-md-12">
{{ f.submit(__('form.save')) }}

View File

@ -138,7 +138,7 @@
{% endif %}
</div>
{% if config('enable_tshirt_size') %}
{% if config('enable_tshirt_size') and not config('other_goodie') %}
<div class="col-md-12">
{{ f.select(
'shirt_size',

View File

@ -47,18 +47,19 @@ class UserShirtController extends BaseController
public function saveShirt(Request $request): Response
{
$userId = (int) $request->getAttribute('user_id');
$shirtEnabled = !$this->config->get('other_goodie');
/** @var User $user */
$user = $this->user->findOrFail($userId);
$data = $this->validate($request, [
'shirt_size' => 'required',
'shirt_size' => $shirtEnabled ? 'required' : 'optional',
'arrived' => 'optional|checked',
'active' => 'optional|checked',
'got_shirt' => 'optional|checked',
]);
if (isset($this->config->get('tshirt_sizes')[$data['shirt_size']])) {
if ($shirtEnabled && isset($this->config->get('tshirt_sizes')[$data['shirt_size']])) {
$user->personalData->shirt_size = $data['shirt_size'];
$user->personalData->save();
}

View File

@ -88,7 +88,11 @@ class SettingsController extends BaseController
$user->settings->email_goody = $data['email_goody'] ?: false;
}
if (config('enable_tshirt_size') && isset(config('tshirt_sizes')[$data['shirt_size']])) {
if (
(config('enable_tshirt_size')
&& !config('other_goodie'))
&& isset(config('tshirt_sizes')[$data['shirt_size']])
) {
$user->personalData->shirt_size = $data['shirt_size'];
}
@ -275,7 +279,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')) {
if (config('enable_tshirt_size') && !config('other_goodie')) {
$rules['shirt_size'] = 'required';
}
return $rules;

View File

@ -68,7 +68,7 @@ class UserShirtControllerTest extends ControllerTest
]);
/** @var Authenticator|MockObject $auth */
$auth = $this->createMock(Authenticator::class);
$this->config->set('tshirt_sizes', ['S' => 'Small']);
$this->config->set('tshirt_sizes', ['S' => 'Small', 'XS' => 'Extra Small']);
/** @var Redirector|MockObject $redirector */
$redirector = $this->createMock(Redirector::class);
User::factory()
@ -77,11 +77,11 @@ class UserShirtControllerTest extends ControllerTest
->create();
$auth
->expects($this->exactly(4))
->expects($this->exactly(5))
->method('can')
->with('admin_arrive')
->willReturnOnConsecutiveCalls(true, true, true, false);
$this->setExpects($redirector, 'back', null, $this->response, $this->exactly(4));
->willReturnOnConsecutiveCalls(true, true, true, false, true);
$this->setExpects($redirector, 'back', null, $this->response, $this->exactly(5));
$controller = new UserShirtController(
$auth,
@ -142,6 +142,17 @@ class UserShirtControllerTest extends ControllerTest
$controller->saveShirt($request);
$user = User::find(1);
$this->assertFalse($user->state->arrived);
// Shirt disabled
$this->config->set('other_goodie');
$request = $request
->withParsedBody([
'shirt_size' => 'XS',
]);
$controller->saveShirt($request);
$user = User::find(1);
$this->assertEquals('XS', $user->personalData->shirt_size);
}
/**