src/Controller/AttributeGroupController.php line 162

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Dto\SearchFormDto;
  4. use App\Entity\Applicant;
  5. use App\Entity\Attribute;
  6. use App\Entity\AttributeGroup;
  7. use App\Entity\City;
  8. use App\Entity\Course;
  9. use App\Entity\CourseRegistrationRequest;
  10. use App\Entity\CourseReview;
  11. use App\Entity\CourseTopic;
  12. use App\Entity\Organizer;
  13. use App\Form\CourseFilterType;
  14. use App\Form\CourseRegistrationRequestType;
  15. use App\Form\CourseReviewType;
  16. use App\Form\CourseType;
  17. use App\Repository\CourseRepository;
  18. use App\Util\ApplicantUtil;
  19. use App\Util\AttributeUtil;
  20. use App\Util\CourseUtil;
  21. use App\Util\FoxentryUtil;
  22. use App\Util\OrganizerUtil;
  23. use Knp\Component\Pager\PaginatorInterface;
  24. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  25. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  26. use Symfony\Component\HttpFoundation\Request;
  27. use Symfony\Component\HttpFoundation\Response;
  28. use Symfony\Component\Routing\Annotation\Route;
  29. /**
  30.  * @Route("/kurzy/skupina")
  31.  */
  32. class AttributeGroupController extends AbstractController
  33. {
  34.     /**
  35.      * @var OrganizerUtil
  36.      */
  37.     private $organizerUtil;
  38.     /**
  39.      * @var ApplicantUtil
  40.      */
  41.     private $applicantUtil;
  42.     /**
  43.      * @var CourseUtil
  44.      */
  45.     private $courseUtil;
  46.     /**
  47.      * @var AttributeUtil
  48.      */
  49.     private $attributeUtil;
  50.     public function __construct(OrganizerUtil $organizerUtilApplicantUtil $applicantUtilCourseUtil $courseUtilAttributeUtil $attributeUtil)
  51.     {
  52.         $this->courseUtil $courseUtil;
  53.         $this->attributeUtil $attributeUtil;
  54.     }
  55.     /**
  56.      * @Route("/{slug}", name="attribute_group_index", methods={"GET","POST"})
  57.      */
  58.     public function index(string $slugRequest $requestFoxentryUtil $foxentryUtilPaginatorInterface $paginator): Response
  59.     {
  60.         $attributeGroup $this->attributeUtil->getAttributeGroupByIdentifier($slug);
  61.         if (!$attributeGroup instanceof AttributeGroup) {
  62.             throw $this->createNotFoundException('Group not found');
  63.         }
  64.         $form $this->createForm(CourseFilterType::class, null);
  65.         $form->handleRequest($request);
  66.         /** @var SearchFormDto $filterData */
  67.         $filterData $form->getData();
  68.         if(!$filterData instanceof SearchFormDto) {
  69.             $filterData = new SearchFormDto();
  70.         }
  71.         $locationsResult = [];
  72.         if ($form->isSubmitted() && !empty($filterData->getLocation())) {
  73.             $locationsResult $foxentryUtil->getSearchResults($filterData->getLocation());
  74.             if (is_array($locationsResult) && count($locationsResult) > 1) {
  75.                 $filterData->setLocation(null);
  76.             }
  77.         }
  78.         if ($locationsResult instanceof City) {
  79.             $locationsResult = [];
  80.         }
  81.         $filterData->setAttributes($attributeGroup->getAttributes()->toArray());
  82.         $submenuGroups $this->attributeUtil->getSubmenuByAttributeGroup($attributeGroup);
  83.         $pagination $paginator->paginate(
  84.             $this->courseUtil->searchCourses($filterData), /* query NOT result */
  85.             $request->query->getInt('page'1), /*page number*/
  86.             20
  87.         /*limit per page*/
  88.         );
  89.         return $this->render('attributeGroup/index.html.twig', [
  90.             'attributeGroup' => $attributeGroup,
  91.             'submenuGroups' => $submenuGroups,
  92.             'form' => $form->createView(),
  93.             'showMap'=>$form->isSubmitted(),
  94.             'courses' => $pagination,
  95.             'locations' => $locationsResult
  96.         ]);
  97.     }
  98.     /**
  99.      * @Route("/{slug}/{attributeSlug}", name="attribute_group_attr_index", methods={"GET","POST"})
  100.      */
  101.     public function attributeGroupSub(string $slugstring $attributeSlugRequest $requestFoxentryUtil $foxentryUtil): Response
  102.     {
  103.         $attributeGroup $this->attributeUtil->getAttributeGroupByIdentifier($slug);
  104.         if (!$attributeGroup instanceof AttributeGroup) {
  105.             throw $this->createNotFoundException('Group not found');
  106.         }
  107.         $attribute $this->attributeUtil->getAttributeByIdentifier($attributeSlug);
  108.         if (!$attribute instanceof Attribute) {
  109.             throw $this->createNotFoundException('Attribute not found');
  110.         }
  111.         $form $this->createForm(CourseFilterType::class, null);
  112.         $form->handleRequest($request);
  113.         /** @var SearchFormDto $filterData */
  114.         $filterData $form->getData();
  115.         if(!$filterData instanceof SearchFormDto) {
  116.             $filterData = new SearchFormDto();
  117.         }
  118.         $locationsResult = [];
  119.         if ($form->isSubmitted() && !empty($filterData->getLocation())) {
  120.             $locationsResult $foxentryUtil->getSearchResults($filterData->getLocation());
  121.             if (is_array($locationsResult) && count($locationsResult) > 1) {
  122.                 $filterData->setLocation(null);
  123.             }
  124.         }
  125.         if ($locationsResult instanceof City) {
  126.             $locationsResult = [];
  127.         }
  128.         $filterData->setAttributes([$attribute]);
  129.         $submenuGroups $this->attributeUtil->getSubmenuByAttributeGroup($attributeGroup);
  130.         return $this->render('attributeGroup/index.html.twig', [
  131.             'attributeGroup' => $attributeGroup,
  132.             'attribute' => $attribute,
  133.             'submenuGroups' => $submenuGroups,
  134.             'form' => $form->createView(),
  135.             'courses' => $this->courseUtil->searchCourses($filterData),
  136.             'locations' => $locationsResult
  137.         ]);
  138.     }
  139. }