You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
engelsystem/includes/view/ShiftCalendarLane.php

87 lines
1.8 KiB
PHTML

<?php
namespace Engelsystem;
use Exception;
/**
* Represents a single lane in a shifts calendar.
*/
8 years ago
class ShiftCalendarLane
{
/** @var int */
8 years ago
private $firstBlockStartTime;
/** @var int */
8 years ago
private $blockCount;
/** @var string */
8 years ago
private $header;
/** @var array[] */
8 years ago
private $shifts = [];
/**
* ShiftCalendarLane constructor.
*
* @param string $header
* @param int $firstBlockStartTime Unix timestamp
* @param int $blockCount
*/
8 years ago
public function __construct($header, $firstBlockStartTime, $blockCount)
{
$this->header = $header;
$this->firstBlockStartTime = $firstBlockStartTime;
$this->blockCount = $blockCount;
}
8 years ago
/**
* Adds a shift to the lane, but only if it fits.
* Returns true on success.
*
* @param array $shift The shift to add
* @throws Exception if the shift doesn't fit into the lane.
8 years ago
*/
public function addShift($shift)
{
if ($this->shiftFits($shift)) {
$this->shifts[] = $shift;
return;
8 years ago
}
throw new Exception('Unable to add shift to shift calendar lane.');
8 years ago
}
8 years ago
/**
* Returns true if given shift fits into this lane.
*
* @param array $newShift
* @return bool
* @internal param array $shift The shift to fit into this lane
8 years ago
*/
public function shiftFits($newShift)
{
foreach ($this->shifts as $laneShift) {
if (!($newShift['start'] >= $laneShift['end'] || $newShift['end'] <= $laneShift['start'])) {
return false;
}
}
return true;
}
/**
* @return string
*/
8 years ago
public function getHeader()
{
return $this->header;
}
/**
* @return array[]
*/
8 years ago
public function getShifts()
{
return $this->shifts;
}
}