rewrite controller for creating shift entries
This commit is contained in:
parent
60da71ff7c
commit
7a3bdda483
|
@ -178,6 +178,24 @@ function shift_entry_create_controller_supporter($shift, $angeltype)
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates an error message for the given shift signup state.
|
||||||
|
* @param ShiftSignupState $shift_signup_state
|
||||||
|
*/
|
||||||
|
function shift_entry_error_message(ShiftSignupState $shift_signup_state) {
|
||||||
|
if ($shift_signup_state->getState() == ShiftSignupState::ANGELTYPE) {
|
||||||
|
error(_('You need be accepted member of the angeltype.'));
|
||||||
|
} elseif ($shift_signup_state->getState() == ShiftSignupState::COLLIDES) {
|
||||||
|
error(_('This shift collides with one of your shifts.'));
|
||||||
|
} elseif ($shift_signup_state->getState() == ShiftSignupState::OCCUPIED) {
|
||||||
|
error(_('This shift is already occupied.'));
|
||||||
|
} elseif ($shift_signup_state->getState() == ShiftSignupState::SHIFT_ENDED) {
|
||||||
|
error(_('This shift ended already.'));
|
||||||
|
} elseif ($shift_signup_state->getState() == ShiftSignupState::SIGNED_UP) {
|
||||||
|
error(_('You are signed up for this shift.'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sign up for a shift.
|
* Sign up for a shift.
|
||||||
* Case: User
|
* Case: User
|
||||||
|
@ -193,21 +211,9 @@ function shift_entry_create_controller_user($shift, $angeltype)
|
||||||
$signup_user = $user;
|
$signup_user = $user;
|
||||||
$needed_angeltype = NeededAngeltype_by_Shift_and_Angeltype($shift, $angeltype);
|
$needed_angeltype = NeededAngeltype_by_Shift_and_Angeltype($shift, $angeltype);
|
||||||
$shift_entries = ShiftEntries_by_shift_and_angeltype($shift['SID'], $angeltype['id']);
|
$shift_entries = ShiftEntries_by_shift_and_angeltype($shift['SID'], $angeltype['id']);
|
||||||
|
|
||||||
$shift_signup_state = Shift_signup_allowed($signup_user, $shift, $angeltype, null, null, $needed_angeltype, $shift_entries);
|
$shift_signup_state = Shift_signup_allowed($signup_user, $shift, $angeltype, null, null, $needed_angeltype, $shift_entries);
|
||||||
|
|
||||||
if (! $shift_signup_state->isSignupAllowed()) {
|
if (! $shift_signup_state->isSignupAllowed()) {
|
||||||
if ($shift_signup_state->getState() == ShiftSignupState::ANGELTYPE) {
|
shift_entry_error_message($shift_signup_state);
|
||||||
error(_('You need be accepted member of the angeltype.'));
|
|
||||||
} elseif ($shift_signup_state->getState() == ShiftSignupState::COLLIDES) {
|
|
||||||
error(_('This shift collides with one of your shifts.'));
|
|
||||||
} elseif ($shift_signup_state->getState() == ShiftSignupState::OCCUPIED) {
|
|
||||||
error(_('This shift is already occupied.'));
|
|
||||||
} elseif ($shift_signup_state->getState() == ShiftSignupState::SHIFT_ENDED) {
|
|
||||||
error(_('This shift ended already.'));
|
|
||||||
} elseif ($shift_signup_state->getState() == ShiftSignupState::SIGNED_UP) {
|
|
||||||
error(_('You are signed up for this shift.'));
|
|
||||||
}
|
|
||||||
redirect(shift_link($shift));
|
redirect(shift_link($shift));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -78,7 +78,7 @@ function Shift_signup_button_render($shift, $angeltype, $user_angeltype = null)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($angeltype['shift_signup_state']->isSignupAllowed()) {
|
if ($angeltype['shift_signup_state']->isSignupAllowed()) {
|
||||||
return button(shift_entry_create_link($shift, $angeltype), _('Sign up'));
|
return button(shift_entry_create_link($shift, $angeltype), _('Sign up'));
|
||||||
} elseif ($user_angeltype == null) {
|
} elseif ($user_angeltype == null) {
|
||||||
return button(
|
return button(
|
||||||
page_link_to('angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype['id']]),
|
page_link_to('angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype['id']]),
|
||||||
|
|
Loading…
Reference in New Issue