diff options
Diffstat (limited to 'includes/view/ShiftCalendarShiftRenderer.php')
-rw-r--r-- | includes/view/ShiftCalendarShiftRenderer.php | 162 |
1 files changed, 83 insertions, 79 deletions
diff --git a/includes/view/ShiftCalendarShiftRenderer.php b/includes/view/ShiftCalendarShiftRenderer.php index fdfefcc2..6d6523c5 100644 --- a/includes/view/ShiftCalendarShiftRenderer.php +++ b/includes/view/ShiftCalendarShiftRenderer.php @@ -5,7 +5,8 @@ namespace Engelsystem; /** * Renders a single shift for the shift calendar */ -class ShiftCalendarShiftRenderer { +class ShiftCalendarShiftRenderer +{ /** * Renders a shift @@ -15,18 +16,19 @@ class ShiftCalendarShiftRenderer { * @param User $user * The user who is viewing the shift calendar */ - public function render($shift, $needed_angeltypes, $shift_entries, $user) { - $info_text = ""; - if ($shift['title'] != '') { - $info_text = glyph('info-sign') . $shift['title'] . '<br>'; - } - list($shift_signup_state, $shifts_row) = $this->renderShiftNeededAngeltypes($shift, $needed_angeltypes, $shift_entries, $user); + public function render($shift, $needed_angeltypes, $shift_entries, $user) + { + $info_text = ""; + if ($shift['title'] != '') { + $info_text = glyph('info-sign') . $shift['title'] . '<br>'; + } + list($shift_signup_state, $shifts_row) = $this->renderShiftNeededAngeltypes($shift, $needed_angeltypes, $shift_entries, $user); - $class = $this->classForSignupState($shift_signup_state); + $class = $this->classForSignupState($shift_signup_state); - $blocks = ceil(($shift["end"] - $shift["start"]) / ShiftCalendarRenderer::SECONDS_PER_ROW); - $blocks = max(1, $blocks); - return [ + $blocks = ceil(($shift["end"] - $shift["start"]) / ShiftCalendarRenderer::SECONDS_PER_ROW); + $blocks = max(1, $blocks); + return [ $blocks, div('shift panel panel-' . $class . '" style="height: ' . ($blocks * ShiftCalendarRenderer::BLOCK_HEIGHT - ShiftCalendarRenderer::MARGIN) . 'px"', [ $this->renderShiftHead($shift), @@ -34,17 +36,18 @@ class ShiftCalendarShiftRenderer { $info_text, Room_name_render([ 'RID' => $shift['RID'], - 'Name' => $shift['room_name'] - ]) + 'Name' => $shift['room_name'] + ]) ]), $shifts_row, - div('shift-spacer') + div('shift-spacer') ]) ]; } - private function classForSignupState(ShiftSignupState $shiftSignupState) { - switch ($shiftSignupState->getState()) { + private function classForSignupState(ShiftSignupState $shiftSignupState) + { + switch ($shiftSignupState->getState()) { case ShiftSignupState::ADMIN: case ShiftSignupState::OCCUPIED: return 'success'; @@ -62,50 +65,51 @@ class ShiftCalendarShiftRenderer { case ShiftSignupState::FREE: return 'danger'; } - } + } - private function renderShiftNeededAngeltypes($shift, $needed_angeltypes, $shift_entries, $user) { - global $privileges; + private function renderShiftNeededAngeltypes($shift, $needed_angeltypes, $shift_entries, $user) + { + global $privileges; - $shift_entries_filtered = []; - foreach ($needed_angeltypes as $needed_angeltype) { - $shift_entries_filtered[$needed_angeltype['id']] = []; - } - foreach ($shift_entries as $shift_entry) { - $shift_entries_filtered[$shift_entry['TID']][] = $shift_entry; - } + $shift_entries_filtered = []; + foreach ($needed_angeltypes as $needed_angeltype) { + $shift_entries_filtered[$needed_angeltype['id']] = []; + } + foreach ($shift_entries as $shift_entry) { + $shift_entries_filtered[$shift_entry['TID']][] = $shift_entry; + } - $html = ""; - $shift_signup_state = null; - foreach ($needed_angeltypes as $angeltype) { - if ($angeltype['count'] > 0 || count($shift_entries_filtered[$angeltype['id']]) > 0) { - list($angeltype_signup_state, $angeltype_html) = $this->renderShiftNeededAngeltype($shift, $shift_entries_filtered[$angeltype['id']], $angeltype, $user); + $html = ""; + $shift_signup_state = null; + foreach ($needed_angeltypes as $angeltype) { + if ($angeltype['count'] > 0 || count($shift_entries_filtered[$angeltype['id']]) > 0) { + list($angeltype_signup_state, $angeltype_html) = $this->renderShiftNeededAngeltype($shift, $shift_entries_filtered[$angeltype['id']], $angeltype, $user); + if ($shift_signup_state == null) { + $shift_signup_state = $angeltype_signup_state; + } else { + $shift_signup_state->combineWith($angeltype_signup_state); + } + $html .= $angeltype_html; + } + } if ($shift_signup_state == null) { - $shift_signup_state = $angeltype_signup_state; - } else { - $shift_signup_state->combineWith($angeltype_signup_state); + $shift_signup_state = new ShiftSignupState(ShiftSignupState::SHIFT_ENDED, 0); } - $html .= $angeltype_html; - } - } - if ($shift_signup_state == null) { - $shift_signup_state = new ShiftSignupState(ShiftSignupState::SHIFT_ENDED, 0); - } - if (in_array('user_shifts_admin', $privileges)) { - $html .= '<li class="list-group-item">' . button(page_link_to('user_shifts') . '&shift_id=' . $shift['SID'], _("Add more angels"), 'btn-xs') . '</li>'; - } - if ($html != '') { - return [ + if (in_array('user_shifts_admin', $privileges)) { + $html .= '<li class="list-group-item">' . button(page_link_to('user_shifts') . '&shift_id=' . $shift['SID'], _("Add more angels"), 'btn-xs') . '</li>'; + } + if ($html != '') { + return [ $shift_signup_state, - '<ul class="list-group">' . $html . '</ul>' + '<ul class="list-group">' . $html . '</ul>' ]; - } - return [ + } + return [ $shift_signup_state, - "" + "" ]; - } + } /** * Renders a list entry containing the needed angels for an angeltype @@ -117,15 +121,16 @@ class ShiftCalendarShiftRenderer { * @param User $user * The user who is viewing the shift calendar */ - private function renderShiftNeededAngeltype($shift, $shift_entries, $angeltype, $user) { - $entry_list = []; - foreach ($shift_entries as $entry) { - $style = $entry['freeloaded'] ? " text-decoration: line-through;" : ''; - $entry_list[] = "<span style=\"$style\">" . User_Nick_render($entry) . "</span>"; - } - $shift_signup_state = Shift_signup_allowed($user, $shift, $angeltype, null, null, $angeltype, $shift_entries); - $inner_text = sprintf(ngettext("%d helper needed", "%d helpers needed", $shift_signup_state->getFreeEntries()), $shift_signup_state->getFreeEntries()); - switch ($shift_signup_state->getState()) { + private function renderShiftNeededAngeltype($shift, $shift_entries, $angeltype, $user) + { + $entry_list = []; + foreach ($shift_entries as $entry) { + $style = $entry['freeloaded'] ? " text-decoration: line-through;" : ''; + $entry_list[] = "<span style=\"$style\">" . User_Nick_render($entry) . "</span>"; + } + $shift_signup_state = Shift_signup_allowed($user, $shift, $angeltype, null, null, $angeltype, $shift_entries); + $inner_text = sprintf(ngettext("%d helper needed", "%d helpers needed", $shift_signup_state->getFreeEntries()), $shift_signup_state->getFreeEntries()); + switch ($shift_signup_state->getState()) { case ShiftSignupState::ADMIN: case ShiftSignupState::FREE: // When admin or free display a link + button for sign up @@ -139,10 +144,10 @@ class ShiftCalendarShiftRenderer { case ShiftSignupState::ANGELTYPE: if ($angeltype['restricted'] == 1) { - // User has to be confirmed on the angeltype first + // User has to be confirmed on the angeltype first $entry_list[] = $inner_text . glyph('lock'); } else { - // Add link to join the angeltype first + // Add link to join the angeltype first $entry_list[] = $inner_text . '<br />' . button(page_link_to('user_angeltypes') . '&action=add&angeltype_id=' . $angeltype['id'], sprintf(_('Become %s'), $angeltype['name']), 'btn-xs'); } break; @@ -158,13 +163,13 @@ class ShiftCalendarShiftRenderer { break; } - $shifts_row = '<li class="list-group-item">'; - $shifts_row .= '<strong>' . AngelType_name_render($angeltype) . ':</strong> '; - $shifts_row .= join(", ", $entry_list); - $shifts_row .= '</li>'; - return [ + $shifts_row = '<li class="list-group-item">'; + $shifts_row .= '<strong>' . AngelType_name_render($angeltype) . ':</strong> '; + $shifts_row .= join(", ", $entry_list); + $shifts_row .= '</li>'; + return [ $shift_signup_state, - $shifts_row + $shifts_row ]; } @@ -174,22 +179,21 @@ class ShiftCalendarShiftRenderer { * @param Shift $shift * The shift */ - private function renderShiftHead($shift) { - global $privileges; + private function renderShiftHead($shift) + { + global $privileges; - $header_buttons = ""; - if (in_array('admin_shifts', $privileges)) { - $header_buttons = '<div class="pull-right">' . table_buttons([ + $header_buttons = ""; + if (in_array('admin_shifts', $privileges)) { + $header_buttons = '<div class="pull-right">' . table_buttons([ button(page_link_to('user_shifts') . '&edit_shift=' . $shift['SID'], glyph('edit'), 'btn-xs'), - button(page_link_to('user_shifts') . '&delete_shift=' . $shift['SID'], glyph('trash'), 'btn-xs') + button(page_link_to('user_shifts') . '&delete_shift=' . $shift['SID'], glyph('trash'), 'btn-xs') ]) . '</div>'; - } - $shift_heading = date('H:i', $shift['start']) . ' ‐ ' . date('H:i', $shift['end']) . ' — ' . $shift['name']; - return div('panel-heading', [ + } + $shift_heading = date('H:i', $shift['start']) . ' ‐ ' . date('H:i', $shift['end']) . ' — ' . $shift['name']; + return div('panel-heading', [ '<a href="' . shift_link($shift) . '">' . $shift_heading . '</a>', - $header_buttons + $header_buttons ]); } } - -?>
\ No newline at end of file |