Skip to content
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

Répare le bug sur la recherche de bénéficiaire via l'autocomplete #633

Merged
merged 2 commits into from
Nov 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ It use the materialize modal class https://materializecss.com/modals.html
{% else %}
Réservé
{% endif %}
le <i>{{ shift.bookedTime | date_fr_with_time }}</i> par {% if shift.booker and shift.booker.beneficiary %}<a href="{{ path("member_show",{'member_number': shift.booker.beneficiary.membership.memberNumber}) }}">{{ shift.booker.beneficiary }}</a>{% else %}{{shift.booker}}{% endif %}.
le <i>{{ shift.bookedTime | date_fr_with_time }}</i> par {% if shift.booker and shift.booker.beneficiary %}<a href="{{ path("member_show",{'member_number': shift.booker.beneficiary.membership.memberNumber}) }}">{{ shift.booker.beneficiary }}</a>{% else %}{{ shift.booker }}{% endif %}.
</p>
{% if is_granted('free',shift) %}
{% if use_card_reader_to_validate_shifts and shift.isPastOrCurrent %}
Expand Down Expand Up @@ -101,8 +101,8 @@ It use the materialize modal class https://materializecss.com/modals.html
<input id="form__token" type="hidden" name="form[_token]" value="{{ csrf_token('form') }}">
<div class="row">
<div class="col {% if use_fly_and_fixed %}s7{% else %}s9{% endif %} input-field">
<label for="appbundle_shift_booker{{ shift.id}}">Bénéficiaire</label>
<input id="appbundle_shift_booker{{ shift.id }}" name="form[booker]" type="text" class="autocomplete" />
<label for="appbundle_shift_shifter{{ shift.id }}">Bénéficiaire</label>
<input id="appbundle_shift_shifter{{ shift.id }}" name="form[shifter]" type="text" class="autocomplete" />
</div>
{% if use_fly_and_fixed %}
<div class="col s2">
Expand Down
2 changes: 1 addition & 1 deletion app/Resources/views/admin/period/edit.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
$('input.autocomplete').autocomplete({
data: {
{% for beneficiary in beneficiaries %}
"{{ beneficiary.displayNameWithMemberNumber }}" : null,
"{{ beneficiary.displayNameWithMemberNumber }}": null,
{% endfor %}
},
limit: 10, // The max amount of results that can be shown at once. Default: Infinity.
Expand Down
8 changes: 5 additions & 3 deletions src/AppBundle/Controller/BookingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ public function bookShiftAdminAction(Request $request, Shift $shift)
$session = new Session();

$form = $this->createFormBuilder()
->add('booker', TextType::class)
->add('shifter', TextType::class)
->add('fixe', RadioType::class)
->getForm();

Expand All @@ -745,9 +745,11 @@ public function bookShiftAdminAction(Request $request, Shift $shift)
}

$fixe = $form->get("fixe")->getData();
$str = $form->get("booker")->getData();
$str = $form->get("shifter")->getData();
$em = $this->getDoctrine()->getManager();
$beneficiary = $em->getRepository('AppBundle:Beneficiary')->findFromAutoComplete($str);
// $membership = $em->getRepository('AppBundle:Membership')->findOneFromAutoComplete($str);
// $beneficiary = $membership->getBeneficiaries()->findOneFromAutoComplete($str);
$beneficiary = $em->getRepository('AppBundle:Beneficiary')->findOneFromAutoComplete($str);

if (!$beneficiary) {
$session->getFlashBag()->add("error", "Impossible de trouve ce béneficiaire 😕");
Expand Down
2 changes: 1 addition & 1 deletion src/AppBundle/Controller/PeriodController.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ public function bookPositionToPeriodAction(Request $request, PeriodPosition $pos
$str = $content->beneficiary;

$em = $this->getDoctrine()->getManager();
$beneficiary = $em->getRepository('AppBundle:Beneficiary')->findFromAutoComplete($str);
$beneficiary = $em->getRepository('AppBundle:Beneficiary')->findOneFromAutoComplete($str);

if (!$beneficiary) {
$session->getFlashBag()->add("error", "Impossible de trouve ce béneficiaire 😕");
Expand Down
30 changes: 22 additions & 8 deletions src/AppBundle/Repository/BeneficiaryRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,28 @@
*/
class BeneficiaryRepository extends \Doctrine\ORM\EntityRepository
{
public function findFromAutoComplete($str)
/**
* findOneFromAutoComplete
*
* We consider that the $str will have the following format:
* "<Membership.member_number> <Beneficiary.firstname> <Beneficiary.lastname>"
*/
public function findOneFromAutoComplete($str)
{
$re = '/^#([0-9]+).*/';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
if (count($matches) == 1) {
$beneficiaryId = $matches[0][1];
return $this->find($beneficiaryId);
$reId = '/^#([0-9]+).*/';
$reFirstname = '/(?<=\s)(.*?)(?=\s)/';
preg_match_all($reId, $str, $matchesId, PREG_SET_ORDER, 0);
preg_match_all($reFirstname, $str, $matchesFirstname, PREG_SET_ORDER, 0);
if ((count($matchesId) == 1) && (count($matchesFirstname) == 1)) {
$qb = $this->createQueryBuilder('b');

$qb->leftJoin('b.membership', 'm')
->where('m.member_number = :membernumber')
->andWhere('b.firstname = :firstname')
->setParameter('membernumber', $matchesId[0][1])
->setParameter('firstname', $matchesFirstname[0][1]);

return $qb->getQuery()->getSingleResult();
}
return null;
}
Expand All @@ -32,11 +47,10 @@ public function findAllActive()

$qb = $this->createQueryBuilder('beneficiary');


$qb->select('beneficiary, membership')
->join('beneficiary.user', 'user')
->join('beneficiary.membership', 'membership')
->where('membership.withdrawn=0');
->where('membership.withdrawn = 0');

return $qb->getQuery()->getResult();
}
Expand Down
7 changes: 6 additions & 1 deletion src/AppBundle/Repository/MembershipRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@
*/
class MembershipRepository extends \Doctrine\ORM\EntityRepository
{

/**
* findOneFromAutoComplete
*
* We consider that the $str will have the following format:
* "<Membership.member_number> <Beneficiary.firstname> <Beneficiary.lastname>"
*/
public function findOneFromAutoComplete($str)
{
$re = '/^#([0-9]+).*/';
Expand Down