-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Booking : fix ne pas permettre de réserver des shifts déjà pris #717
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -193,42 +193,42 @@ public function getBeneficiariesWhoCanBookForCycle(Membership $member, $cycle = | |
|
||
public function isShiftBookable(Shift $shift, Beneficiary $beneficiary = null) | ||
{ | ||
// Do not book old or locked shifts | ||
if ($shift->getIsPast() || $shift->isLocked()) { | ||
if (!$beneficiary) { | ||
return true; | ||
} | ||
|
||
// Do not book old or locked or booked shifts | ||
if ($shift->getIsPast() || $shift->isLocked() || $shift->getShifter()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Attention, tu es sur pour le Je me demande si on n'appelle pas cette methode avec un shift mais ca pourrait aussi concerner un bucket ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. je viens de re-vérifier, c'est toujours un $shift qui est le premier paramètre lorsque la fonction |
||
return false; | ||
} | ||
// Do not book pre-booked shift | ||
if ($shift->getLastShifter() && $beneficiary->getId() != $shift->getLastShifter()->getId()) { | ||
return false; | ||
} | ||
if (!$beneficiary) { | ||
return true; | ||
} | ||
// Do not book shift i do not know how to handle (formation) | ||
// Do not book shift the beneficiary cannot handle (formation) | ||
if ($shift->getFormation() && !$beneficiary->getFormations()->contains($shift->getFormation())) { | ||
return false; | ||
} | ||
|
||
$member = $beneficiary->getMembership(); | ||
if ($member->isCurrentlyExemptedFromShifts($shift->getStart())) | ||
return false; | ||
|
||
if ($member->isWithdrawn()) | ||
return false; | ||
|
||
if ($member->getFirstShiftDate() > $shift->getStart()) | ||
return false; | ||
|
||
// First shift ever of the beneficiary, check he or she is not the first one to book the bucket | ||
if ($this->isBeginner($beneficiary) && $this->isShiftEmpty($shift)) { | ||
return false; | ||
} | ||
|
||
// Check that beneficiary did not book a shift that overlaps the current | ||
if (!$this->canBookShift($beneficiary, $shift)) { | ||
return false; | ||
} | ||
|
||
// membership rules (exemption, withdrawn, frozen) | ||
$member = $beneficiary->getMembership(); | ||
if ($member->isCurrentlyExemptedFromShifts($shift->getStart())) { | ||
return false; | ||
} | ||
if ($member->isWithdrawn()) { | ||
return false; | ||
} | ||
if ($member->getFirstShiftDate() > $shift->getStart()) { | ||
return false; | ||
} | ||
if ($member->getFrozen()) { | ||
$cycle_end = $this->membershipService->getEndOfCycle($member); | ||
//current cycle : cannot book when frozen | ||
|
@@ -295,8 +295,9 @@ public function isShiftEmpty($shift) | |
public function getBookableShifts(ShiftBucket $bucket, Beneficiary $beneficiary = null) | ||
{ | ||
if (!$beneficiary) { | ||
// return all free shifts | ||
$bookableShifts = $bucket->getShifts()->filter(function (Shift $shift) { | ||
return !$shift->getShifter(); // free | ||
return !$shift->getShifter(); | ||
}); | ||
} else { | ||
if ($bucket->canBookInterval($beneficiary)) { | ||
|
@@ -340,8 +341,11 @@ public function getFirstBookable(ShiftBucket $bucket, Beneficiary $beneficiary = | |
public function getBookableShiftsCount(ShiftBucket $bucket, Beneficiary $beneficiary = null) | ||
{ | ||
$bookableShifts = $this->getBookableShifts($bucket, $beneficiary); | ||
if (!$beneficiary) | ||
|
||
if (!$beneficiary) { | ||
return count($bookableShifts); | ||
} | ||
|
||
return count(ShiftBucket::filterByFormations($bookableShifts, $beneficiary->getFormations())); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pour le
if !beneficiary
, dans quel cas ca pourrait se produire en fait ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Si un salarié utilise le lien direct pour réserver un créneau (oui, c'est un peu tordu car il n'a pas le lien dans sa vue)