src/Controller/CourseController.php line 421

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\AccountRole;
  4. use App\Entity\AccountType;
  5. use App\Entity\Address;
  6. use App\Entity\Applicant;
  7. use App\Entity\City;
  8. use App\Entity\Course;
  9. use App\Entity\CourseRegistrationRequest;
  10. use App\Entity\CourseReview;
  11. use App\Entity\CourseState;
  12. use App\Entity\CourseTerm;
  13. use App\Entity\CourseTopic;
  14. use App\Entity\District;
  15. use App\Entity\Organizer;
  16. use App\Entity\Region;
  17. use App\Entity\SonataUserUser;
  18. use App\Form\CourseRegistrationCompanyRequestType;
  19. use App\Form\CourseRegistrationRequestType;
  20. use App\Form\CourseReviewType;
  21. use App\Form\CourseTermType;
  22. use App\Form\CourseType;
  23. use App\Form\ImportFileType;
  24. use App\Repository\AttributeGroupRepository;
  25. use App\Repository\CertificationRepository;
  26. use App\Repository\CityRepository;
  27. use App\Repository\CourseLengthRepository;
  28. use App\Repository\CourseProgressLevelRepository;
  29. use App\Repository\CourseRepository;
  30. use App\Repository\CourseTermRepository;
  31. use App\Repository\DistrictRepository;
  32. use App\Repository\LanguageLevelRepository;
  33. use App\Repository\RegionRepository;
  34. use App\Repository\TargetGroupRepository;
  35. use App\Repository\TeachingTypeRepository;
  36. use App\Util\AddressUtil;
  37. use App\Util\ApplicantUtil;
  38. use App\Util\CourseImportValidator;
  39. use App\Util\CourseUtil;
  40. use App\Util\EmailUtil;
  41. use App\Util\LogUtil;
  42. use App\Util\OrganizerUtil;
  43. use App\Util\StatsUtil;
  44. use App\Util\UserUtil;
  45. use Knp\Component\Pager\PaginatorInterface;
  46. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  47. use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
  48. use Sonata\UserBundle\Model\UserInterface;
  49. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  50. use Symfony\Component\HttpFoundation\File\Exception\FileException;
  51. use Symfony\Component\HttpFoundation\Request;
  52. use Symfony\Component\HttpFoundation\Response;
  53. use Symfony\Component\Routing\Annotation\Route;
  54. /**
  55.  * @Route("/kurzy")
  56.  */
  57. class CourseController extends AbstractController
  58. {
  59.     /**
  60.      * @var OrganizerUtil
  61.      */
  62.     private $organizerUtil;
  63.     /**
  64.      * @var ApplicantUtil
  65.      */
  66.     private $applicantUtil;
  67.     public function __construct(OrganizerUtil $organizerUtilApplicantUtil $applicantUtil)
  68.     {
  69.         $this->organizerUtil $organizerUtil;
  70.         $this->applicantUtil $applicantUtil;
  71.     }
  72.     /**
  73.      * @return Organizer
  74.      */
  75.     private function getOrganizer()
  76.     {
  77.         $user $this->getUser();
  78.         if (!$user instanceof UserInterface) {
  79.             throw $this->createAccessDeniedException();
  80.         }
  81.         $organizer $this->organizerUtil->getOrganizerByUser($user);
  82.         if (!$organizer instanceof Organizer) {
  83.             throw $this->createAccessDeniedException();
  84.         }
  85.         return $organizer;
  86.     }
  87.     /**
  88.      * @return Organizer
  89.      */
  90.     private function getApplicant()
  91.     {
  92.         $user $this->getUser();
  93.         $applicant $this->applicantUtil->getApplicantByUser($user);
  94.         if (!$applicant instanceof Applicant) {
  95.             return null;
  96.         }
  97.         return $applicant;
  98.     }
  99.     /**
  100.      * @Route("/", name="course_index", methods={"GET"})
  101.      */
  102.     public function index(CourseRepository $courseRepository): Response
  103.     {
  104.         return $this->render('course/index.html.twig', [
  105.             'courses' => $courseRepository->findAll(),
  106.         ]);
  107.     }
  108.     /**
  109.      * @Route("/new", name="course_new", methods={"GET","POST"})
  110.      */
  111.     public function new(Request $request): Response
  112.     {
  113.         $course = new Course();
  114.         $course->setOrganizer($this->getOrganizer());
  115.         $form $this->createForm(CourseType::class, $course);
  116.         $step $course->getLastStep();
  117.         $form->handleRequest($request);
  118.         if ($form->isSubmitted() && $form->isValid() && $form->get('save')->isClicked()) {
  119.             $entityManager $this->getDoctrine()->getManager();
  120.             $entityManager->persist($course);
  121.             $entityManager->flush();
  122.             return $this->redirectToRoute('dashboard');
  123.         }
  124.         if ($form->isSubmitted() && $form->isValid() && $form->get('save')->isClicked()) {
  125.             $course->setLastStep($step 1);
  126.             $entityManager $this->getDoctrine()->getManager();
  127.             $entityManager->persist($course);
  128.             $entityManager->flush();
  129.             return $this->redirectToRoute('dashboard');
  130.         }
  131.         if ($form->isSubmitted() && $form->isValid() && $form->get('continue')->isClicked()) {
  132.             $course->setLastStep($step 1);
  133.             $entityManager $this->getDoctrine()->getManager();
  134.             $entityManager->persist($course);
  135.             $entityManager->flush();
  136.             return $this->redirectToRoute('course_edit', ['id' => $course->getId()]);
  137.         }
  138.         $template $request->isXmlHttpRequest() ? '_form.html.twig' 'new.html.twig';
  139.         return $this->render('course/' $template, [
  140.             'course' => $course,
  141.             'step' => $step,
  142.             'organizer' => $this->getOrganizer(),
  143.             'form' => $form->createView(),
  144.         ]);
  145.     }
  146.     /**
  147.      * @Route("/new-import", name="course_new_import", methods={"GET", "POST"})
  148.      */
  149.     public function newImport(Request $request,RegionRepository  $regionRepository,
  150.                               DistrictRepository $districtRepository,
  151.                               CityRepository  $cityRepository,
  152.                               CourseProgressLevelRepository $courseProgressLevelRepository,
  153.                               LanguageLevelRepository $languageLevelRepository,
  154.                               CourseLengthRepository $courseLengthRepository,
  155.                               AttributeGroupRepository $attributeGroupRepository,
  156.                               TeachingTypeRepository $teachingTypeRepository,
  157.                               TargetGroupRepository $targetGroupRepository,
  158.                               CertificationRepository $certificationRepository,
  159.     CourseImportValidator $validator
  160.     ): Response
  161.     {
  162.         $form $this->createForm(ImportFileType::class);
  163.         $form->handleRequest($request);
  164.         if ($form->isSubmitted() && $form->isValid()) {
  165.             $importFile $form->get('importFile')->getData();
  166.             if ($importFile) {
  167.                 $originalFilename pathinfo($importFile->getClientOriginalName(), PATHINFO_FILENAME);
  168.                 $newFilename uniqid().'.'.$importFile->guessExtension();
  169.                 try {
  170.                     $importFile->move(
  171.                         $this->getParameter('kernel.project_dir') . '/var/imports',
  172.                         $newFilename
  173.                     );
  174.                 } catch (FileException $e) {
  175.                     $this->addFlash('danger''Chyba při nahrávání souboru.');
  176.                     return $this->redirectToRoute('course_new_import');
  177.                 }
  178.                 $this->addFlash('success''Soubor byl úspěšně nahrán a uložen jako ' $newFilename);
  179.                 $fullPath $this->getParameter('kernel.project_dir') . '/var/imports/' $newFilename;
  180. // Tady bude naše nová validační třída
  181.                 $errors $validator->validateFromOrganizerCsv($fullPath);
  182. // Předáme chyby do session pro zobrazení
  183.                 if (!empty($errors)) {
  184.                     $this->addFlash('danger''V souboru byly nalezeny chyby.');
  185.                     $request->getSession()->set('import_errors'$errors);
  186.                 } else {
  187.                     $this->addFlash('success''Soubor byl úspěšně ověřen – žádné chyby nenalezeny.');
  188.                 }
  189.                 return $this->redirectToRoute('course_new_import');
  190.             }
  191.         }
  192.         return $this->render('course/import.html.twig', [
  193.             'form' => $form->createView(),
  194.             'districts' => $districtRepository->findBy([], ['name' => 'ASC']),
  195.             'regions' => $regionRepository->findBy([], ['name' => 'ASC']),
  196.             'progressLevels' => $courseProgressLevelRepository->findBy([], ['name' => 'ASC']),
  197.             'languageLevels' => $languageLevelRepository->findBy([], ['name' => 'ASC']),
  198.             'courseLengths' => $courseLengthRepository->findBy([], ['name' => 'ASC']),
  199.             'attributeGroups' => $attributeGroupRepository->findBy([], ['name' => 'ASC']),
  200.             'teachingTypes' => $teachingTypeRepository->findBy([], ['name' => 'ASC']),
  201.             'targetGroups' => $targetGroupRepository->findBy([], ['name' => 'ASC']),
  202.             'certifications' => $certificationRepository->findBy([], ['name' => 'ASC']),
  203.         ]);
  204.     }
  205.     /**
  206.      * @Route("/{id}/terms/new", name="course_terms_new", methods={"GET","POST"})
  207.      */
  208.     public function newTerm(Request $requestCourse $courseCourseUtil $courseUtil): Response
  209.     {
  210.         $courseTerm = new CourseTerm();
  211.         $courseTerm->setPublishedAt(new \DateTime());
  212.         $courseTerm->setState($courseUtil->getCourseStateByIdentifier(CourseState::COURSE_STATE_DRAFT));
  213.         $form $this->createForm(CourseTermType::class, $courseTerm);
  214.         $form->handleRequest($request);
  215.         if ($form->isSubmitted() && $form->isValid()) {
  216.             $course->addTerm($courseTerm);
  217.             $entityManager $this->getDoctrine()->getManager();
  218.             $entityManager->persist($course);
  219.             $entityManager->flush();
  220.             return $this->redirectToRoute('dashboard');
  221.         }
  222.         return $this->render('course/terms.new.html.twig', [
  223.             'course' => $course,
  224.             'courseTerm' => $courseTerm,
  225.             'form' => $form->createView(),
  226.         ]);
  227.     }
  228.     /**
  229.      * @Route("/{id}/registrace", name="course_registration", methods={"GET","POST"})
  230.      */
  231.     public function registration(CourseTerm $courseTermRequest $requestEmailUtil $emailUtilUserUtil $userUtilLogUtil $logUtil): Response
  232.     {
  233.         $course $courseTerm->getCourse();
  234.         $courseRegistration = new CourseRegistrationRequest();
  235.         $courseRegistration->setCourseTerm($courseTerm);
  236.         $applicant $this->getApplicant();
  237.         if ($applicant instanceof Applicant) {
  238.             $courseRegistration->setApplicant($applicant);
  239.             if ($applicant->getAddress() instanceof Address) {
  240.                 $address = clone $applicant->getAddress();
  241.                 $courseRegistration->setAddress($address);
  242.             }
  243.         }
  244. //
  245.         $form $this->createForm(CourseRegistrationRequestType::class, $courseRegistration);
  246.         $form->handleRequest($request);
  247.         if ($form->isSubmitted() && $form->isValid() && $form->get('save')->isClicked()) {
  248.             /** @var CourseRegistrationRequest $data */
  249.             $data $form->getData();
  250.             if (!$applicant instanceof Applicant) {
  251.                 $newUser = new SonataUserUser();
  252.                 $newUser->setAccountRole($userUtil->getAccountRoleByIdentifier(AccountRole::ACCOUNT_ROLE_APPLICANT));
  253.                 $newUser->setAccountType($userUtil->getAccountTypeByIdentifier(AccountType::ACCOUNT_TYPE_INDIVIDUAL));
  254.                 $newUser->setUsername($data->getEmail());
  255.                 $newUser->setEmail($data->getEmail());
  256.                 $newUser->setFirstname($data->getFirstname());
  257.                 $newUser->setLastname($data->getLastname());
  258.                 $newUser->setPhone($data->getPhone());
  259.                 $newUser->setPlainPassword($userUtil->generatePassword());
  260.                 $newUser->setEnabled(true);
  261.                 $newUser->setEmailPublic($newUser->getEmail());
  262.                 $this->addFlash('success''Byl Vám vytvořen uživatelský účet. Přihlašovací údaje Vám byly odeslány e-mailem');
  263.                 $userUtil->createRoleData($newUser);
  264.             }
  265.             $entityManager $this->getDoctrine()->getManager();
  266.             $entityManager->persist($courseRegistration);
  267.             $entityManager->flush();
  268.             $this->addFlash('success''Registrace byla přijata');
  269.             $emailUtil->addEmailToQueueFromTemplateWithDataTransform($course->getOrganizer()->getUserAccount()->getEmail(), EmailUtil::REGISTRATION_REQUEST_PROMOTER$courseRegistration);
  270.             $emailUtil->addEmailToQueueFromTemplateWithDataTransform($courseRegistration->getEmail(), EmailUtil::REGISTRATION_REQUEST_APPLICANT$courseRegistration);
  271.             $logUtil->addNewMessage('Nový zájemce o kurz čeká na schválení registrace''registration_request'$courseRegistration->getId(), $courseRegistration->getCourseTerm()->getCourse());
  272.             return $this->redirectToRoute('course_show', ['id' => $course->getId()], Response::HTTP_SEE_OTHER);
  273.         }
  274.         $template $request->isXmlHttpRequest() ? '_form.html.twig' 'registration.html.twig';
  275.         return $this->render('course/' $template, [
  276.             'course' => $course,
  277.             'courseTerm' => $courseTerm,
  278.             'courseRegistrationRequest' => $courseRegistration,
  279.             'form' => $form->createView(),
  280.         ]);
  281.     }
  282.     /**
  283.      * @Route("/{id}/registrace-firma", name="course_registration_company", methods={"GET","POST"})
  284.      */
  285.     public function registrationCompany(CourseTerm $courseTermRequest $requestEmailUtil $emailUtil): Response
  286.     {
  287.         $course $courseTerm->getCourse();
  288.         $courseRegistration = new CourseRegistrationRequest();
  289.         $courseRegistration->setCourseTerm($courseTerm);
  290.         $form $this->createForm(CourseRegistrationCompanyRequestType::class, $courseRegistration);
  291.         $form->handleRequest($request);
  292.         if ($form->isSubmitted() && $form->isValid() && $form->get('save')->isClicked()) {
  293.             /** @var CourseRegistrationRequest $data */
  294.             $data $form->getData();
  295.             $applicant $data->getApplicant();
  296.             $courseRegistration->setApplicant($applicant);
  297.             if ($applicant->getAddress() instanceof Address) {
  298.                 $address = clone $applicant->getAddress();
  299.                 $courseRegistration->setAddress($address);
  300.             }
  301.             $entityManager $this->getDoctrine()->getManager();
  302.             $entityManager->persist($courseRegistration);
  303.             $entityManager->flush();
  304.             $this->addFlash('success''Registrace byla přijata');
  305.             $emailUtil->addEmailToQueueFromTemplateWithDataTransform($course->getOrganizer()->getUserAccount()->getEmail(), EmailUtil::REGISTRATION_REQUEST_PROMOTER$courseRegistration);
  306.             $emailUtil->addEmailToQueueFromTemplateWithDataTransform($courseRegistration->getEmail(), EmailUtil::REGISTRATION_REQUEST_APPLICANT$courseRegistration);
  307.             return $this->redirectToRoute('course_show', ['id' => $course->getId()], Response::HTTP_SEE_OTHER);
  308.         }
  309.         $template $request->isXmlHttpRequest() ? '_form.html.twig' 'registration_company.html.twig';
  310.         return $this->render('course/' $template, [
  311.             'course' => $course,
  312.             'courseTerm' => $courseTerm,
  313.             'courseRegistrationRequest' => $courseRegistration,
  314.             'form' => $form->createView(),
  315.         ]);
  316.     }
  317.     /**
  318.      * @Route("/{id}/pridat-hodnoceni", name="course_review_create", methods={"GET","POST"})
  319.      */
  320.     public function reviewCreate(Course $courseRequest $requestEmailUtil $emailUtilLogUtil $logUtil): Response
  321.     {
  322.         $courseReview = new CourseReview();
  323.         $courseReview->setCourse($course);
  324.         $applicant $this->getApplicant();
  325.         if ($applicant instanceof Applicant) {
  326.             $courseReview->setApplicant($applicant);
  327.         }
  328. //
  329.         $form $this->createForm(CourseReviewType::class, $courseReview);
  330.         $form->handleRequest($request);
  331.         if ($form->isSubmitted() && $form->isValid() && $form->get('save')->isClicked()) {
  332.             $entityManager $this->getDoctrine()->getManager();
  333.             $entityManager->persist($courseReview);
  334.             $entityManager->flush();
  335.             $emailUtil->addEmailToQueueFromTemplateWithDataTransform($this->getUser()->getEmail(), EmailUtil::NEW_REVIEW_PROMOTER$courseReview);
  336.             $this->addFlash('success''Recenze byla přijata');
  337.             $logUtil->addNewMessage('Obdrželi jste nové hodnocení u kurzu ' $courseReview->getCourse()->getName(), 'review'$courseReview->getId(), $courseReview->getCourse());
  338.             return $this->redirectToRoute('course_show', ['id' => $course->getId()], Response::HTTP_SEE_OTHER);
  339.         }
  340.         $template $request->isXmlHttpRequest() ? '_form.html.twig' 'create.html.twig';
  341.         return $this->render('review/' $template, [
  342.             'course' => $course,
  343.             'courseReview' => $courseReview,
  344.             'organizer' => $course->getOrganizer(),
  345.             'form' => $form->createView(),
  346.         ]);
  347.     }
  348.     /**
  349.      * @Route("/{id}", name="course_show", methods={"GET"})
  350.      */
  351.     public function show(Course $courseStatsUtil $statsUtil): Response
  352.     {
  353.         $statsUtil->saveStatsForCourse($course);
  354.         return $this->render('course/show.html.twig', [
  355.             'course' => $course,
  356.         ]);
  357.     }
  358.     /**
  359.      * @Route("/{id}/podobne", name="course_alternative", methods={"GET"})
  360.      */
  361.     public function alternative(Course $courseCourseRepository $courseRepository): Response
  362.     {
  363.         $courses $courseRepository->findAlternative($course);
  364.         return $this->render('course/alternative.html.twig', [
  365.             'course' => $course,
  366.             'courses' => $courses
  367.         ]);
  368.     }
  369.     /**
  370.      * @Route("/{id}/edit", name="course_edit", methods={"GET","POST"})
  371.      */
  372.     public function edit(Request $requestCourse $course): Response
  373.     {
  374.         if ($request->query->has('step')) {
  375.             $course->setLastStep($request->query->getInt('step'));
  376.         }
  377.         $organizer $this->getOrganizer();
  378.         if ($organizer->getId() != $course->getOrganizer()->getId()) {
  379.             throw $this->createAccessDeniedException();
  380.         }
  381.         $form $this->createForm(CourseType::class, $course);
  382.         $form->handleRequest($request);
  383.         $step $course->getLastStep();
  384.         if ($form->isSubmitted() && $form->isValid() && $form->get('save')->isClicked()) {
  385.             $course->setLastStep($step 1);
  386.             $entityManager $this->getDoctrine()->getManager();
  387.             $entityManager->persist($course);
  388.             $entityManager->flush();
  389.             return $this->redirectToRoute('dashboard');
  390.         }
  391.         if ($form->isSubmitted() && $form->isValid() && $form->get('continue')->isClicked()) {
  392.             $course->setLastStep($step 1);
  393.             $entityManager $this->getDoctrine()->getManager();
  394.             $entityManager->persist($course);
  395.             $entityManager->flush();
  396.             return $this->redirectToRoute('course_edit', ['id' => $course->getId()]);
  397.         }
  398.         $template $request->isXmlHttpRequest() ? '_form.html.twig' 'edit.html.twig';
  399.         return $this->render('course/' $template, [
  400.             'course' => $course,
  401.             'step' => $step,
  402.             'organizer' => $this->getOrganizer(),
  403.             'form' => $form->createView(),
  404.         ]);
  405.     }
  406.     /**
  407.      * @Route("/{id}/cancel", name="course_cancel", methods={"GET","POST"})
  408.      */
  409.     public function cancel(Request $requestCourse $courseCourseUtil $courseUtil): Response
  410.     {
  411.         $organizer $this->getOrganizer();
  412.         if ($organizer->getId() != $course->getOrganizer()->getId()) {
  413.             throw $this->createAccessDeniedException();
  414.         }
  415.         $course->setState($courseUtil->getCourseStateByIdentifier('canceled-by-organizer'));
  416.         $courseUtil->cancelCourseNotify($course);
  417.         $courseUtil->saveCourse($course);
  418.         return $this->redirectToRoute('dashboard');
  419.     }
  420.     /**
  421.      * @Route("/{id}/terms/{termId}/cancel", name="course_terms_cancel", methods={"GET","POST"})
  422.      */
  423.     public function cancelTerms(Request $requestCourse $courseint $termIdCourseUtil $courseUtilCourseTermRepository $courseTermRepository): Response
  424.     {
  425.         $courseTerm $courseTermRepository->find($termId);
  426.         $organizer $this->getOrganizer();
  427.         if ($organizer->getId() != $course->getOrganizer()->getId()) {
  428.             throw $this->createAccessDeniedException();
  429.         }
  430.         $courseTerm->setState($courseUtil->getCourseStateByIdentifier('canceled-by-organizer'));
  431.         $courseUtil->cancelCourseTermNotify($courseTerm);
  432.         $courseUtil->saveCourseTerm($courseTerm);
  433.         return $this->redirectToRoute('dashboard');
  434.     }
  435.     /**
  436.      * @Route("/{id}/terms/{termId}/edit", name="course_terms_edit", methods={"GET","POST"}, requirements={"id" = "\d+","termId" = "\d+",})
  437.      */
  438.     public function editTerm(Request $requestCourse $courseint $termIdCourseTermRepository $courseTermRepository): Response
  439.     {
  440.         $courseTerm $courseTermRepository->find($termId);
  441.         $organizer $this->getOrganizer();
  442.         if ($organizer->getId() != $course->getOrganizer()->getId()) {
  443.             throw $this->createAccessDeniedException();
  444.         }
  445.         $form $this->createForm(CourseTermType::class, $courseTerm);
  446.         $form->handleRequest($request);
  447.         $step $course->getLastStep();
  448.         if ($form->isSubmitted() && $form->isValid()) {
  449.             $entityManager $this->getDoctrine()->getManager();
  450.             $entityManager->persist($courseTerm);
  451.             $entityManager->flush();
  452.             return $this->redirectToRoute('dashboard');
  453.         }
  454.         return $this->render('course/terms.edit.html.twig', [
  455.             'course' => $course,
  456.             'courseTerm' => $courseTerm,
  457.             'form' => $form->createView(),
  458.         ]);
  459.     }
  460.     /**
  461.      * @Route("/{id}/terms", name="course_terms_list", methods={"GET","POST"})
  462.      */
  463.     public function termsList(Request $requestCourse $coursePaginatorInterface $paginator): Response
  464.     {
  465.         return $this->render('course/terms.list.html.twig', [
  466.             'course' => $course,
  467.         ]);
  468.     }
  469.     /**
  470.      * @Route("/{id}/terms/{termId}/registrations", name="course_terms_registrations", methods={"GET","POST"}, requirements={"id" = "\d+","termId" = "\d+",})
  471.      */
  472.     public function termRegistrations(Request $requestCourse $courseint $termIdCourseTermRepository $courseTermRepository): Response
  473.     {
  474.         $courseTerm $courseTermRepository->find($termId);
  475.         return $this->render('course/terms.registrations.html.twig', [
  476.             'course' => $course,
  477.             'courseTerm' => $courseTerm,
  478.         ]);
  479.     }
  480.     /**
  481.      * @Route("/{id}", name="course_delete", methods={"POST"})
  482.      */
  483.     public function delete(Request $requestCourse $course): Response
  484.     {
  485.         if ($this->isCsrfTokenValid('delete' $course->getId(), $request->request->get('_token'))) {
  486.             $entityManager $this->getDoctrine()->getManager();
  487.             $entityManager->remove($course);
  488.             $entityManager->flush();
  489.         }
  490.         return $this->redirectToRoute('course_index', [], Response::HTTP_SEE_OTHER);
  491.     }
  492.     /**
  493.      * @Route("/import/city", name="import_city")
  494.      */
  495.     public function importCity(AddressUtil $addressUtil): Response
  496.     {
  497.         ini_set('max_execution_time'600);
  498.         $country $addressUtil->getCountryByIdentifier('cz');
  499.         $row 1;
  500.         $startId 1;
  501.         if (($handle fopen("https://raw.githubusercontent.com/33bcdd/souradnice-mest/master/souradnice.csv""r")) !== FALSE) {
  502.             while (($data fgetcsv($handle1000",")) !== FALSE) {
  503.                 if ($row == 1) {
  504.                     $row++;
  505.                     continue;
  506.                 }
  507.                 $regionName $data[4];
  508.                 $regionCode $data[5];
  509.                 $districtName $data[2];
  510.                 $districtCode $data[3];
  511.                 $cityName $data[0];
  512.                 $cityCode $data[1];
  513.                 $latitude $data[7];
  514.                 $longitude $data[8];
  515.                 $postcode $data[6];
  516.                 $id $row $startId;
  517.                 $city $addressUtil->getCity($id);
  518.                 if ($city->getName() == $cityName && $city->getPostcode() == $postcode && $city->getLatitude() == $latitude && $city->getLongitude() == $longitude) {
  519.                     $city->setIdentifier($cityCode);
  520.                     $addressUtil->saveCity($city);
  521.                     $row++;
  522.                     continue;
  523.                 }
  524.                 dump($city->getName() == $cityName);
  525.                 dump($city->getPostcode() == $postcode);
  526.                 dump($city->getLatitude() == $latitude);
  527.                 dump($city->getLongitude() == $longitude);
  528.                 dump($city);
  529.                 dump($data);
  530.                 exit;
  531.                 $cities $addressUtil->getCityByName($cityName);
  532.                 if (count($cities) <= 1) {
  533.                     continue;
  534.                 }
  535.                 foreach ($cities as $city) {
  536.                     if ($city->getLongitude() == $longitude && $city->getLongitude() == $longitude) {
  537.                         $city->setPostcode($postcode);
  538.                         $addressUtil->saveCity($city);
  539.                         continue;
  540.                     }
  541.                 }
  542.                 continue;
  543.                 $region $addressUtil->getRegionByIdentifier($regionCode);
  544.                 if (!$region instanceof Region) {
  545.                     $region = new Region();
  546.                     $region->setName($regionName);
  547.                     $region->setIdentifier($regionCode);
  548.                     $region->setCountry($country);
  549.                     $addressUtil->saveRegion($region);
  550.                 }
  551.                 $district $addressUtil->getDistrictByIdentifier($districtCode);
  552.                 if (!$district instanceof District) {
  553.                     $district = new District();
  554.                     $district->setName($districtName);
  555.                     $district->setIdentifier($districtCode);
  556.                     $district->setRegion($region);
  557.                     $addressUtil->saveDistrict($district);
  558.                 }
  559.                 $city = new City();
  560.                 $city->setName($cityName);
  561.                 $city->setLatitude($latitude);
  562.                 $city->setLongitude($longitude);
  563.                 $city->setDistrict($district);
  564.                 $addressUtil->saveCity($city);
  565.             }
  566.             fclose($handle);
  567.         }
  568.         die("AAAA");
  569.     }
  570. }