fix shift signup state calculation
This commit is contained in:
parent
3fbd62ab7d
commit
51eb22a1c6
|
@ -61,10 +61,29 @@ class ShiftSignupState {
|
||||||
public function combineWith(ShiftSignupState $shiftSignupState) {
|
public function combineWith(ShiftSignupState $shiftSignupState) {
|
||||||
$this->freeEntries += $shiftSignupState->getFreeEntries();
|
$this->freeEntries += $shiftSignupState->getFreeEntries();
|
||||||
|
|
||||||
switch ($this->state) {
|
if ($this->valueForState($shiftSignupState->state) > $this->valueForState($this->state)) {
|
||||||
|
$this->state = $shiftSignupState->state;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function valueForState($state) {
|
||||||
|
switch ($state) {
|
||||||
|
case ShiftSignupState::SHIFT_ENDED:
|
||||||
|
return 100;
|
||||||
|
|
||||||
|
case ShiftSignupState::SIGNED_UP:
|
||||||
|
return 90;
|
||||||
|
|
||||||
|
case ShiftSignupState::FREE:
|
||||||
|
return 80;
|
||||||
|
|
||||||
case ShiftSignupState::ANGELTYPE:
|
case ShiftSignupState::ANGELTYPE:
|
||||||
|
case ShiftSignupState::COLLIDES:
|
||||||
|
return 70;
|
||||||
|
|
||||||
case ShiftSignupState::OCCUPIED:
|
case ShiftSignupState::OCCUPIED:
|
||||||
$this->state = $shiftSignupState->getState();
|
case ShiftSignupState::ADMIN:
|
||||||
|
return 60;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -229,6 +229,7 @@ function Shift_signup_allowed_angeltype_supporter($angeltype, $needed_angeltype,
|
||||||
*/
|
*/
|
||||||
function Shift_signup_allowed_admin($angeltype, $needed_angeltype, $shift_entries) {
|
function Shift_signup_allowed_admin($angeltype, $needed_angeltype, $shift_entries) {
|
||||||
$free_entries = Shift_free_entries($needed_angeltype, $shift_entries);
|
$free_entries = Shift_free_entries($needed_angeltype, $shift_entries);
|
||||||
|
|
||||||
if ($free_entries == 0) {
|
if ($free_entries == 0) {
|
||||||
// User shift admins may join anybody in every shift
|
// User shift admins may join anybody in every shift
|
||||||
return new ShiftSignupState(ShiftSignupState::ADMIN, $free_entries);
|
return new ShiftSignupState(ShiftSignupState::ADMIN, $free_entries);
|
||||||
|
@ -250,6 +251,10 @@ function Shift_signup_allowed_admin($angeltype, $needed_angeltype, $shift_entrie
|
||||||
function Shift_signup_allowed($signup_user, $shift, $angeltype, $user_angeltype = null, $user_shifts = null, $needed_angeltype, $shift_entries) {
|
function Shift_signup_allowed($signup_user, $shift, $angeltype, $user_angeltype = null, $user_shifts = null, $needed_angeltype, $shift_entries) {
|
||||||
global $user, $privileges;
|
global $user, $privileges;
|
||||||
|
|
||||||
|
// if($shift['SID']==1907) {
|
||||||
|
// print_r(Shift_signup_allowed_admin($angeltype, $needed_angeltype, $shift_entries));
|
||||||
|
// }
|
||||||
|
|
||||||
if (in_array('user_shifts_admin', $privileges)) {
|
if (in_array('user_shifts_admin', $privileges)) {
|
||||||
return Shift_signup_allowed_admin($angeltype, $needed_angeltype, $shift_entries);
|
return Shift_signup_allowed_admin($angeltype, $needed_angeltype, $shift_entries);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue