engelsystem/includes/view/Shifts_view.php

101 lines
4.1 KiB
PHP
Raw Normal View History

<?php
2014-12-19 22:41:55 +01:00
2014-12-22 18:22:54 +01:00
function Shift_view($shift, $shifttype, $room, $shift_admin, $angeltypes_source, $user_shift_admin, $admin_rooms, $admin_shifttypes) {
2014-12-19 22:41:55 +01:00
$parsedown = new Parsedown();
$angeltypes = [];
foreach ($angeltypes_source as $angeltype)
$angeltypes[$angeltype['id']] = $angeltype;
$needed_angels = '';
foreach ($shift['NeedAngels'] as $needed_angeltype) {
$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 .= '<div class="list-group-item">';
$needed_angels .= '<div class="pull-right">' . button(page_link_to('user_shifts') . '&shift_id=' . $shift['SID'] . '&type_id=' . $needed_angeltype['TID'], _('Sign up')) . '</div>';
2014-12-19 22:59:18 +01:00
$needed_angels .= '<h3>' . AngelType_name_render($angeltypes[$needed_angeltype['TID']]) . '</h3>';
2014-12-19 22:41:55 +01:00
$needed_angels .= progress_bar(0, $needed_angeltype['count'], $needed_angeltype['taken'], $class, $needed_angeltype['taken'] . ' / ' . $needed_angeltype['count']);
$angels = [];
foreach ($shift['ShiftEntry'] as $shift_entry) {
if ($shift_entry['TID'] == $needed_angeltype['TID']) {
$entry = User_Nick_render(User($shift_entry['UID']));
if ($shift_entry['freeloaded'])
$entry = '<strike>' . $entry . '</strike>';
if ($user_shift_admin) {
$entry .= ' <div class="btn-group">';
$entry .= button_glyph(page_link_to('user_myshifts') . '&edit=' . $shift['SID'] . '&id=' . $shift_entry['UID'], 'pencil', 'btn-xs');
$entry .= button_glyph(page_link_to('user_shifts') . '&entry_id=' . $shift_entry['id'], 'trash', 'btn-xs');
$entry .= '</div>';
}
$angels[] = $entry;
}
}
$needed_angels .= join(', ', $angels);
$needed_angels .= '</div>';
}
return page_with_title($shift['name'] . ' <small class="moment-countdown" data-timestamp="' . $shift['start'] . '">%c</small>', [
msg(),
2014-12-22 18:22:54 +01:00
($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']) : ''
2014-12-19 22:41:55 +01:00
]) : '',
div('row', [
2014-12-22 18:06:58 +01:00
div('col-sm-3 col-xs-6', [
'<h4>' . _('Title') . '</h4>',
'<p class="lead">' . ($shift['URL'] != '' ? '<a href="' . $shift['URL'] . '">' . $shift['title'] . '</a>' : $shift['title']) . '</p>'
]),
2014-12-19 22:59:18 +01:00
div('col-sm-3 col-xs-6', [
2014-12-19 22:41:55 +01:00
'<h4>' . _('Start') . '</h4>',
'<p class="lead">',
2014-12-22 18:22:54 +01:00
glyph('calendar') . date('y-m-d', $shift['start']),
2014-12-19 22:41:55 +01:00
'<br />',
2014-12-22 18:22:54 +01:00
glyph('time') . date('H:i', $shift['start']),
2014-12-19 22:41:55 +01:00
'</p>'
]),
2014-12-19 22:59:18 +01:00
div('col-sm-3 col-xs-6', [
2014-12-19 22:41:55 +01:00
'<h4>' . _('End') . '</h4>',
'<p class="lead">',
2014-12-22 18:22:54 +01:00
glyph('calendar') . date('y-m-d', $shift['end']),
2014-12-19 22:41:55 +01:00
'<br />',
2014-12-22 18:22:54 +01:00
glyph('time') . date('H:i', $shift['end']),
2014-12-19 22:41:55 +01:00
'</p>'
]),
2014-12-19 22:59:18 +01:00
div('col-sm-3 col-xs-6', [
2014-12-19 22:41:55 +01:00
'<h4>' . _('Location') . '</h4>',
2014-12-22 18:22:54 +01:00
'<p class="lead">' . glyph('map-marker') . $room['Name'] . '</p>'
2014-12-19 22:41:55 +01:00
])
]),
div('row', [
div('col-sm-6', [
'<h2>' . _('Needed angels') . '</h2>',
'<div class="list-group">' . $needed_angels . '</div>'
]),
div('col-sm-6', [
'<h2>' . _('Description') . '</h2>',
$parsedown->parse($shifttype['description'])
])
])
]);
}
/**
* Calc shift length in format 12:23h.
2014-12-19 22:41:55 +01:00
*
* @param Shift $shift
*/
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;
}
?>