From 0ab9f4f9886ca61fe0711ba1ee551394ceda877a Mon Sep 17 00:00:00 2001 From: msquare Date: Mon, 14 Nov 2016 17:40:24 +0100 Subject: fix shift ended recognition and displayed time range end --- includes/model/Shifts_model.php | 2 +- includes/view/ShiftCalendarRenderer.php | 21 +++++++++++++++++++-- includes/view/ShiftCalendarShiftRenderer.php | 10 +--------- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/includes/model/Shifts_model.php b/includes/model/Shifts_model.php index 306d3e13..3d3fa356 100644 --- a/includes/model/Shifts_model.php +++ b/includes/model/Shifts_model.php @@ -133,7 +133,7 @@ function Shift_signup_allowed($user, $shift, $angeltype, $user_angeltype = null, return new ShiftSignupState(ShiftSignupState::FREE, $free_entries); } - if (time() < $shift['start']) { + if (time() > $shift['start']) { // you can only join if the shift is in future return new ShiftSignupState(ShiftSignupState::SHIFT_ENDED, $free_entries); } diff --git a/includes/view/ShiftCalendarRenderer.php b/includes/view/ShiftCalendarRenderer.php index 3f0d81f7..989bd890 100644 --- a/includes/view/ShiftCalendarRenderer.php +++ b/includes/view/ShiftCalendarRenderer.php @@ -25,12 +25,15 @@ class ShiftCalendarRenderer { private $shiftsFilter; private $firstBlockStartTime = null; + + private $lastBlockEndTime = null; private $blocksPerSlot = null; public function __construct($shifts, ShiftsFilter $shiftsFilter) { $this->shiftsFilter = $shiftsFilter; $this->firstBlockStartTime = $this->calcFirstBlockStartTime($shifts); + $this->lastBlockEndTime = $this->calcLastBlockEndTime($shifts); $this->lanes = $this->assignShiftsToLanes($shifts); } @@ -82,6 +85,10 @@ class ShiftCalendarRenderer { public function getFirstBlockStartTime() { return $this->firstBlockStartTime; } + + public function getLastBlockEndTime() { + return $this->lastBlockEndTime; + } public function getBlocksPerSlot() { if ($this->blocksPerSlot == null) { @@ -137,7 +144,7 @@ class ShiftCalendarRenderer { $html .= $shift_html; $rendered_until += $shift_height * ShiftCalendarRenderer::SECONDS_PER_ROW; } - while ($rendered_until <= $this->shiftsFilter->getEndTime()) { + while ($rendered_until < $this->getLastBlockEndTime()) { $html .= $this->renderTick($rendered_until); $rendered_until += ShiftCalendarRenderer::SECONDS_PER_ROW; } @@ -202,8 +209,18 @@ class ShiftCalendarRenderer { return ShiftCalendarRenderer::SECONDS_PER_ROW * floor(($start_time - 60 * 60) / ShiftCalendarRenderer::SECONDS_PER_ROW); } + private function calcLastBlockEndTime($shifts) { + $end_time = $this->shiftsFilter->getStartTime(); + foreach ($shifts as $shift) { + if ($shift['end'] > $end_time) { + $end_time = $shift['end']; + } + } + return ShiftCalendarRenderer::SECONDS_PER_ROW * ceil(($end_time + 60 * 60) / ShiftCalendarRenderer::SECONDS_PER_ROW); + } + private function calcBlocksPerSlot() { - return ceil(($this->shiftsFilter->getEndTime() - $this->getFirstBlockStartTime()) / ShiftCalendarRenderer::SECONDS_PER_ROW); + return ceil(($this->getLastBlockEndTime() - $this->getFirstBlockStartTime()) / ShiftCalendarRenderer::SECONDS_PER_ROW); } } diff --git a/includes/view/ShiftCalendarShiftRenderer.php b/includes/view/ShiftCalendarShiftRenderer.php index 86a6f91d..7aa79e07 100644 --- a/includes/view/ShiftCalendarShiftRenderer.php +++ b/includes/view/ShiftCalendarShiftRenderer.php @@ -44,6 +44,7 @@ class ShiftCalendarShiftRenderer { private function classForSignupState(ShiftSignupState $shiftSignupState) { switch ($shiftSignupState->getState()) { + case ShiftSignupState::ADMIN: case ShiftSignupState::OCCUPIED: return 'success'; @@ -57,7 +58,6 @@ class ShiftCalendarShiftRenderer { case ShiftSignupState::COLLIDES: return 'warning'; - case ShiftSignupState::ADMIN: case ShiftSignupState::FREE: return 'danger'; } @@ -176,14 +176,6 @@ class ShiftCalendarShiftRenderer { $header_buttons ]); } - - /** - * Does the shift collide with the user's shifts - */ - private function collides() { - // TODO - return false; - } } ?> \ No newline at end of file -- cgit v1.2.3-70-g09d2