continue working on shifts calendar renderer

main
msquare 8 years ago
parent 6fff6a6c1a
commit 6d97aa2d27

@ -1,6 +1,7 @@
<?php
use Engelsystem\ShiftsFilterRenderer;
use Engelsystem\ShiftsFilter;
use Engelsystem\ShiftCalendarRenderer;
/**
* Room controllers for managing everything room related.
@ -26,18 +27,27 @@ function room_controller() {
}
}
$shiftsFilter = new ShiftsFilter(false, [
$shiftsFilter = new ShiftsFilter(true, [
$room['RID']
], []);
$shiftsFilter->setStartTime(time());
$shiftsFilter->setEndTime(time() + 24 * 60 * 60);
], AngelType_ids());
$selected_day = date("Y-m-d");
if (! empty($days)) {
$selected_day = $days[0];
}
if (isset($_REQUEST['shifts_filter_day'])) {
$selected_day = $_REQUEST['shifts_filter_day'];
}
$shiftsFilter->setStartTime(parse_date("Y-m-d H:i", $selected_day . ' 00:00'));
$shiftsFilter->setEndTime(parse_date("Y-m-d H:i", $selected_day . ' 23:59'));
$shiftsFilterRenderer = new ShiftsFilterRenderer($shiftsFilter);
$shiftsFilterRenderer->enableDaySelection($days, EventConfig());
$shiftsFilterRenderer->enableDaySelection($days);
$shifts = Shifts_by_ShiftsFilter($shiftsFilter, $user);
return [
$room['Name'],
Room_view($room, $shiftsFilterRenderer)
Room_view($room, $shiftsFilterRenderer, new ShiftCalendarRenderer($shifts, $shiftsFilter))
];
}

@ -124,14 +124,11 @@ function AngelTypes() {
* Returns AngelType id array
*/
function AngelType_ids() {
$angelType_source = sql_select("SELECT `id` FROM `AngelTypes`");
if ($angelType_source === false) {
return false;
}
if (count($angelType_source) > 0) {
return $angelType_source;
$result = sql_select("SELECT `id` FROM `AngelTypes`");
if ($result === false) {
engelsystem_error("Unable to load angeltypes.");
}
return null;
return select_array($result, 'id', 'id');
}
/**

@ -49,7 +49,7 @@ function Shifts_by_ShiftsFilter(ShiftsFilter $shiftsFilter, $user) {
AND `ShiftEntry`.`SID` = `Shifts`.`SID`
)
)";
} elseif ($_SESSION['user_shifts']['filled'][0] == 1) {
} elseif ($_SESSION['user_shifts']['filled'][0] == ShiftsFilter::FILLED_FILLED) {
$SQL .= "
AND (
nat.`count` <= entries.`count`

@ -1,9 +1,11 @@
<?php
use Engelsystem\ShiftsFilterRenderer;
use Engelsystem\ShiftCalendarRenderer;
function Room_view($room, ShiftsFilterRenderer $shiftsFilterRenderer) {
function Room_view($room, ShiftsFilterRenderer $shiftsFilterRenderer, ShiftCalendarRenderer $shiftCalendarRenderer) {
return page_with_title(glyph('map-marker') . $room['Name'], [
$shiftsFilterRenderer->render()
$shiftsFilterRenderer->render(room_link($room)) ,
$shiftCalendarRenderer->render()
]);
}

@ -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);
}
}

@ -18,10 +18,14 @@ class ShiftsFilterRenderer {
*/
private $daySelectionEnabled = false;
/**
* Days that can be selected.
* Format Y-m-d
*
* @var string[]
*/
private $days = [];
private $event_config = null;
public function __construct(ShiftsFilter $shiftsFilter) {
$this->shiftsFilter = $shiftsFilter;
}
@ -31,14 +35,14 @@ class ShiftsFilterRenderer {
*
* @return Generated HTML
*/
public function render() {
public function render($link_base) {
$toolbar = [];
if ($this->daySelectionEnabled && ! empty($this->days)) {
$today = date("Y-m-d");
$selected_day = date("Y-m-d", $this->shiftsFilter->getStartTime());
$day_dropdown_items = [];
foreach ($this->days as $day) {
$day_dropdown_items[] = toolbar_item_link('', '', $day);
$day_dropdown_items[] = toolbar_item_link($link_base . '&shifts_filter_day=' . $day, '', $day);
}
$toolbar[] = toolbar_dropdown('', $selected_day, $day_dropdown_items, 'active');
}
@ -48,10 +52,9 @@ class ShiftsFilterRenderer {
/**
* Should the filter display a day selection.
*/
public function enableDaySelection($days, $event_config) {
public function enableDaySelection($days) {
$this->daySelectionEnabled = true;
$this->days = $days;
$this->event_config = $event_config;
}
/**

Loading…
Cancel
Save