engelsystem/includes/view/ShiftEntry_view.php

230 lines
6.5 KiB
PHP
Raw Normal View History

2013-11-25 22:04:32 +01:00
<?php
use Carbon\Carbon;
2022-11-09 00:02:30 +01:00
use Engelsystem\Models\AngelType;
2020-09-06 23:50:36 +02:00
use Engelsystem\Models\Room;
2018-10-10 03:10:28 +02:00
use Engelsystem\Models\User\User;
/**
2022-11-09 00:02:30 +01:00
* Sign off from a user from a shift with admin permissions, asking for ack.
*
* @param array $shift
2022-11-09 00:02:30 +01:00
* @param AngelType $angeltype
2018-10-10 03:10:28 +02:00
* @param User $signoff_user
*
* @return string HTML
*/
2022-11-09 00:02:30 +01:00
function ShiftEntry_delete_view_admin($shift, AngelType $angeltype, $signoff_user)
{
return page_with_title(ShiftEntry_delete_title(), [
2017-12-25 23:12:52 +01:00
info(sprintf(
__('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),
$shift['name'],
date('Y-m-d H:i', $shift['start']),
date('Y-m-d H:i', $shift['end']),
2022-11-09 00:02:30 +01:00
$angeltype->name
2017-12-25 23:12:52 +01:00
), true),
form([
buttons([
button(user_link($signoff_user->id), icon('x-lg') . __('cancel')),
form_submit('delete', icon('trash') . __('sign off'), 'btn-danger', false)
]),
]),
]);
}
/**
* Sign off from a shift, asking for ack.
*
2017-12-25 23:12:52 +01:00
* @param array $shift
2022-11-09 00:02:30 +01:00
* @param AngelType $angeltype
2018-10-10 03:10:28 +02:00
* @param int $signoff_user_id
*
* @return string HTML
*/
2022-11-09 00:02:30 +01:00
function ShiftEntry_delete_view($shift, AngelType $angeltype, $signoff_user_id)
{
return page_with_title(ShiftEntry_delete_title(), [
2017-12-25 23:12:52 +01:00
info(sprintf(
__('Do you want to sign off from your shift %s from %s to %s as %s?'),
2017-12-25 23:12:52 +01:00
$shift['name'],
date('Y-m-d H:i', $shift['start']),
date('Y-m-d H:i', $shift['end']),
2022-11-09 00:02:30 +01:00
$angeltype->name
2017-12-25 23:12:52 +01:00
), true),
form([
buttons([
button(user_link($signoff_user_id), icon('x-lg') . __('cancel')),
form_submit('delete', icon('trash') . __('delete'), 'btn-danger', false),
]),
]),
]);
}
/**
* Title for deleting a shift entry.
*/
function ShiftEntry_delete_title()
{
return __('Shift sign off');
}
/**
* Admin puts user into shift.
*
2022-11-09 00:02:30 +01:00
* @param array $shift
* @param Room $room
* @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
*/
2022-11-09 00:02:30 +01:00
function ShiftEntry_create_view_admin(
$shift,
Room $room,
AngelType $angeltype,
$angeltypes_select,
$signup_user,
$users_select
) {
$start = Carbon::createFromTimestamp($shift['start'])->format(__('Y-m-d H:i'));
2017-12-25 23:12:52 +01:00
return page_with_title(
ShiftEntry_create_title() . ': ' . $shift['name']
. ' <small title="' . $start . '" data-countdown-ts="' . $shift['start'] . '">%c</small>',
2017-12-25 23:12:52 +01:00
[
Shift_view_header($shift, $room),
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),
form_select('user_id', __('User'), $users_select, $signup_user->id),
form_submit('submit', icon('check-lg') . __('Save'))
2017-12-25 23:12:52 +01:00
])
2022-10-18 19:15:22 +02:00
]
);
}
/**
* Supporter puts user into shift.
*
2017-12-25 23:12:52 +01:00
* @param array $shift
2020-09-06 23:50:36 +02:00
* @param Room $room
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
*/
2022-11-09 00:02:30 +01:00
function ShiftEntry_create_view_supporter($shift, Room $room, AngelType $angeltype, $signup_user, $users_select)
{
$start = Carbon::createFromTimestamp($shift['start'])->format(__('Y-m-d H:i'));
2022-10-18 19:15:22 +02:00
return page_with_title(
ShiftEntry_create_title() . ': ' . $shift['name']
. ' <small title="' . $start . '" data-countdown-ts="' . $shift['start'] . '">%c</small>',
2017-12-25 23:12:52 +01:00
[
Shift_view_header($shift, $room),
2022-10-18 19:15:22 +02:00
info(sprintf(
__('Do you want to sign up the following user for this shift as %s?'),
AngelType_name_render($angeltype)
), true),
2017-12-25 23:12:52 +01:00
form([
2018-10-10 03:10:28 +02:00
form_select('user_id', __('User'), $users_select, $signup_user->id),
form_submit('submit', icon('check-lg') . __('Save'))
2017-12-25 23:12:52 +01:00
])
2022-10-18 19:15:22 +02:00
]
);
}
/**
* User joining a shift.
2017-12-25 23:12:52 +01:00
*
* @param array $shift
2020-09-06 23:50:36 +02:00
* @param Room $room
2022-11-09 00:02:30 +01:00
* @param AngelType $angeltype
* @param string $comment
2017-12-25 23:12:52 +01:00
* @return string
*/
2022-11-09 00:02:30 +01:00
function ShiftEntry_create_view_user($shift, Room $room, AngelType $angeltype, $comment)
{
$start = Carbon::createFromTimestamp($shift['start'])->format(__('Y-m-d H:i'));
2022-10-18 19:15:22 +02:00
return page_with_title(
ShiftEntry_create_title() . ': ' . $shift['name']
. ' <small title="' . $start . '" data-countdown-ts="' . $shift['start'] . '">%c</small>',
2017-12-25 23:12:52 +01:00
[
Shift_view_header($shift, $room),
info(sprintf(__('Do you want to sign up for this shift as %s?'), AngelType_name_render($angeltype)), true),
2017-12-25 23:12:52 +01:00
form([
form_textarea('comment', __('Comment (for your eyes only):'), $comment),
form_submit('submit', icon('check-lg') . __('Save'))
2017-12-25 23:12:52 +01:00
])
2022-10-18 19:15:22 +02:00
]
);
}
/**
* Title for creating a shift entry.
*/
function ShiftEntry_create_title()
{
return __('Shift signup');
}
2013-11-25 22:04:32 +01:00
/**
* Display form for adding/editing a shift entry.
2017-01-02 15:43:36 +01: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
* @param string $freeload_comment
* @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,
$freeload_comment,
$user_admin_shifts = false
) {
2017-01-02 03:57:23 +01:00
$freeload_form = [];
if ($user_admin_shifts) {
$freeload_form = [
form_checkbox('freeloaded', __('Freeloaded'), $freeloaded),
2017-12-25 23:12:52 +01:00
form_textarea(
'freeload_comment',
__('Freeload comment (Only for shift coordination):'),
2017-12-25 23:12:52 +01:00
$freeload_comment
)
2017-01-02 15:43:36 +01:00
];
2017-01-02 03:57:23 +01:00
}
if ($angel->id == auth()->user()->id) {
$comment = form_textarea('comment', __('Comment (for your eyes only):'), $comment);
} else {
$comment = '';
}
return page_with_title(__('Edit shift entry'), [
2017-01-02 15:43:36 +01:00
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,
2017-01-03 14:12:17 +01:00
join('', $freeload_form),
form_submit('submit', __('Save'))
2017-01-02 15:43:36 +01:00
])
]);
2013-11-25 22:04:32 +01:00
}