continue working on shifts calendar renderer
This commit is contained in:
parent
6fff6a6c1a
commit
6d97aa2d27
|
@ -1,6 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
use Engelsystem\ShiftsFilterRenderer;
|
use Engelsystem\ShiftsFilterRenderer;
|
||||||
use Engelsystem\ShiftsFilter;
|
use Engelsystem\ShiftsFilter;
|
||||||
|
use Engelsystem\ShiftCalendarRenderer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Room controllers for managing everything room related.
|
* Room controllers for managing everything room related.
|
||||||
|
@ -26,18 +27,27 @@ function room_controller() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$shiftsFilter = new ShiftsFilter(false, [
|
$shiftsFilter = new ShiftsFilter(true, [
|
||||||
$room['RID']
|
$room['RID']
|
||||||
], []);
|
], AngelType_ids());
|
||||||
$shiftsFilter->setStartTime(time());
|
$selected_day = date("Y-m-d");
|
||||||
$shiftsFilter->setEndTime(time() + 24 * 60 * 60);
|
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 = new ShiftsFilterRenderer($shiftsFilter);
|
||||||
$shiftsFilterRenderer->enableDaySelection($days, EventConfig());
|
$shiftsFilterRenderer->enableDaySelection($days);
|
||||||
|
|
||||||
|
$shifts = Shifts_by_ShiftsFilter($shiftsFilter, $user);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
$room['Name'],
|
$room['Name'],
|
||||||
Room_view($room, $shiftsFilterRenderer)
|
Room_view($room, $shiftsFilterRenderer, new ShiftCalendarRenderer($shifts, $shiftsFilter))
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -124,14 +124,11 @@ function AngelTypes() {
|
||||||
* Returns AngelType id array
|
* Returns AngelType id array
|
||||||
*/
|
*/
|
||||||
function AngelType_ids() {
|
function AngelType_ids() {
|
||||||
$angelType_source = sql_select("SELECT `id` FROM `AngelTypes`");
|
$result = sql_select("SELECT `id` FROM `AngelTypes`");
|
||||||
if ($angelType_source === false) {
|
if ($result === false) {
|
||||||
return false;
|
engelsystem_error("Unable to load angeltypes.");
|
||||||
}
|
}
|
||||||
if (count($angelType_source) > 0) {
|
return select_array($result, 'id', 'id');
|
||||||
return $angelType_source;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -49,7 +49,7 @@ function Shifts_by_ShiftsFilter(ShiftsFilter $shiftsFilter, $user) {
|
||||||
AND `ShiftEntry`.`SID` = `Shifts`.`SID`
|
AND `ShiftEntry`.`SID` = `Shifts`.`SID`
|
||||||
)
|
)
|
||||||
)";
|
)";
|
||||||
} elseif ($_SESSION['user_shifts']['filled'][0] == 1) {
|
} elseif ($_SESSION['user_shifts']['filled'][0] == ShiftsFilter::FILLED_FILLED) {
|
||||||
$SQL .= "
|
$SQL .= "
|
||||||
AND (
|
AND (
|
||||||
nat.`count` <= entries.`count`
|
nat.`count` <= entries.`count`
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
use Engelsystem\ShiftsFilterRenderer;
|
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'], [
|
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 {
|
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;
|
private $daySelectionEnabled = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Days that can be selected.
|
||||||
|
* Format Y-m-d
|
||||||
|
*
|
||||||
|
* @var string[]
|
||||||
|
*/
|
||||||
private $days = [];
|
private $days = [];
|
||||||
|
|
||||||
private $event_config = null;
|
|
||||||
|
|
||||||
public function __construct(ShiftsFilter $shiftsFilter) {
|
public function __construct(ShiftsFilter $shiftsFilter) {
|
||||||
$this->shiftsFilter = $shiftsFilter;
|
$this->shiftsFilter = $shiftsFilter;
|
||||||
}
|
}
|
||||||
|
@ -31,14 +35,14 @@ class ShiftsFilterRenderer {
|
||||||
*
|
*
|
||||||
* @return Generated HTML
|
* @return Generated HTML
|
||||||
*/
|
*/
|
||||||
public function render() {
|
public function render($link_base) {
|
||||||
$toolbar = [];
|
$toolbar = [];
|
||||||
if ($this->daySelectionEnabled && ! empty($this->days)) {
|
if ($this->daySelectionEnabled && ! empty($this->days)) {
|
||||||
$today = date("Y-m-d");
|
$today = date("Y-m-d");
|
||||||
$selected_day = date("Y-m-d", $this->shiftsFilter->getStartTime());
|
$selected_day = date("Y-m-d", $this->shiftsFilter->getStartTime());
|
||||||
$day_dropdown_items = [];
|
$day_dropdown_items = [];
|
||||||
foreach ($this->days as $day) {
|
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');
|
$toolbar[] = toolbar_dropdown('', $selected_day, $day_dropdown_items, 'active');
|
||||||
}
|
}
|
||||||
|
@ -48,10 +52,9 @@ class ShiftsFilterRenderer {
|
||||||
/**
|
/**
|
||||||
* Should the filter display a day selection.
|
* Should the filter display a day selection.
|
||||||
*/
|
*/
|
||||||
public function enableDaySelection($days, $event_config) {
|
public function enableDaySelection($days) {
|
||||||
$this->daySelectionEnabled = true;
|
$this->daySelectionEnabled = true;
|
||||||
$this->days = $days;
|
$this->days = $days;
|
||||||
$this->event_config = $event_config;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue