diff options
author | Philip Häusler <msquare@notrademark.de> | 2014-12-25 22:32:18 +0100 |
---|---|---|
committer | Philip Häusler <msquare@notrademark.de> | 2014-12-25 22:32:18 +0100 |
commit | e89acc0c1d1188662da7490e3a75a4a5c3950a75 (patch) | |
tree | f646260cc23195008f6ca5152426b17641fc4f69 /includes/view/Shifts_view.php | |
parent | bcd33c02c814a8d82c08c078c8fae287d1cd95a5 (diff) | |
parent | 544a51612f14c4f3cf7d1c4a6de26a99ea94b788 (diff) |
merge feature-shift-types
Diffstat (limited to 'includes/view/Shifts_view.php')
-rw-r--r-- | includes/view/Shifts_view.php | 112 |
1 files changed, 111 insertions, 1 deletions
diff --git a/includes/view/Shifts_view.php b/includes/view/Shifts_view.php index d0e7d809..00c18572 100644 --- a/includes/view/Shifts_view.php +++ b/includes/view/Shifts_view.php @@ -1,7 +1,117 @@ <?php + +function Shift_signup_button_render($shift, $angeltype, $user_angeltype = null, $user_shifts = null) { + global $user; + + if ($user_angeltype == null) { + $user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype); + if ($user_angeltype === false) + engelsystem_error('Unable to load user angeltype.'); + } + + if (Shift_signup_allowed($shift, $angeltype, $user_angeltype, $user_shifts)) + return button(page_link_to('user_shifts') . '&shift_id=' . $shift['SID'] . '&type_id=' . $angeltype['id'], _('Sign up')); + elseif ($user_angeltype == null) + return button(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id'], sprintf('Become %s', $angeltype['name'])); + else + return ''; +} + +function Shift_view($shift, $shifttype, $room, $shift_admin, $angeltypes_source, $user_shift_admin, $admin_rooms, $admin_shifttypes, $user_shifts, $signed_up) { + $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">' . Shift_signup_button_render($shift, $angeltypes[$needed_angeltype['TID']]) . '</div>'; + + $needed_angels .= '<h3>' . AngelType_name_render($angeltypes[$needed_angeltype['TID']]) . '</h3>'; + $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(), + Shift_collides($shift, $user_shifts) ? info(_('This shift collides with one of your shifts.'), true) : '', + $signed_up ? info(_('You are signed up for this shift.'), true) : '', + ($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']) : '' + ]) : '', + div('row', [ + 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>' + ]), + 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">' . glyph('map-marker') . $room['Name'] . '</p>' + ]) + ]), + 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. - * @param Shift $shift + * + * @param Shift $shift */ function shift_length($shift) { $length = floor(($shift['end'] - $shift['start']) / (60 * 60)) . ":"; |