Skip to content

Commit

Permalink
Restriction: max 1 book retrieval shift per day implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
d1ff1cult0 committed Oct 6, 2024
1 parent e2aa6bc commit 968b5aa
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
24 changes: 24 additions & 0 deletions module/ShiftBundle/Entity/RegistrationShift.php
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,10 @@ public function canHaveAsRegistered(EntityManager $entityManager, Person $regist
if ($this->getStartDate() < $shift->getEndDate() && $shift->getStartDate() < $this->getEndDate()) {
return false;
}

if ($this->getStartDate()->format('Y-m-d') === $shift->getStartDate()->format('Y-m-d')) {
return false;
}
}

if ($this->getFinalSigninDate() !== null && $this->getFinalSigninDate() < new DateTime()) {
Expand All @@ -414,6 +418,26 @@ public function canHaveAsRegistered(EntityManager $entityManager, Person $regist
return !($this->countRegistered() >= $this->getNbRegistered());
}

/**
* Checks whether or not the given person already has a registered shift on the same day as this shift
* shift.
*
* @param EntityManager $entityManager The EntityManager instance
* @param Person $registered The person that should be checked
* @return boolean
*/
public function hasShiftOnThisDay(EntityManager $entityManager, Person $registered)
{
$shifts = $entityManager->getRepository('ShiftBundle\Entity\RegistrationShift')
->findAllActiveByPerson($registered);//TODO: Create
foreach ($shifts as $shift) {
if ($this->getStartDate()->format('Y-m-d') === $shift->getStartDate()->format('Y-m-d')) {
return true;
}
}
return false;
}

/**
* @return Unit
*/
Expand Down
1 change: 1 addition & 0 deletions module/ShiftBundle/Resources/translations/shift.en.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
'Final Signup' => 'Final Signup',
'Final Signout' => 'Final Signout',

'You already have a timeslot on this day' => 'You already have a timeslot on this day',
'on the event' => 'on the event',
'You have currently <span class="label label-info">%unPayedShifts%</span> unpayed shift(s). You can get your reward from the vice-preases at \'blok 6\'. This reward will expire at the end of this academic year.' => 'You have currently <span class="label label-info">%unPayedShifts%</span> unpayed shift(s). You can get your reward from the vice-preases at \'blok 6\'. This reward will expire at the end of this academic year.',
'You haven\'t done any shifts this year yet. Sign up for a shift, have fun with the others while working and get some coins in return!' => 'You haven\'t done any shifts this year yet. Sign up for a shift, have fun with the others while working and get some coins in return!',
Expand Down
1 change: 1 addition & 0 deletions module/ShiftBundle/Resources/translations/shift.nl.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
'Final Signup' => 'Einde Inschrijvingen',
'Final Signout' => 'Einde Uitschrijvingen',

'You already have a timeslot on this day' => 'Je hebt al een tijdslot op deze dag',
'You have currently <span class="label label-info">%unPayedShifts%</span> unpayed shift(s). You can get your reward from the vice-preases at \'blok 6\'. This reward will expire at the end of this academic year.' => 'Je hebt momenteel <span class="label label-info">%unPayedShifts%</span> onbetaalde shift(en). Je kan je beloning komen halen bij de vice-praeses op \'blok 6\'. Deze beloning zal vervallen op het einde van dit academiejaar.',
'You haven\'t done any shifts this year yet. Sign up for a shift, have fun with the others while working and get some coins in return!' => 'Je hebt momenteel nog geen shiften gedaan dit jaar. Schrijf je in voor een shift, have fun tijdens de shift, leer nieuwe mensen kennen en krijg bonnetjes als beloning!',
'You have done your last shift on %lastShift%.' => 'Je hebt je laatste shift gedaan op %lastShift%.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@
panel.fadeIn();
$('#shifts-search ' + button.data('panel')).fadeOut(function () {$(this).remove()});
} else {
console.log("error");
errorSave();
}
},
Expand All @@ -324,7 +325,7 @@

<div class="shiftHolder">
<div class="shiftHeader">
<div class="shiftFlexCenter">
<div class="shiftFlexCenter">
<h5 style="margin-bottom: 0px">{{ shift.getName() }}</h5>
<p style="font-size: 14px; margin-bottom: 0px">{{dateLocalized(shift.getStartDate(), 'd/M/y')}} | {{ dateLocalized(shift.getStartDate(), 'HH:mm') }}-{{ dateLocalized(shift.getEndDate(), 'HH:mm') }}</p>
</div>
Expand Down Expand Up @@ -443,11 +444,15 @@
<button class="btn btn-default btn-xs {{ self.buttonStyle(shift, 'registered') }} registered" data-id="{{ shift.getId() }}" data-count="{{ shift.countRegistered() }}" data-max="{{ shift.getNbRegistered() }}" data-panel="#group_{{ accordionName }}_shift-{{ shift.getId() }}" type="button">
{{ translate('Registered') }} (<span class="count">{{ shift.countRegistered() }}</span>/{{ shift.getNbRegistered() }})
</button>
{% endif %}
{% if shift.countRegistered() == shift.getNbRegistered() %}
{% elseif shift.countRegistered() == shift.getNbRegistered() %}
<button disabled style="padding: 4px 8px; display: inline-block; margin-left: 10px;" class="btn btn-default btn-xs {{ self.buttonStyle(shift, 'registered') }} registered" data-id="{{ shift.getId() }}" data-count="{{ shift.countRegistered() }}" data-max="{{ shift.getNbRegistered() }}" data-panel="#group_{{ accordionName }}_shift-{{ shift.getId() }}" type="button" disabled>
{{ translate('Registered') }} (<span class="count">{{ shift.countRegistered() }}</span>/{{ shift.getNbRegistered() }})
</button>
{% elseif shift.hasShiftOnThisDay(entityManager, authenticatedPerson) %}
<button class="btn btn-xs btn-default">
{{ translate('You already have a timeslot on this day') }}
</button>

{% endif %}

{% else %}
Expand Down

0 comments on commit 968b5aa

Please sign in to comment.