From 0f2c7c53944bb6ac4d3a410c297bc488edf9e516 Mon Sep 17 00:00:00 2001 From: Xu Date: Wed, 10 Apr 2024 18:29:12 +0200 Subject: [PATCH] refactor shirt to goodie --- config/routes.php | 6 +- db/factories/User/StateFactory.php | 2 +- ...24_04_10_000001_rename_shirt_to_goodie.php | 49 ++++++++++++++++ includes/controller/users_controller.php | 12 ++-- includes/model/User_model.php | 14 ++--- includes/pages/admin_active.php | 16 ++--- includes/pages/admin_user.php | 26 ++++----- includes/sys_menu.php | 2 +- includes/view/User_view.php | 46 +++++++-------- resources/lang/en_US/default.po | 3 - .../{edit-shirt.twig => edit-goodie.twig} | 4 +- resources/views/pages/settings/profile.twig | 2 +- ...ontroller.php => UserGoodieController.php} | 22 +++---- src/Controllers/Metrics/Controller.php | 2 +- src/Controllers/Metrics/Stats.php | 4 +- src/Controllers/SettingsController.php | 4 +- src/Models/User/State.php | 10 ++-- ...rTest.php => UserGoodieControllerTest.php} | 58 +++++++++---------- .../Controllers/Metrics/ControllerTest.php | 4 +- tests/Unit/Controllers/Metrics/StatsTest.php | 10 ++-- 20 files changed, 171 insertions(+), 125 deletions(-) create mode 100644 db/migrations/2024_04_10_000001_rename_shirt_to_goodie.php rename resources/views/admin/user/{edit-shirt.twig => edit-goodie.twig} (92%) rename src/Controllers/Admin/{UserShirtController.php => UserGoodieController.php} (81%) rename tests/Unit/Controllers/Admin/{UserShirtControllerTest.php => UserGoodieControllerTest.php} (75%) diff --git a/config/routes.php b/config/routes.php index b1322eb3..3639c660 100644 --- a/config/routes.php +++ b/config/routes.php @@ -252,12 +252,12 @@ $route->addGroup( $route->addGroup( '/user/{user_id:\d+}', function (RouteCollector $route): void { - // Shirts + // Goodies $route->addGroup( '/goodie', function (RouteCollector $route): void { - $route->get('', 'Admin\\UserShirtController@editShirt'); - $route->post('', 'Admin\\UserShirtController@saveShirt'); + $route->get('', 'Admin\\UserGoodieController@editGoodie'); + $route->post('', 'Admin\\UserGoodieController@saveGoodie'); } ); diff --git a/db/factories/User/StateFactory.php b/db/factories/User/StateFactory.php index 27780777..b87c3b2e 100644 --- a/db/factories/User/StateFactory.php +++ b/db/factories/User/StateFactory.php @@ -25,7 +25,7 @@ class StateFactory extends Factory 'user_info' => $this->faker->optional(.1)->text(), 'active' => $this->faker->boolean(.3), 'force_active' => $this->faker->boolean(.1), - 'got_shirt' => $this->faker->boolean(), + 'got_goodie' => $this->faker->boolean(), 'got_voucher' => $this->faker->numberBetween(0, 10), ]; } diff --git a/db/migrations/2024_04_10_000001_rename_shirt_to_goodie.php b/db/migrations/2024_04_10_000001_rename_shirt_to_goodie.php new file mode 100644 index 00000000..a141b521 --- /dev/null +++ b/db/migrations/2024_04_10_000001_rename_shirt_to_goodie.php @@ -0,0 +1,49 @@ +schema->table('users_state', function (Blueprint $table): void { + $table->renameColumn('got_shirt', 'got_goodie'); + }); + + $db = $this->schema->getConnection(); + $db->table('privileges')->where('name', 'admin_active')->update([ + 'description' => 'Mark angels as active and if they got a goodie.', + ]); + $db->table('privileges')->where('name', 'user.edit.shirt')->update([ + 'name' => 'user.goodie.edit', + 'description' => 'Edit user goodies', + ]); + } + + /** + * Reverse the migration + */ + public function down(): void + { + $this->schema->table('users_state', function (Blueprint $table): void { + $table->renameColumn('got_goodie', 'got_shirt'); + }); + + $db = $this->schema->getConnection(); + $db->table('privileges')->where('name', 'admin_active')->update([ + 'description' => 'Mark angels as active and if they got a t-shirt.', + ]); + $db->table('privileges')->where('name', 'user.goodie.edit')->update([ + 'name' => 'user.edit.shirt', + 'description' => 'Edit user shirts', + ]); + } +} diff --git a/includes/controller/users_controller.php b/includes/controller/users_controller.php index 4a588933..4cfe8b75 100644 --- a/includes/controller/users_controller.php +++ b/includes/controller/users_controller.php @@ -239,9 +239,9 @@ function user_controller() auth()->resetApiKey($user_source); } - $tshirt_score = sprintf('%.2f', User_tshirt_score($user_source->id)) . ' h'; + $goodie_score = sprintf('%.2f', User_goodie_score($user_source->id)) . ' h'; if ($user_source->state->force_active && config('enable_force_active')) { - $tshirt_score = '' . __('Enough') . ''; + $goodie_score = '' . __('Enough') . ''; } $worklogs = $user_source->worklogs() @@ -270,8 +270,8 @@ function user_controller() $user_source->groups, $shifts, $user->id == $user_source->id, - $tshirt_score, - auth()->can('user.edit.shirt'), + $goodie_score, + auth()->can('user.goodie.edit'), auth()->can('admin_user_worklog'), $worklogs, auth()->can('user.ifsg.edit') @@ -307,7 +307,7 @@ function users_list_controller() 'freeloads', 'active', 'force_active', - 'got_shirt', + 'got_goodie', 'shirt_size', 'planned_arrival_date', 'planned_departure_date', @@ -351,7 +351,7 @@ function users_list_controller() State::whereActive(true)->count(), State::whereForceActive(true)->count(), ShiftEntry::whereFreeloaded(true)->count(), - State::whereGotShirt(true)->count(), + State::whereGotGoodie(true)->count(), State::query()->sum('got_voucher') ), ]; diff --git a/includes/model/User_model.php b/includes/model/User_model.php index 56116294..5db2d0be 100644 --- a/includes/model/User_model.php +++ b/includes/model/User_model.php @@ -13,17 +13,17 @@ use Illuminate\Support\Collection; */ /** - * Returns the tshirt score (number of hours counted for tshirt). + * Returns the goodie score (number of hours counted for tshirt). * Accounts only ended shifts. * * @param int $userId - * @return int + * @return float */ -function User_tshirt_score($userId) +function User_goodie_score(int $userId): float { $shift_sum_formula = User_get_shifts_sum_query(); $result_shifts = Db::selectOne(sprintf(' - SELECT ROUND((%s) / 3600, 2) AS `tshirt_score` + SELECT ROUND((%s) / 3600, 2) AS `goodie_score` FROM `users` LEFT JOIN `shift_entries` ON `users`.`id` = `shift_entries`.`user_id` LEFT JOIN `shifts` ON `shift_entries`.`shift_id` = `shifts`.`id` WHERE `users`.`id` = ? @@ -32,8 +32,8 @@ function User_tshirt_score($userId) ', $shift_sum_formula), [ $userId, ]); - if (!isset($result_shifts['tshirt_score'])) { - $result_shifts = ['tshirt_score' => 0]; + if (!isset($result_shifts['goodie_score'])) { + $result_shifts = ['goodie_score' => 0]; } $worklogHours = Worklog::query() @@ -41,7 +41,7 @@ function User_tshirt_score($userId) ->where('worked_at', '<=', Carbon::Now()) ->sum('hours'); - return $result_shifts['tshirt_score'] + $worklogHours; + return $result_shifts['goodie_score'] + $worklogHours; } /** diff --git a/includes/pages/admin_active.php b/includes/pages/admin_active.php index c2e3ec00..c1893f5c 100644 --- a/includes/pages/admin_active.php +++ b/includes/pages/admin_active.php @@ -58,7 +58,7 @@ function admin_active() if ($request->hasPostData('ack')) { State::query() - ->where('got_shirt', '=', false) + ->where('got_goodie', '=', false) ->update(['active' => false]); $query = User::query() @@ -140,7 +140,7 @@ function admin_active() $user_id = $request->input('tshirt'); $user_source = User::find($user_id); if ($user_source) { - $user_source->state->got_shirt = true; + $user_source->state->got_goodie = true; $user_source->state->save(); engelsystem_log('User ' . User_Nick_render($user_source, true) . ' has tshirt now.'); $msg = success(($goodie_tshirt ? __('Angel has got a T-shirt.') : __('Angel has got a goodie.')), true); @@ -151,7 +151,7 @@ function admin_active() $user_id = $request->input('not_tshirt'); $user_source = User::find($user_id); if ($user_source) { - $user_source->state->got_shirt = false; + $user_source->state->got_goodie = false; $user_source->state->save(); engelsystem_log('User ' . User_Nick_render($user_source, true) . ' has NO tshirt.'); $msg = success(($goodie_tshirt ? __('Angel has got no T-shirt.') : __('Angel has got no goodie.')), true); @@ -257,7 +257,7 @@ function admin_active() . ' min (' . sprintf('%.2f', $usr['shift_length'] / 3600) . ' h)'; $userData['active'] = icon_bool($usr->state->active); $userData['force_active'] = icon_bool($usr->state->force_active); - $userData['tshirt'] = icon_bool($usr->state->got_shirt); + $userData['tshirt'] = icon_bool($usr->state->got_goodie); $userData['shift_count'] = $usr['shift_count']; $actions = []; @@ -291,7 +291,7 @@ function admin_active() true ); } - if (!$usr->state->got_shirt) { + if (!$usr->state->got_goodie) { $parametersShirt = [ 'tshirt' => $usr->id, 'search' => $search, @@ -309,7 +309,7 @@ function admin_active() ); } } - if ($usr->state->got_shirt) { + if ($usr->state->got_goodie) { $parameters = [ 'not_tshirt' => $usr->id, 'search' => $search, @@ -343,7 +343,7 @@ function admin_active() $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_state.got_goodie', '=', true) ->where('users_personal_data.shirt_size', '=', $size) ->count(); $goodie_statistics[] = [ @@ -355,7 +355,7 @@ function admin_active() $goodie_statistics[] = array_merge( ($goodie_tshirt ? ['size' => '' . __('Sum') . ''] : []), - ['given' => '' . State::whereGotShirt(true)->count() . ''] + ['given' => '' . State::whereGotGoodie(true)->count() . ''] ); return page_with_title(admin_active_title(), [ diff --git a/includes/pages/admin_user.php b/includes/pages/admin_user.php index f33bd222..9e09e45b 100644 --- a/includes/pages/admin_user.php +++ b/includes/pages/admin_user.php @@ -28,7 +28,7 @@ function admin_user() $goodie_enabled = $goodie !== GoodieType::None; $goodie_tshirt = $goodie === GoodieType::Tshirt; $user_info_edit = auth()->can('user.info.edit'); - $user_edit_shirt = auth()->can('user.edit.shirt'); + $user_goodie_edit = auth()->can('user.goodie.edit'); $user_edit = auth()->can('user.edit'); $admin_arrive = auth()->can('admin_arrive'); @@ -45,7 +45,7 @@ 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 ($goodie_enabled && $user_edit_shirt) { + if ($goodie_enabled && $user_goodie_edit) { 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 { @@ -89,7 +89,7 @@ function admin_user() . '' . '' . "\n"; } - if ($goodie_tshirt && $user_edit_shirt) { + if ($goodie_tshirt && $user_goodie_edit) { $html .= ' ' . __('user.shirt_size') . '' . html_select_key( 'size', @@ -129,7 +129,7 @@ function admin_user() // Active? $html .= ' ' . __('user.active') . '' . "\n"; - $html .= $user_edit_shirt + $html .= $user_goodie_edit ? html_options('eAktiv', $options, $user_source->state->active) : icon_bool($user_source->state->active); $html .= '' . "\n"; @@ -144,13 +144,13 @@ function admin_user() } if ($goodie_enabled) { - // T-Shirt bekommen? + // got goodie? $html .= ' ' . ($goodie_tshirt ? __('T-shirt') : __('Goodie')) . '' . "\n"; - $html .= $user_edit_shirt - ? html_options('eTshirt', $options, $user_source->state->got_shirt) - : icon_bool($user_source->state->got_shirt); + $html .= $user_goodie_edit + ? html_options('eTshirt', $options, $user_source->state->got_goodie) + : icon_bool($user_source->state->got_goodie); $html .= '' . "\n"; } @@ -317,7 +317,7 @@ function admin_user() $user_source->personalData->first_name = $request->postData('eVorname'); $user_source->personalData->last_name = $request->postData('eName'); } - if ($goodie_tshirt && $user_edit_shirt) { + if ($goodie_tshirt && $user_goodie_edit) { $user_source->personalData->shirt_size = $request->postData('eSize'); } $user_source->personalData->save(); @@ -328,8 +328,8 @@ function admin_user() } $user_source->contact->save(); - if ($goodie_enabled && $user_edit_shirt) { - $user_source->state->got_shirt = $request->postData('eTshirt'); + if ($goodie_enabled && $user_goodie_edit) { + $user_source->state->got_goodie = $request->postData('eTshirt'); } if ($user_info_edit) { $user_source->state->user_info = $request->postData('userInfo'); @@ -338,7 +338,7 @@ function admin_user() $user_source->state->arrived = $request->postData('arrive'); } - if ($user_edit_shirt) { + if ($user_goodie_edit) { $user_source->state->active = $request->postData('eAktiv'); } if (auth()->can('user.fa.edit') && config('enable_force_active')) { @@ -356,7 +356,7 @@ function admin_user() . ', arrived: ' . $user_source->state->arrived . ', active: ' . $user_source->state->active . ', force-active: ' . $user_source->state->force_active - . ($goodie_tshirt ? ', t-shirt: ' : ', goodie: ' . $user_source->state->got_shirt) + . ($goodie_tshirt ? ', t-shirt: ' : ', goodie: ' . $user_source->state->got_goodie) . ($user_info_edit ? ', user-info: ' . $user_source->state->user_info : '') ); $html .= success(__('Changes were saved.') . "\n", true); diff --git a/includes/sys_menu.php b/includes/sys_menu.php index 6d791bad..4e84b19e 100644 --- a/includes/sys_menu.php +++ b/includes/sys_menu.php @@ -28,7 +28,7 @@ function header_render_hints() $hints_renderer->addHint(render_user_pronoun_hint(), true); $hints_renderer->addHint(render_user_firstname_hint(), true); $hints_renderer->addHint(render_user_lastname_hint(), true); - $hints_renderer->addHint(render_user_tshirt_hint(), true); + $hints_renderer->addHint(render_user_goodie_hint(), true); $hints_renderer->addHint(render_user_dect_hint(), true); $hints_renderer->addHint(render_user_mobile_hint(), true); diff --git a/includes/view/User_view.php b/includes/view/User_view.php index d2d21b4a..8d524ec0 100644 --- a/includes/view/User_view.php +++ b/includes/view/User_view.php @@ -71,7 +71,7 @@ function User_edit_vouchers_view($user) * @param int $active_count * @param int $force_active_count * @param int $freeloads_count - * @param int $tshirts_count + * @param int $goodies_count * @param int $voucher_count * @return string */ @@ -82,7 +82,7 @@ function Users_view( $active_count, $force_active_count, $freeloads_count, - $tshirts_count, + $goodies_count, $voucher_count ) { $goodie = GoodieType::from(config('goodie_type')); @@ -105,7 +105,7 @@ function Users_view( $u['active'] = icon_bool($user->state->active); $u['force_active'] = icon_bool($user->state->force_active); if ($goodie_enabled) { - $u['got_shirt'] = icon_bool($user->state->got_shirt); + $u['got_goodie'] = icon_bool($user->state->got_goodie); if ($goodie_tshirt) { $u['shirt_size'] = $user->personalData->shirt_size; } @@ -136,7 +136,7 @@ function Users_view( 'active' => $active_count, 'force_active' => $force_active_count, 'freeloads' => $freeloads_count, - 'got_shirt' => $tshirts_count, + 'got_goodie' => $goodies_count, 'actions' => '' . count($usersList) . '', ]; @@ -163,10 +163,10 @@ function Users_view( } if ($goodie_enabled) { if ($goodie_tshirt) { - $user_table_headers['got_shirt'] = Users_table_header_link('got_shirt', __('T-Shirt'), $order_by); + $user_table_headers['got_goodie'] = Users_table_header_link('got_goodie', __('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); + $user_table_headers['got_goodie'] = Users_table_header_link('got_goodie', __('Goodie'), $order_by); } } $user_table_headers['arrival_date'] = Users_table_header_link( @@ -413,8 +413,8 @@ function User_view_myshift(Shift $shift, $user_source, $its_me) * @param Shift[]|Collection $shifts * @param User $user_source * @param bool $its_me - * @param string $tshirt_score - * @param bool $tshirt_admin + * @param string $goodie_score + * @param bool $goodie_admin * @param Worklog[]|Collection $user_worklogs * @param bool $admin_user_worklog_privilege * @@ -424,8 +424,8 @@ function User_view_myshifts( $shifts, $user_source, $its_me, - $tshirt_score, - $tshirt_admin, + $goodie_score, + $goodie_admin, $user_worklogs, $admin_user_worklog_privilege ) { @@ -475,10 +475,10 @@ function User_view_myshifts( 'comment' => '', 'actions' => '', ]; - if ($goodie_enabled && ($its_me || $tshirt_admin || auth()->can('admin_user'))) { + if ($goodie_enabled && ($its_me || $goodie_admin || auth()->can('admin_user'))) { $myshifts_table[] = [ 'date' => '' . ($goodie_tshirt ? __('T-shirt score') : __('Goodie score')) . '™:', - 'duration' => '' . $tshirt_score . '', + 'duration' => '' . $goodie_score . '', 'hints' => '', 'location' => '', 'shift_info' => '', @@ -548,8 +548,8 @@ function User_view_worklog(Worklog $worklog, $admin_user_worklog_privilege) * @param Group[] $user_groups * @param Shift[]|Collection $shifts * @param bool $its_me - * @param string $tshirt_score - * @param bool $tshirt_admin + * @param string $goodie_score + * @param bool $goodie_admin * @param bool $admin_user_worklog_privilege * @param Worklog[]|Collection $user_worklogs * @param bool $admin_certificates @@ -564,8 +564,8 @@ function User_view( $user_groups, $shifts, $its_me, - $tshirt_score, - $tshirt_admin, + $goodie_score, + $goodie_admin, $admin_user_worklog_privilege, $user_worklogs, $admin_certificates @@ -578,13 +578,13 @@ function User_view( $user_name = htmlspecialchars((string) $user_source->personalData->first_name) . ' ' . htmlspecialchars((string) $user_source->personalData->last_name); $myshifts_table = ''; - if ($its_me || $admin_user_privilege || $tshirt_admin) { + if ($its_me || $admin_user_privilege || $goodie_admin) { $my_shifts = User_view_myshifts( $shifts, $user_source, $its_me, - $tshirt_score, - $tshirt_admin, + $goodie_score, + $goodie_admin, $user_worklogs, $admin_user_worklog_privilege ); @@ -629,9 +629,9 @@ function User_view( div('row', [ div('col-md-12', [ table_buttons([ - $auth->can('user.edit.shirt') && $goodie_enabled ? button( + $auth->can('user.goodie.edit') && $goodie_enabled ? button( url('/admin/user/' . $user_source->id . '/goodie'), - icon('person') . ($goodie_tshirt ? __('Shirt') : __('Goodie')) + icon('person') . ($goodie_tshirt ? __('T-shirt') : __('Goodie')) ) : '', $admin_user_privilege ? button( url('/admin-user', ['id' => $user_source->id]), @@ -825,7 +825,7 @@ function User_view_state_admin($freeloader, $user_source) } elseif ($user_source->state->active) { $state[] = '' . __('user.active') . ''; } - if ($user_source->state->got_shirt && $goodie_enabled) { + if ($user_source->state->got_goodie && $goodie_enabled) { $state[] = '' . ($goodie_tshirt ? __('T-shirt') : __('Goodie')) . ''; } } else { @@ -1044,7 +1044,7 @@ function render_user_arrived_hint(bool $is_sys_menu = false) /** * @return string|null */ -function render_user_tshirt_hint() +function render_user_goodie_hint() { $goodie = GoodieType::from(config('goodie_type')); $goodie_tshirt = $goodie === GoodieType::Tshirt; diff --git a/resources/lang/en_US/default.po b/resources/lang/en_US/default.po index ae2be65f..e1776171 100644 --- a/resources/lang/en_US/default.po +++ b/resources/lang/en_US/default.po @@ -612,9 +612,6 @@ msgstr "Edit T-shirt" msgid "user.edit.goodie" msgstr "Edit goodie" -msgid "form.shirt" -msgstr "T-shirt" - msgid "user.shirt_size" msgstr "T-shirt size" diff --git a/resources/views/admin/user/edit-shirt.twig b/resources/views/admin/user/edit-goodie.twig similarity index 92% rename from resources/views/admin/user/edit-shirt.twig rename to resources/views/admin/user/edit-goodie.twig index b56e11a2..0b99800b 100644 --- a/resources/views/admin/user/edit-shirt.twig +++ b/resources/views/admin/user/edit-goodie.twig @@ -46,8 +46,8 @@ 'checked': userdata.state.active, }) }} - {{ f.switch('got_shirt', is_tshirt ? __('user.got_shirt') : __('user.got_goodie'), { - 'checked': userdata.state.got_shirt, + {{ f.switch('got_goodie', is_tshirt ? __('user.got_shirt') : __('user.got_goodie'), { + 'checked': userdata.state.got_goodie, }) }}
diff --git a/resources/views/pages/settings/profile.twig b/resources/views/pages/settings/profile.twig index cf9ae2d9..ced28751 100644 --- a/resources/views/pages/settings/profile.twig +++ b/resources/views/pages/settings/profile.twig @@ -155,7 +155,7 @@ 'required': isTShirtSizeRequired, 'required_icon': isTShirtSizeRequired, 'default_option': __('form.select_placeholder'), - 'disabled': userdata.state.got_shirt, + 'disabled': userdata.state.got_goodie, 'info': __('settings.profile.shirt_size.hint'), 'raw_form_text': true, 'form_text': (tShirtLink ? m.icon('info-circle') diff --git a/src/Controllers/Admin/UserShirtController.php b/src/Controllers/Admin/UserGoodieController.php similarity index 81% rename from src/Controllers/Admin/UserShirtController.php rename to src/Controllers/Admin/UserGoodieController.php index d213b0bc..a84cdd49 100644 --- a/src/Controllers/Admin/UserShirtController.php +++ b/src/Controllers/Admin/UserGoodieController.php @@ -15,14 +15,14 @@ use Engelsystem\Http\Response; use Engelsystem\Models\User\User; use Psr\Log\LoggerInterface; -class UserShirtController extends BaseController +class UserGoodieController extends BaseController { use HasUserNotifications; /** @var array */ protected array $permissions = [ - 'editShirt' => 'user.edit.shirt', - 'saveShirt' => 'user.edit.shirt', + 'editGoodie' => 'user.goodie.edit', + 'saveGoodie' => 'user.goodie.edit', ]; public function __construct( @@ -35,14 +35,14 @@ class UserShirtController extends BaseController ) { } - public function editShirt(Request $request): Response + public function editGoodie(Request $request): Response { $userId = (int) $request->getAttribute('user_id'); $user = $this->user->findOrFail($userId); return $this->response->withView( - 'admin/user/edit-shirt.twig', + 'admin/user/edit-goodie.twig', [ 'userdata' => $user, 'is_tshirt' => $this->config->get('goodie_type') === GoodieType::Tshirt->value, @@ -50,7 +50,7 @@ class UserShirtController extends BaseController ); } - public function saveShirt(Request $request): Response + public function saveGoodie(Request $request): Response { $userId = (int) $request->getAttribute('user_id'); $shirtEnabled = $this->config->get('goodie_type') === GoodieType::Tshirt->value; @@ -61,7 +61,7 @@ class UserShirtController extends BaseController 'shirt_size' => ($shirtEnabled ? 'required' : 'optional') . '|shirt_size', 'arrived' => 'optional|checked', 'active' => 'optional|checked', - 'got_shirt' => 'optional|checked', + 'got_goodie' => 'optional|checked', ]); if ($shirtEnabled) { @@ -74,19 +74,19 @@ class UserShirtController extends BaseController } $user->state->active = (bool) $data['active']; - $user->state->got_shirt = (bool) $data['got_shirt']; + $user->state->got_goodie = (bool) $data['got_goodie']; $user->state->save(); $this->log->info( - 'Updated user shirt state "{user}" ({id}): ' - . '{size}, arrived: {arrived}, active: {active}, got shirt: {got_shirt}', + 'Updated user goodie state "{user}" ({id}): ' + . '{size}, arrived: {arrived}, active: {active}, got goodie: {got_goodie}', [ 'id' => $user->id, 'user' => $user->name, 'size' => $user->personalData->shirt_size, 'arrived' => $user->state->arrived ? 'yes' : 'no', 'active' => $user->state->active ? 'yes' : 'no', - 'got_shirt' => $user->state->got_shirt ? 'yes' : 'no', + 'got_goodie' => $user->state->got_goodie ? 'yes' : 'no', ] ); diff --git a/src/Controllers/Metrics/Controller.php b/src/Controllers/Metrics/Controller.php index 8f50c55a..2121c067 100644 --- a/src/Controllers/Metrics/Controller.php +++ b/src/Controllers/Metrics/Controller.php @@ -142,7 +142,7 @@ class Controller extends BaseController 'type' => 'histogram', $this->stats->vouchersBuckets($metrics['voucher']) + ['sum' => $this->stats->vouchers()], ], - 'tshirts_issued' => ['type' => 'counter', 'help' => 'Issued T-Shirts', $this->stats->tshirts()], + 'goodies_issued' => ['type' => 'counter', 'help' => 'Issued Goodies', $this->stats->goodies()], 'tshirt_sizes' => [ 'type' => 'gauge', 'help' => 'The sizes users have configured', diff --git a/src/Controllers/Metrics/Stats.php b/src/Controllers/Metrics/Stats.php index fceede8a..e6a89e12 100644 --- a/src/Controllers/Metrics/Stats.php +++ b/src/Controllers/Metrics/Stats.php @@ -146,9 +146,9 @@ class Stats return $return; } - public function tshirts(): int + public function goodies(): int { - return State::whereGotShirt(true)->count(); + return State::whereGotGoodie(true)->count(); } public function tshirtSizes(): Collection diff --git a/src/Controllers/SettingsController.php b/src/Controllers/SettingsController.php index cfd5dbaf..908e39b5 100644 --- a/src/Controllers/SettingsController.php +++ b/src/Controllers/SettingsController.php @@ -113,7 +113,7 @@ class SettingsController extends BaseController if ( $goodie_tshirt && isset(config('tshirt_sizes')[$data['shirt_size'] ?? '']) - && !$user->state->got_shirt + && !$user->state->got_goodie ) { $user->personalData->shirt_size = $data['shirt_size']; } @@ -477,7 +477,7 @@ class SettingsController extends BaseController $rules['planned_arrival_date'] = 'required|date:Y-m-d'; $rules['planned_departure_date'] = 'optional|date:Y-m-d'; } - if ($goodie_tshirt && !$user->state->got_shirt) { + if ($goodie_tshirt && !$user->state->got_goodie) { $rules['shirt_size'] = $this->isRequired('tshirt_size') . '|shirt_size'; } return $rules; diff --git a/src/Models/User/State.php b/src/Models/User/State.php index 64c0ea40..e3000a58 100644 --- a/src/Models/User/State.php +++ b/src/Models/User/State.php @@ -14,7 +14,7 @@ use Illuminate\Database\Query\Builder as QueryBuilder; * @property string|null $user_info * @property bool $active * @property bool $force_active - * @property bool $got_shirt + * @property bool $got_goodie * @property int $got_voucher * * @method static QueryBuilder|State[] whereArrived($value) @@ -22,7 +22,7 @@ use Illuminate\Database\Query\Builder as QueryBuilder; * @method static QueryBuilder|State[] whereUserInfo($value) * @method static QueryBuilder|State[] whereActive($value) * @method static QueryBuilder|State[] whereForceActive($value) - * @method static QueryBuilder|State[] whereGotShirt($value) + * @method static QueryBuilder|State[] whereGotGoodie($value) * @method static QueryBuilder|State[] whereGotVoucher($value) */ class State extends HasUserModel @@ -39,7 +39,7 @@ class State extends HasUserModel 'user_info' => null, 'active' => false, 'force_active' => false, - 'got_shirt' => false, + 'got_goodie' => false, 'got_voucher' => 0, ]; @@ -49,7 +49,7 @@ class State extends HasUserModel 'arrived' => 'boolean', 'active' => 'boolean', 'force_active' => 'boolean', - 'got_shirt' => 'boolean', + 'got_goodie' => 'boolean', 'got_voucher' => 'integer', 'arrival_date' => 'datetime', ]; @@ -66,7 +66,7 @@ class State extends HasUserModel 'user_info', 'active', 'force_active', - 'got_shirt', + 'got_goodie', 'got_voucher', ]; } diff --git a/tests/Unit/Controllers/Admin/UserShirtControllerTest.php b/tests/Unit/Controllers/Admin/UserGoodieControllerTest.php similarity index 75% rename from tests/Unit/Controllers/Admin/UserShirtControllerTest.php rename to tests/Unit/Controllers/Admin/UserGoodieControllerTest.php index 6626d64e..17299df8 100644 --- a/tests/Unit/Controllers/Admin/UserShirtControllerTest.php +++ b/tests/Unit/Controllers/Admin/UserGoodieControllerTest.php @@ -5,7 +5,7 @@ declare(strict_types=1); namespace Engelsystem\Test\Unit\Controllers\Admin; use Engelsystem\Config\GoodieType; -use Engelsystem\Controllers\Admin\UserShirtController; +use Engelsystem\Controllers\Admin\UserGoodieController; use Engelsystem\Helpers\Authenticator; use Engelsystem\Http\Exceptions\ValidationException; use Engelsystem\Http\Redirector; @@ -18,13 +18,13 @@ use Engelsystem\Test\Unit\HasDatabase; use Illuminate\Database\Eloquent\ModelNotFoundException; use PHPUnit\Framework\MockObject\MockObject; -class UserShirtControllerTest extends ControllerTest +class UserGoodieControllerTest extends ControllerTest { use HasDatabase; /** - * @covers \Engelsystem\Controllers\Admin\UserShirtController::editShirt - * @covers \Engelsystem\Controllers\Admin\UserShirtController::__construct + * @covers \Engelsystem\Controllers\Admin\UserGoodieController::editGoodie + * @covers \Engelsystem\Controllers\Admin\UserGoodieController::__construct */ public function testIndex(): void { @@ -36,15 +36,15 @@ class UserShirtControllerTest extends ControllerTest $user = new User(); User::factory()->create(); - $this->setExpects($this->response, 'withView', ['admin/user/edit-shirt.twig'], $this->response); + $this->setExpects($this->response, 'withView', ['admin/user/edit-goodie.twig'], $this->response); - $controller = new UserShirtController($auth, $this->config, $this->log, $redirector, $this->response, $user); + $controller = new UserGoodieController($auth, $this->config, $this->log, $redirector, $this->response, $user); - $controller->editShirt($request); + $controller->editGoodie($request); } /** - * @covers \Engelsystem\Controllers\Admin\UserShirtController::editShirt + * @covers \Engelsystem\Controllers\Admin\UserGoodieController::editGoodie */ public function testIndexUserNotFound(): void { @@ -54,17 +54,17 @@ class UserShirtControllerTest extends ControllerTest $redirector = $this->createMock(Redirector::class); $user = new User(); - $controller = new UserShirtController($auth, $this->config, $this->log, $redirector, $this->response, $user); + $controller = new UserGoodieController($auth, $this->config, $this->log, $redirector, $this->response, $user); $this->expectException(ModelNotFoundException::class); - $controller->editShirt($this->request); + $controller->editGoodie($this->request); } /** * @todo Factor out separate tests. Isolated User, Config and permissions per test. - * @covers \Engelsystem\Controllers\Admin\UserShirtController::saveShirt + * @covers \Engelsystem\Controllers\Admin\UserGoodieController::saveGoodie */ - public function testSaveShirt(): void + public function testSaveGoodie(): void { $this->config->set('goodie_type', GoodieType::Tshirt->value); $request = $this->request @@ -89,7 +89,7 @@ class UserShirtControllerTest extends ControllerTest ->willReturnOnConsecutiveCalls(true, true, false, false, true); $this->setExpects($redirector, 'back', null, $this->response, $this->exactly(5)); - $controller = new UserShirtController( + $controller = new UserGoodieController( $auth, $this->config, $this->log, @@ -100,32 +100,32 @@ class UserShirtControllerTest extends ControllerTest $controller->setValidator(new Validator()); // Set shirt size - $controller->saveShirt($request); + $controller->saveGoodie($request); $this->assertHasNotification('user.edit.success'); - $this->assertTrue($this->log->hasInfoThatContains('Updated user shirt state')); + $this->assertTrue($this->log->hasInfoThatContains('Updated user goodie state')); $user = User::find(1); $this->assertEquals('S', $user->personalData->shirt_size); $this->assertFalse($user->state->arrived); $this->assertFalse($user->state->active); - $this->assertFalse($user->state->got_shirt); + $this->assertFalse($user->state->got_goodie); - // Set active, arrived and got_shirt + // Set active, arrived and got_goodie $request = $request ->withParsedBody([ 'shirt_size' => 'S', 'arrived' => '1', 'active' => '1', - 'got_shirt' => '1', + 'got_goodie' => '1', ]); - $controller->saveShirt($request); + $controller->saveGoodie($request); $user = User::find(1); $this->assertTrue($user->state->active); $this->assertTrue($user->state->arrived); - $this->assertTrue($user->state->got_shirt); + $this->assertTrue($user->state->got_goodie); // Shirt size not available $request = $request @@ -134,7 +134,7 @@ class UserShirtControllerTest extends ControllerTest ]); try { - $controller->saveShirt($request); + $controller->saveGoodie($request); self::fail('Expected exception was not raised'); } catch (ValidationException) { // ignore @@ -152,18 +152,18 @@ class UserShirtControllerTest extends ControllerTest $user->state->arrived = false; $user->state->save(); $this->assertFalse($user->state->arrived); - $controller->saveShirt($request); + $controller->saveGoodie($request); $user = User::find(1); $this->assertFalse($user->state->arrived); - // Shirt disabled + // Goodie disabled $this->config->set('goodie_type', GoodieType::None->value); $request = $request ->withParsedBody([ 'shirt_size' => 'XS', ]); - $controller->saveShirt($request); + $controller->saveGoodie($request); $user = User::find(1); $this->assertEquals('S', $user->personalData->shirt_size); @@ -174,15 +174,15 @@ class UserShirtControllerTest extends ControllerTest 'shirt_size' => 'XS', ]); - $controller->saveShirt($request); + $controller->saveGoodie($request); $user = User::find(1); $this->assertEquals('XS', $user->personalData->shirt_size); } /** - * @covers \Engelsystem\Controllers\Admin\UserShirtController::saveShirt + * @covers \Engelsystem\Controllers\Admin\UserGoodieController::saveGoodie */ - public function testSaveShirtUserNotFound(): void + public function testSaveGoodieUserNotFound(): void { /** @var Authenticator|MockObject $auth */ $auth = $this->createMock(Authenticator::class); @@ -190,9 +190,9 @@ class UserShirtControllerTest extends ControllerTest $redirector = $this->createMock(Redirector::class); $user = new User(); - $controller = new UserShirtController($auth, $this->config, $this->log, $redirector, $this->response, $user); + $controller = new UserGoodieController($auth, $this->config, $this->log, $redirector, $this->response, $user); $this->expectException(ModelNotFoundException::class); - $controller->editShirt($this->request); + $controller->editGoodie($this->request); } } diff --git a/tests/Unit/Controllers/Metrics/ControllerTest.php b/tests/Unit/Controllers/Metrics/ControllerTest.php index c9d26d2e..79ec3df4 100644 --- a/tests/Unit/Controllers/Metrics/ControllerTest.php +++ b/tests/Unit/Controllers/Metrics/ControllerTest.php @@ -52,7 +52,7 @@ class ControllerTest extends TestCase $this->assertArrayHasKey('work_seconds', $data); $this->assertArrayHasKey('worklog_seconds', $data); $this->assertArrayHasKey('vouchers', $data); - $this->assertArrayHasKey('tshirts_issued', $data); + $this->assertArrayHasKey('goodies_issued', $data); $this->assertArrayHasKey('tshirt_sizes', $data); $this->assertArrayHasKey('locales', $data); $this->assertArrayHasKey('themes', $data); @@ -141,7 +141,7 @@ class ControllerTest extends TestCase ->willReturnOnConsecutiveCalls(0, 1, 0, 5, 999, 4, 55, 3); $this->setExpects($stats, 'worklogSeconds', null, 39 * 60 * 60); $this->setExpects($stats, 'vouchers', null, 17); - $this->setExpects($stats, 'tshirts', null, 3); + $this->setExpects($stats, 'goodies', null, 3); $this->setExpects($stats, 'tshirtSizes', null, new Collection([ ['shirt_size' => 'L', 'count' => 2], ])); diff --git a/tests/Unit/Controllers/Metrics/StatsTest.php b/tests/Unit/Controllers/Metrics/StatsTest.php index 8b4355e7..024b9882 100644 --- a/tests/Unit/Controllers/Metrics/StatsTest.php +++ b/tests/Unit/Controllers/Metrics/StatsTest.php @@ -59,14 +59,14 @@ class StatsTest extends TestCase } /** - * @covers \Engelsystem\Controllers\Metrics\Stats::tshirts + * @covers \Engelsystem\Controllers\Metrics\Stats::goodies */ - public function testTshirts(): void + public function testGoodies(): void { $this->addUsers(); $stats = new Stats($this->database); - $this->assertEquals(2, $stats->tshirts()); + $this->assertEquals(2, $stats->goodies()); } /** @@ -539,8 +539,8 @@ class StatsTest extends TestCase 'ifsg_confirmed' => true, ] ); - $this->addUser(['arrived' => 1, 'active' => 1, 'got_shirt' => true, 'force_active' => true]); - $this->addUser(['arrived' => 1, 'active' => 1, 'got_shirt' => true], ['shirt_size' => 'L'], ['theme' => 4]); + $this->addUser(['arrived' => 1, 'active' => 1, 'got_goodie' => true, 'force_active' => true]); + $this->addUser(['arrived' => 1, 'active' => 1, 'got_goodie' => true], ['shirt_size' => 'L'], ['theme' => 4]); } protected function addUser(