From 22520532c78b3a032aec6ececb7623ba094da8de Mon Sep 17 00:00:00 2001 From: msquare Date: Mon, 7 Nov 2016 21:24:05 +0100 Subject: [PATCH] fix shift occupied calculation --- includes/view/ShiftCalendarShiftRenderer.php | 50 +++++++++++++------- 1 file 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'] . '
'; } + 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 .= '
  • ' . button(page_link_to('user_shifts') . '&shift_id=' . $shift['SID'] . '&type_id=' . $angeltype['id'], _("Add more angels"), 'btn-xs') . '
  • '; - } - if ($shifts_row != '') { - $shifts_row = ''; - } 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, '' . 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 .= '
  • ' . button(page_link_to('user_shifts') . '&shift_id=' . $shift['SID'] . '&type_id=' . $angeltype['id'], _("Add more angels"), 'btn-xs') . '
  • '; + } + if ($html != '') { + return [ + $is_free, + '' + ]; + } + 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 = '
  • '; $shifts_row .= '' . AngelType_name_render($angeltype) . ': '; $shifts_row .= join(", ", $entry_list); $shifts_row .= '
  • '; - return $shifts_row; + return [ + $is_free, + $shifts_row + ]; } /**