' . __('Title') . '',
'
'
. ($shift['URL'] != ''
? '' . $shift['title'] . ''
: $shift['title'])
. '
'
]),
div('col-sm-3 col-xs-6', [
'' . __('Start') . '
',
'',
glyph('calendar') . date(__('Y-m-d'), $shift['start']),
'
',
glyph('time') . date('H:i', $shift['start']),
'
'
]),
div('col-sm-3 col-xs-6', [
'' . __('End') . '
',
'',
glyph('calendar') . date(__('Y-m-d'), $shift['end']),
'
',
glyph('time') . date('H:i', $shift['end']),
'
'
]),
div('col-sm-3 col-xs-6', [
'' . __('Location') . '
',
'' . Room_name_render($room) . '
'
])
]);
}
/**
* @param array $shift
* @return string
*/
function Shift_editor_info_render($shift)
{
$info = [];
if (!empty($shift['created_by_user_id'])) {
$info[] = sprintf(
glyph('plus') . __('created at %s by %s'),
date('Y-m-d H:i', $shift['created_at_timestamp']),
User_Nick_render(User($shift['created_by_user_id']))
);
}
if (!empty($shift['edited_by_user_id'])) {
$info[] = sprintf(
glyph('pencil') . __('edited at %s by %s'),
date('Y-m-d H:i', $shift['edited_at_timestamp']),
User_Nick_render(User($shift['edited_by_user_id']))
);
}
return join('
', $info);
}
/**
* @param array $shift
* @param array $angeltype
* @param array $user_angeltype
* @return string
*/
function Shift_signup_button_render($shift, $angeltype, $user_angeltype = null)
{
$user = auth()->user();
if (empty($user_angeltype)) {
$user_angeltype = UserAngelType_by_User_and_AngelType($user->id, $angeltype);
}
if ($angeltype['shift_signup_state']->isSignupAllowed()) {
return button(shift_entry_create_link($shift, $angeltype), __('Sign up'));
} elseif (empty($user_angeltype)) {
return button(
page_link_to('angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype['id']]),
sprintf(__('Become %s'),
$angeltype['name'])
);
}
return '';
}
/**
* @param array $shift
* @param array $shifttype
* @param array $room
* @param array[] $angeltypes_source
* @param ShiftSignupState $shift_signup_state
* @return string
*/
function Shift_view($shift, $shifttype, $room, $angeltypes_source, ShiftSignupState $shift_signup_state)
{
global $privileges;
$user = auth()->user();
$shift_admin = in_array('admin_shifts', $privileges);
$user_shift_admin = in_array('user_shifts_admin', $privileges);
$admin_rooms = in_array('admin_rooms', $privileges);
$admin_shifttypes = in_array('shifttypes', $privileges);
$parsedown = new Parsedown();
$angeltypes = [];
foreach ($angeltypes_source as $angeltype) {
$angeltypes[$angeltype['id']] = $angeltype;
}
$needed_angels = '';
foreach ($shift['NeedAngels'] as $needed_angeltype) {
$needed_angels .= Shift_view_render_needed_angeltype($needed_angeltype, $angeltypes, $shift, $user_shift_admin);
}
$content = [msg()];
if ($shift_signup_state->getState() == ShiftSignupState::COLLIDES) {
$content[] = info(__('This shift collides with one of your shifts.'), true);
}
if ($shift_signup_state->getState() == ShiftSignupState::SIGNED_UP) {
$content[] = info(__('You are signed up for this shift.'), true);
}
$buttons = [];
if ($shift_admin || $admin_shifttypes || $admin_rooms) {
$buttons = [
$shift_admin ? button(shift_edit_link($shift), glyph('pencil') . __('edit')) : '',
$shift_admin ? button(shift_delete_link($shift), glyph('trash') . __('delete')) : '',
$admin_shifttypes ? button(shifttype_link($shifttype), $shifttype['name']) : '',
$admin_rooms ? button(room_link($room), glyph('map-marker') . $room['Name']) : '',
];
}
$buttons[] = button(user_link($user->id), ' ' . __('My shifts'));
$content[] = buttons($buttons);
$content[] = Shift_view_header($shift, $room);
$content[] = div('row', [
div('col-sm-6', [
'' . __('Needed angels') . '
',
'' . $needed_angels . '
'
]),
div('col-sm-6', [
'' . __('Description') . '
',
$parsedown->parse($shifttype['description'])
])
]);
if ($shift_admin) {
$content[] = Shift_editor_info_render($shift);
}
return page_with_title(
$shift['name'] . ' %c',
$content
);
}
/**
* @param array $needed_angeltype
* @param array $angeltypes
* @param array[] $shift
* @param bool $user_shift_admin
* @return string
*/
function Shift_view_render_needed_angeltype($needed_angeltype, $angeltypes, $shift, $user_shift_admin)
{
global $user;
$angeltype = $angeltypes[$needed_angeltype['TID']];
$angeltype_supporter = User_is_AngelType_supporter($user, $angeltype);
$needed_angels = '';
$class = 'progress-bar-warning';
if ($needed_angeltype['taken'] == 0) {
$class = 'progress-bar-danger';
}
if ($needed_angeltype['taken'] >= $needed_angeltype['count']) {
$class = 'progress-bar-success';
}
$needed_angels .= '';
$needed_angels .= '
' . Shift_signup_button_render($shift, $angeltype) . '
';
$needed_angels .= '
' . AngelType_name_render($angeltype) . '
';
$bar_max = max($needed_angeltype['count'] * 10, $needed_angeltype['taken'] * 10, 10);
$bar_value = max(1, $needed_angeltype['taken'] * 10);
$needed_angels .= progress_bar(
0,
$bar_max,
$bar_value,
$class,
$needed_angeltype['taken'] . ' / ' . $needed_angeltype['count']
);
$angels = [];
foreach ($shift['ShiftEntry'] as $shift_entry) {
if ($shift_entry['TID'] == $needed_angeltype['TID']) {
$angels[] = Shift_view_render_shift_entry($shift_entry, $user_shift_admin, $angeltype_supporter);
}
}
$needed_angels .= join(', ', $angels);
$needed_angels .= '
';
return $needed_angels;
}
/**
* @param array $shift_entry
* @param bool $user_shift_admin
* @param bool $angeltype_supporter
* @return string
*/
function Shift_view_render_shift_entry($shift_entry, $user_shift_admin, $angeltype_supporter)
{
$entry = User_Nick_render(User($shift_entry['UID']));
if ($shift_entry['freeloaded']) {
$entry = '' . $entry . '';
}
if ($user_shift_admin || $angeltype_supporter) {
$entry .= ' ';
if ($user_shift_admin) {
$entry .= button_glyph(
page_link_to('user_myshifts', ['edit' => $shift_entry['id'], 'id' => $shift_entry['UID']]),
'pencil',
'btn-xs'
);
}
$entry .= button_glyph(shift_entry_delete_link($shift_entry), 'trash', 'btn-xs');
$entry .= '
';
}
return $entry;
}
/**
* Calc shift length in format 12:23h.
*
* @param array $shift
* @return string
*/
function shift_length($shift)
{
$length = floor(($shift['end'] - $shift['start']) / (60 * 60)) . ':';
$length .= str_pad(
(($shift['end'] - $shift['start']) % (60 * 60)) / 60,
2,
'0',
STR_PAD_LEFT
) . 'h';
return $length;
}