2013-09-18 01:38:36 +02:00
|
|
|
<?php
|
2017-08-28 16:21:10 +02:00
|
|
|
|
2016-11-15 17:22:15 +01:00
|
|
|
use Engelsystem\ShiftSignupState;
|
2014-12-19 22:41:55 +01:00
|
|
|
|
2017-12-20 00:42:58 +01:00
|
|
|
/**
|
|
|
|
* Renders the basic shift view header.
|
2017-12-25 23:12:52 +01:00
|
|
|
*
|
2017-12-20 00:42:58 +01:00
|
|
|
* @param array $shift
|
|
|
|
* @param array $room
|
|
|
|
* @return string HTML
|
|
|
|
*/
|
2017-12-25 23:12:52 +01:00
|
|
|
function Shift_view_header($shift, $room)
|
|
|
|
{
|
2017-12-20 00:42:58 +01:00
|
|
|
return div('row', [
|
|
|
|
div('col-sm-3 col-xs-6', [
|
|
|
|
'<h4>' . _('Title') . '</h4>',
|
2017-12-25 23:12:52 +01:00
|
|
|
'<p class="lead">'
|
|
|
|
. ($shift['URL'] != ''
|
|
|
|
? '<a href="' . $shift['URL'] . '">' . $shift['title'] . '</a>'
|
|
|
|
: $shift['title'])
|
|
|
|
. '</p>'
|
2017-12-20 00:42:58 +01:00
|
|
|
]),
|
|
|
|
div('col-sm-3 col-xs-6', [
|
|
|
|
'<h4>' . _('Start') . '</h4>',
|
|
|
|
'<p class="lead' . (time() >= $shift['start'] ? ' text-success' : '') . '">',
|
|
|
|
glyph('calendar') . date(_('Y-m-d'), $shift['start']),
|
|
|
|
'<br />',
|
|
|
|
glyph('time') . date('H:i', $shift['start']),
|
|
|
|
'</p>'
|
|
|
|
]),
|
|
|
|
div('col-sm-3 col-xs-6', [
|
|
|
|
'<h4>' . _('End') . '</h4>',
|
|
|
|
'<p class="lead' . (time() >= $shift['end'] ? ' text-success' : '') . '">',
|
|
|
|
glyph('calendar') . date(_('Y-m-d'), $shift['end']),
|
|
|
|
'<br />',
|
|
|
|
glyph('time') . date('H:i', $shift['end']),
|
|
|
|
'</p>'
|
|
|
|
]),
|
|
|
|
div('col-sm-3 col-xs-6', [
|
|
|
|
'<h4>' . _('Location') . '</h4>',
|
|
|
|
'<p class="lead">' . Room_name_render($room) . '</p>'
|
|
|
|
])
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2017-01-03 03:22:48 +01:00
|
|
|
/**
|
|
|
|
* @param array $shift
|
|
|
|
* @return string
|
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
function Shift_editor_info_render($shift)
|
|
|
|
{
|
|
|
|
$info = [];
|
|
|
|
if ($shift['created_by_user_id'] != null) {
|
2017-01-02 15:43:36 +01:00
|
|
|
$info[] = sprintf(
|
2017-01-03 14:12:17 +01:00
|
|
|
glyph('plus') . _('created at %s by %s'),
|
2017-01-02 15:43:36 +01:00
|
|
|
date('Y-m-d H:i', $shift['created_at_timestamp']),
|
|
|
|
User_Nick_render(User($shift['created_by_user_id']))
|
|
|
|
);
|
2017-01-02 03:57:23 +01:00
|
|
|
}
|
|
|
|
if ($shift['edited_by_user_id'] != null) {
|
2017-01-02 15:43:36 +01:00
|
|
|
$info[] = sprintf(
|
2017-01-03 14:12:17 +01:00
|
|
|
glyph('pencil') . _('edited at %s by %s'),
|
2017-01-02 15:43:36 +01:00
|
|
|
date('Y-m-d H:i', $shift['edited_at_timestamp']),
|
|
|
|
User_Nick_render(User($shift['edited_by_user_id']))
|
|
|
|
);
|
2017-01-02 03:57:23 +01:00
|
|
|
}
|
|
|
|
return join('<br />', $info);
|
2015-08-15 23:36:38 +02:00
|
|
|
}
|
|
|
|
|
2017-01-03 03:22:48 +01:00
|
|
|
/**
|
|
|
|
* @param array $shift
|
|
|
|
* @param array $angeltype
|
|
|
|
* @param array $user_angeltype
|
|
|
|
* @return string
|
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
function Shift_signup_button_render($shift, $angeltype, $user_angeltype = null)
|
|
|
|
{
|
|
|
|
global $user;
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-01-02 03:57:23 +01:00
|
|
|
if ($user_angeltype == null) {
|
|
|
|
$user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype);
|
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-01-02 03:57:23 +01:00
|
|
|
if ($angeltype['shift_signup_state']->isSignupAllowed()) {
|
2017-12-20 00:54:57 +01:00
|
|
|
return button(shift_entry_create_link($shift, $angeltype), _('Sign up'));
|
2017-01-02 03:57:23 +01:00
|
|
|
} elseif ($user_angeltype == null) {
|
2017-01-02 15:43:36 +01:00
|
|
|
return button(
|
2017-08-28 16:21:10 +02:00
|
|
|
page_link_to('angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype['id']]),
|
2017-01-02 15:43:36 +01:00
|
|
|
sprintf(_('Become %s'),
|
|
|
|
$angeltype['name'])
|
|
|
|
);
|
2017-01-02 03:57:23 +01:00
|
|
|
}
|
|
|
|
return '';
|
2014-12-25 22:23:18 +01:00
|
|
|
}
|
|
|
|
|
2017-01-03 03:22:48 +01:00
|
|
|
/**
|
|
|
|
* @param array $shift
|
|
|
|
* @param array $shifttype
|
|
|
|
* @param array $room
|
|
|
|
* @param array[] $angeltypes_source
|
|
|
|
* @param ShiftSignupState $shift_signup_state
|
|
|
|
* @return string
|
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
function Shift_view($shift, $shifttype, $room, $angeltypes_source, ShiftSignupState $shift_signup_state)
|
|
|
|
{
|
2017-12-26 12:17:51 +01:00
|
|
|
global $user, $privileges;
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-01-02 03:57:23 +01:00
|
|
|
$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);
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-01-02 03:57:23 +01:00
|
|
|
$parsedown = new Parsedown();
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-01-02 03:57:23 +01:00
|
|
|
$angeltypes = [];
|
|
|
|
foreach ($angeltypes_source as $angeltype) {
|
|
|
|
$angeltypes[$angeltype['id']] = $angeltype;
|
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-01-02 03:57:23 +01:00
|
|
|
$needed_angels = '';
|
|
|
|
foreach ($shift['NeedAngels'] as $needed_angeltype) {
|
|
|
|
$needed_angels .= Shift_view_render_needed_angeltype($needed_angeltype, $angeltypes, $shift, $user_shift_admin);
|
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
|
|
|
|
return page_with_title(
|
|
|
|
$shift['name'] . ' <small class="moment-countdown" data-timestamp="' . $shift['start'] . '">%c</small>',
|
|
|
|
[
|
|
|
|
msg(),
|
|
|
|
$shift_signup_state->getState() == ShiftSignupState::COLLIDES
|
|
|
|
? info(_('This shift collides with one of your shifts.'), true)
|
|
|
|
: '',
|
|
|
|
$shift_signup_state->getState() == ShiftSignupState::SIGNED_UP
|
|
|
|
? info(_('You are signed up for this shift.'), true)
|
|
|
|
: '',
|
2017-12-26 12:17:51 +01:00
|
|
|
buttons(
|
|
|
|
($shift_admin || $admin_shifttypes || $admin_rooms) ? [
|
2017-01-02 15:43:36 +01:00
|
|
|
$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']) : '',
|
2017-12-26 12:17:51 +01:00
|
|
|
$admin_rooms ? button(room_link($room), glyph('map-marker') . $room['Name']) : '',
|
|
|
|
button(user_link($user), '<span class="icon-icon_angel"></span> ' . _('My shifts'))
|
|
|
|
] : [
|
|
|
|
button(user_link($user), '<span class="icon-icon_angel"></span> ' . _('My shifts'))
|
|
|
|
]),
|
2017-12-20 00:42:58 +01:00
|
|
|
Shift_view_header($shift, $room),
|
2017-01-02 15:43:36 +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'])
|
|
|
|
])
|
|
|
|
]),
|
|
|
|
$shift_admin ? Shift_editor_info_render($shift) : ''
|
|
|
|
]
|
|
|
|
);
|
2014-12-19 22:41:55 +01:00
|
|
|
}
|
|
|
|
|
2017-01-03 03:22:48 +01:00
|
|
|
/**
|
|
|
|
* @param array $needed_angeltype
|
|
|
|
* @param array $angeltypes
|
|
|
|
* @param array[] $shift
|
|
|
|
* @param bool $user_shift_admin
|
|
|
|
* @return string
|
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
function Shift_view_render_needed_angeltype($needed_angeltype, $angeltypes, $shift, $user_shift_admin)
|
|
|
|
{
|
|
|
|
global $user;
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-01-02 03:57:23 +01:00
|
|
|
$angeltype = $angeltypes[$needed_angeltype['TID']];
|
|
|
|
$angeltype_supporter = User_is_AngelType_supporter($user, $angeltype);
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-01-02 03:57:23 +01:00
|
|
|
$needed_angels = '';
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-01-02 03:57:23 +01:00
|
|
|
$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">';
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-01-02 03:57:23 +01:00
|
|
|
$needed_angels .= '<div class="pull-right">' . Shift_signup_button_render($shift, $angeltype) . '</div>';
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-01-02 03:57:23 +01:00
|
|
|
$needed_angels .= '<h3>' . AngelType_name_render($angeltype) . '</h3>';
|
|
|
|
$bar_max = max($needed_angeltype['count'] * 10, $needed_angeltype['taken'] * 10, 10);
|
|
|
|
$bar_value = max(1, $needed_angeltype['taken'] * 10);
|
2017-01-02 15:43:36 +01:00
|
|
|
$needed_angels .= progress_bar(
|
|
|
|
0,
|
|
|
|
$bar_max,
|
|
|
|
$bar_value,
|
|
|
|
$class,
|
|
|
|
$needed_angeltype['taken'] . ' / ' . $needed_angeltype['count']
|
|
|
|
);
|
|
|
|
|
2017-01-02 03:57:23 +01:00
|
|
|
$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);
|
|
|
|
}
|
2016-11-15 17:54:59 +01:00
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-01-02 03:57:23 +01:00
|
|
|
$needed_angels .= join(', ', $angels);
|
|
|
|
$needed_angels .= '</div>';
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-01-02 03:57:23 +01:00
|
|
|
return $needed_angels;
|
2016-11-15 17:54:59 +01:00
|
|
|
}
|
|
|
|
|
2017-01-03 03:22:48 +01:00
|
|
|
/**
|
|
|
|
* @param array $shift_entry
|
|
|
|
* @param bool $user_shift_admin
|
|
|
|
* @param bool $angeltype_supporter
|
|
|
|
* @return string
|
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
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']) {
|
2017-01-03 03:22:48 +01:00
|
|
|
$entry = '<del>' . $entry . '</del>';
|
2017-01-02 03:57:23 +01:00
|
|
|
}
|
|
|
|
if ($user_shift_admin || $angeltype_supporter) {
|
|
|
|
$entry .= ' <div class="btn-group">';
|
|
|
|
if ($user_shift_admin) {
|
2017-01-02 15:43:36 +01:00
|
|
|
$entry .= button_glyph(
|
2017-08-28 16:21:10 +02:00
|
|
|
page_link_to('user_myshifts', ['edit' => $shift_entry['id'], 'id' => $shift_entry['UID']]),
|
2017-01-02 15:43:36 +01:00
|
|
|
'pencil',
|
|
|
|
'btn-xs'
|
|
|
|
);
|
2017-01-02 03:57:23 +01:00
|
|
|
}
|
2017-12-20 00:42:58 +01:00
|
|
|
$entry .= button_glyph(shift_entry_delete_link($shift_entry), 'trash', 'btn-xs');
|
2017-01-02 03:57:23 +01:00
|
|
|
$entry .= '</div>';
|
2016-12-24 17:29:12 +01:00
|
|
|
}
|
2017-01-02 03:57:23 +01:00
|
|
|
return $entry;
|
2016-11-15 17:54:59 +01:00
|
|
|
}
|
|
|
|
|
2013-09-18 01:38:36 +02:00
|
|
|
/**
|
|
|
|
* Calc shift length in format 12:23h.
|
2014-12-19 22:41:55 +01:00
|
|
|
*
|
2017-01-03 03:22:48 +01:00
|
|
|
* @param array $shift
|
|
|
|
* @return string
|
2013-09-18 01:38:36 +02:00
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
function shift_length($shift)
|
|
|
|
{
|
2017-01-03 14:12:17 +01:00
|
|
|
$length = floor(($shift['end'] - $shift['start']) / (60 * 60)) . ':';
|
2017-12-25 23:12:52 +01:00
|
|
|
$length .= str_pad(
|
|
|
|
(($shift['end'] - $shift['start']) % (60 * 60)) / 60,
|
|
|
|
2,
|
|
|
|
'0',
|
|
|
|
STR_PAD_LEFT
|
|
|
|
) . 'h';
|
2017-01-02 03:57:23 +01:00
|
|
|
return $length;
|
2013-09-18 01:38:36 +02:00
|
|
|
}
|