2016-11-05 10:06:06 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Engelsystem;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Represents a single lane in a shifts calendar.
|
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
class ShiftCalendarLane
|
|
|
|
{
|
|
|
|
private $firstBlockStartTime;
|
2016-11-05 10:06:06 +01:00
|
|
|
|
2017-01-02 03:57:23 +01:00
|
|
|
private $blockCount;
|
2016-11-05 10:06:06 +01:00
|
|
|
|
2017-01-02 03:57:23 +01:00
|
|
|
private $header;
|
2016-11-05 10:06:06 +01:00
|
|
|
|
2017-01-02 03:57:23 +01:00
|
|
|
private $shifts = [];
|
2016-11-05 10:06:06 +01:00
|
|
|
|
2017-01-02 03:57:23 +01:00
|
|
|
public function __construct($header, $firstBlockStartTime, $blockCount)
|
|
|
|
{
|
|
|
|
$this->header = $header;
|
|
|
|
$this->firstBlockStartTime = $firstBlockStartTime;
|
|
|
|
$this->blockCount = $blockCount;
|
|
|
|
}
|
2016-11-05 10:06:06 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a shift to the lane, but only if it fits.
|
|
|
|
* Returns true on success.
|
|
|
|
*
|
|
|
|
* @param Shift $shift
|
|
|
|
* The shift to add
|
|
|
|
* @return boolean true on success
|
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
public function addShift($shift)
|
|
|
|
{
|
|
|
|
if ($this->shiftFits($shift)) {
|
|
|
|
$this->shifts[] = $shift;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2016-11-05 10:06:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if given shift fits into this lane.
|
|
|
|
*
|
|
|
|
* @param Shift $shift
|
|
|
|
* The shift to fit into this lane
|
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
public function shiftFits($newShift)
|
|
|
|
{
|
|
|
|
foreach ($this->shifts as $laneShift) {
|
|
|
|
if (! ($newShift['start'] >= $laneShift['end'] || $newShift['end'] <= $laneShift['start'])) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-11-05 10:06:06 +01:00
|
|
|
}
|
2017-01-02 03:57:23 +01:00
|
|
|
return true;
|
2016-11-05 10:06:06 +01:00
|
|
|
}
|
|
|
|
|
2017-01-02 03:57:23 +01:00
|
|
|
public function getHeader()
|
|
|
|
{
|
|
|
|
return $this->header;
|
|
|
|
}
|
2016-11-05 10:06:06 +01:00
|
|
|
|
2017-01-02 03:57:23 +01:00
|
|
|
public function getShifts()
|
|
|
|
{
|
|
|
|
return $this->shifts;
|
|
|
|
}
|
2016-11-05 10:06:06 +01:00
|
|
|
}
|