From 624185646463b51a77e2d7e16abb4a820492753b Mon Sep 17 00:00:00 2001 From: adametz Date: Thu, 18 Oct 2018 08:04:06 +0000 Subject: [PATCH] #1480 Frontent git-svn-id: http://78.47.251.156/svn/dev/sterntours-3@3473 f459cee4-fb09-11de-96c3-f9c5f16c3c76 --- .../views/default/pages/booking.html.twig | 17 +++++---- .../Controller/BookingController.php | 37 ++++++++++++++++++- .../Entity/TravelNationalityRepository.php | 16 ++++++++ ...TravelNationalityRequirementRepository.php | 22 +++++++++++ trunk/src/AppBundle/Entity/Traveler.php | 8 ++++ .../src/AppBundle/Form/BookingRequestType.php | 8 ++++ trunk/src/AppBundle/Form/RoomType.php | 6 +++ trunk/src/AppBundle/Form/TravelerType.php | 33 ++++++++++++----- .../Listener/KernelControllerListener.php | 2 +- .../AppBundle/Resources/public/js/booking.js | 36 +++++++++++++++--- 10 files changed, 160 insertions(+), 25 deletions(-) create mode 100644 trunk/src/AppBundle/Entity/TravelNationalityRepository.php create mode 100644 trunk/src/AppBundle/Entity/TravelNationalityRequirementRepository.php diff --git a/trunk/app/Resources/views/default/pages/booking.html.twig b/trunk/app/Resources/views/default/pages/booking.html.twig index a785f4a9..871da8af 100644 --- a/trunk/app/Resources/views/default/pages/booking.html.twig +++ b/trunk/app/Resources/views/default/pages/booking.html.twig @@ -543,6 +543,12 @@
+ +
{% set currentIndex = 0 %} {% for room in form.rooms %} @@ -607,7 +613,7 @@
-
+
{{ form_field_pho(traveler.nationality, 'Nationalität') }}
@@ -633,11 +639,8 @@

Einreise-, Visabestimmungen und gesundheitspolizeilichen Vorschriften

-
- {% for country in travel_program.countries %} -

{{ country.name }}

- {{ country.entryRequirements|raw|nl2br }} - {% endfor %} +
+
@@ -663,7 +666,7 @@

Hinweis

-

Sofern Sie nicht oder nicht ausschließlich nur die deutsche Staatsbürgerschaft besitzen, können Sie die Reise nicht buchen, +

Sofern Sie nicht oder nicht ausschließlich nur die deutsche, österreichische oder schweizerische Staatsbürgerschaft besitzen, können Sie die Reise nicht buchen, da wir Sie vorher u.a. über die Einreisebestimmungen für Ihre individuelle Staatsbürgerschaft informieren müssen. Bitte nehmen Sie vor einer Buchung Kontakt mit uns auf, damit Sie nach Erhalt der Informationen entscheiden können, ob Sie die Reise buchen möchten.

diff --git a/trunk/src/AppBundle/Controller/BookingController.php b/trunk/src/AppBundle/Controller/BookingController.php index 131e82f4..7ec70901 100644 --- a/trunk/src/AppBundle/Controller/BookingController.php +++ b/trunk/src/AppBundle/Controller/BookingController.php @@ -16,6 +16,7 @@ use AppBundle\Entity\TravelPeriodPrice; use AppBundle\Entity\TravelPeriodPriceType; use AppBundle\Form\BookingRequestType; use AppBundle\Util; +use Doctrine\ORM\Query; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -55,9 +56,34 @@ class BookingController extends Controller return $errors; } + public function getEntityManager() + { + return $this->getDoctrine()->getManager(); + } public function indexAction(Page $travelProgramPage, $action, Request $request) { + if($action == '/show_nationality_country_text') + { + $ret = ""; + $nationality_id = $request->request->get('nationality_id'); + $country_ids = $request->request->get('country_ids'); + foreach ($country_ids as $country_id){ + + $country = $this->getEntityManager()->getRepository('AppBundle:TravelCountry') + ->findOneBy(['id' => $country_id]); + $req = $this->getDoctrine()->getRepository('AppBundle:TravelNationalityRequirement')->findOneByCountryAndNationality($country_id, $nationality_id); + if($req && $country){ + $ret .= "

".$country->getName()."

"; + $ret .= "

".$req->getText()."

"; + $ret .= "
"; + } + } + echo $ret; + die(); + + } + $travelProgram = $travelProgramPage->getTravelProgram(); if (!$request->query->has('nr')) { @@ -90,6 +116,12 @@ class BookingController extends Controller throw $this->createNotFoundException(); } + /**/ + $nationalities = $this->getDoctrine() + ->getRepository('AppBundle:TravelNationality') + ->createQueryBuilder('n') + ->getQuery()->getResult(Query::HYDRATE_ARRAY);; + /** @var BookingRequest $bookingRequest */ $bookingRequest = new BookingRequest(); @@ -99,7 +131,8 @@ class BookingController extends Controller } $form = $this->createForm(BookingRequestType::class, $bookingRequest, [ 'travel_date' => $travelDate, - 'travel_program' => $travelProgram + 'travel_program' => $travelProgram, + 'nationalities' => $nationalities ]); if ($request->getMethod() == 'POST') { @@ -110,6 +143,8 @@ class BookingController extends Controller $bookingPriceInfo = []; $totalPrice = $this->calculatePrice($travelDate, $bookingRequest, $travelProgram->getCategory()->getId(), $travelProgram->getDepositPercent(), $htmlSummary, $bookingPriceInfo); + + if ($action == '/buchen') { $breadcrumbEntries = Util::createBreadcrumb($travelProgramPage); diff --git a/trunk/src/AppBundle/Entity/TravelNationalityRepository.php b/trunk/src/AppBundle/Entity/TravelNationalityRepository.php new file mode 100644 index 00000000..68222d2a --- /dev/null +++ b/trunk/src/AppBundle/Entity/TravelNationalityRepository.php @@ -0,0 +1,16 @@ +createQueryBuilder('n')->select('n')->getQuery()->execute(); + } +} diff --git a/trunk/src/AppBundle/Entity/TravelNationalityRequirementRepository.php b/trunk/src/AppBundle/Entity/TravelNationalityRequirementRepository.php new file mode 100644 index 00000000..f89d7f56 --- /dev/null +++ b/trunk/src/AppBundle/Entity/TravelNationalityRequirementRepository.php @@ -0,0 +1,22 @@ +createQueryBuilder('nr'); + return $qb + ->where('nr.travelCountryId = '.$travel_country_id) + ->andWhere('nr.travelNationalityId = '.$travel_nationality_id) + ->setMaxResults(1) + ->getQuery() + ->getOneOrNullResult(); + } +} diff --git a/trunk/src/AppBundle/Entity/Traveler.php b/trunk/src/AppBundle/Entity/Traveler.php index 10cbdae7..aee01a5a 100644 --- a/trunk/src/AppBundle/Entity/Traveler.php +++ b/trunk/src/AppBundle/Entity/Traveler.php @@ -55,6 +55,13 @@ class Traveler */ private $child = false; + /** + * Constructor + */ + public function __construct() + { + $this->nationalities = new \Doctrine\Common\Collections\ArrayCollection(); + } /** * @return int */ @@ -141,6 +148,7 @@ class Traveler $this->nationality = $nationality; } + /** * @return int */ diff --git a/trunk/src/AppBundle/Form/BookingRequestType.php b/trunk/src/AppBundle/Form/BookingRequestType.php index a0a02671..976ff62f 100644 --- a/trunk/src/AppBundle/Form/BookingRequestType.php +++ b/trunk/src/AppBundle/Form/BookingRequestType.php @@ -107,11 +107,14 @@ class BookingRequestType extends AbstractType $resolver->setDefaults([ 'travel_date' => null, 'travel_program' => null, + 'nationalities' => null, 'data_class' => 'AppBundle\Entity\BookingRequest', ]); $resolver->setAllowedTypes('travel_date', ['AppBundle\Entity\TravelDate']); $resolver->setAllowedTypes('travel_program', ['AppBundle\Entity\TravelProgram']); + + } /** @@ -125,6 +128,8 @@ class BookingRequestType extends AbstractType /* @var TravelProgram $travelProgram */ $travelProgram = $options['travel_program']; + $nationalities = $options['nationalities']; + $builder ->add('salutation', ChoiceType::class, [ //'placeholder' => 'Anrede (Bitte wählen) *', @@ -161,6 +166,9 @@ class BookingRequestType extends AbstractType ]) ->add('rooms', CollectionType::class, [ 'entry_type' => RoomType::class, + 'entry_options' => array( + 'nationalities' =>$nationalities, + ), 'by_reference' => false, ]) ->add('notes', TextareaType::class, ['required' => false]) diff --git a/trunk/src/AppBundle/Form/RoomType.php b/trunk/src/AppBundle/Form/RoomType.php index 7a58e15b..ca76719e 100644 --- a/trunk/src/AppBundle/Form/RoomType.php +++ b/trunk/src/AppBundle/Form/RoomType.php @@ -29,6 +29,7 @@ class RoomType extends AbstractType public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( + 'nationalities' => null, 'data_class' => 'AppBundle\Entity\Room' )); } @@ -39,9 +40,14 @@ class RoomType extends AbstractType */ public function buildForm(FormBuilderInterface $builder, array $options) { + $nationalities = $options['nationalities']; + $builder ->add('travelers', CollectionType::class, [ 'entry_type' => TravelerType::class, + 'entry_options' => array( + 'nationalities' =>$nationalities, + ), ]); } } \ No newline at end of file diff --git a/trunk/src/AppBundle/Form/TravelerType.php b/trunk/src/AppBundle/Form/TravelerType.php index dad858c5..534d8770 100644 --- a/trunk/src/AppBundle/Form/TravelerType.php +++ b/trunk/src/AppBundle/Form/TravelerType.php @@ -7,6 +7,10 @@ namespace AppBundle\Form; use AppBundle\Entity\Traveler; +use AppBundle\Entity\TravelNationality; +use AppBundle\Entity\TravelNationalityRepository; +use Doctrine\ORM\EntityManager; +use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\CheckboxType; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; @@ -24,10 +28,8 @@ class TravelerType extends AbstractType 'weiblich' => Traveler::FEMALE ]; - public static $NATIONALITY_CHOICES = [ - 'Nationalität (Bitte wählen)' => '', - 'deutsch' => 1, - ]; + public static $NATIONALITY_CHOICES = []; + /** * @param OptionsResolver $resolver @@ -35,8 +37,10 @@ class TravelerType extends AbstractType public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( + 'nationalities' => null, 'data_class' => 'AppBundle\Entity\Traveler' )); + } /** @@ -45,6 +49,18 @@ class TravelerType extends AbstractType */ public function buildForm(FormBuilderInterface $builder, array $options) { + + if(!count(self::$NATIONALITY_CHOICES)){ + $nationalities = $options['nationalities']; + self::$NATIONALITY_CHOICES = [ + 'Nationalität (Bitte wählen)' => '', + ]; + foreach ($nationalities as $nationality){ + self::$NATIONALITY_CHOICES[$nationality['name']] = $nationality['id']; + } + } + + /* @var TravelProgram $travelProgram */ $builder ->add('sex', ChoiceType::class, [ //'placeholder' => 'Geschlecht (Bitte wählen) *', @@ -57,6 +73,7 @@ class TravelerType extends AbstractType ->add('firstName') ->add('lastName') ->add('birthDate') + ->add('nationality', ChoiceType::class, [ 'choices' => self::$NATIONALITY_CHOICES, 'constraints' => [ @@ -67,13 +84,9 @@ class TravelerType extends AbstractType ]) ->add('acceptEntryRequirements', CheckboxType::class, ['required' => true]) - + ; - /* - , StDateType::class, [ - 'format' => 'dd.MM.yyyy' - ] - */ + } } diff --git a/trunk/src/AppBundle/Listener/KernelControllerListener.php b/trunk/src/AppBundle/Listener/KernelControllerListener.php index 038c7c11..ed593051 100644 --- a/trunk/src/AppBundle/Listener/KernelControllerListener.php +++ b/trunk/src/AppBundle/Listener/KernelControllerListener.php @@ -126,7 +126,7 @@ class KernelControllerListener $request->attributes->set('page', $node); if ($node->getTravelProgram() != null && ( - $restOfPath == '/buchen' || $restOfPath == '/berechne-gesamtpreis')) + $restOfPath == '/buchen' || $restOfPath == '/berechne-gesamtpreis' || $restOfPath == '/show_nationality_country_text')) { // Special case: Booking actions $request->attributes->set('travelProgramPage', $node); diff --git a/trunk/src/AppBundle/Resources/public/js/booking.js b/trunk/src/AppBundle/Resources/public/js/booking.js index 2f9081ee..f2d8aa4e 100644 --- a/trunk/src/AppBundle/Resources/public/js/booking.js +++ b/trunk/src/AppBundle/Resources/public/js/booking.js @@ -63,16 +63,40 @@ $(document).ready(function() { $('#no_flight_time').show(); } }); - var toggle_first = false; + var toggle_first= []; function updateNationality(ele){ var obj = ele.parents('.nationality_select').data('toggle'); if(ele.val()){ - $(obj).show('slow'); - if(!toggle_first){ - $(obj).find('.accordion-toggle').click(); - toggle_first = true; - } + var values = $("input[name='travel_program_countries_id[]']").map(function(){return $(this).val();}).get(); + + var tmp = location.href.split('?'); + var tmp2 = tmp[0].split('/'); + tmp2.pop(); + var url = tmp2.join('/') + '/show_nationality_country_text'; + if (tmp[1]) + { + url += '?'+ tmp[1]; + } + + var data = {nationality_id : ele.val(), country_ids: values}; + + $.ajax({ + url:url, + type: "POST", + data: data, + }).then(function(r) { + $(obj).find('.set_nationality_country_text').html(r); + $(obj).show('slow'); + if(!toggle_first[ele.val()]){ + $(obj).find('.accordion-toggle').click(); + toggle_first[ele.val()] = true; + } + + + }, function() { + summary$.html('Aufgrund eines Fehlers konnte kein Angebot ermittelt werden.'); + }); }else{ $(obj).hide(); }