|
|
@ -1,9 +1,9 @@
|
|
|
|
<?php
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
namespace Engelsystem;
|
|
|
|
namespace Engelsystem;
|
|
|
|
|
|
|
|
|
|
|
|
class ShiftCalendarRenderer
|
|
|
|
class ShiftCalendarRenderer
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 15m * 60s/m = 900s
|
|
|
|
* 15m * 60s/m = 900s
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -49,9 +49,9 @@ class ShiftCalendarRenderer
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* ShiftCalendarRenderer constructor.
|
|
|
|
* ShiftCalendarRenderer constructor.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param array[] $shifts
|
|
|
|
* @param array[] $shifts
|
|
|
|
* @param array[] $needed_angeltypes
|
|
|
|
* @param array[] $needed_angeltypes
|
|
|
|
* @param array[] $shift_entries
|
|
|
|
* @param array[] $shift_entries
|
|
|
|
* @param ShiftsFilter $shiftsFilter
|
|
|
|
* @param ShiftsFilter $shiftsFilter
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function __construct($shifts, $needed_angeltypes, $shift_entries, ShiftsFilter $shiftsFilter)
|
|
|
|
public function __construct($shifts, $needed_angeltypes, $shift_entries, ShiftsFilter $shiftsFilter)
|
|
|
@ -67,7 +67,8 @@ class ShiftCalendarRenderer
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Assigns the shifts to different lanes per room if they collide
|
|
|
|
* Assigns the shifts to different lanes per room if they collide
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param array[] $shifts The shifts to assign
|
|
|
|
* @param array[] $shifts
|
|
|
|
|
|
|
|
* The shifts to assign
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @return array Returns an array that assigns a room_id to an array of ShiftCalendarLane containing the shifts
|
|
|
|
* @return array Returns an array that assigns a room_id to an array of ShiftCalendarLane containing the shifts
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -79,10 +80,10 @@ class ShiftCalendarRenderer
|
|
|
|
foreach ($shifts as $shift) {
|
|
|
|
foreach ($shifts as $shift) {
|
|
|
|
$room_id = $shift['RID'];
|
|
|
|
$room_id = $shift['RID'];
|
|
|
|
$header = Room_name_render([
|
|
|
|
$header = Room_name_render([
|
|
|
|
'RID' => $room_id,
|
|
|
|
'RID' => $room_id,
|
|
|
|
'Name' => $shift['room_name']
|
|
|
|
'Name' => $shift['room_name']
|
|
|
|
]);
|
|
|
|
]);
|
|
|
|
if (!isset($lanes[$room_id])) {
|
|
|
|
if (! isset($lanes[$room_id])) {
|
|
|
|
// initialize room with one lane
|
|
|
|
// initialize room with one lane
|
|
|
|
$lanes[$room_id] = [
|
|
|
|
$lanes[$room_id] = [
|
|
|
|
new ShiftCalendarLane($header, $this->getFirstBlockStartTime(), $this->getBlocksPerSlot())
|
|
|
|
new ShiftCalendarLane($header, $this->getFirstBlockStartTime(), $this->getBlocksPerSlot())
|
|
|
@ -92,17 +93,16 @@ class ShiftCalendarRenderer
|
|
|
|
$shift_added = false;
|
|
|
|
$shift_added = false;
|
|
|
|
foreach ($lanes[$room_id] as $lane) {
|
|
|
|
foreach ($lanes[$room_id] as $lane) {
|
|
|
|
/** @var ShiftCalendarLane $lane */
|
|
|
|
/** @var ShiftCalendarLane $lane */
|
|
|
|
$shift_added = $lane->addShift($shift);
|
|
|
|
try {
|
|
|
|
if ($shift_added == true) {
|
|
|
|
$lane->addShift($shift);
|
|
|
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// If all lanes for this room are busy, create a new lane and add shift to it
|
|
|
|
// If all lanes for this room are busy, create a new lane and add shift to it
|
|
|
|
if ($shift_added == false) {
|
|
|
|
if ($shift_added == false) {
|
|
|
|
$newLane = new ShiftCalendarLane($header, $this->getFirstBlockStartTime(), $this->getBlocksPerSlot());
|
|
|
|
$newLane = new ShiftCalendarLane($header, $this->getFirstBlockStartTime(), $this->getBlocksPerSlot());
|
|
|
|
if (!$newLane->addShift($shift)) {
|
|
|
|
$newLane->addShift($shift);
|
|
|
|
engelsystem_error('Unable to add shift to new lane.');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$lanes[$room_id][] = $newLane;
|
|
|
|
$lanes[$room_id][] = $newLane;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -111,6 +111,7 @@ class ShiftCalendarRenderer
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function getFirstBlockStartTime()
|
|
|
|
public function getFirstBlockStartTime()
|
|
|
@ -119,6 +120,7 @@ class ShiftCalendarRenderer
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function getLastBlockEndTime()
|
|
|
|
public function getLastBlockEndTime()
|
|
|
@ -127,6 +129,7 @@ class ShiftCalendarRenderer
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
|
|
|
|
*
|
|
|
|
* @return float
|
|
|
|
* @return float
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function getBlocksPerSlot()
|
|
|
|
public function getBlocksPerSlot()
|
|
|
@ -148,9 +151,9 @@ class ShiftCalendarRenderer
|
|
|
|
return '';
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return div('shift-calendar', [
|
|
|
|
return div('shift-calendar', [
|
|
|
|
$this->renderTimeLane(),
|
|
|
|
$this->renderTimeLane(),
|
|
|
|
$this->renderShiftLanes()
|
|
|
|
$this->renderShiftLanes()
|
|
|
|
]) . $this->renderLegend();
|
|
|
|
]) . $this->renderLegend();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -173,7 +176,8 @@ class ShiftCalendarRenderer
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Renders a single lane
|
|
|
|
* Renders a single lane
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param ShiftCalendarLane $lane The lane to render
|
|
|
|
* @param ShiftCalendarLane $lane
|
|
|
|
|
|
|
|
* The lane to render
|
|
|
|
* @return string
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private function renderLane(ShiftCalendarLane $lane)
|
|
|
|
private function renderLane(ShiftCalendarLane $lane)
|
|
|
@ -190,12 +194,7 @@ class ShiftCalendarRenderer
|
|
|
|
$rendered_until += ShiftCalendarRenderer::SECONDS_PER_ROW;
|
|
|
|
$rendered_until += ShiftCalendarRenderer::SECONDS_PER_ROW;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
list($shift_height, $shift_html) = $shift_renderer->render(
|
|
|
|
list ($shift_height, $shift_html) = $shift_renderer->render($shift, $this->needed_angeltypes[$shift['SID']], $this->shift_entries[$shift['SID']], $user);
|
|
|
|
$shift,
|
|
|
|
|
|
|
|
$this->needed_angeltypes[$shift['SID']],
|
|
|
|
|
|
|
|
$this->shift_entries[$shift['SID']],
|
|
|
|
|
|
|
|
$user
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
$html .= $shift_html;
|
|
|
|
$html .= $shift_html;
|
|
|
|
$rendered_until += $shift_height * ShiftCalendarRenderer::SECONDS_PER_ROW;
|
|
|
|
$rendered_until += $shift_height * ShiftCalendarRenderer::SECONDS_PER_ROW;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -214,21 +213,23 @@ class ShiftCalendarRenderer
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Renders a tick/block for given time
|
|
|
|
* Renders a tick/block for given time
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param int $time unix timestamp
|
|
|
|
* @param int $time
|
|
|
|
* @param boolean $label Should time labels be generated?
|
|
|
|
* unix timestamp
|
|
|
|
|
|
|
|
* @param boolean $label
|
|
|
|
|
|
|
|
* Should time labels be generated?
|
|
|
|
* @return string rendered tick html
|
|
|
|
* @return string rendered tick html
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private function renderTick($time, $label = false)
|
|
|
|
private function renderTick($time, $label = false)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if ($time % (24 * 60 * 60) == 23 * 60 * 60) {
|
|
|
|
if ($time % (24 * 60 * 60) == 23 * 60 * 60) {
|
|
|
|
if (!$label) {
|
|
|
|
if (! $label) {
|
|
|
|
return div('tick day');
|
|
|
|
return div('tick day');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return div('tick day', [
|
|
|
|
return div('tick day', [
|
|
|
|
date('m-d<b\r />H:i', $time)
|
|
|
|
date('m-d<b\r />H:i', $time)
|
|
|
|
]);
|
|
|
|
]);
|
|
|
|
} elseif ($time % (60 * 60) == 0) {
|
|
|
|
} elseif ($time % (60 * 60) == 0) {
|
|
|
|
if (!$label) {
|
|
|
|
if (! $label) {
|
|
|
|
return div('tick hour');
|
|
|
|
return div('tick hour');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return div('tick hour', [
|
|
|
|
return div('tick hour', [
|
|
|
@ -250,7 +251,7 @@ class ShiftCalendarRenderer
|
|
|
|
_('Time')
|
|
|
|
_('Time')
|
|
|
|
])
|
|
|
|
])
|
|
|
|
];
|
|
|
|
];
|
|
|
|
for ($block = 0; $block < $this->getBlocksPerSlot(); $block++) {
|
|
|
|
for ($block = 0; $block < $this->getBlocksPerSlot(); $block ++) {
|
|
|
|
$thistime = $this->getFirstBlockStartTime() + ($block * ShiftCalendarRenderer::SECONDS_PER_ROW);
|
|
|
|
$thistime = $this->getFirstBlockStartTime() + ($block * ShiftCalendarRenderer::SECONDS_PER_ROW);
|
|
|
|
$time_slot[] = $this->renderTick($thistime, true);
|
|
|
|
$time_slot[] = $this->renderTick($thistime, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -258,6 +259,7 @@ class ShiftCalendarRenderer
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
|
|
|
|
*
|
|
|
|
* @param array[] $shifts
|
|
|
|
* @param array[] $shifts
|
|
|
|
* @return int
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -273,6 +275,7 @@ class ShiftCalendarRenderer
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
|
|
|
|
*
|
|
|
|
* @param array[] $shifts
|
|
|
|
* @param array[] $shifts
|
|
|
|
* @return int
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -288,6 +291,7 @@ class ShiftCalendarRenderer
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private function calcBlocksPerSlot()
|
|
|
|
private function calcBlocksPerSlot()
|
|
|
|