diff --git a/app/Resources/views/base.html.twig b/app/Resources/views/base.html.twig index 4f5d87e..7f2ade8 100644 --- a/app/Resources/views/base.html.twig +++ b/app/Resources/views/base.html.twig @@ -46,6 +46,9 @@
  • Domů
  • +
  • + Faq +
  • {{ product.price }} Kč

    -

    {{ product.title }}

    diff --git a/app/Resources/views/components/list_faq.html.twig b/app/Resources/views/components/list_faq.html.twig new file mode 100644 index 0000000..9420b89 --- /dev/null +++ b/app/Resources/views/components/list_faq.html.twig @@ -0,0 +1,7 @@ +
    + +
    \ No newline at end of file diff --git a/app/Resources/views/components/paginator.html.twig b/app/Resources/views/components/paginator.html.twig index 99220f0..563d19f 100644 --- a/app/Resources/views/components/paginator.html.twig +++ b/app/Resources/views/components/paginator.html.twig @@ -18,4 +18,4 @@ {% endif %} - \ No newline at end of file + diff --git a/app/Resources/views/faq/list.html.twig b/app/Resources/views/faq/list.html.twig new file mode 100644 index 0000000..23aa487 --- /dev/null +++ b/app/Resources/views/faq/list.html.twig @@ -0,0 +1,17 @@ +{% extends 'base.html.twig' %} + +{% block body %} +

    Faq - Časté dotazy

    + + {{ form_start(form) }} + {{ form_row(form.email) }} + {{ form_row(form.question) }} +
    + + {{ form_end(form) }} + +
    + {% include 'components/list_faq.html.twig' %} +
    + {% include ":components:paginator.html.twig" %} +{% endblock %} \ No newline at end of file diff --git a/app/config/services.yml b/app/config/services.yml index 59f9fb4..f8d1c5c 100644 --- a/app/config/services.yml +++ b/app/config/services.yml @@ -20,6 +20,10 @@ services: class: AppBundle\Controller\UserController autowire: true + app.controller.faq_controller: + class: AppBundle\Controller\FaqController + autowire: true + app.facade.category_facade: class: AppBundle\Facade\CategoryFacade autowire: true @@ -32,6 +36,10 @@ services: class: AppBundle\Facade\UserFacade autowire: true + app.facade.faq_facade: + class: AppBundle\Facade\FaqFacade + autowire: true + app.repository.category_repository: class: AppBundle\Repository\CategoryRepository factory: ['@doctrine.orm.default_entity_manager', getRepository] @@ -42,6 +50,11 @@ services: factory: ['@doctrine.orm.default_entity_manager', getRepository] arguments: ['AppBundle\Entity\Product'] + app.repository.faq_repository: + class: AppBundle\Repository\FaqRepository + factory: ['@doctrine.orm.default_entity_manager', getRepository] + arguments: ['AppBundle\Entity\Faq'] + encoder: class: Symfony\Component\Security\Core\Encoder\BCryptPasswordEncoder arguments: diff --git a/src/AppBundle/Controller/FaqController.php b/src/AppBundle/Controller/FaqController.php new file mode 100644 index 0000000..ed0755e --- /dev/null +++ b/src/AppBundle/Controller/FaqController.php @@ -0,0 +1,80 @@ + + * @author Jan Klat + * @Route(service="app.controller.faq_controller") + */ +class FaqController +{ + private $faqFacade; + private $entityManager; + private $formFactory; + private $router; + + public function __construct( + FaqFacade $faqFacade, + FormFactory $formFactory, + RouterInterface $router, + EntityManager $entityManager + ) { + $this->faqFacade = $faqFacade; + $this->entityManager = $entityManager; + $this->formFactory = $formFactory; + $this->router = $router; + } + /** + * @Route("/faq", name="faq_list") + * @Template("faq/list.html.twig") + * + * @param Request $request + * @return RedirectResponse|array + */ + public function listAction(Request $request) + { + if(!$page = $request->query->get("page")){ + $page = 1; + } + + + $faq = new Faq(); + $form = $this->formFactory->create(FaqFormType::class, $faq); + + $form->handleRequest($request); + if ($form->isSubmitted() && $form->isValid()) { + + $this->entityManager->persist($faq); + $this->entityManager->flush([$faq]); + + return RedirectResponse::create($this->router->generate("faq_list")); + } + + $countByFaq = $this->faqFacade->countAll(); + $paginator = new Paginator($countByFaq, 10); + $paginator->setCurrentPage($page); + + return [ + "faqs" => $this->faqFacade->getAll($paginator->getLimit(), $paginator->getOffset()), + "form" => $form->createView(), + "currentPage" => $page, + "totalPages" => $paginator->getTotalPageCount(), + "pageRange" => $paginator->getPageRange(5), + ]; + } + +} diff --git a/src/AppBundle/Entity/Faq.php b/src/AppBundle/Entity/Faq.php new file mode 100644 index 0000000..4deefb7 --- /dev/null +++ b/src/AppBundle/Entity/Faq.php @@ -0,0 +1,82 @@ + + * @author Jan Klat + * + * @ORM\Entity(repositoryClass="AppBundle\Repository\FaqRepository") + */ +class Faq +{ + + /** + * @var int + * @ORM\Id + * @ORM\GeneratedValue + * @ORM\Column(type="integer") + */ + private $id; + + /** + * @ORM\Column(type="string", length=255, name="email") + * @Assert\NotBlank() + * @Assert\Email() + */ + private $email; + + /** + * @var string + * @ORM\Column(type="text", length=255) + */ + private $question; + + /** + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * @return string + */ + public function getEmail() + { + return $this->email; + } + + /** + * @param string $email + * @return self + */ + public function setEmail($email) + { + $this->email = $email; + return $this; + } + + /** + * @return string + */ + public function getQuestion() + { + return $this->question; + } + + /** + * @param string $description + * @return self + */ + public function setQuestion($question) + { + $this->question = $question; + return $this; + } +} \ No newline at end of file diff --git a/src/AppBundle/Facade/FaqFacade.php b/src/AppBundle/Facade/FaqFacade.php new file mode 100644 index 0000000..e271bdb --- /dev/null +++ b/src/AppBundle/Facade/FaqFacade.php @@ -0,0 +1,34 @@ + + * @author Jan Klat + */ +class FaqFacade { + + private $faqRepository; + + public function __construct(FaqRepository $faqRepository) { + $this->faqRepository = $faqRepository; + } + + public function getAll($limit, $offset) { + return $this->faqRepository->findBy( + [], + [ + "id" => "desc" + ], + $limit, + $offset + ); + } + + public function countAll() { + return $this->faqRepository->countAll(); + } +} \ No newline at end of file diff --git a/src/AppBundle/FormType/FaqFormType.php b/src/AppBundle/FormType/FaqFormType.php new file mode 100644 index 0000000..194b257 --- /dev/null +++ b/src/AppBundle/FormType/FaqFormType.php @@ -0,0 +1,45 @@ + + * @author Jan Klat + */ +class FaqFormType extends AbstractType +{ + public function buildForm(FormBuilderInterface $builder, array $options) + { + $builder + ->add("email", EmailType::class, [ + "label" => "E-mail", + "attr" => [ + "class" => "form-control", + ], + ])->add("question", TextareaType::class, [ + "label" => "Question", + "attr" => [ + "class" => "form-control", + ], + "constraints" => [ + new NotBlank(["message" => "Prosím vyplňte Váš dotaz"]), + ], + ]); + } + + public function configureOptions(OptionsResolver $resolver) + { + + $resolver->setDefaults(array( + "data_class" => Faq::class, + )); + + } +} \ No newline at end of file diff --git a/src/AppBundle/Repository/FaqRepository.php b/src/AppBundle/Repository/FaqRepository.php new file mode 100644 index 0000000..76f08d4 --- /dev/null +++ b/src/AppBundle/Repository/FaqRepository.php @@ -0,0 +1,32 @@ + + * @author Jan Klat + */ +class FaqRepository extends EntityRepository +{ + /** + * @param Faq $faq + * @return QueryBuilder + */ + public function findByFaq(Faq $faq) + { + $builder = $this->_em->createQueryBuilder() + ->select('f') + ->from('AppBundle\Entity\Faq', 'f'); + return $builder; + } + + public function countAll() { + return $this->_em->createQueryBuilder() + ->select('COUNT(f.id)') + ->from('AppBundle\Entity\Faq', 'f') + ->getQuery()->getSingleScalarResult(); + } +} diff --git a/web/config.php b/web/config.php index 1368c8a..a031a3a 100644 --- a/web/config.php +++ b/web/config.php @@ -38,9 +38,216 @@ Symfony Configuration Checker - - -