fix shift ended recognition and displayed time range end

This commit is contained in:
msquare 2016-11-14 17:40:24 +01:00
parent 1a3b4e2a33
commit 0ab9f4f988
3 changed files with 21 additions and 12 deletions

View File

@ -133,7 +133,7 @@ function Shift_signup_allowed($user, $shift, $angeltype, $user_angeltype = null,
return new ShiftSignupState(ShiftSignupState::FREE, $free_entries); 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 // you can only join if the shift is in future
return new ShiftSignupState(ShiftSignupState::SHIFT_ENDED, $free_entries); return new ShiftSignupState(ShiftSignupState::SHIFT_ENDED, $free_entries);
} }

View File

@ -26,11 +26,14 @@ class ShiftCalendarRenderer {
private $firstBlockStartTime = null; private $firstBlockStartTime = null;
private $lastBlockEndTime = null;
private $blocksPerSlot = null; private $blocksPerSlot = null;
public function __construct($shifts, ShiftsFilter $shiftsFilter) { public function __construct($shifts, ShiftsFilter $shiftsFilter) {
$this->shiftsFilter = $shiftsFilter; $this->shiftsFilter = $shiftsFilter;
$this->firstBlockStartTime = $this->calcFirstBlockStartTime($shifts); $this->firstBlockStartTime = $this->calcFirstBlockStartTime($shifts);
$this->lastBlockEndTime = $this->calcLastBlockEndTime($shifts);
$this->lanes = $this->assignShiftsToLanes($shifts); $this->lanes = $this->assignShiftsToLanes($shifts);
} }
@ -83,6 +86,10 @@ class ShiftCalendarRenderer {
return $this->firstBlockStartTime; return $this->firstBlockStartTime;
} }
public function getLastBlockEndTime() {
return $this->lastBlockEndTime;
}
public function getBlocksPerSlot() { public function getBlocksPerSlot() {
if ($this->blocksPerSlot == null) { if ($this->blocksPerSlot == null) {
$this->blocksPerSlot = $this->calcBlocksPerSlot(); $this->blocksPerSlot = $this->calcBlocksPerSlot();
@ -137,7 +144,7 @@ class ShiftCalendarRenderer {
$html .= $shift_html; $html .= $shift_html;
$rendered_until += $shift_height * ShiftCalendarRenderer::SECONDS_PER_ROW; $rendered_until += $shift_height * ShiftCalendarRenderer::SECONDS_PER_ROW;
} }
while ($rendered_until <= $this->shiftsFilter->getEndTime()) { while ($rendered_until < $this->getLastBlockEndTime()) {
$html .= $this->renderTick($rendered_until); $html .= $this->renderTick($rendered_until);
$rendered_until += ShiftCalendarRenderer::SECONDS_PER_ROW; $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); 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() { private function calcBlocksPerSlot() {
return ceil(($this->shiftsFilter->getEndTime() - $this->getFirstBlockStartTime()) / ShiftCalendarRenderer::SECONDS_PER_ROW); return ceil(($this->getLastBlockEndTime() - $this->getFirstBlockStartTime()) / ShiftCalendarRenderer::SECONDS_PER_ROW);
} }
} }

View File

@ -44,6 +44,7 @@ class ShiftCalendarShiftRenderer {
private function classForSignupState(ShiftSignupState $shiftSignupState) { private function classForSignupState(ShiftSignupState $shiftSignupState) {
switch ($shiftSignupState->getState()) { switch ($shiftSignupState->getState()) {
case ShiftSignupState::ADMIN:
case ShiftSignupState::OCCUPIED: case ShiftSignupState::OCCUPIED:
return 'success'; return 'success';
@ -57,7 +58,6 @@ class ShiftCalendarShiftRenderer {
case ShiftSignupState::COLLIDES: case ShiftSignupState::COLLIDES:
return 'warning'; return 'warning';
case ShiftSignupState::ADMIN:
case ShiftSignupState::FREE: case ShiftSignupState::FREE:
return 'danger'; return 'danger';
} }
@ -176,14 +176,6 @@ class ShiftCalendarShiftRenderer {
$header_buttons $header_buttons
]); ]);
} }
/**
* Does the shift collide with the user's shifts
*/
private function collides() {
// TODO
return false;
}
} }
?> ?>