refactor goodie config option as enum (#1100)
* goodie config as enum * Unified goodie check, updated test * Changed tshirt to goodie in url --------- Co-authored-by: Igor Scheller <igor.scheller@igorshp.de>
This commit is contained in:
parent
523e984122
commit
668a9e86f5
|
@ -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),
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Engelsystem\Migrations;
|
||||
|
||||
use Engelsystem\Database\Migration\Migration;
|
||||
|
||||
class RenameShirtManager extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migration
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
$db = $this->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']);
|
||||
}
|
||||
}
|
|
@ -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' => '<b>' . __('Sum') . '</b>'] : []),
|
||||
$goodie_statistics[] = array_merge(
|
||||
($goodie_tshirt ? ['size' => '<b>' . __('Sum') . '</b>'] : []),
|
||||
['given' => '<b>' . State::whereGotShirt(true)->count() . '</b>']
|
||||
);
|
||||
|
||||
|
@ -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
|
||||
),
|
||||
'<h2>' . ($other_goodie ? __('Goodie statistic') : __('Shirt statistic')) . '</h2>',
|
||||
table(array_merge(
|
||||
(!$other_goodie ? ['size' => __('Size')] : []),
|
||||
['given' => $other_goodie ? __('Given goodies') : __('Given shirts') ]
|
||||
), $shirt_statistics),
|
||||
$goodie_enabled ? '<h2>' . ($goodie_tshirt ? __('Shirt statistic') : __('Goodie statistic')) . '</h2>' : '',
|
||||
$goodie_enabled ? table(array_merge(
|
||||
($goodie_tshirt ? ['size' => __('Size')] : []),
|
||||
['given' => $goodie_tshirt ? __('Given shirts') : __('Given goodies') ]
|
||||
), $goodie_statistics) : '',
|
||||
]);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
|
||||
use Engelsystem\Config\GoodieType;
|
||||
use Engelsystem\Models\Group;
|
||||
use Engelsystem\Models\User\User;
|
||||
use Illuminate\Database\Query\JoinClause;
|
||||
|
@ -22,6 +23,9 @@ function admin_user()
|
|||
$tshirt_sizes = config('tshirt_sizes');
|
||||
$request = request();
|
||||
$html = '';
|
||||
$goodie = GoodieType::from(config('goodie_type'));
|
||||
$goodie_enabled = $goodie !== GoodieType::None;
|
||||
$goodie_tshirt = $goodie === GoodieType::Tshirt;
|
||||
|
||||
if (!$request->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 .= '<br /><br />';
|
||||
|
@ -67,7 +71,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') && !config('other_goodie')) {
|
||||
if ($goodie_tshirt) {
|
||||
$html .= ' <tr><td>' . __('user.shirt_size') . '</td><td>'
|
||||
. html_select_key(
|
||||
'size',
|
||||
|
@ -103,12 +107,12 @@ function admin_user()
|
|||
$html .= html_options('force_active', $options, $user_source->state->force_active) . '</td></tr>' . "\n";
|
||||
}
|
||||
|
||||
if (config('enable_tshirt_size')) {
|
||||
if ($goodie_enabled) {
|
||||
// T-Shirt bekommen?
|
||||
if (config('other_goodie')) {
|
||||
$html .= ' <tr><td>' . __('Goodie') . '</td><td>' . "\n";
|
||||
} else {
|
||||
if ($goodie_tshirt) {
|
||||
$html .= ' <tr><td>' . __('T-Shirt') . '</td><td>' . "\n";
|
||||
} else {
|
||||
$html .= ' <tr><td>' . __('Goodie') . '</td><td>' . "\n";
|
||||
}
|
||||
$html .= html_options('eTshirt', $options, $user_source->state->got_shirt) . '</td></tr>' . "\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;
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Engelsystem\Config\GoodieType;
|
||||
use Engelsystem\Models\AngelType;
|
||||
use Engelsystem\Models\Group;
|
||||
use Engelsystem\Models\Shifts\Shift;
|
||||
|
@ -84,6 +85,9 @@ function Users_view(
|
|||
$tshirts_count,
|
||||
$voucher_count
|
||||
) {
|
||||
$goodie = GoodieType::from(config('goodie_type'));
|
||||
$goodie_enabled = $goodie !== GoodieType::None;
|
||||
$goodie_tshirt = $goodie === GoodieType::Tshirt;
|
||||
$usersList = [];
|
||||
foreach ($users as $user) {
|
||||
$u = [];
|
||||
|
@ -98,9 +102,9 @@ function Users_view(
|
|||
$u['freeloads'] = $user->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' => '<b>' . (config('other_goodie') ? __('Your goodie score') : __('Your t-shirt score')) . '™:</b>',
|
||||
'date' => '<b>' . ($goodie_tshirt ? __('Your t-shirt score') : __('Your goodie score')) . '™:</b>',
|
||||
'duration' => '<b>' . $tshirt_score . '</b>',
|
||||
'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) ? '<h2>' . __('Shifts') . '</h2>' : '',
|
||||
$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[] = '<span class="text-danger">' . icon('exclamation-circle') . __('Freeloader') . '</span>';
|
||||
|
@ -720,8 +731,8 @@ function User_view_state_admin($freeloader, $user_source)
|
|||
} elseif ($user_source->state->active) {
|
||||
$state[] = '<span class="text-success">' . __('Active') . '</span>';
|
||||
}
|
||||
if ($user_source->state->got_shirt) {
|
||||
$state[] = '<span class="text-success">' . __('T-Shirt') . '</span>';
|
||||
if ($user_source->state->got_shirt && $goodie_enabled) {
|
||||
$state[] = '<span class="text-success">' . ($goodie_tshirt ? __('T-Shirt') : __('Goodie')) . '</span>';
|
||||
}
|
||||
} 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');
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
|
@ -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() }}
|
||||
|
||||
<div class="row">
|
||||
{% if not config('other_goodie') %}
|
||||
{% if is_tshirt %}
|
||||
<div class="col-md-6">
|
||||
{{ f.select('shirt_size', config('tshirt_sizes'), __('user.shirt_size'), userdata.personalData.shirt_size) }}
|
||||
</div>
|
||||
|
@ -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) }}
|
||||
</div>
|
||||
<div class="col-md-12">
|
||||
{{ f.submit(__('form.save')) }}
|
||||
|
|
|
@ -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 %}
|
||||
</div>
|
||||
|
||||
{% if config('enable_tshirt_size') and not config('other_goodie') %}
|
||||
{% if goodie_tshirt %}
|
||||
<div class="col-md-12">
|
||||
{{ f.select(
|
||||
'shirt_size',
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Engelsystem\Config;
|
||||
|
||||
enum GoodieType : string
|
||||
{
|
||||
case None = 'none';
|
||||
case Goodie = 'goodie';
|
||||
case Tshirt = 'tshirt';
|
||||
}
|
|
@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||
namespace Engelsystem\Controllers\Admin;
|
||||
|
||||
use Engelsystem\Config\Config;
|
||||
use Engelsystem\Config\GoodieType;
|
||||
use Engelsystem\Controllers\BaseController;
|
||||
use Engelsystem\Controllers\HasUserNotifications;
|
||||
use Engelsystem\Helpers\Authenticator;
|
||||
|
@ -42,15 +43,17 @@ class UserShirtController extends BaseController
|
|||
|
||||
return $this->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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue