diff --git a/includes/includes.php b/includes/includes.php
index 34678103..65be2323 100644
--- a/includes/includes.php
+++ b/includes/includes.php
@@ -74,7 +74,6 @@ $includeFiles = [
__DIR__ . '/../includes/pages/admin_user.php',
__DIR__ . '/../includes/pages/guest_login.php',
__DIR__ . '/../includes/pages/user_myshifts.php',
- __DIR__ . '/../includes/pages/user_settings.php',
__DIR__ . '/../includes/pages/user_shifts.php',
__DIR__ . '/../includes/pages/schedule/ImportSchedule.php',
diff --git a/includes/pages/user_settings.php b/includes/pages/user_settings.php
deleted file mode 100644
index 5df5c82e..00000000
--- a/includes/pages/user_settings.php
+++ /dev/null
@@ -1,149 +0,0 @@
-has('mail')) {
- $result = User_validate_mail($request->input('mail'));
- $user_source->email = $result->getValue();
- if (!$result->isValid()) {
- $valid = false;
- error(__('E-mail address is not correct.'));
- }
- } else {
- $valid = false;
- error(__('Please enter your e-mail.'));
- }
-
- $user_source->settings->email_shiftinfo = $request->has('email_shiftinfo');
- $user_source->settings->email_human = $request->has('email_by_human_allowed');
- $user_source->settings->email_news = $request->has('email_news');
- if (config('enable_goody')) {
- $user_source->settings->email_goody = $request->has('email_goody');
- }
-
- if ($request->has('tshirt_size') && isset($tshirt_sizes[$request->input('tshirt_size')])) {
- $user_source->personalData->shirt_size = $request->input('tshirt_size');
- } elseif ($enable_tshirt_size) {
- $valid = false;
- }
-
- if ($request->has('planned_arrival_date') && $request->input('planned_arrival_date')) {
- $tmp = parse_date('Y-m-d H:i', $request->input('planned_arrival_date') . ' 00:00');
- $result = User_validate_planned_arrival_date($tmp);
- $user_source->personalData->planned_arrival_date = Carbon::createFromTimestamp($result->getValue());
- if (!$result->isValid()) {
- $valid = false;
- error(__('Please enter your planned date of arrival. It should be after the buildup start date and before teardown end date.'));
- }
- }
-
- if ($request->has('planned_departure_date') && $request->input('planned_departure_date')) {
- $tmp = parse_date('Y-m-d H:i', $request->input('planned_departure_date') . ' 00:00');
- $plannedArrivalDate = $user_source->personalData->planned_arrival_date;
- $result = User_validate_planned_departure_date(
- $plannedArrivalDate ? $plannedArrivalDate->getTimestamp() : 0,
- $tmp
- );
- $user_source->personalData->planned_departure_date = Carbon::createFromTimestamp($result->getValue());
- if (!$result->isValid()) {
- $valid = false;
- error(__('Please enter your planned date of departure. It should be after your planned arrival date and after buildup start date and before teardown end date.'));
- }
- }
-
- // Trivia
- $pronoun = strip_request_item('pronoun', $user_source->personalData->pronoun);
- if (config('enable_pronoun') && mb_strlen($pronoun) <= 15) {
- $user_source->personalData->pronoun = $pronoun;
- }
- if (config('enable_user_name')) {
- $user_source->personalData->last_name = strip_request_item('lastname', $user_source->personalData->last_name);
- $user_source->personalData->first_name = strip_request_item('prename', $user_source->personalData->first_name);
- }
- if (config('enable_dect')) {
- if (strlen(strip_request_item('dect')) <= 40) {
- $user_source->contact->dect = strip_request_item('dect', $user_source->contact->dect);
- } else {
- $valid = false;
- error(__('For dect numbers are only 40 digits allowed.'));
- }
- }
- $user_source->contact->mobile = strip_request_item('mobile', $user_source->contact->mobile);
- if (config('enable_mobile_show')) {
- $user_source->settings->mobile_show = $request->has('mobile_show');
- }
-
- if ($valid) {
- $user_source->save();
- $user_source->contact->save();
- $user_source->personalData->save();
- $user_source->settings->save();
-
- success(__('Settings saved.'));
- throw_redirect(page_link_to('user_settings'));
- }
-
- return $user_source;
-}
-
-/**
- * Main user settings page/controller
- *
- * @return string
- */
-function user_settings()
-{
- $request = request();
- $config = config();
-
- $enable_tshirt_size = config('enable_tshirt_size');
- $tshirt_sizes = config('tshirt_sizes');
-
- $buildup_start_date = null;
- $teardown_end_date = null;
-
- if ($buildup = $config->get('buildup_start')) {
- /** @var Carbon $buildup */
- $buildup_start_date = $buildup->getTimestamp();
- }
-
- if ($teardown = $config->get('teardown_end')) {
- /** @var Carbon $teardown */
- $teardown_end_date = $teardown->getTimestamp();
- }
-
- $user_source = auth()->user();
- if ($request->hasPostData('submit')) {
- $user_source = user_settings_main($user_source, $enable_tshirt_size, $tshirt_sizes);
- }
-
- return User_settings_view(
- $user_source,
- $buildup_start_date,
- $teardown_end_date,
- $enable_tshirt_size,
- $tshirt_sizes
- );
-}
diff --git a/includes/sys_menu.php b/includes/sys_menu.php
index 0d653b2f..c7e70675 100644
--- a/includes/sys_menu.php
+++ b/includes/sys_menu.php
@@ -65,9 +65,9 @@ function make_user_submenu()
if (auth()->can('user_settings')) {
$user_submenu[] = toolbar_dropdown_item(
- page_link_to('user_settings'),
+ page_link_to('settings/profile'),
__('Settings'),
- $page == 'user_settings',
+ $page == 'settings/profile',
'gear'
);
}
diff --git a/includes/view/User_view.php b/includes/view/User_view.php
index 0b8fc197..db8a4f22 100644
--- a/includes/view/User_view.php
+++ b/includes/view/User_view.php
@@ -1,139 +1,11 @@
personalData;
- $enable_user_name = config('enable_user_name');
- $enable_pronoun = config('enable_pronoun');
- $enable_dect = config('enable_dect');
- $enable_planned_arrival = config('enable_planned_arrival');
- $enable_goody = config('enable_goody');
- $enable_mobile_show = config('enable_mobile_show');
-
- /** @var $urlGenerator UrlGeneratorInterface */
- $urlGenerator = app(UrlGeneratorInterface::class);
- /** @var Renderer $renderer */
- $renderer = app(Renderer::class);
- return $renderer->render(
- 'pages/settings/settings.twig',
- [
- 'title' => 'settings.profile',
- 'settings_menu' => app()->make(SettingsController::class)->settingsMenu(),
- 'content' =>
- msg()
- . div('row', [
- div('col-md-9', [
- form([
- form_info('', __('Here you can change your user details.')),
- form_info(entry_required() . ' = ' . __('Entry required!')),
- form_text('nick', __('Nick'), $user_source->name, true),
- $enable_pronoun
- ? form_text('pronoun', __('Pronoun'), $personalData->pronoun, false, 15)
- . form_info('', __('Will be shown on your profile page and in angel lists.'))
- : '',
- $enable_user_name
- ? form_text('lastname', __('Last name'), $personalData->last_name, false, 64)
- : '',
- $enable_user_name
- ? form_text('prename', __('First name'), $personalData->first_name, false, 64)
- : '',
- $enable_planned_arrival ? form_date(
- 'planned_arrival_date',
- __('Planned date of arrival') . ' ' . entry_required(),
- $personalData->planned_arrival_date
- ? $personalData->planned_arrival_date->getTimestamp()
- : '',
- $buildup_start_date,
- $teardown_end_date
- ) : '',
- $enable_planned_arrival ? form_date(
- 'planned_departure_date',
- __('Planned date of departure'),
- $personalData->planned_departure_date
- ? $personalData->planned_departure_date->getTimestamp()
- : '',
- $buildup_start_date,
- $teardown_end_date
- ) : '',
- $enable_dect ? form_text('dect', __('DECT'), $user_source->contact->dect, false, 40) : '',
- form_text('mobile', __('Mobile'), $user_source->contact->mobile, false, 40),
- $enable_mobile_show ? form_checkbox(
- 'mobile_show',
- __('Show mobile number to other users to contact me'),
- $user_source->settings->mobile_show
- ) : '',
- form_text('mail', __('E-Mail') . ' ' . entry_required(), $user_source->email, false, 254),
- form_checkbox(
- 'email_shiftinfo',
- __(
- 'The %s is allowed to send me an email (e.g. when my shifts change)',
- [config('app_name')]
- ),
- $user_source->settings->email_shiftinfo
- ),
- form_checkbox(
- 'email_news',
- __('Notify me of new news'),
- $user_source->settings->email_news
- ),
- form_checkbox(
- 'email_by_human_allowed',
- __('Allow heaven angels to contact you by e-mail.'),
- $user_source->settings->email_human
- ),
- $enable_goody ? 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.')
- . (config('privacy_email') ? ' ' . __('To withdraw your approval, send an email to %1$s.', [config('privacy_email')]) : ''),
- $user_source->settings->email_goody
- ) : '',
- $enable_tshirt_size ? form_select(
- 'tshirt_size',
- __('Shirt size'),
- $tshirt_sizes,
- $personalData->shirt_size,
- __('Please select...')
- ) : '',
- form_info(
- '',
- __(
- 'You can manage your Angeltypes on the Angeltypes page.',
- [$urlGenerator->to('angeltypes')]
- )
- ),
- form_submit('submit', __('Save'))
- ]),
- ])
- ])
- ]
- );
-}
/**
* Gui for deleting user with password field.
@@ -363,7 +235,7 @@ function User_view_shiftentries($needed_angel_type)
{
$shift_info = '
' . $needed_angel_type['name'] . ': ';
+ .'">' . $needed_angel_type['name'] . ': ';
$shift_entries = [];
foreach ($needed_angel_type['users'] as $user_shift) {
@@ -585,8 +457,8 @@ function User_view(
$auth = auth();
$nightShiftsConfig = config('night_shifts');
$user_name = htmlspecialchars(
- $user_source->personalData->first_name
- ) . ' ' . htmlspecialchars($user_source->personalData->last_name);
+ $user_source->personalData->first_name) . ' ' . htmlspecialchars($user_source->personalData->last_name
+ );
$myshifts_table = '';
if ($its_me || $admin_user_privilege) {
$my_shifts = User_view_myshifts(
@@ -658,7 +530,7 @@ function User_view(
icon('list') . __('Add work log')
) : '',
$its_me ? button(
- page_link_to('user_settings'),
+ page_link_to('settings/profile'),
icon('gear') . __('Settings')
) : '',
($its_me && $auth->can('ical')) ? button(
@@ -682,7 +554,7 @@ function User_view(
]),
div('row user-info', [
div('col-md-2', [
- config('enable_dect') && $user_source->contact->dect ?
+ config('enable_dect') ?
heading(
icon('phone')
. ' '
@@ -690,16 +562,6 @@ function User_view(
. ''
)
: '' ,
- config('enable_mobile_show') && $user_source->contact->mobile ?
- $user_source->settings->mobile_show ?
- heading(
- icon('phone')
- . ' '
- . $user_source->contact->mobile
- . ''
- )
- : ''
- : '' ,
$auth->can('user_messages') ?
heading(
''
@@ -725,9 +587,9 @@ function User_view(
) : '',
$its_me && count($shifts) == 0
? error(sprintf(
- __('Go to the shifts table to sign yourself up for some shifts.'),
- page_link_to('user_shifts')
- ), true)
+ __('Go to the shifts table to sign yourself up for some shifts.'),
+ page_link_to('user_shifts')
+ ), true)
: '',
$its_me ? ical_hint() : ''
]
@@ -952,7 +814,7 @@ function User_Pronoun_render(User $user): string
*/
function render_profile_link($text, $user_id = null, $class = '')
{
- $profile_link = page_link_to('user-settings');
+ $profile_link = page_link_to('settings/profile');
if (!is_null($user_id)) {
$profile_link = page_link_to('users', ['action' => 'view', 'user_id' => $user_id]);
}
diff --git a/resources/lang/de_DE/default.po b/resources/lang/de_DE/default.po
index 0b37716e..4a83a98b 100644
--- a/resources/lang/de_DE/default.po
+++ b/resources/lang/de_DE/default.po
@@ -245,7 +245,6 @@ msgstr ""
"Wir haben dir eine eMail mit einem Link zum Passwort-zurücksetzen geschickt."
#: resources/views/pages/password/reset-success.twig:9
-#: includes/pages/user_settings.php:120
msgid "Password saved."
msgstr "Passwort gespeichert."
@@ -388,7 +387,6 @@ msgid "The buildup start date has to be before the teardown end date."
msgstr "Das Aufbau Start Datum muss vor dem Abbau Ende Datum liegen."
#: includes/controller/event_config_controller.php:120
-#: includes/pages/user_settings.php:93
msgid "Settings saved."
msgstr "Einstellungen gespeichert."
@@ -1586,7 +1584,7 @@ msgstr "Der Nick "%s" existiert schon."
msgid "Please enter a nickname."
msgstr "Gib bitte einen Nick an."
-#: includes/pages/guest_login.php:93 includes/pages/user_settings.php:32
+#: includes/pages/guest_login.php:93
msgid "E-mail address is not correct."
msgstr "Die E-Mail Adresse ist nicht in Ordnung."
@@ -1594,7 +1592,7 @@ msgstr "Die E-Mail Adresse ist nicht in Ordnung."
msgid "E-mail address is already used by another user."
msgstr "Die E-Mail Adresse wurde bereits von einem anderen User benutzt."
-#: includes/pages/guest_login.php:101 includes/pages/user_settings.php:36
+#: includes/pages/guest_login.php:101
msgid "Please enter your e-mail."
msgstr "Bitte gib Deine E-Mail-Adresse ein."
@@ -1608,7 +1606,6 @@ msgid "Your password is too short (please use at least %s characters)."
msgstr "Dein Passwort ist zu kurz (Bitte mindestens %s Zeichen nutzen)."
#: includes/pages/guest_login.php:140 includes/pages/guest_login.php:144
-#: includes/pages/user_settings.php:54
msgid ""
"Please enter your planned date of arrival. It should be after the buildup "
"start date and before teardown end date."
@@ -1616,7 +1613,7 @@ msgstr ""
"Bitte gib Dein geplantes Ankunftsdatum an. Es sollte nach dem Aufbaubeginn "
"und vor dem Abbauende liegen."
-#: includes/pages/guest_login.php:166 includes/pages/user_settings.php:82
+#: includes/pages/guest_login.php:166
msgid "For dect numbers are only 40 digits allowed."
msgstr "Die DECT Nummer darf nur 40 Zeichen lang sein."
@@ -1809,12 +1806,11 @@ msgstr "Unvollständiger Aufruf, fehlende Fragen ID."
msgid "No question found."
msgstr "Keine Frage gefunden."
-#: includes/pages/user_settings.php:11 includes/sys_menu.php:69
+#: includes/sys_menu.php:69
#: includes/view/User_view.php:616
msgid "Settings"
msgstr "Einstellungen"
-#: includes/pages/user_settings.php:68
msgid ""
"Please enter your planned date of departure. It should be after your planned "
"arrival date and after buildup start date and before teardown end date."
@@ -1822,11 +1818,9 @@ msgstr ""
"Bitte gibt dein geplantes Abreisedatum an. Es sollte nach Deinem "
"Anreisedatum, nach dem Aufbaubeginn und vor dem Abbauende liegen."
-#: includes/pages/user_settings.php:113
msgid "-> not OK. Please try again."
msgstr "-> Nicht OK. Bitte erneut versuchen."
-#: includes/pages/user_settings.php:115
msgid "Your password is to short (please use at least 6 characters)."
msgstr "Dein Passwort ist zu kurz (Bitte mindestens 6 Zeichen nutzen)."
diff --git a/resources/lang/pt_BR/default.po b/resources/lang/pt_BR/default.po
index 56baa9a2..2cf11581 100644
--- a/resources/lang/pt_BR/default.po
+++ b/resources/lang/pt_BR/default.po
@@ -139,7 +139,6 @@ msgid "The buildup start date has to be before the teardown end date."
msgstr "A data de montagem deve ser anterior a data de desmontagem do evento."
#: includes/controller/event_config_controller.php:92
-#: includes/pages/user_settings.php:77
msgid "Settings saved."
msgstr "Configurações salvas."
@@ -515,28 +514,26 @@ msgid "Token is not correct."
msgstr "O token não está correto."
#: includes/controller/users_controller.php:227
-#: includes/pages/guest_login.php:102 includes/pages/user_settings.php:97
+#: includes/pages/guest_login.php:102
msgid "Your passwords don't match."
msgstr "Suas senhas não correspondem."
#: includes/controller/users_controller.php:231
-#: includes/pages/user_settings.php:95
msgid "Your password is to short (please use at least 6 characters)."
msgstr "Sua senha é muito curta (por favor use no mínimo 6 caracteres)."
#: includes/controller/users_controller.php:236
-#: includes/pages/user_settings.php:99
msgid "Password saved."
msgstr "Sua senha foi salva."
#: includes/controller/users_controller.php:257
#: includes/controller/users_controller.php:261
-#: includes/pages/guest_login.php:67 includes/pages/user_settings.php:21
+#: includes/pages/guest_login.php:67
msgid "E-mail address is not correct."
msgstr "E-mail não está correto."
#: includes/controller/users_controller.php:265
-#: includes/pages/guest_login.php:71 includes/pages/user_settings.php:25
+#: includes/pages/guest_login.php:71
msgid "Please enter your e-mail."
msgstr "Por favor digite seu e-mail."
@@ -1307,7 +1304,7 @@ msgstr "Seu apelido "%s" já existe."
msgid "Your nick "%s" is too short (min. 2 characters)."
msgstr "Seu apelido "%s" é muito pequeno (mínimo 2 caracteres)."
-#: includes/pages/guest_login.php:86 includes/pages/user_settings.php:36
+#: includes/pages/guest_login.php:86
msgid "Please check your jabber account information."
msgstr "Por favor verifique a informação da sua conta jabber."
@@ -1320,7 +1317,7 @@ msgstr "Por favor escolha o tamanho da camisa."
msgid "Your password is too short (please use at least %s characters)."
msgstr "Sua senha é muito curta (por favor use pelo menos %s caracteres)."
-#: includes/pages/guest_login.php:115 includes/pages/user_settings.php:52
+#: includes/pages/guest_login.php:115
msgid ""
"Please enter your planned date of arrival. It should be after the buildup "
"start date and before teardown end date."
@@ -1593,11 +1590,10 @@ msgstr "Chamada incompletada, falta o ID da pergunta."
msgid "No question found."
msgstr "Nenhuma dúvida encontrada."
-#: includes/pages/user_settings.php:4 includes/view/User_view.php:332
+#: includes/view/User_view.php:332
msgid "Settings"
msgstr "Configurações"
-#: includes/pages/user_settings.php:62
msgid ""
"Please enter your planned date of departure. It should be after your planned "
"arrival date and after buildup start date and before teardown end date."
@@ -1606,11 +1602,9 @@ msgstr ""
"chegada\n"
"e ao início da montagem, e anterior à data de desmontagem."
-#: includes/pages/user_settings.php:93
msgid "-> not OK. Please try again."
msgstr "-> não OK. Por favor tente novamente."
-#: includes/pages/user_settings.php:101
msgid "Failed setting password."
msgstr "A alteração da senha falhaou."
diff --git a/resources/views/pages/settings/profile.twig b/resources/views/pages/settings/profile.twig
index ee56eda0..10d72044 100644
--- a/resources/views/pages/settings/profile.twig
+++ b/resources/views/pages/settings/profile.twig
@@ -57,12 +57,13 @@
'max': config('teardown_end') ? config('teardown_end').format('Y-m-d') : '',
}
) }}
+ {% set planned_departure_date = user.personalData.planned_departure_date %}
{{ f.input(
'planned_departure_date',
__('settings.profile.planned_departure_date'),
'date',
{
- 'value': user.personalData.planned_departure_date.format('Y-m-d'),
+ 'value': planned_departure_date ? planned_departure_date.format('Y-m-d') : '',
'min': config('buildup_start') ? config('buildup_start').format('Y-m-d') : '',
'max': config('teardown_end') ? config('teardown_end').format('Y-m-d') : '',
}
diff --git a/src/Controllers/ChecksArrivalsAndDepartures.php b/src/Controllers/ChecksArrivalsAndDepartures.php
index a1f211e4..a8d20f7d 100644
--- a/src/Controllers/ChecksArrivalsAndDepartures.php
+++ b/src/Controllers/ChecksArrivalsAndDepartures.php
@@ -9,13 +9,14 @@ trait ChecksArrivalsAndDepartures
{
protected function isArrivalDateValid(?string $arrival, ?string $departure): bool
{
- if (is_null($arrival)) {
+ $arrival_carbon = $this->toCarbon($arrival);
+ $departure_carbon = $this->toCarbon($departure);
+
+ if (is_null($arrival_carbon)) {
return false; // since required value
}
- $arrival_carbon = $this->toCarbon($arrival);
-
- if (!is_null($departure) && $arrival_carbon->greaterThan($this->toCarbon($departure))) {
+ if (!is_null($departure_carbon) && $arrival_carbon->greaterThan($departure_carbon)) {
return false;
}
@@ -24,29 +25,32 @@ trait ChecksArrivalsAndDepartures
protected function isDepartureDateValid(?string $arrival, ?string $departure): bool
{
- if (is_null($departure)) {
- return true; // since optional value
- }
+ $arrival_carbon = $this->toCarbon($arrival);
$departure_carbon = $this->toCarbon($departure);
- return $departure_carbon->greaterThanOrEqualTo($this->toCarbon($arrival)) &&
+ if (is_null($departure_carbon)) {
+ return true; // since optional value
+ }
+
+ return $departure_carbon->greaterThanOrEqualTo($arrival_carbon) &&
!$this->isBeforeBuildup($departure_carbon) && !$this->isAfterTeardown($departure_carbon);
}
- private function toCarbon(string $date_string): Carbon
+ private function toCarbon(?string $date_string): ?Carbon
{
- return new Carbon(DateTime::createFromFormat('Y-m-d', $date_string));
+ $dateTime = DateTime::createFromFormat('Y-m-d', $date_string ?: '');
+ return $dateTime ? new Carbon($dateTime) : null;
}
private function isBeforeBuildup(Carbon $date): bool
{
$buildup = config('buildup_start');
- return !empty($buildup) && $date->lessThan($buildup->setTime(0,0));
+ return !empty($buildup) && $date->lessThan($buildup->setTime(0, 0));
}
private function isAfterTeardown(Carbon $date): bool
{
$teardown = config('teardown_end');
- return !empty($teardown) && $date->greaterThanOrEqualTo($teardown->addDay()->setTime(0,0));
+ return !empty($teardown) && $date->greaterThanOrEqualTo($teardown->addDay()->setTime(0, 0));
}
}
diff --git a/src/Controllers/SettingsController.php b/src/Controllers/SettingsController.php
index 777c8a6c..178d83ce 100644
--- a/src/Controllers/SettingsController.php
+++ b/src/Controllers/SettingsController.php
@@ -2,7 +2,6 @@
namespace Engelsystem\Controllers;
-use Carbon\Carbon;
use Engelsystem\Config\Config;
use Engelsystem\Http\Exceptions\HttpNotFound;
use Engelsystem\Http\Response;
@@ -107,14 +106,12 @@ class SettingsController extends BaseController
if (!$this->isArrivalDateValid($data['planned_arrival_date'], $data['planned_departure_date'])) {
$this->addNotification('settings.profile.planned_arrival_date.invalid', 'errors');
return $this->redirect->to('/settings/profile');
-
- } else if (!$this->isDepartureDateValid($data['planned_arrival_date'], $data['planned_departure_date'])) {
+ } elseif (!$this->isDepartureDateValid($data['planned_arrival_date'], $data['planned_departure_date'])) {
$this->addNotification('settings.profile.planned_departure_date.invalid', 'errors');
return $this->redirect->to('/settings/profile');
-
} else {
$user->personalData->planned_arrival_date = $data['planned_arrival_date'];
- $user->personalData->planned_departure_date = $data['planned_departure_date'];
+ $user->personalData->planned_departure_date = $data['planned_departure_date'] ?: null;
}
}
@@ -124,12 +121,12 @@ class SettingsController extends BaseController
$user->contact->mobile = $data['mobile'];
$user->email = $data['email'];
- $user->settings->email_shiftinfo = $data['email_shiftinfo'];
- $user->settings->email_news = $data['email_news'];
- $user->settings->email_human = $data['email_human'];
+ $user->settings->email_shiftinfo = $data['email_shiftinfo'] ?: false;
+ $user->settings->email_news = $data['email_news'] ?: false;
+ $user->settings->email_human = $data['email_human'] ?: false;
if (config('enable_goody')) {
- $user->settings->email_goody = $data['email_goody'];
+ $user->settings->email_goody = $data['email_goody'] ?: false;
}
if (isset(config('tshirt_sizes')[$data['shirt_size']])) {
@@ -301,7 +298,7 @@ class SettingsController extends BaseController
public function settingsMenu(): array
{
$menu = [
- url('/user-settings') => 'settings.profile',
+ url('/settings/profile') => 'settings.profile',
url('/settings/password') => 'settings.password',
url('/settings/language') => 'settings.language',
url('/settings/theme') => 'settings.theme'
diff --git a/src/Middleware/LegacyMiddleware.php b/src/Middleware/LegacyMiddleware.php
index 457d7590..4f860eba 100644
--- a/src/Middleware/LegacyMiddleware.php
+++ b/src/Middleware/LegacyMiddleware.php
@@ -141,10 +141,6 @@ class LegacyMiddleware implements MiddlewareInterface
return [$title, $content];
case 'user_worklog':
return user_worklog_controller();
- case 'user_settings':
- $title = settings_title();
- $content = user_settings();
- return [$title, $content];
case 'register':
$title = register_title();
$content = guest_register();
diff --git a/tests/Unit/Controllers/ChecksArrivalsAndDeparturesTest.php b/tests/Unit/Controllers/ChecksArrivalsAndDeparturesTest.php
index 085b92bb..89e246c0 100644
--- a/tests/Unit/Controllers/ChecksArrivalsAndDeparturesTest.php
+++ b/tests/Unit/Controllers/ChecksArrivalsAndDeparturesTest.php
@@ -9,35 +9,57 @@ use Engelsystem\Test\Unit\TestCase;
class ChecksArrivalsAndDeparturesTest extends TestCase
{
- public function invalidDateCombinations(): array
+ public function invalidArrivalCombinations(): array
{
return [
- [null, null, '2022-01-16', '2022-01-15'], # arrival greater than departure
- ['2022-01-15', '2022-01-15', '2022-01-14', '2022-01-16'], # arrival before buildup, departure after teardown
+ [null, null, null, null], # arrival being null
+ [null, null, '2022-01-16', '2022-01-15'], # arrival greater than departure
+ ['2022-01-15', null, '2022-01-14', null], # arrival before buildup
+ [null, '2022-01-14', '2022-01-15', null], # arrival after teardown
];
}
- public function validDateCombinations(): array
+ public function invalidDepartureCombinations(): array
+ {
+ return [
+ [null, null, '2022-01-16', '2022-01-15'], # departure smaller than arrival
+ ['2022-01-15', null, null, '2022-01-14'], # departure before buildup
+ [null, '2022-01-14', null, '2022-01-15'], # departure after teardown
+ ];
+ }
+
+ public function validArrivalCombinations(): array
{
return [
[null, null, '2022-01-15', '2022-01-15'], # arrival equals departure
[null, null, '2022-01-14', '2022-01-15'], # arrival smaller than departure
['2022-01-14', null, '2022-01-14', '2022-01-15'], # arrival on buildup
['2022-01-13', null, '2022-01-14', '2022-01-15'], # arrival after buildup
+ ];
+ }
+
+ public function validDepartureCombinations(): array
+ {
+ return [
+ [null, null, '2022-01-15', null], # departure being null
+ [null, null, '2022-01-15', '2022-01-15'], # departure equals arrival
+ [null, null, '2022-01-14', '2022-01-15'], # departure greater than arrival
[null, '2022-01-15', '2022-01-14', '2022-01-15'], # departure on teardown
[null, '2022-01-16', '2022-01-14', '2022-01-15'], # departure before teardown
- ['2022-01-14', '2022-01-16', '2022-01-14', '2022-01-15'], # all together
];
}
/**
* @covers \Engelsystem\Controllers\ChecksArrivalsAndDepartures::isArrivalDateValid
- * @dataProvider invalidDateCombinations
+ * @covers \Engelsystem\Controllers\ChecksArrivalsAndDepartures::toCarbon
+ * @covers \Engelsystem\Controllers\ChecksArrivalsAndDepartures::isBeforeBuildup
+ * @covers \Engelsystem\Controllers\ChecksArrivalsAndDepartures::isAfterTeardown
+ * @dataProvider invalidArrivalCombinations
*/
public function testCheckInvalidDatesForArrival($buildup, $teardown, $arrival, $departure)
{
- config(['buildup_start' => is_null($buildup) ? null: new Carbon($buildup)]);
- config(['teardown_end' => is_null($teardown) ? null: new Carbon($teardown)]);
+ config(['buildup_start' => is_null($buildup) ? null : new Carbon($buildup)]);
+ config(['teardown_end' => is_null($teardown) ? null : new Carbon($teardown)]);
$check = new ChecksArrivalsAndDeparturesImplementation();
$this->assertFalse($check->checkArrival($arrival, $departure));
@@ -45,12 +67,15 @@ class ChecksArrivalsAndDeparturesTest extends TestCase
/**
* @covers \Engelsystem\Controllers\ChecksArrivalsAndDepartures::isDepartureDateValid
- * @dataProvider invalidDateCombinations
+ * @covers \Engelsystem\Controllers\ChecksArrivalsAndDepartures::toCarbon
+ * @covers \Engelsystem\Controllers\ChecksArrivalsAndDepartures::isBeforeBuildup
+ * @covers \Engelsystem\Controllers\ChecksArrivalsAndDepartures::isAfterTeardown
+ * @dataProvider invalidDepartureCombinations
*/
public function testCheckInvalidDatesForDeparture($buildup, $teardown, $arrival, $departure)
{
- config(['buildup_start' => is_null($buildup) ? null: new Carbon($buildup)]);
- config(['teardown_end' => is_null($teardown) ? null: new Carbon($teardown)]);
+ config(['buildup_start' => is_null($buildup) ? null : new Carbon($buildup)]);
+ config(['teardown_end' => is_null($teardown) ? null : new Carbon($teardown)]);
$check = new ChecksArrivalsAndDeparturesImplementation();
$this->assertFalse($check->checkDeparture($arrival, $departure));
@@ -58,12 +83,15 @@ class ChecksArrivalsAndDeparturesTest extends TestCase
/**
* @covers \Engelsystem\Controllers\ChecksArrivalsAndDepartures::isArrivalDateValid
- * @dataProvider validDateCombinations
+ * @covers \Engelsystem\Controllers\ChecksArrivalsAndDepartures::toCarbon
+ * @covers \Engelsystem\Controllers\ChecksArrivalsAndDepartures::isBeforeBuildup
+ * @covers \Engelsystem\Controllers\ChecksArrivalsAndDepartures::isAfterTeardown
+ * @dataProvider validArrivalCombinations
*/
public function testCheckValidDatesForArrival($buildup, $teardown, $arrival, $departure)
{
- config(['buildup_start' => is_null($buildup) ? null: new Carbon($buildup)]);
- config(['teardown_end' => is_null($teardown) ? null: new Carbon($teardown)]);
+ config(['buildup_start' => is_null($buildup) ? null : new Carbon($buildup)]);
+ config(['teardown_end' => is_null($teardown) ? null : new Carbon($teardown)]);
$check = new ChecksArrivalsAndDeparturesImplementation();
$this->assertTrue($check->checkArrival($arrival, $departure));
@@ -71,12 +99,15 @@ class ChecksArrivalsAndDeparturesTest extends TestCase
/**
* @covers \Engelsystem\Controllers\ChecksArrivalsAndDepartures::isDepartureDateValid
- * @dataProvider validDateCombinations
+ * @covers \Engelsystem\Controllers\ChecksArrivalsAndDepartures::toCarbon
+ * @covers \Engelsystem\Controllers\ChecksArrivalsAndDepartures::isBeforeBuildup
+ * @covers \Engelsystem\Controllers\ChecksArrivalsAndDepartures::isAfterTeardown
+ * @dataProvider validDepartureCombinations
*/
public function testCheckValidDatesForDeparture($buildup, $teardown, $arrival, $departure)
{
- config(['buildup_start' => is_null($buildup) ? null: new Carbon($buildup)]);
- config(['teardown_end' => is_null($teardown) ? null: new Carbon($teardown)]);
+ config(['buildup_start' => is_null($buildup) ? null : new Carbon($buildup)]);
+ config(['teardown_end' => is_null($teardown) ? null : new Carbon($teardown)]);
$check = new ChecksArrivalsAndDeparturesImplementation();
$this->assertTrue($check->checkDeparture($arrival, $departure));
diff --git a/tests/Unit/Controllers/SettingsControllerTest.php b/tests/Unit/Controllers/SettingsControllerTest.php
index b3ff8e30..87735228 100644
--- a/tests/Unit/Controllers/SettingsControllerTest.php
+++ b/tests/Unit/Controllers/SettingsControllerTest.php
@@ -3,15 +3,10 @@
namespace Engelsystem\Test\Unit\Controllers;
use Engelsystem\Config\Config;
-use Engelsystem\Controllers\Admin\UserShirtController;
use Engelsystem\Controllers\SettingsController;
use Engelsystem\Http\Exceptions\HttpNotFound;
-use Engelsystem\Http\Redirector;
use Engelsystem\Http\Response;
-use Engelsystem\Models\User\Contact;
-use Engelsystem\Models\User\PersonalData;
use Engelsystem\Models\User\Settings;
-use Engelsystem\Models\User\State;
use Engelsystem\Test\Unit\TestCase;
use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Component\HttpFoundation\Session\Session;
@@ -56,7 +51,8 @@ class SettingsControllerTest extends TestCase
/** @var SettingsController */
protected $controller;
- protected function setUpProfileTest() {
+ protected function setUpProfileTest()
+ {
$body = [
'pronoun' => 'Herr',
'first_name' => 'John',
@@ -128,8 +124,14 @@ class SettingsControllerTest extends TestCase
$this->assertEquals($body['pronoun'], $this->user->personalData->pronoun);
$this->assertEquals($body['first_name'], $this->user->personalData->first_name);
$this->assertEquals($body['last_name'], $this->user->personalData->last_name);
- $this->assertEquals($body['planned_arrival_date'], $this->user->personalData->planned_arrival_date->format('Y-m-d'));
- $this->assertEquals($body['planned_departure_date'], $this->user->personalData->planned_departure_date->format('Y-m-d'));
+ $this->assertEquals(
+ $body['planned_arrival_date'],
+ $this->user->personalData->planned_arrival_date->format('Y-m-d')
+ );
+ $this->assertEquals(
+ $body['planned_departure_date'],
+ $this->user->personalData->planned_departure_date->format('Y-m-d')
+ );
$this->assertEquals($body['dect'], $this->user->contact->dect);
$this->assertEquals($body['mobile'], $this->user->contact->mobile);
$this->assertEquals($body['email'], $this->user->email);
@@ -565,7 +567,7 @@ class SettingsControllerTest extends TestCase
config(['oauth' => $providers]);
$this->assertEquals([
- 'http://localhost/user-settings' => 'settings.profile',
+ 'http://localhost/settings/profile' => 'settings.profile',
'http://localhost/settings/password' => 'settings.password',
'http://localhost/settings/language' => 'settings.language',
'http://localhost/settings/theme' => 'settings.theme',
@@ -574,7 +576,7 @@ class SettingsControllerTest extends TestCase
config(['oauth' => $providersHidden]);
$this->assertEquals([
- 'http://localhost/user-settings' => 'settings.profile',
+ 'http://localhost/settings/profile' => 'settings.profile',
'http://localhost/settings/password' => 'settings.password',
'http://localhost/settings/language' => 'settings.language',
'http://localhost/settings/theme' => 'settings.theme',
@@ -590,7 +592,7 @@ class SettingsControllerTest extends TestCase
config(['oauth' => []]);
$this->assertEquals([
- 'http://localhost/user-settings' => 'settings.profile',
+ 'http://localhost/settings/profile' => 'settings.profile',
'http://localhost/settings/password' => 'settings.password',
'http://localhost/settings/language' => 'settings.language',
'http://localhost/settings/theme' => 'settings.theme'
diff --git a/tests/Unit/Controllers/Stub/ChecksArrivalsAndDeparturesImplementation.php b/tests/Unit/Controllers/Stub/ChecksArrivalsAndDeparturesImplementation.php
index 06465d7a..87ab1128 100644
--- a/tests/Unit/Controllers/Stub/ChecksArrivalsAndDeparturesImplementation.php
+++ b/tests/Unit/Controllers/Stub/ChecksArrivalsAndDeparturesImplementation.php
@@ -8,12 +8,12 @@ class ChecksArrivalsAndDeparturesImplementation
{
use ChecksArrivalsAndDepartures;
- public function checkArrival(string $arrival, string $departure): bool
+ public function checkArrival(?string $arrival, ?string $departure): bool
{
return $this->isArrivalDateValid($arrival, $departure);
}
- public function checkDeparture(string $arrival, string $departure): bool
+ public function checkDeparture(?string $arrival, ?string $departure): bool
{
return $this->isDepartureDateValid($arrival, $departure);
}