summaryrefslogtreecommitdiff
path: root/includes/model/ShiftSignupState.php
diff options
context:
space:
mode:
authormsquare <msquare@notrademark.de>2016-11-12 23:00:46 +0100
committermsquare <msquare@notrademark.de>2016-11-12 23:00:46 +0100
commit1a3b4e2a334c57cc403be1d8e21fd8e162d9df5c (patch)
treebd61f7ab438d50a57ccb34866022aab13d4fdfcb /includes/model/ShiftSignupState.php
parent106a6788086f9be3ef6d30d1844f512fcbf22e23 (diff)
redone shift coloring and shift signup state
Diffstat (limited to 'includes/model/ShiftSignupState.php')
-rw-r--r--includes/model/ShiftSignupState.php98
1 files changed, 98 insertions, 0 deletions
diff --git a/includes/model/ShiftSignupState.php b/includes/model/ShiftSignupState.php
new file mode 100644
index 00000000..f9226375
--- /dev/null
+++ b/includes/model/ShiftSignupState.php
@@ -0,0 +1,98 @@
+<?php
+
+namespace Engelsystem;
+
+/**
+ * BO to represent if there are free slots on a shift for a given angeltype
+ * and if signup for a given user is possible (or not, because of collisions, etc.)
+ */
+class ShiftSignupState {
+
+ /**
+ * Shift has free places
+ */
+ const FREE = 'FREE';
+
+ /**
+ * Shift collides with users shifts
+ */
+ const COLLIDES = 'COLLIDES';
+
+ /**
+ * User cannot join because of a restricted angeltype or user is not in the angeltype
+ */
+ const ANGELTYPE = 'ANGELTYPE';
+
+ /**
+ * Shift is full
+ */
+ const OCCUPIED = 'OCCUPIED';
+
+ /**
+ * User is admin and can do what he wants.
+ */
+ const ADMIN = 'ADMIN';
+
+ /**
+ * Shift has already ended, no signup
+ */
+ const SHIFT_ENDED = 'SHIFT_ENDED';
+
+ /**
+ * User is already signed up
+ */
+ const SIGNED_UP = 'SIGNED_UP';
+
+ private $state;
+
+ private $freeEntries;
+
+ public function __construct($state, $free_entries) {
+ $this->state = $state;
+ $this->freeEntries = $free_entries;
+ }
+
+ /**
+ * Combine this state with another state from the same shift.
+ *
+ * @param ShiftSignupState $shiftSignupState
+ * The other state to combine
+ */
+ public function combineWith(ShiftSignupState $shiftSignupState) {
+ $this->freeEntries += $shiftSignupState->getFreeEntries();
+
+ switch ($this->state) {
+ case ShiftSignupState::ANGELTYPE:
+ case ShiftSignupState::OCCUPIED:
+ $this->state = $shiftSignupState->getState();
+ }
+ }
+
+ /**
+ * Returns true, if signup is allowed
+ */
+ public function isSignupAllowed() {
+ switch ($this->state) {
+ case ShiftSignupState::FREE:
+ case ShiftSignupState::ADMIN:
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Return the shift signup state
+ */
+ public function getState() {
+ return $this->state;
+ }
+
+ /**
+ * How many places are free in this shift for the angeltype?
+ */
+ public function getFreeEntries() {
+ return $this->freeEntries;
+ }
+}
+
+?> \ No newline at end of file