2016-10-03 17:41:14 +02:00
|
|
|
<?php
|
2017-12-25 23:12:52 +01:00
|
|
|
|
2022-11-09 00:02:30 +01:00
|
|
|
use Engelsystem\Models\AngelType;
|
2023-01-03 22:19:03 +01:00
|
|
|
use Engelsystem\Models\Shifts\Shift;
|
2023-01-18 13:02:11 +01:00
|
|
|
use Engelsystem\Models\Shifts\ShiftEntry;
|
2023-01-24 19:23:57 +01:00
|
|
|
use Engelsystem\Models\Shifts\ShiftSignupStatus;
|
2018-10-09 21:47:31 +02:00
|
|
|
use Engelsystem\Models\User\User;
|
2022-12-03 00:57:04 +01:00
|
|
|
use Engelsystem\Models\UserAngelType;
|
2017-12-20 00:42:58 +01:00
|
|
|
use Engelsystem\ShiftSignupState;
|
2018-12-25 10:25:32 +01:00
|
|
|
use Illuminate\Database\Eloquent\Collection;
|
2016-10-03 17:41:14 +02:00
|
|
|
|
2017-12-20 00:42:58 +01:00
|
|
|
/**
|
|
|
|
* Route shift entry actions.
|
2017-12-25 23:12:52 +01:00
|
|
|
*
|
|
|
|
* @return array
|
2017-12-20 00:42:58 +01:00
|
|
|
*/
|
2021-11-30 23:29:51 +01:00
|
|
|
function shift_entries_controller(): array
|
2017-12-20 00:42:58 +01:00
|
|
|
{
|
2018-10-09 21:47:31 +02:00
|
|
|
$user = auth()->user();
|
2018-10-17 01:30:10 +02:00
|
|
|
if (!$user) {
|
2019-09-08 02:25:49 +02:00
|
|
|
throw_redirect(page_link_to('login'));
|
2017-12-26 20:41:35 +01:00
|
|
|
}
|
2017-12-25 23:12:52 +01:00
|
|
|
|
2017-12-20 00:42:58 +01:00
|
|
|
$action = strip_request_item('action');
|
2018-01-14 17:47:26 +01:00
|
|
|
if (empty($action)) {
|
2019-09-08 02:25:49 +02:00
|
|
|
throw_redirect(user_link($user->id));
|
2017-12-20 00:42:58 +01:00
|
|
|
}
|
2017-12-25 23:12:52 +01:00
|
|
|
|
2022-12-22 00:08:54 +01:00
|
|
|
return match ($action) {
|
|
|
|
'create' => shift_entry_create_controller(),
|
|
|
|
'delete' => shift_entry_delete_controller(),
|
2023-01-18 13:02:11 +01:00
|
|
|
default => ['', ''],
|
2022-12-22 00:08:54 +01:00
|
|
|
};
|
2017-12-20 00:42:58 +01:00
|
|
|
}
|
2017-01-21 13:58:53 +01:00
|
|
|
|
2016-10-03 17:41:14 +02:00
|
|
|
/**
|
|
|
|
* Sign up for a shift.
|
2017-12-25 23:12:52 +01:00
|
|
|
*
|
|
|
|
* @return array
|
2016-10-03 17:41:14 +02:00
|
|
|
*/
|
2021-11-30 23:29:51 +01:00
|
|
|
function shift_entry_create_controller(): array
|
2017-01-02 03:57:23 +01:00
|
|
|
{
|
2018-10-10 03:10:28 +02:00
|
|
|
$user = auth()->user();
|
2017-07-18 21:38:53 +02:00
|
|
|
$request = request();
|
2017-12-25 23:12:52 +01:00
|
|
|
|
2023-01-18 13:02:11 +01:00
|
|
|
if ($user->isFreeloader()) {
|
2019-09-08 02:25:49 +02:00
|
|
|
throw_redirect(page_link_to('user_myshifts'));
|
2017-01-02 03:57:23 +01:00
|
|
|
}
|
2017-12-25 23:12:52 +01:00
|
|
|
|
2017-12-20 00:42:58 +01:00
|
|
|
$shift = Shift($request->input('shift_id'));
|
2018-01-14 17:47:26 +01:00
|
|
|
if (empty($shift)) {
|
2019-09-08 02:25:49 +02:00
|
|
|
throw_redirect(user_link($user->id));
|
2017-01-02 03:57:23 +01:00
|
|
|
}
|
2017-12-25 23:12:52 +01:00
|
|
|
|
2022-11-09 00:02:30 +01:00
|
|
|
$angeltype = AngelType::find($request->input('angeltype_id'));
|
2017-12-25 23:12:52 +01:00
|
|
|
|
2018-11-12 14:41:23 +01:00
|
|
|
if (auth()->can('user_shifts_admin')) {
|
2017-12-20 00:42:58 +01:00
|
|
|
return shift_entry_create_controller_admin($shift, $angeltype);
|
2017-01-02 03:57:23 +01:00
|
|
|
}
|
2017-12-25 23:12:52 +01:00
|
|
|
|
2018-01-14 17:47:26 +01:00
|
|
|
if (empty($angeltype)) {
|
2019-09-08 02:25:49 +02:00
|
|
|
throw_redirect(user_link($user->id));
|
2017-01-02 03:57:23 +01:00
|
|
|
}
|
2017-12-25 23:12:52 +01:00
|
|
|
|
2022-12-03 00:57:04 +01:00
|
|
|
if ($user->isAngelTypeSupporter($angeltype) || auth()->can('admin_user_angeltypes')) {
|
2017-12-20 00:42:58 +01:00
|
|
|
return shift_entry_create_controller_supporter($shift, $angeltype);
|
2017-01-02 03:57:23 +01:00
|
|
|
}
|
2017-12-25 23:12:52 +01:00
|
|
|
|
2017-12-20 00:42:58 +01:00
|
|
|
return shift_entry_create_controller_user($shift, $angeltype);
|
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-12-20 00:42:58 +01:00
|
|
|
/**
|
|
|
|
* Sign up for a shift.
|
|
|
|
* Case: Admin
|
|
|
|
*
|
2023-01-03 22:19:03 +01:00
|
|
|
* @param Shift $shift
|
2022-11-09 00:02:30 +01:00
|
|
|
* @param AngelType|null $angeltype
|
2017-12-25 23:12:52 +01:00
|
|
|
* @return array
|
2017-12-20 00:42:58 +01:00
|
|
|
*/
|
2023-01-03 22:19:03 +01:00
|
|
|
function shift_entry_create_controller_admin(Shift $shift, ?AngelType $angeltype): array
|
2017-12-20 00:42:58 +01:00
|
|
|
{
|
2018-10-17 01:30:10 +02:00
|
|
|
$signup_user = auth()->user();
|
2017-12-20 00:42:58 +01:00
|
|
|
$request = request();
|
2017-12-25 23:12:52 +01:00
|
|
|
|
2017-12-20 00:42:58 +01:00
|
|
|
if ($request->has('user_id')) {
|
2018-10-09 21:47:31 +02:00
|
|
|
$signup_user = User::find($request->input('user_id'));
|
2017-01-02 03:57:23 +01:00
|
|
|
}
|
2018-10-09 21:47:31 +02:00
|
|
|
if (!$signup_user) {
|
2019-09-08 02:25:49 +02:00
|
|
|
throw_redirect(shift_link($shift));
|
2017-01-02 03:57:23 +01:00
|
|
|
}
|
2017-12-25 23:12:52 +01:00
|
|
|
|
2022-11-09 00:02:30 +01:00
|
|
|
$angeltypes = AngelType::all();
|
2021-04-16 21:50:45 +02:00
|
|
|
if ($request->hasPostData('angeltype_id')) {
|
2022-11-09 00:02:30 +01:00
|
|
|
$angeltype = AngelType::find($request->postData('angeltype_id'));
|
2017-12-20 00:42:58 +01:00
|
|
|
}
|
2018-01-14 17:47:26 +01:00
|
|
|
if (empty($angeltype)) {
|
2017-12-25 23:12:52 +01:00
|
|
|
if (count($angeltypes) == 0) {
|
2019-09-08 02:25:49 +02:00
|
|
|
throw_redirect(shift_link($shift));
|
2017-01-02 03:57:23 +01:00
|
|
|
}
|
2017-12-20 00:42:58 +01:00
|
|
|
$angeltype = $angeltypes[0];
|
|
|
|
}
|
2017-12-25 23:12:52 +01:00
|
|
|
|
2018-11-20 16:02:03 +01:00
|
|
|
if ($request->hasPostData('submit')) {
|
2023-01-18 13:02:11 +01:00
|
|
|
$shiftEntry = new ShiftEntry();
|
|
|
|
$shiftEntry->shift()->associate($shift);
|
|
|
|
$shiftEntry->angelType()->associate($angeltype);
|
|
|
|
$shiftEntry->user()->associate($signup_user);
|
|
|
|
$shiftEntry->save();
|
|
|
|
ShiftEntry_onCreate($shiftEntry);
|
2017-12-25 23:12:52 +01:00
|
|
|
|
2018-08-29 21:55:32 +02:00
|
|
|
success(sprintf(__('%s has been subscribed to the shift.'), User_Nick_render($signup_user)));
|
2019-09-08 02:25:49 +02:00
|
|
|
throw_redirect(shift_link($shift));
|
2017-12-20 00:42:58 +01:00
|
|
|
}
|
2017-12-25 23:12:52 +01:00
|
|
|
|
2018-12-25 10:25:32 +01:00
|
|
|
/** @var User[]|Collection $users */
|
|
|
|
$users = User::query()->orderBy('name')->get();
|
2017-12-20 00:42:58 +01:00
|
|
|
$users_select = [];
|
2018-10-17 01:30:10 +02:00
|
|
|
foreach ($users as $user) {
|
|
|
|
$users_select[$user->id] = $user->name;
|
2017-12-20 00:42:58 +01:00
|
|
|
}
|
2017-12-25 23:12:52 +01:00
|
|
|
|
2022-11-09 00:02:30 +01:00
|
|
|
$angeltypes_select = $angeltypes->pluck('name', 'id')->toArray();
|
2023-01-03 22:19:03 +01:00
|
|
|
$room = $shift->room;
|
2017-12-20 00:42:58 +01:00
|
|
|
return [
|
|
|
|
ShiftEntry_create_title(),
|
2023-02-05 18:03:00 +01:00
|
|
|
ShiftEntry_create_view_admin($shift, $room, $angeltype, $angeltypes_select, $signup_user, $users_select),
|
2017-12-20 00:42:58 +01:00
|
|
|
];
|
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-12-20 00:42:58 +01:00
|
|
|
/**
|
|
|
|
* Sign up for a shift.
|
|
|
|
* Case: Supporter
|
|
|
|
*
|
2023-01-03 22:19:03 +01:00
|
|
|
* @param Shift $shift
|
2022-11-09 00:02:30 +01:00
|
|
|
* @param AngelType $angeltype
|
2017-12-25 23:12:52 +01:00
|
|
|
* @return array
|
2017-12-20 00:42:58 +01:00
|
|
|
*/
|
2023-01-03 22:19:03 +01:00
|
|
|
function shift_entry_create_controller_supporter(Shift $shift, AngelType $angeltype): array
|
2017-12-20 00:42:58 +01:00
|
|
|
{
|
|
|
|
$request = request();
|
2018-10-10 03:10:28 +02:00
|
|
|
$signup_user = auth()->user();
|
2017-12-25 23:12:52 +01:00
|
|
|
|
2017-12-20 00:42:58 +01:00
|
|
|
if ($request->has('user_id')) {
|
2018-10-10 03:10:28 +02:00
|
|
|
$signup_user = User::find($request->input('user_id'));
|
2017-12-20 00:42:58 +01:00
|
|
|
}
|
2022-12-03 00:57:04 +01:00
|
|
|
|
|
|
|
if (!$signup_user->userAngelTypes()->wherePivot('angel_type_id', $angeltype->id)->exists()) {
|
2018-08-29 21:55:32 +02:00
|
|
|
error(__('User is not in angeltype.'));
|
2019-09-08 02:25:49 +02:00
|
|
|
throw_redirect(shift_link($shift));
|
2017-12-20 00:42:58 +01:00
|
|
|
}
|
2017-12-25 23:12:52 +01:00
|
|
|
|
2018-11-20 16:02:03 +01:00
|
|
|
if ($request->hasPostData('submit')) {
|
2023-01-18 13:02:11 +01:00
|
|
|
$shiftEntry = new ShiftEntry();
|
|
|
|
$shiftEntry->shift()->associate($shift);
|
|
|
|
$shiftEntry->angelType()->associate($angeltype);
|
|
|
|
$shiftEntry->user()->associate($signup_user);
|
|
|
|
$shiftEntry->save();
|
|
|
|
ShiftEntry_onCreate($shiftEntry);
|
2017-12-25 23:12:52 +01:00
|
|
|
|
2018-08-29 21:55:32 +02:00
|
|
|
success(sprintf(__('%s has been subscribed to the shift.'), User_Nick_render($signup_user)));
|
2019-09-08 02:25:49 +02:00
|
|
|
throw_redirect(shift_link($shift));
|
2017-12-20 00:42:58 +01:00
|
|
|
}
|
2017-12-25 23:12:52 +01:00
|
|
|
|
2022-12-03 00:57:04 +01:00
|
|
|
$users = $angeltype->userAngelTypes->sortBy('name');
|
2017-12-20 00:42:58 +01:00
|
|
|
$users_select = [];
|
|
|
|
foreach ($users as $u) {
|
2018-10-11 01:26:34 +02:00
|
|
|
$users_select[$u->id] = $u->name;
|
2017-12-20 00:42:58 +01:00
|
|
|
}
|
2017-12-25 23:12:52 +01:00
|
|
|
|
2023-01-03 22:19:03 +01:00
|
|
|
$room = $shift->room;
|
2017-12-20 00:42:58 +01:00
|
|
|
return [
|
|
|
|
ShiftEntry_create_title(),
|
2023-02-05 18:03:00 +01:00
|
|
|
ShiftEntry_create_view_supporter($shift, $room, $angeltype, $signup_user, $users_select),
|
2017-12-20 00:42:58 +01:00
|
|
|
];
|
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-12-20 00:54:57 +01:00
|
|
|
/**
|
|
|
|
* Generates an error message for the given shift signup state.
|
2017-12-25 23:12:52 +01:00
|
|
|
*
|
2017-12-20 00:54:57 +01:00
|
|
|
* @param ShiftSignupState $shift_signup_state
|
|
|
|
*/
|
2017-12-25 23:12:52 +01:00
|
|
|
function shift_entry_error_message(ShiftSignupState $shift_signup_state)
|
|
|
|
{
|
2023-01-24 19:23:57 +01:00
|
|
|
match ($shift_signup_state->getState()) {
|
|
|
|
ShiftSignupStatus::ANGELTYPE => error(__('You need be accepted member of the angeltype.')),
|
|
|
|
ShiftSignupStatus::COLLIDES => error(__('This shift collides with one of your shifts.')),
|
|
|
|
ShiftSignupStatus::OCCUPIED => error(__('This shift is already occupied.')),
|
|
|
|
ShiftSignupStatus::SHIFT_ENDED => error(__('This shift ended already.')),
|
|
|
|
ShiftSignupStatus::NOT_ARRIVED => error(__('You are not marked as arrived.')),
|
|
|
|
ShiftSignupStatus::NOT_YET => error(__('You are not allowed to sign up yet.')),
|
|
|
|
ShiftSignupStatus::SIGNED_UP => error(__('You are signed up for this shift.')),
|
|
|
|
default => null, // ShiftSignupStatus::FREE|ShiftSignupStatus::ADMIN
|
|
|
|
};
|
2017-12-20 00:54:57 +01:00
|
|
|
}
|
|
|
|
|
2017-12-20 00:42:58 +01:00
|
|
|
/**
|
|
|
|
* Sign up for a shift.
|
|
|
|
* Case: User
|
|
|
|
*
|
2023-01-03 22:19:03 +01:00
|
|
|
* @param Shift $shift
|
2022-11-09 00:02:30 +01:00
|
|
|
* @param AngelType $angeltype
|
2017-12-25 23:12:52 +01:00
|
|
|
* @return array
|
2017-12-20 00:42:58 +01:00
|
|
|
*/
|
2023-01-03 22:19:03 +01:00
|
|
|
function shift_entry_create_controller_user(Shift $shift, AngelType $angeltype): array
|
2017-12-20 00:42:58 +01:00
|
|
|
{
|
|
|
|
$request = request();
|
2017-12-25 23:12:52 +01:00
|
|
|
|
2018-10-10 03:10:28 +02:00
|
|
|
$signup_user = auth()->user();
|
2022-11-09 00:02:30 +01:00
|
|
|
$needed_angeltype = (new AngelType())->forceFill(NeededAngeltype_by_Shift_and_Angeltype($shift, $angeltype));
|
2023-01-18 13:02:11 +01:00
|
|
|
$shift_entries = $shift->shiftEntries()
|
|
|
|
->where('angel_type_id', $angeltype->id)
|
|
|
|
->get();
|
2017-12-25 23:12:52 +01:00
|
|
|
$shift_signup_state = Shift_signup_allowed(
|
|
|
|
$signup_user,
|
|
|
|
$shift,
|
|
|
|
$angeltype,
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
$needed_angeltype,
|
|
|
|
$shift_entries
|
|
|
|
);
|
|
|
|
if (!$shift_signup_state->isSignupAllowed()) {
|
2017-12-20 00:54:57 +01:00
|
|
|
shift_entry_error_message($shift_signup_state);
|
2019-09-08 02:25:49 +02:00
|
|
|
throw_redirect(shift_link($shift));
|
2017-12-20 00:42:58 +01:00
|
|
|
}
|
2017-12-25 23:12:52 +01:00
|
|
|
|
2017-12-20 00:42:58 +01:00
|
|
|
$comment = '';
|
2018-11-20 16:02:03 +01:00
|
|
|
if ($request->hasPostData('submit')) {
|
2017-01-02 03:57:23 +01:00
|
|
|
$comment = strip_request_item_nl('comment');
|
2023-01-18 13:02:11 +01:00
|
|
|
|
|
|
|
$shiftEntry = new ShiftEntry();
|
|
|
|
$shiftEntry->shift()->associate($shift);
|
|
|
|
$shiftEntry->angelType()->associate($angeltype);
|
|
|
|
$shiftEntry->user()->associate($signup_user);
|
|
|
|
$shiftEntry->user_comment = $comment;
|
|
|
|
$shiftEntry->save();
|
|
|
|
ShiftEntry_onCreate($shiftEntry);
|
2017-12-25 23:12:52 +01:00
|
|
|
|
2022-12-03 00:57:04 +01:00
|
|
|
if (
|
|
|
|
!$angeltype->restricted
|
|
|
|
&& !$angeltype->userAngelTypes()->wherePivot('user_id', $signup_user->id)->exists()
|
|
|
|
) {
|
|
|
|
$userAngelType = new UserAngelType();
|
|
|
|
$userAngelType->user()->associate($signup_user);
|
|
|
|
$userAngelType->angelType()->associate($angeltype);
|
|
|
|
$userAngelType->save();
|
2017-01-02 03:57:23 +01:00
|
|
|
}
|
2017-12-25 23:12:52 +01:00
|
|
|
|
2018-08-29 21:55:32 +02:00
|
|
|
success(__('You are subscribed. Thank you!'));
|
2019-09-08 02:25:49 +02:00
|
|
|
throw_redirect(shift_link($shift));
|
2016-10-03 17:41:14 +02:00
|
|
|
}
|
2017-12-25 23:12:52 +01:00
|
|
|
|
2023-01-03 22:19:03 +01:00
|
|
|
$room = $shift->room;
|
2017-12-20 00:42:58 +01:00
|
|
|
return [
|
|
|
|
ShiftEntry_create_title(),
|
2023-02-05 18:03:00 +01:00
|
|
|
ShiftEntry_create_view_user($shift, $room, $angeltype, $comment),
|
2017-12-20 00:42:58 +01:00
|
|
|
];
|
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-12-20 00:42:58 +01:00
|
|
|
/**
|
|
|
|
* Link to create a shift entry.
|
|
|
|
*
|
2023-01-03 22:19:03 +01:00
|
|
|
* @param Shift $shift
|
2022-11-09 00:02:30 +01:00
|
|
|
* @param AngelType $angeltype
|
2022-12-03 00:57:04 +01:00
|
|
|
* @param array $params
|
2017-12-20 00:42:58 +01:00
|
|
|
* @return string URL
|
|
|
|
*/
|
2023-01-03 22:19:03 +01:00
|
|
|
function shift_entry_create_link(Shift $shift, AngelType $angeltype, $params = [])
|
2017-12-20 00:42:58 +01:00
|
|
|
{
|
|
|
|
$params = array_merge([
|
2017-12-25 23:12:52 +01:00
|
|
|
'action' => 'create',
|
2023-01-03 22:19:03 +01:00
|
|
|
'shift_id' => $shift->id,
|
2023-02-05 18:03:00 +01:00
|
|
|
'angeltype_id' => $angeltype->id,
|
2017-12-20 00:42:58 +01:00
|
|
|
], $params);
|
|
|
|
return page_link_to('shift_entries', $params);
|
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-12-20 00:42:58 +01:00
|
|
|
/**
|
|
|
|
* Link to create a shift entry as admin.
|
|
|
|
*
|
2023-01-03 22:19:03 +01:00
|
|
|
* @param Shift $shift
|
2017-12-25 23:12:52 +01:00
|
|
|
* @param array $params
|
2017-12-20 00:42:58 +01:00
|
|
|
* @return string URL
|
|
|
|
*/
|
2023-01-03 22:19:03 +01:00
|
|
|
function shift_entry_create_link_admin(Shift $shift, $params = [])
|
2017-12-20 00:42:58 +01:00
|
|
|
{
|
|
|
|
$params = array_merge([
|
2017-12-25 23:12:52 +01:00
|
|
|
'action' => 'create',
|
2023-02-05 18:03:00 +01:00
|
|
|
'shift_id' => $shift->id,
|
2017-12-20 00:42:58 +01:00
|
|
|
], $params);
|
|
|
|
return page_link_to('shift_entries', $params);
|
2016-10-03 17:41:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-12-20 00:42:58 +01:00
|
|
|
* Load a shift entry from get parameter shift_entry_id.
|
2017-12-25 23:12:52 +01:00
|
|
|
*
|
2023-01-18 13:02:11 +01:00
|
|
|
* @return ShiftEntry
|
2016-10-03 17:41:14 +02:00
|
|
|
*/
|
2017-12-20 00:42:58 +01:00
|
|
|
function shift_entry_load()
|
|
|
|
{
|
2017-07-18 21:38:53 +02:00
|
|
|
$request = request();
|
2017-12-25 23:12:52 +01:00
|
|
|
|
|
|
|
if (!$request->has('shift_entry_id') || !test_request_int('shift_entry_id')) {
|
2019-09-08 02:25:49 +02:00
|
|
|
throw_redirect(page_link_to('user_shifts'));
|
2017-01-02 03:57:23 +01:00
|
|
|
}
|
2023-01-18 13:02:11 +01:00
|
|
|
$shiftEntry = ShiftEntry::findOrFail($request->input('shift_entry_id'));
|
2017-12-25 23:12:52 +01:00
|
|
|
|
2017-12-19 20:58:01 +01:00
|
|
|
return $shiftEntry;
|
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-12-19 20:58:01 +01:00
|
|
|
/**
|
|
|
|
* Remove somebody from a shift.
|
2017-12-25 23:12:52 +01:00
|
|
|
*
|
|
|
|
* @return array
|
2017-12-19 20:58:01 +01:00
|
|
|
*/
|
|
|
|
function shift_entry_delete_controller()
|
|
|
|
{
|
2018-10-31 12:48:22 +01:00
|
|
|
$user = auth()->user();
|
2017-12-19 20:58:01 +01:00
|
|
|
$request = request();
|
|
|
|
$shiftEntry = shift_entry_load();
|
2017-12-25 23:12:52 +01:00
|
|
|
|
2023-01-18 13:02:11 +01:00
|
|
|
$shift = Shift($shiftEntry->shift);
|
|
|
|
$angeltype = $shiftEntry->angelType;
|
|
|
|
$signout_user = $shiftEntry->user;
|
2018-10-10 03:10:28 +02:00
|
|
|
if (!Shift_signout_allowed($shift, $angeltype, $signout_user->id)) {
|
2020-09-06 23:50:36 +02:00
|
|
|
error(__(
|
|
|
|
'You are not allowed to remove this shift entry. If necessary, ask your supporter or heaven to do so.'
|
|
|
|
));
|
2019-09-08 02:25:49 +02:00
|
|
|
throw_redirect(user_link($signout_user->id));
|
2017-12-19 20:58:01 +01:00
|
|
|
}
|
2017-12-25 23:12:52 +01:00
|
|
|
|
2018-11-20 16:02:03 +01:00
|
|
|
if ($request->hasPostData('delete')) {
|
2023-01-18 13:02:11 +01:00
|
|
|
$shiftEntry->delete();
|
|
|
|
ShiftEntry_onDelete($shiftEntry);
|
2018-08-29 21:55:32 +02:00
|
|
|
success(__('Shift entry removed.'));
|
2019-09-08 02:25:49 +02:00
|
|
|
throw_redirect(shift_link($shift));
|
2017-01-02 03:57:23 +01:00
|
|
|
}
|
2017-12-25 23:12:52 +01:00
|
|
|
|
2018-10-10 03:10:28 +02:00
|
|
|
if ($user->id == $signout_user->id) {
|
2017-12-20 00:42:58 +01:00
|
|
|
return [
|
|
|
|
ShiftEntry_delete_title(),
|
2023-02-05 18:03:00 +01:00
|
|
|
ShiftEntry_delete_view($shift, $angeltype, $signout_user),
|
2017-12-20 00:42:58 +01:00
|
|
|
];
|
2017-12-19 20:58:01 +01:00
|
|
|
}
|
2017-12-25 23:12:52 +01:00
|
|
|
|
2017-12-20 00:42:58 +01:00
|
|
|
return [
|
|
|
|
ShiftEntry_delete_title(),
|
2023-02-05 18:03:00 +01:00
|
|
|
ShiftEntry_delete_view_admin($shift, $angeltype, $signout_user),
|
2017-12-20 00:42:58 +01:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Link to delete a shift entry.
|
|
|
|
*
|
2023-01-18 13:02:11 +01:00
|
|
|
* @param Shift|ShiftEntry $shiftEntry
|
|
|
|
* @param array $params
|
2017-12-20 00:42:58 +01:00
|
|
|
* @return string URL
|
|
|
|
*/
|
|
|
|
function shift_entry_delete_link($shiftEntry, $params = [])
|
|
|
|
{
|
|
|
|
$params = array_merge([
|
2017-12-25 23:12:52 +01:00
|
|
|
'action' => 'delete',
|
2023-02-05 18:03:00 +01:00
|
|
|
'shift_entry_id' => $shiftEntry['shift_entry_id'] ?? $shiftEntry['id'],
|
2017-12-20 00:42:58 +01:00
|
|
|
], $params);
|
|
|
|
return page_link_to('shift_entries', $params);
|
2016-10-03 17:41:14 +02:00
|
|
|
}
|