summaryrefslogtreecommitdiff
path: root/includes/view/ShiftCalendarLane.php
diff options
context:
space:
mode:
authormsquare <msquare@notrademark.de>2016-11-09 17:43:56 +0100
committerGitHub <noreply@github.com>2016-11-09 17:43:56 +0100
commitd43eb41d25d0d5c0509417247030dd6c21118cf6 (patch)
tree2c3f78bf8fbd4215e70af7dbc2ce30cfef674816 /includes/view/ShiftCalendarLane.php
parentd5d2acc7d80920eef5f0ed779a3738a12d5db348 (diff)
parent22520532c78b3a032aec6ececb7623ba094da8de (diff)
Merge pull request #274 from engelsystem/task-164-shift-view
Task 164 shift view
Diffstat (limited to 'includes/view/ShiftCalendarLane.php')
-rw-r--r--includes/view/ShiftCalendarLane.php63
1 files changed, 63 insertions, 0 deletions
diff --git a/includes/view/ShiftCalendarLane.php b/includes/view/ShiftCalendarLane.php
new file mode 100644
index 00000000..33fccec3
--- /dev/null
+++ b/includes/view/ShiftCalendarLane.php
@@ -0,0 +1,63 @@
+<?php
+
+namespace Engelsystem;
+
+/**
+ * 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;
+ }
+ 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;
+ }
+ }
+ return true;
+ }
+
+ public function getHeader() {
+ return $this->header;
+ }
+
+ public function getShifts() {
+ return $this->shifts;
+ }
+}
+?> \ No newline at end of file