2013-11-25 22:04:32 +01:00
|
|
|
<?php
|
|
|
|
|
2022-11-09 00:02:30 +01:00
|
|
|
use Engelsystem\Models\AngelType;
|
2023-10-15 19:25:55 +02:00
|
|
|
use Engelsystem\Models\Location;
|
2023-01-03 22:19:03 +01:00
|
|
|
use Engelsystem\Models\Shifts\Shift;
|
2018-10-10 03:10:28 +02:00
|
|
|
use Engelsystem\Models\User\User;
|
|
|
|
|
2017-12-19 20:58:01 +01:00
|
|
|
/**
|
2022-11-09 00:02:30 +01:00
|
|
|
* Sign off from a user from a shift with admin permissions, asking for ack.
|
2017-12-19 20:58:01 +01:00
|
|
|
*
|
2023-01-03 22:19:03 +01:00
|
|
|
* @param Shift $shift
|
2022-11-09 00:02:30 +01:00
|
|
|
* @param AngelType $angeltype
|
2018-10-10 03:10:28 +02:00
|
|
|
* @param User $signoff_user
|
2017-12-19 20:58:01 +01:00
|
|
|
*
|
|
|
|
* @return string HTML
|
|
|
|
*/
|
2023-01-03 22:19:03 +01:00
|
|
|
function ShiftEntry_delete_view_admin(Shift $shift, AngelType $angeltype, User $signoff_user)
|
2017-12-20 00:42:58 +01:00
|
|
|
{
|
2017-12-19 20:58:01 +01:00
|
|
|
return page_with_title(ShiftEntry_delete_title(), [
|
2017-12-25 23:12:52 +01:00
|
|
|
info(sprintf(
|
2018-08-29 21:55:32 +02:00
|
|
|
__('Do you want to sign off %s from shift %s from %s to %s as %s?'),
|
2017-12-25 23:12:52 +01:00
|
|
|
User_Nick_render($signoff_user),
|
2023-01-03 22:19:03 +01:00
|
|
|
$shift->shiftType->name,
|
2023-02-04 02:43:47 +01:00
|
|
|
$shift->start->format(__('Y-m-d H:i')),
|
|
|
|
$shift->end->format(__('Y-m-d H:i')),
|
2022-11-09 00:02:30 +01:00
|
|
|
$angeltype->name
|
2017-12-25 23:12:52 +01:00
|
|
|
), true),
|
2018-11-20 16:02:03 +01:00
|
|
|
form([
|
|
|
|
buttons([
|
2023-10-03 18:59:46 +02:00
|
|
|
button(user_link($signoff_user->id), icon('x-lg') . __('form.cancel')),
|
2023-02-05 18:03:00 +01:00
|
|
|
form_submit('delete', icon('trash') . __('sign off'), 'btn-danger', false),
|
2018-11-20 16:02:03 +01:00
|
|
|
]),
|
|
|
|
]),
|
2017-12-19 20:58:01 +01:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sign off from a shift, asking for ack.
|
2017-12-20 00:42:58 +01:00
|
|
|
*
|
2023-01-03 22:19:03 +01:00
|
|
|
* @param Shift $shift
|
2022-11-09 00:02:30 +01:00
|
|
|
* @param AngelType $angeltype
|
2023-01-18 13:02:11 +01:00
|
|
|
* @param User $signoff_user
|
2017-12-20 00:42:58 +01:00
|
|
|
*
|
2017-12-19 20:58:01 +01:00
|
|
|
* @return string HTML
|
|
|
|
*/
|
2023-01-18 13:02:11 +01:00
|
|
|
function ShiftEntry_delete_view(Shift $shift, AngelType $angeltype, User $signoff_user)
|
2017-12-20 00:42:58 +01:00
|
|
|
{
|
2017-12-19 20:58:01 +01:00
|
|
|
return page_with_title(ShiftEntry_delete_title(), [
|
2017-12-25 23:12:52 +01:00
|
|
|
info(sprintf(
|
2018-08-29 21:55:32 +02:00
|
|
|
__('Do you want to sign off from your shift %s from %s to %s as %s?'),
|
2023-01-03 22:19:03 +01:00
|
|
|
$shift->shiftType->name,
|
2023-02-04 02:43:47 +01:00
|
|
|
$shift->start->format(__('Y-m-d H:i')),
|
|
|
|
$shift->end->format(__('Y-m-d H:i')),
|
2022-11-09 00:02:30 +01:00
|
|
|
$angeltype->name
|
2017-12-25 23:12:52 +01:00
|
|
|
), true),
|
2018-11-20 16:02:03 +01:00
|
|
|
|
|
|
|
form([
|
|
|
|
buttons([
|
2023-10-03 18:59:46 +02:00
|
|
|
button(user_link($signoff_user->id), icon('x-lg') . __('form.cancel')),
|
2021-07-22 21:22:21 +02:00
|
|
|
form_submit('delete', icon('trash') . __('delete'), 'btn-danger', false),
|
2018-11-20 16:02:03 +01:00
|
|
|
]),
|
|
|
|
]),
|
2017-12-19 20:58:01 +01:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-12-20 00:42:58 +01:00
|
|
|
* Title for deleting a shift entry.
|
|
|
|
*/
|
|
|
|
function ShiftEntry_delete_title()
|
|
|
|
{
|
2018-08-29 21:55:32 +02:00
|
|
|
return __('Shift sign off');
|
2017-12-20 00:42:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Admin puts user into shift.
|
|
|
|
*
|
2023-01-03 22:19:03 +01:00
|
|
|
* @param Shift $shift
|
2023-10-15 19:25:55 +02:00
|
|
|
* @param Location $location
|
2022-11-09 00:02:30 +01:00
|
|
|
* @param AngelType $angeltype
|
|
|
|
* @param array $angeltypes_select
|
|
|
|
* @param User $signup_user
|
|
|
|
* @param array $users_select
|
2017-12-25 23:12:52 +01:00
|
|
|
* @return string
|
2017-12-20 00:42:58 +01:00
|
|
|
*/
|
2022-11-09 00:02:30 +01:00
|
|
|
function ShiftEntry_create_view_admin(
|
2023-01-03 22:19:03 +01:00
|
|
|
Shift $shift,
|
2023-10-15 19:25:55 +02:00
|
|
|
Location $location,
|
2022-11-09 00:02:30 +01:00
|
|
|
AngelType $angeltype,
|
|
|
|
$angeltypes_select,
|
|
|
|
$signup_user,
|
|
|
|
$users_select
|
|
|
|
) {
|
2023-01-03 22:19:03 +01:00
|
|
|
$start = $shift->start->format(__('Y-m-d H:i'));
|
2017-12-25 23:12:52 +01:00
|
|
|
return page_with_title(
|
2023-01-03 22:19:03 +01:00
|
|
|
ShiftEntry_create_title() . ': ' . $shift->shiftType->name
|
|
|
|
. ' <small title="' . $start . '" data-countdown-ts="' . $shift->start->timestamp . '">%c</small>',
|
2017-12-25 23:12:52 +01:00
|
|
|
[
|
2023-10-15 19:25:55 +02:00
|
|
|
Shift_view_header($shift, $location),
|
2018-08-29 21:55:32 +02:00
|
|
|
info(__('Do you want to sign up the following user for this shift?'), true),
|
2017-12-25 23:12:52 +01:00
|
|
|
form([
|
2022-11-09 00:02:30 +01:00
|
|
|
form_select('angeltype_id', __('Angeltype'), $angeltypes_select, $angeltype->id),
|
2023-10-22 18:37:29 +02:00
|
|
|
form_select('user_id', __('general.user'), $users_select, $signup_user->id),
|
2023-10-01 22:33:58 +02:00
|
|
|
form_submit('submit', icon('check-lg') . __('form.save')),
|
2023-02-05 18:03:00 +01:00
|
|
|
]),
|
2022-10-18 19:15:22 +02:00
|
|
|
]
|
|
|
|
);
|
2017-12-20 00:42:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Supporter puts user into shift.
|
|
|
|
*
|
2023-01-03 22:19:03 +01:00
|
|
|
* @param Shift $shift
|
2023-10-15 19:25:55 +02:00
|
|
|
* @param Location $location
|
2022-11-09 00:02:30 +01:00
|
|
|
* @param AngelType $angeltype
|
2018-10-10 03:10:28 +02:00
|
|
|
* @param User $signup_user
|
2017-12-25 23:12:52 +01:00
|
|
|
* @param array $users_select
|
|
|
|
* @return string
|
2017-12-20 00:42:58 +01:00
|
|
|
*/
|
2023-10-15 19:25:55 +02:00
|
|
|
function ShiftEntry_create_view_supporter(
|
|
|
|
Shift $shift,
|
|
|
|
Location $location,
|
|
|
|
AngelType $angeltype,
|
|
|
|
$signup_user,
|
|
|
|
$users_select
|
|
|
|
) {
|
2023-01-03 22:19:03 +01:00
|
|
|
$start = $shift->start->format(__('Y-m-d H:i'));
|
2022-10-18 19:15:22 +02:00
|
|
|
return page_with_title(
|
2023-01-03 22:19:03 +01:00
|
|
|
ShiftEntry_create_title() . ': ' . $shift->shiftType->name
|
|
|
|
. ' <small title="' . $start . '" data-countdown-ts="' . $shift->start->timestamp . '">%c</small>',
|
2017-12-25 23:12:52 +01:00
|
|
|
[
|
2023-10-15 19:25:55 +02:00
|
|
|
Shift_view_header($shift, $location),
|
2022-10-18 19:15:22 +02:00
|
|
|
info(sprintf(
|
|
|
|
__('Do you want to sign up the following user for this shift as %s?'),
|
2023-02-02 22:53:51 +01:00
|
|
|
$angeltype->name
|
2022-10-18 19:15:22 +02:00
|
|
|
), true),
|
2017-12-25 23:12:52 +01:00
|
|
|
form([
|
2023-10-22 18:37:29 +02:00
|
|
|
form_select('user_id', __('general.user'), $users_select, $signup_user->id),
|
2023-10-01 22:33:58 +02:00
|
|
|
form_submit('submit', icon('check-lg') . __('form.save')),
|
2023-02-05 18:03:00 +01:00
|
|
|
]),
|
2022-10-18 19:15:22 +02:00
|
|
|
]
|
|
|
|
);
|
2017-12-20 00:42:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* User joining a shift.
|
2017-12-25 23:12:52 +01:00
|
|
|
*
|
2023-01-03 22:19:03 +01:00
|
|
|
* @param Shift $shift
|
2023-10-15 19:25:55 +02:00
|
|
|
* @param Location $location
|
2022-11-09 00:02:30 +01:00
|
|
|
* @param AngelType $angeltype
|
2017-12-20 00:42:58 +01:00
|
|
|
* @param string $comment
|
2017-12-25 23:12:52 +01:00
|
|
|
* @return string
|
2017-12-19 20:58:01 +01:00
|
|
|
*/
|
2023-10-15 19:25:55 +02:00
|
|
|
function ShiftEntry_create_view_user(Shift $shift, Location $location, AngelType $angeltype, $comment)
|
2017-12-20 00:42:58 +01:00
|
|
|
{
|
2023-01-03 22:19:03 +01:00
|
|
|
$start = $shift->start->format(__('Y-m-d H:i'));
|
2022-10-18 19:15:22 +02:00
|
|
|
return page_with_title(
|
2023-01-03 22:19:03 +01:00
|
|
|
ShiftEntry_create_title() . ': ' . $shift->shiftType->name
|
|
|
|
. ' <small title="' . $start . '" data-countdown-ts="' . $shift->start->timestamp . '">%c</small>',
|
2017-12-25 23:12:52 +01:00
|
|
|
[
|
2023-10-15 19:25:55 +02:00
|
|
|
Shift_view_header($shift, $location),
|
2023-02-02 22:53:51 +01:00
|
|
|
info(sprintf(__('Do you want to sign up for this shift as %s?'), $angeltype->name), true),
|
2017-12-25 23:12:52 +01:00
|
|
|
form([
|
2018-08-29 21:55:32 +02:00
|
|
|
form_textarea('comment', __('Comment (for your eyes only):'), $comment),
|
2023-10-01 22:33:58 +02:00
|
|
|
form_submit('submit', icon('check-lg') . __('form.save')),
|
2023-02-05 18:03:00 +01:00
|
|
|
]),
|
2022-10-18 19:15:22 +02:00
|
|
|
]
|
|
|
|
);
|
2017-12-19 20:58:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-12-20 00:42:58 +01:00
|
|
|
* Title for creating a shift entry.
|
2017-12-19 20:58:01 +01:00
|
|
|
*/
|
2017-12-20 00:42:58 +01:00
|
|
|
function ShiftEntry_create_title()
|
|
|
|
{
|
2018-08-29 21:55:32 +02:00
|
|
|
return __('Shift signup');
|
2017-12-19 20:58:01 +01:00
|
|
|
}
|
|
|
|
|
2013-11-25 22:04:32 +01:00
|
|
|
/**
|
|
|
|
* Display form for adding/editing a shift entry.
|
2017-01-02 15:43:36 +01:00
|
|
|
*
|
2019-06-04 20:51:26 +02:00
|
|
|
* @param User $angel
|
2017-12-25 23:12:52 +01:00
|
|
|
* @param string $date
|
|
|
|
* @param string $location
|
|
|
|
* @param string $title
|
|
|
|
* @param string $type
|
|
|
|
* @param string $comment
|
|
|
|
* @param bool $freeloaded
|
2023-01-18 13:02:11 +01:00
|
|
|
* @param string $freeloaded_comment
|
2017-12-25 23:12:52 +01:00
|
|
|
* @param bool $user_admin_shifts
|
2013-11-25 22:04:32 +01:00
|
|
|
* @return string
|
|
|
|
*/
|
2017-12-25 23:12:52 +01:00
|
|
|
function ShiftEntry_edit_view(
|
|
|
|
$angel,
|
|
|
|
$date,
|
|
|
|
$location,
|
|
|
|
$title,
|
|
|
|
$type,
|
|
|
|
$comment,
|
|
|
|
$freeloaded,
|
2023-01-18 13:02:11 +01:00
|
|
|
$freeloaded_comment,
|
2017-12-25 23:12:52 +01:00
|
|
|
$user_admin_shifts = false
|
|
|
|
) {
|
2017-01-02 03:57:23 +01:00
|
|
|
$freeload_form = [];
|
|
|
|
if ($user_admin_shifts) {
|
|
|
|
$freeload_form = [
|
2018-08-29 21:55:32 +02:00
|
|
|
form_checkbox('freeloaded', __('Freeloaded'), $freeloaded),
|
2017-12-25 23:12:52 +01:00
|
|
|
form_textarea(
|
2023-01-18 13:02:11 +01:00
|
|
|
'freeloaded_comment',
|
2018-08-29 21:55:32 +02:00
|
|
|
__('Freeload comment (Only for shift coordination):'),
|
2023-01-18 13:02:11 +01:00
|
|
|
$freeloaded_comment
|
2023-02-05 18:03:00 +01:00
|
|
|
),
|
2017-01-02 15:43:36 +01:00
|
|
|
];
|
2017-01-02 03:57:23 +01:00
|
|
|
}
|
2019-06-04 20:51:26 +02:00
|
|
|
|
|
|
|
if ($angel->id == auth()->user()->id) {
|
|
|
|
$comment = form_textarea('comment', __('Comment (for your eyes only):'), $comment);
|
|
|
|
} else {
|
|
|
|
$comment = '';
|
|
|
|
}
|
|
|
|
|
2023-10-25 17:38:23 +02:00
|
|
|
$link = button(
|
2023-11-13 16:56:52 +01:00
|
|
|
url('/users', ['action' => 'view', 'user_id' => $angel->id]),
|
2023-10-25 17:38:23 +02:00
|
|
|
icon('chevron-left'),
|
|
|
|
'btn-sm'
|
|
|
|
);
|
|
|
|
return page_with_title(
|
|
|
|
$link . ' ' . __('Edit shift entry'),
|
|
|
|
[
|
|
|
|
msg(),
|
|
|
|
form([
|
|
|
|
form_info(__('Angel:'), User_Nick_render($angel)),
|
|
|
|
form_info(__('Date, Duration:'), $date),
|
|
|
|
form_info(__('Location:'), $location),
|
|
|
|
form_info(__('Title:'), $title),
|
|
|
|
form_info(__('Type:'), $type),
|
|
|
|
$comment,
|
|
|
|
join('', $freeload_form),
|
|
|
|
form_submit('submit', __('form.save')),
|
|
|
|
]),
|
|
|
|
]
|
|
|
|
);
|
2013-11-25 22:04:32 +01:00
|
|
|
}
|