diff --git a/includes/controller/angeltypes_controller.php b/includes/controller/angeltypes_controller.php index 75691602..c2a54774 100644 --- a/includes/controller/angeltypes_controller.php +++ b/includes/controller/angeltypes_controller.php @@ -88,7 +88,7 @@ function angeltype_delete_controller() if (request()->hasPostData('delete')) { $angeltype->delete(); engelsystem_log('Deleted angeltype: ' . AngelType_name_render($angeltype, true)); - success(sprintf(__('Angeltype %s deleted.'), AngelType_name_render($angeltype))); + success(sprintf(__('Angeltype %s deleted.'), $angeltype->name)); throw_redirect(page_link_to('angeltypes')); } diff --git a/includes/controller/shift_entries_controller.php b/includes/controller/shift_entries_controller.php index fa3f6d95..b28ff009 100644 --- a/includes/controller/shift_entries_controller.php +++ b/includes/controller/shift_entries_controller.php @@ -108,7 +108,7 @@ function shift_entry_create_controller_admin(Shift $shift, ?AngelType $angeltype $shiftEntry->save(); ShiftEntry_onCreate($shiftEntry); - success(sprintf(__('%s has been subscribed to the shift.'), User_Nick_render($signup_user))); + success(sprintf(__('%s has been subscribed to the shift.'), $signup_user->name)); throw_redirect(shift_link($shift)); } @@ -157,7 +157,7 @@ function shift_entry_create_controller_supporter(Shift $shift, AngelType $angelt $shiftEntry->save(); ShiftEntry_onCreate($shiftEntry); - success(sprintf(__('%s has been subscribed to the shift.'), User_Nick_render($signup_user))); + success(sprintf(__('%s has been subscribed to the shift.'), $signup_user->name)); throw_redirect(shift_link($shift)); } diff --git a/includes/controller/user_angeltypes_controller.php b/includes/controller/user_angeltypes_controller.php index 4710a50a..917769f6 100644 --- a/includes/controller/user_angeltypes_controller.php +++ b/includes/controller/user_angeltypes_controller.php @@ -82,7 +82,7 @@ function user_angeltypes_delete_all_controller(): array ->delete(); engelsystem_log(sprintf('Denied all users for angeltype %s', AngelType_name_render($angeltype, true))); - success(sprintf(__('Denied all users for angeltype %s.'), AngelType_name_render($angeltype))); + success(sprintf(__('Denied all users for angeltype %s.'), $angeltype->name)); throw_redirect(page_link_to('angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype->id])); } @@ -121,7 +121,7 @@ function user_angeltypes_confirm_all_controller(): array ->update(['confirm_user_id' => $user->id]); engelsystem_log(sprintf('Confirmed all users for angeltype %s', AngelType_name_render($angeltype, true))); - success(sprintf(__('Confirmed all users for angeltype %s.'), AngelType_name_render($angeltype))); + success(sprintf(__('Confirmed all users for angeltype %s.'), $angeltype->name)); foreach ($users as $user) { user_angeltype_confirm_email($user, $angeltype); @@ -169,11 +169,7 @@ function user_angeltype_confirm_controller(): array User_Nick_render($user_source, true), AngelType_name_render($angeltype, true) )); - success(sprintf( - __('%s confirmed for angeltype %s.'), - User_Nick_render($user_source), - AngelType_name_render($angeltype) - )); + success(sprintf(__('%s confirmed for angeltype %s.'), $user_source->name, $angeltype->name)); user_angeltype_confirm_email($user_source, $angeltype); @@ -268,7 +264,7 @@ function user_angeltype_delete_controller(): array $user_angeltype->delete(); engelsystem_log(sprintf('User %s removed from %s.', User_Nick_render($user_source, true), $angeltype->name)); - success(sprintf(__('User %s removed from %s.'), User_Nick_render($user_source), $angeltype->name)); + success(sprintf(__('User %s removed from %s.'), $user_source->name, $angeltype->name)); throw_redirect(page_link_to('angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype->id])); } @@ -323,11 +319,7 @@ function user_angeltype_update_controller(): array AngelType_name_render($angeltype, true), User_Nick_render($user_source, true) )); - success(sprintf( - $msg, - AngelType_name_render($angeltype), - User_Nick_render($user_source) - )); + success(sprintf($msg, $angeltype->name, $user_source->name)); throw_redirect(page_link_to('angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype->id])); } @@ -375,11 +367,7 @@ function user_angeltype_add_controller(): array User_Nick_render($user_source, true), AngelType_name_render($angeltype, true) )); - success(sprintf( - __('User %s added to %s.'), - User_Nick_render($user_source), - AngelType_name_render($angeltype) - )); + success(sprintf(__('User %s added to %s.'), $user_source->name, $angeltype->name)); if ($request->hasPostData('auto_confirm_user')) { $userAngelType->confirmUser()->associate($user_source); diff --git a/includes/helper/email_helper.php b/includes/helper/email_helper.php index eff64675..f3b8826c 100644 --- a/includes/helper/email_helper.php +++ b/includes/helper/email_helper.php @@ -48,7 +48,7 @@ function engelsystem_email_to_user($recipientUser, $title, $message, $notIfItsMe $translator->setLocale($locale); if (!$status) { - error(sprintf(__('User %s could not be notified by email due to an error.'), User_Nick_render($recipientUser))); + error(sprintf(__('User %s could not be notified by email due to an error.'), $recipientUser->name)); engelsystem_log(sprintf('User %s could not be notified by email due to an error.', $recipientUser->name)); } diff --git a/includes/helper/message_helper.php b/includes/helper/message_helper.php index 52c63eb3..13526a63 100644 --- a/includes/helper/message_helper.php +++ b/includes/helper/message_helper.php @@ -1,40 +1,15 @@ get('msg', ''); - $session->set('msg', ''); - - if ($includeMessagesFromNewProcedure) { - foreach (session()->get('errors', []) as $msg) { - $message .= error(__($msg), true); - } - foreach (session()->get('warnings', []) as $msg) { - $message .= warning(__($msg), true); - } - foreach (session()->get('information', []) as $msg) { - $message .= info(__($msg), true); - } - foreach (session()->get('messages', []) as $msg) { - $message .= success(__($msg), true); - } - - foreach (['errors', 'warnings', 'information', 'messages'] as $type) { - session()->remove($type); - } - } - - return $message; + return view('layouts/parts/messages.twig'); } /** @@ -46,7 +21,7 @@ function msg(bool $includeMessagesFromNewProcedure = false) */ function info($msg, $immediately = false) { - return alert('info', $msg, $immediately); + return alert(NotificationType::INFORMATION, $msg, $immediately); } /** @@ -58,7 +33,7 @@ function info($msg, $immediately = false) */ function warning($msg, $immediately = false) { - return alert('warning', $msg, $immediately); + return alert(NotificationType::WARNING, $msg, $immediately); } /** @@ -70,7 +45,7 @@ function warning($msg, $immediately = false) */ function error($msg, $immediately = false) { - return alert('danger', $msg, $immediately); + return alert(NotificationType::ERROR, $msg, $immediately); } /** @@ -82,31 +57,44 @@ function error($msg, $immediately = false) */ function success($msg, $immediately = false) { - return alert('success', $msg, $immediately); + return alert(NotificationType::MESSAGE, $msg, $immediately); } /** - * Renders an alert message with the given alert-* class. + * Renders an alert message with the given alert-* class or sets it in session * - * @param string $class - * @param string $msg - * @param bool $immediately + * @see \Engelsystem\Controllers\HasUserNotifications + * + * @param NotificationType $type + * @param string $msg + * @param bool $immediately * @return string */ -function alert($class, $msg, $immediately = false) +function alert(NotificationType $type, $msg, $immediately = false) { if (empty($msg)) { return ''; } if ($immediately) { - return '