Skip to content

Commit

Permalink
Améliore la gestion de l'autocompletion (elefan-grenoble#657)
Browse files Browse the repository at this point in the history
* Refactor autocomplete for beneficiary

* Use AutocompleteBeneficiaryType in period position

* Use AutocompleteBeneficiaryType in joining membership

* Use AutocompleteBeneficiaryCollectionType for sending emails

* Refactor non-members completion in sending emails form to avoid ajax call

* Use AutocompleteBeneficiaryCollectionType for sending emails during shifts

* Use AutocompleteBeneficiaryType for booking shifts in admin view

* Add RadioChoice type and block + use it booking shift admin view

* Remove duplicated method getAutocompleteLabel and use instead getDisplayNameWithMemberNumber
  • Loading branch information
petitalb authored and quot17 committed Mar 28, 2023
1 parent d49b8b6 commit c444270
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 70 deletions.
1 change: 1 addition & 0 deletions app/Resources/views/admin/mail/edit.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

31 changes: 31 additions & 0 deletions src/AppBundle/Controller/BookingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -651,4 +651,35 @@ private function createShiftValidateInvalidateForm(Shift $shift)
->setMethod('POST')
->getForm();
}

/**
* Creates a form to book a shift entity.
*
* @param Shift $shift The shift entity
*
* @return \Symfony\Component\Form\Form The form
*/
private function createBookForm(Shift $shift)
{
$form = $this->get('form.factory')->createNamedBuilder('shift_book_forms_' . $shift->getId())
->setAction($this->generateUrl('admin_shift_book', array('id' => $shift->getId())))
->add('shifter', AutocompleteBeneficiaryType::class, array('label'=>'Numéro d\'adhérent ou nom du membre', 'required'=>true));

if ($this->useFlyAndFixed) {
$form = $form->add('fixe', RadioChoiceType::class, [
'choices' => [
'Volant' => 0,
'Fixe' => 1,
],
'data' => 0
]);
} else {
$form = $form->add('fixe', HiddenType::class, [
'data' => 0
]);
}

return $form->getForm();
}

}
69 changes: 0 additions & 69 deletions src/AppBundle/Controller/PeriodController.php
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,6 @@ public function bookPeriodPositionAction(Request $request, Period $period, Perio
{
$session = new Session();

$form = $this->createPeriodPositionBookForm($period, $position);
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {

Expand Down Expand Up @@ -539,71 +537,4 @@ public function generateShiftsForDateAction(Request $request, KernelInterface $k
));
}

/**
* Creates a form to delete a period entity.
*
* @param Period $period The period entity
*
* @return \Symfony\Component\Form\Form The form
*/
private function createPeriodDeleteForm(Period $period)
{
return $this->createFormBuilder()
->setAction($this->generateUrl('period_delete', array('id' => $period->getId())))
->setMethod('DELETE')
->getForm();
}

/**
* Creates a form to add a period position entity.
*
* @param Period $period The period entity
*
* @return \Symfony\Component\Form\Form The form
*/
private function createPeriodPositionAddForm(Period $period)
{
return $this->createForm(
PeriodPositionType::class,
new PeriodPosition(),
array(
'action' => $this->generateUrl(
'period_position_new',
array('id' => $period->getId())
)
));
}

/**
* Creates a form to book a period position entity.
*
* @param Period $period The period entity
* @param PeriodPosition $position The period position entity
*
* @return \Symfony\Component\Form\Form The form
*/
private function createPeriodPositionBookForm(Period $period, PeriodPosition $position)
{
return $this->get('form.factory')->createNamedBuilder('positions_book_forms_' . $position->getId())
->setAction($this->generateUrl('period_position_book', array('id' => $period->getId(), 'position' => $position->getId())))
->setMethod('POST')
->add('shifter', AutocompleteBeneficiaryType::class, array('label' => 'Numéro d\'adhérent ou nom du membre', 'required' => true))
->getForm();
}

/**
* Creates a form to delete a period position entity.
*
* @param Period $period The period entity
* @param PeriodPosition $position The period position entity
*
* @return \Symfony\Component\Form\Form The form
*/
private function createPeriodPositionDeleteForm(Period $period, PeriodPosition $position)
{
return $this->get('form.factory')->createNamedBuilder('positions_delete_forms_' . $position->getId())
->setAction($this->generateUrl('period_position_delete', array('id' => $period->getId(), 'position' => $position->getId())))
->setMethod('DELETE')
->getForm();
}
}
2 changes: 1 addition & 1 deletion src/AppBundle/Entity/Beneficiary.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public function getDisplayName(): string
*/
public function getDisplayNameWithMemberNumber(): string
{
return '#' . $this->getMemberNumber() . ' ' . $this->getDisplayName();
return '#' . $this->getMemberNumber() . ' ' . $this->getFirstname() . ' ' . $this->getLastname();
}

public function getPublicDisplayName(): string
Expand Down
20 changes: 20 additions & 0 deletions src/AppBundle/Repository/BeneficiaryRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,24 @@ public function findCoShifters($shift)
->getResult();

}

public function findCoShifters($shift)
{
$qb = $this->createQueryBuilder('b')
->leftJoin('b.shifts', 's')
->where('s.start = :start')
->andWhere('s.end = :end')
->andWhere('s.job = :job')
->andWhere('s.id != :id')
->andWhere('s.shifter IS NOT NULL')
->setParameter('start', $shift->getStart())
->setParameter('end', $shift->getEnd())
->setParameter('job', $shift->getJob())
->setParameter('id', $shift->getId());

return $qb
->getQuery()
->getResult();

}
}

0 comments on commit c444270

Please sign in to comment.