Skip to content

Commit

Permalink
Add parameters to limit the days in advance a flying or fixe member c…
Browse files Browse the repository at this point in the history
…an book shifts
  • Loading branch information
petitalb committed Aug 5, 2023
1 parent fe65be1 commit 33d2ac4
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 14 deletions.
5 changes: 4 additions & 1 deletion app/Resources/views/booking/_partial/list.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@
<i class="material-icons">event_busy</i> et après ?
</div>
<div class="collapsible-body">
Seuls les 27 prochains jours sont ouverts à la réservation, si tu veux voir plus loin, reviens un peu plus tard :)
{% set now = date('now') %}
{% set lastDay = (bucketsByDay|last|first|first).start %}
{% set difference = date(lastDay).diff(now) %}
Seuls les {{ difference.days }} prochains jours sont ouverts à la réservation, si tu veux voir plus loin, reviens un peu plus tard :)
</div>
</li>
{% endif %}
Expand Down
4 changes: 3 additions & 1 deletion app/config/parameters.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ parameters:
min_shift_duration: 90
cycle_duration: '28 days'
cycle_type: 'abcd'
use_fly_and_fixed: false
max_booking_lead_time_flying:
max_booking_lead_time_fixe:
maximum_nb_of_beneficiaries_in_membership: 2
new_users_start_as_beginner: true
allow_extra_shifts: true
Expand All @@ -111,7 +114,6 @@ parameters:
forbid_own_timelog_new_admin: false
display_name_shifters: false
max_nb_of_past_cycles_to_display: 3
use_fly_and_fixed: false
use_card_reader_to_validate_shifts: false
use_time_log_saving: false

Expand Down
2 changes: 2 additions & 0 deletions app/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ services:
$local_currency_name: '%local_currency_name%'
$use_fly_and_fixed: '%use_fly_and_fixed%'
$cycle_type: '%cycle_type%'
$max_booking_lead_time_flying: '%max_booking_lead_time_flying%'
$max_booking_lead_time_fixe: '%max_booking_lead_time_fixe%'

# makes classes in src/AppBundle available to be used as services
# this creates a service per class whose id is the fully-qualified class name
Expand Down
33 changes: 21 additions & 12 deletions src/AppBundle/Service/MembershipService.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,11 @@
class MembershipService
{
protected $em;
protected $registration_duration;
protected $registration_every_civil_year;
protected $cycle_type;
protected $use_fly_and_fixed;

public function __construct(ContainerInterface $container, EntityManagerInterface $em)
{
$this->container = $container;

Check failure on line 22 in src/AppBundle/Service/MembershipService.php

View workflow job for this annotation

GitHub Actions / Symfony 3.4 (PHP 7.4)

Access to an undefined property AppBundle\Service\MembershipService::$container.
$this->em = $em;
$this->registration_duration = $container->getParameter('registration_duration');
$this->registration_every_civil_year = $container->getParameter('registration_every_civil_year');
$this->cycle_type = $container->getParameter('cycle_type');
$this->use_fly_and_fixed = $container->getParameter('use_fly_and_fixed');
}

/**
Expand Down Expand Up @@ -76,7 +69,8 @@ public function canRegister(Membership $membership)
*/
public function getExpire($membership): ?\DateTime
{
if ($this->registration_every_civil_year) {
$registration_every_civil_year = $this->container->getParameter('registration_every_civil_year');

Check failure on line 72 in src/AppBundle/Service/MembershipService.php

View workflow job for this annotation

GitHub Actions / Symfony 3.4 (PHP 7.4)

Access to an undefined property AppBundle\Service\MembershipService::$container.
if ($registration_every_civil_year) {
if ($membership->getLastRegistration()) {
$expire = $membership->getLastRegistration()->getDate();
} else {
Expand All @@ -86,7 +80,8 @@ public function getExpire($membership): ?\DateTime
} else {
if ($membership->getLastRegistration()) {
$expire = clone $membership->getLastRegistration()->getDate();
$expire = $expire->add(\DateInterval::createFromDateString($this->registration_duration));
$registration_duration = $this->container->getParameter('registration_duration');

Check failure on line 83 in src/AppBundle/Service/MembershipService.php

View workflow job for this annotation

GitHub Actions / Symfony 3.4 (PHP 7.4)

Access to an undefined property AppBundle\Service\MembershipService::$container.
$expire = $expire->add(\DateInterval::createFromDateString($registration_duration));
$expire->modify('-1 day');
} else {
$expire = new \DateTime('-1 day');
Expand Down Expand Up @@ -117,7 +112,8 @@ public function isUptodate(Membership $member)
*/
public function getStartOfCycle(Membership $membership, $cycleOffset = 0)
{
if ($this->cycle_type == "abcd") {
$cycle_type = $this->container->getParameter('cycle_type');

Check failure on line 115 in src/AppBundle/Service/MembershipService.php

View workflow job for this annotation

GitHub Actions / Symfony 3.4 (PHP 7.4)

Access to an undefined property AppBundle\Service\MembershipService::$container.
if ($cycle_type == "abcd") {
$date = new DateTime('now');
// 0 (for Monday) through 6 (for Sunday)
$day = $date->format("N") - 1;
Expand Down Expand Up @@ -201,7 +197,7 @@ public function hasWarningStatus(Membership $member): bool
$member->isCurrentlyExemptedFromShifts() ||
!$this->isUptodate($member);

if ($this->use_fly_and_fixed) {
if ($this->container->getParameter('use_fly_and_fixed')) {

Check failure on line 200 in src/AppBundle/Service/MembershipService.php

View workflow job for this annotation

GitHub Actions / Symfony 3.4 (PHP 7.4)

Access to an undefined property AppBundle\Service\MembershipService::$container.
$hasWarningStatus = $hasWarningStatus || $member->isFlying();
}

Expand All @@ -212,4 +208,17 @@ public function getShiftFreeLogs(Membership $member)
{
return $this->em->getRepository('AppBundle:ShiftFreeLog')->getMemberShiftFreed($member);
}

public function getMaximumBookingLeadTime(Membership $member)
{
if ($this->container->getParameter('use_fly_and_fixed')) {

Check failure on line 214 in src/AppBundle/Service/MembershipService.php

View workflow job for this annotation

GitHub Actions / Symfony 3.4 (PHP 7.4)

Access to an undefined property AppBundle\Service\MembershipService::$container.
if ($member->isFlying()) {
$nb_days = $this->container->getParameter('max_booking_lead_time_flying');

Check failure on line 216 in src/AppBundle/Service/MembershipService.php

View workflow job for this annotation

GitHub Actions / Symfony 3.4 (PHP 7.4)

Access to an undefined property AppBundle\Service\MembershipService::$container.
} else {
$nb_days = $this->container->getParameter('max_booking_lead_time_fixe');

Check failure on line 218 in src/AppBundle/Service/MembershipService.php

View workflow job for this annotation

GitHub Actions / Symfony 3.4 (PHP 7.4)

Access to an undefined property AppBundle\Service\MembershipService::$container.
}
return $nb_days;
}
return null;
}
}
8 changes: 8 additions & 0 deletions src/AppBundle/Service/ShiftService.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,14 @@ public function isShiftBookable(Shift $shift, Beneficiary $beneficiary = null)
if ($shift->getStart() > $cycle_end && !$member->getFrozenChange())
return false;
}
// restrict max booking lead time for flying or fixe
$max_booking_lead_time = $this->membershipService->getMaximumBookingLeadTime($member);
if ($max_booking_lead_time) {
$max_booking_lead_time = (new \Datetime())->modify('+' . $max_booking_lead_time)->setTime(0, 0, 0);
if ($shift->getEnd() > $max_booking_lead_time) {
return false;
}
}

// TODO refactor code to remove shift_cycle
// canBookDuration method should not use TimeLog but request shifts
Expand Down

0 comments on commit 33d2ac4

Please sign in to comment.