From 6d97aa2d273464e3cb6703a0527793c52583d4cd Mon Sep 17 00:00:00 2001 From: msquare Date: Wed, 5 Oct 2016 22:28:39 +0200 Subject: continue working on shifts calendar renderer --- includes/view/ShiftCalendarRenderer.php | 56 ++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) (limited to 'includes/view/ShiftCalendarRenderer.php') diff --git a/includes/view/ShiftCalendarRenderer.php b/includes/view/ShiftCalendarRenderer.php index 8356d033..41cf6f94 100644 --- a/includes/view/ShiftCalendarRenderer.php +++ b/includes/view/ShiftCalendarRenderer.php @@ -4,7 +4,61 @@ namespace Engelsystem; class ShiftCalendarRenderer { - public function __construct() { + /** + * 15m * 60s/m = 900s + */ + const MINUTES_PER_ROW = 900; + + private $shifts; + + private $shiftsFilter; + + public function __construct($shifts, ShiftsFilter $shiftsFilter) { + $this->shifts = $shifts; + $this->shiftsFilter = $shiftsFilter; + } + + public function render() { + $rooms = $this->rooms(); + $slotSizes = $this->calcSlotSizes($rooms); + + return ''; + } + + /** + * Calculates the slots for each room that appears in the shifts + */ + private function rooms() { + $rooms = []; + foreach ($this->shifts as $shift) { + if (! isset($rooms[$shift['RID']])) { + $rooms[$shift['RID']] = $shift['room_name']; + } + } + return $rooms; + } + + private function calcSlotSizes($rooms) { + $first_block_start_time = ShiftCalendarRenderer::MINUTES_PER_ROW * floor($this->shiftsFilter->getStartTime() / ShiftCalendarRenderer::MINUTES_PER_ROW); + $blocks_per_slot = ceil(($this->shiftsFilter->getEndTime() - $first_block_start_time) / ShiftCalendarRenderer::MINUTES_PER_ROW); + $parallel_blocks = []; + + // initialize $block array + foreach (array_keys($rooms) as $room_id) { + $parallel_blocks[$room_id] = array_fill(0, $blocks_per_slot, 0); + } + + // calculate number of parallel shifts in each timeslot for each room + foreach ($this->shifts as $shift) { + $room_id = $shift["RID"]; + $shift_blocks = ($shift["end"] - $shift["start"]) / ShiftCalendarRenderer::MINUTES_PER_ROW; + $firstblock = floor(($shift["start"] - $first_block_start_time) / ShiftCalendarRenderer::MINUTES_PER_ROW); + for ($block = $firstblock; $block < $shift_blocks + $firstblock && $block < $blocks_per_slot; $block ++) { + $parallel_blocks[$room_id][$block] ++; + } + } + + return array_map('max', $parallel_blocks); } } -- cgit v1.2.3-54-g00ecf