fix shift occupied calculation

This commit is contained in:
msquare 2016-11-07 21:24:05 +01:00
parent 125f34133d
commit 22520532c7
1 changed files with 34 additions and 16 deletions

View File

@ -17,23 +17,12 @@ class ShiftCalendarShiftRenderer {
global $privileges; global $privileges;
$collides = $this->collides(); $collides = $this->collides();
$is_free = false;
$shifts_row = '';
$info_text = ""; $info_text = "";
if ($shift['title'] != '') { if ($shift['title'] != '') {
$info_text = glyph('info-sign') . $shift['title'] . '<br>'; $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') . '&amp;shift_id=' . $shift['SID'] . '&amp;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)) { if (isset($shift['own']) && $shift['own'] && ! in_array('user_shifts_admin', $privileges)) {
$class = 'primary'; $class = 'primary';
} elseif ($collides && ! in_array('user_shifts_admin', $privileges)) { } elseif ($collides && ! in_array('user_shifts_admin', $privileges)) {
@ -45,9 +34,7 @@ class ShiftCalendarShiftRenderer {
} }
$blocks = ceil(($shift["end"] - $shift["start"]) / ShiftCalendarRenderer::SECONDS_PER_ROW); $blocks = ceil(($shift["end"] - $shift["start"]) / ShiftCalendarRenderer::SECONDS_PER_ROW);
if ($blocks < 1) { $blocks = max(1, $blocks);
$blocks = 1;
}
return [ return [
$blocks, $blocks,
'<td class="shift" rowspan="' . $blocks . '">' . div('shift panel panel-' . $class . '" style="height: ' . ($blocks * ShiftCalendarRenderer::BLOCK_HEIGHT - ShiftCalendarRenderer::MARGIN) . 'px"', [ '<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') . '&amp;shift_id=' . $shift['SID'] . '&amp;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 * Renders a list entry containing the needed angels for an angeltype
* *
@ -78,6 +91,7 @@ class ShiftCalendarShiftRenderer {
private function renderShiftNeededAngeltype($shift, $angeltype, $collides) { private function renderShiftNeededAngeltype($shift, $angeltype, $collides) {
global $privileges; global $privileges;
$is_free = false;
$entry_list = []; $entry_list = [];
$freeloader = 0; $freeloader = 0;
foreach ($angeltype['shift_entries'] as $entry) { foreach ($angeltype['shift_entries'] as $entry) {
@ -126,13 +140,17 @@ class ShiftCalendarShiftRenderer {
} }
unset($inner_text); unset($inner_text);
$is_free = true;
} }
$shifts_row = '<li class="list-group-item">'; $shifts_row = '<li class="list-group-item">';
$shifts_row .= '<strong>' . AngelType_name_render($angeltype) . ':</strong> '; $shifts_row .= '<strong>' . AngelType_name_render($angeltype) . ':</strong> ';
$shifts_row .= join(", ", $entry_list); $shifts_row .= join(", ", $entry_list);
$shifts_row .= '</li>'; $shifts_row .= '</li>';
return $shifts_row; return [
$is_free,
$shifts_row
];
} }
/** /**