diff options
author | msquare <msquare@notrademark.de> | 2017-11-28 15:43:51 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-28 15:43:51 +0100 |
commit | 599f2fd264bfc7b1b6826fe206442806e317340f (patch) | |
tree | 50cf84d7d07d11bd65b45c2c17f37632f6cd8eff /includes/view/ShiftCalendarLane.php | |
parent | a5fc5bd0979e8de1fce8a8addd351a6e7bd6aeb8 (diff) | |
parent | eda7f7788ea8012bd8be46405c56a666c11f3fa5 (diff) |
Merge pull request #365 from engelsystem/feature-igel-rewrite
Feature igel rewrite
Diffstat (limited to 'includes/view/ShiftCalendarLane.php')
-rw-r--r-- | includes/view/ShiftCalendarLane.php | 125 |
1 files changed, 74 insertions, 51 deletions
diff --git a/includes/view/ShiftCalendarLane.php b/includes/view/ShiftCalendarLane.php index 33fccec3..fd4c6f06 100644 --- a/includes/view/ShiftCalendarLane.php +++ b/includes/view/ShiftCalendarLane.php @@ -2,62 +2,85 @@ namespace Engelsystem; +use Exception; + /** * Represents a single lane in a shifts calendar. */ -class ShiftCalendarLane { - - private $firstBlockStartTime; - - private $blockCount; - - private $header; - - private $shifts = []; - - public function __construct($header, $firstBlockStartTime, $blockCount) { - $this->header = $header; - $this->firstBlockStartTime = $firstBlockStartTime; - $this->blockCount = $blockCount; - } - - /** - * 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 - */ - public function addShift($shift) { - if ($this->shiftFits($shift)) { - $this->shifts[] = $shift; - return true; +class ShiftCalendarLane +{ + /** @var int */ + private $firstBlockStartTime; + + /** @var int */ + private $blockCount; + + /** @var string */ + private $header; + + /** @var array[] */ + private $shifts = []; + + /** + * ShiftCalendarLane constructor. + * + * @param string $header + * @param int $firstBlockStartTime Unix timestamp + * @param int $blockCount + */ + public function __construct($header, $firstBlockStartTime, $blockCount) + { + $this->header = $header; + $this->firstBlockStartTime = $firstBlockStartTime; + $this->blockCount = $blockCount; } - return false; - } - - /** - * Returns true if given shift fits into this lane. - * - * @param Shift $shift - * The shift to fit into this lane - */ - public function shiftFits($newShift) { - foreach ($this->shifts as $laneShift) { - if (! ($newShift['start'] >= $laneShift['end'] || $newShift['end'] <= $laneShift['start'])) { - return false; - } + + /** + * 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. + */ + public function addShift($shift) + { + if ($this->shiftFits($shift)) { + $this->shifts[] = $shift; + return; + } + throw new Exception('Unable to add shift to shift calendar lane.'); } - return true; - } - public function getHeader() { - return $this->header; - } + /** + * 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 + */ + public function shiftFits($newShift) + { + foreach ($this->shifts as $laneShift) { + if (!($newShift['start'] >= $laneShift['end'] || $newShift['end'] <= $laneShift['start'])) { + return false; + } + } + return true; + } - public function getShifts() { - return $this->shifts; - } + /** + * @return string + */ + public function getHeader() + { + return $this->header; + } + + /** + * @return array[] + */ + public function getShifts() + { + return $this->shifts; + } } -?>
\ No newline at end of file |