diff options
author | msquare <msquare@notrademark.de> | 2016-11-07 21:24:05 +0100 |
---|---|---|
committer | msquare <msquare@notrademark.de> | 2016-11-07 21:24:05 +0100 |
commit | 22520532c78b3a032aec6ececb7623ba094da8de (patch) | |
tree | 2c3f78bf8fbd4215e70af7dbc2ce30cfef674816 /includes | |
parent | 125f34133d9c6b39cb9937e0ce29764ab86d1346 (diff) |
fix shift occupied calculation
Diffstat (limited to 'includes')
-rw-r--r-- | includes/view/ShiftCalendarShiftRenderer.php | 50 |
1 files changed, 34 insertions, 16 deletions
diff --git a/includes/view/ShiftCalendarShiftRenderer.php b/includes/view/ShiftCalendarShiftRenderer.php index a0791f85..e86f7baa 100644 --- a/includes/view/ShiftCalendarShiftRenderer.php +++ b/includes/view/ShiftCalendarShiftRenderer.php @@ -17,23 +17,12 @@ class ShiftCalendarShiftRenderer { global $privileges; $collides = $this->collides(); - $is_free = false; - $shifts_row = ''; $info_text = ""; if ($shift['title'] != '') { $info_text = glyph('info-sign') . $shift['title'] . '<br>'; } + list($is_free, $shifts_row) = $this->renderShiftNeededAngeltypes($shift, $collides); - $angeltypes = NeededAngelTypes_by_shift($shift['SID']); - foreach ($angeltypes as $angeltype) { - $shifts_row .= $this->renderShiftNeededAngeltype($shift, $angeltype, $collides); - } - if (in_array('user_shifts_admin', $privileges)) { - $shifts_row .= '<li class="list-group-item">' . button(page_link_to('user_shifts') . '&shift_id=' . $shift['SID'] . '&type_id=' . $angeltype['id'], _("Add more angels"), 'btn-xs') . '</li>'; - } - if ($shifts_row != '') { - $shifts_row = '<ul class="list-group">' . $shifts_row . '</ul>'; - } if (isset($shift['own']) && $shift['own'] && ! in_array('user_shifts_admin', $privileges)) { $class = 'primary'; } elseif ($collides && ! in_array('user_shifts_admin', $privileges)) { @@ -45,9 +34,7 @@ class ShiftCalendarShiftRenderer { } $blocks = ceil(($shift["end"] - $shift["start"]) / ShiftCalendarRenderer::SECONDS_PER_ROW); - if ($blocks < 1) { - $blocks = 1; - } + $blocks = max(1, $blocks); return [ $blocks, '<td class="shift" rowspan="' . $blocks . '">' . div('shift panel panel-' . $class . '" style="height: ' . ($blocks * ShiftCalendarRenderer::BLOCK_HEIGHT - ShiftCalendarRenderer::MARGIN) . 'px"', [ @@ -65,6 +52,32 @@ class ShiftCalendarShiftRenderer { ]; } + private function renderShiftNeededAngeltypes($shift, $collides) { + global $privileges; + + $html = ""; + $is_free = false; + $angeltypes = NeededAngelTypes_by_shift($shift['SID']); + foreach ($angeltypes as $angeltype) { + list($angeltype_free, $angeltype_html) = $this->renderShiftNeededAngeltype($shift, $angeltype, $collides); + $is_free |= $angeltype_free; + $html .= $angeltype_html; + } + if (in_array('user_shifts_admin', $privileges)) { + $html .= '<li class="list-group-item">' . button(page_link_to('user_shifts') . '&shift_id=' . $shift['SID'] . '&type_id=' . $angeltype['id'], _("Add more angels"), 'btn-xs') . '</li>'; + } + if ($html != '') { + return [ + $is_free, + '<ul class="list-group">' . $html . '</ul>' + ]; + } + return [ + $is_free, + "" + ]; + } + /** * Renders a list entry containing the needed angels for an angeltype * @@ -78,6 +91,7 @@ class ShiftCalendarShiftRenderer { private function renderShiftNeededAngeltype($shift, $angeltype, $collides) { global $privileges; + $is_free = false; $entry_list = []; $freeloader = 0; foreach ($angeltype['shift_entries'] as $entry) { @@ -126,13 +140,17 @@ class ShiftCalendarShiftRenderer { } unset($inner_text); + $is_free = true; } $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; + return [ + $is_free, + $shifts_row + ]; } /** |