summaryrefslogtreecommitdiff
path: root/includes/view/ShiftCalendarLane.php
blob: 33fccec38ae74e090c68bb50e148ef9e7a393808 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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;
  }
}
?>