From 74340d1388d3827627df9ed894ade81ef1a56748 Mon Sep 17 00:00:00 2001 From: Aleku22 Date: Mon, 31 Oct 2016 15:12:07 +0100 Subject: [PATCH 1/3] =?UTF-8?q?-=20FAQ=20=E2=80=93=20seznam=20ot=C3=A1zek?= =?UTF-8?q?=20a=20odpovedi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Resources/views/faq/faq.html.twig | 20 ++++++ app/config/services.yml | 15 +++- src/AppBundle/Controller/FaqController.php | 33 +++++++++ src/AppBundle/Entity/Faq.php | 81 ++++++++++++++++++++++ src/AppBundle/Facade/FaqFacade.php | 22 ++++++ src/AppBundle/Repository/FaqRepository.php | 9 +++ 6 files changed, 179 insertions(+), 1 deletion(-) create mode 100644 app/Resources/views/faq/faq.html.twig create mode 100644 src/AppBundle/Controller/FaqController.php create mode 100644 src/AppBundle/Entity/Faq.php create mode 100644 src/AppBundle/Facade/FaqFacade.php create mode 100644 src/AppBundle/Repository/FaqRepository.php diff --git a/app/Resources/views/faq/faq.html.twig b/app/Resources/views/faq/faq.html.twig new file mode 100644 index 0000000..3bc1a33 --- /dev/null +++ b/app/Resources/views/faq/faq.html.twig @@ -0,0 +1,20 @@ +{% extends 'base.html.twig' %} + +{% block body %} +
+ {% for f in faq %} +
+ +
+
+ {{ f.reply }} +
+
+
+ {% endfor %} +
+{% endblock %} diff --git a/app/config/services.yml b/app/config/services.yml index 59f9fb4..54eb1ef 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 @@ -31,7 +35,11 @@ services: app.facade.user_facade: 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..b940db5 --- /dev/null +++ b/src/AppBundle/Controller/FaqController.php @@ -0,0 +1,33 @@ +faqFacade = $faqFacade; + } + + /** + * @Route("/", name="faq") + * @Template("faq/faq.html.twig") + */ + public function faqAction() { + $faq = $this->faqFacade->getAll(); + return [ + 'faq' => $faq + ]; + } + +} diff --git a/src/AppBundle/Entity/Faq.php b/src/AppBundle/Entity/Faq.php new file mode 100644 index 0000000..6cc26b0 --- /dev/null +++ b/src/AppBundle/Entity/Faq.php @@ -0,0 +1,81 @@ +id; + } + + /** + * @param int $id + * @return self + */ + public function setId($id) { + $this->id = $id; + return $this; + } + + /** + * @return string + */ + public function getQuestion() { + return $this->question; + } + + /** + * @param string $question + * @return self + */ + public function setQuestion($question) { + $this->question = $question; + return $this; + } + + /** + * @return string + */ + public function getReply() { + return $this->reply; + } + + /** + * @param string $reply + * @return self + */ + public function setReply($reply) { + $this->reply = $reply; + return $this; + } + +} diff --git a/src/AppBundle/Facade/FaqFacade.php b/src/AppBundle/Facade/FaqFacade.php new file mode 100644 index 0000000..87bf4a6 --- /dev/null +++ b/src/AppBundle/Facade/FaqFacade.php @@ -0,0 +1,22 @@ +faqRepository = $faqRepository; + } + + public function getAll() { + return $this->faqRepository->findAll(); + } + +} diff --git a/src/AppBundle/Repository/FaqRepository.php b/src/AppBundle/Repository/FaqRepository.php new file mode 100644 index 0000000..4f571c7 --- /dev/null +++ b/src/AppBundle/Repository/FaqRepository.php @@ -0,0 +1,9 @@ + Date: Mon, 31 Oct 2016 16:21:41 +0100 Subject: [PATCH 2/3] - kontaktni formular --- app/Resources/views/contact/contact.html.twig | 12 ++ app/config/services.yml | 13 ++ .../Controller/ContactController.php | 55 ++++++++ src/AppBundle/Entity/Contact.php | 124 ++++++++++++++++++ src/AppBundle/Facade/ContactFacade.php | 18 +++ src/AppBundle/FormType/ContactFormType.php | 50 +++++++ .../Repository/ContactRepository.php | 9 ++ 7 files changed, 281 insertions(+) create mode 100644 app/Resources/views/contact/contact.html.twig create mode 100644 src/AppBundle/Controller/ContactController.php create mode 100644 src/AppBundle/Entity/Contact.php create mode 100644 src/AppBundle/Facade/ContactFacade.php create mode 100644 src/AppBundle/FormType/ContactFormType.php create mode 100644 src/AppBundle/Repository/ContactRepository.php diff --git a/app/Resources/views/contact/contact.html.twig b/app/Resources/views/contact/contact.html.twig new file mode 100644 index 0000000..27091ef --- /dev/null +++ b/app/Resources/views/contact/contact.html.twig @@ -0,0 +1,12 @@ +{% extends 'base.html.twig' %} + +{% block body %} + {{ form_start(form) }} + {{ form_row(form.firstName) }} + {{ form_row(form.surname) }} + {{ form_row(form.email) }} + {{ form_row(form.query) }} +
+ + {{ form_end(form) }} +{% endblock %} \ No newline at end of file diff --git a/app/config/services.yml b/app/config/services.yml index 54eb1ef..38ef124 100644 --- a/app/config/services.yml +++ b/app/config/services.yml @@ -24,6 +24,10 @@ services: class: AppBundle\Controller\FaqController autowire: true + app.controller.contact_controller: + class: AppBundle\Controller\ContactController + autowire: true + app.facade.category_facade: class: AppBundle\Facade\CategoryFacade autowire: true @@ -40,6 +44,10 @@ services: class: AppBundle\Facade\FaqFacade autowire: true + app.facade.faq_facade: + class: AppBundle\Facade\ContactFacade + autowire: true + app.repository.category_repository: class: AppBundle\Repository\CategoryRepository factory: ['@doctrine.orm.default_entity_manager', getRepository] @@ -55,6 +63,11 @@ services: factory: ['@doctrine.orm.default_entity_manager', getRepository] arguments: ['AppBundle\Entity\Faq'] + app.repository.contact_repository: + class: AppBundle\Repository\ContactRepository + factory: ['@doctrine.orm.default_entity_manager', getRepository] + arguments: ['AppBundle\Entity\Contact'] + encoder: class: Symfony\Component\Security\Core\Encoder\BCryptPasswordEncoder arguments: diff --git a/src/AppBundle/Controller/ContactController.php b/src/AppBundle/Controller/ContactController.php new file mode 100644 index 0000000..6d7d187 --- /dev/null +++ b/src/AppBundle/Controller/ContactController.php @@ -0,0 +1,55 @@ +contactFacade = $contactFacade; + $this->formFactory = $formFactory; + $this->entityManager = $entityManager; + } + + /** + * @Route("/", name="contact") + * @Template("contact/contact.html.twig") + * + * @param Request $request + * @return array + */ + public function contactAction(Request $request) { + $contact = new Contact(); + $form = $this->formFactory->create(ContactFormType::class, $contact); + + $form->handleRequest($request); + if ($form->isSubmitted() && $form->isValid()) { + $this->entityManager->persist($contact); + $this->entityManager->flush([$contact]); + } + + return [ + "form" => $form->createView(), + ]; + } + +} diff --git a/src/AppBundle/Entity/Contact.php b/src/AppBundle/Entity/Contact.php new file mode 100644 index 0000000..dd129d2 --- /dev/null +++ b/src/AppBundle/Entity/Contact.php @@ -0,0 +1,124 @@ +id; + } + + /** + * @param int $id + * @return self + */ + public function setId($id) { + $this->id = $id; + return $this; + } + + /** + * @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 getFirstName() { + return $this->firstName; + } + + /** + * @param string $firstName + * @return self + */ + public function setFirstName($firstName) { + $this->firstName = $firstName; + return $this; + } + + /** + * @return string + */ + public function getSurname() { + return $this->surname; + } + + /** + * @param string $surname + * @return self + */ + public function setSurname($surname) { + $this->surname = $surname; + return $this; + } + + /** + * @return string + */ + public function getQuery() { + return $this->query; + } + + /** + * @param string $query + * @return self + */ + public function setQuery($query) { + $this->query = $query; + return $this; + } +} diff --git a/src/AppBundle/Facade/ContactFacade.php b/src/AppBundle/Facade/ContactFacade.php new file mode 100644 index 0000000..f962f6c --- /dev/null +++ b/src/AppBundle/Facade/ContactFacade.php @@ -0,0 +1,18 @@ +contactRepository = $contactRepository; + } + +} diff --git a/src/AppBundle/FormType/ContactFormType.php b/src/AppBundle/FormType/ContactFormType.php new file mode 100644 index 0000000..7dfc87a --- /dev/null +++ b/src/AppBundle/FormType/ContactFormType.php @@ -0,0 +1,50 @@ +add("email", EmailType::class, [ + "label" => "E-mail", + "attr" => [ + "class" => "form-control", + ], + ])->add("firstName", TextType::class, [ + "label" => "Jméno", + "attr" => [ + "class" => "form-control", + ], + "constraints" => [ + new NotBlank(["message" => "Prosím vyplňte Vaše jméno"]), + ] + ])->add("surname", TextType::class, [ + "label" => "Příjmení", + "attr" => [ + "class" => "form-control", + ], + "constraints" => [ + new NotBlank(["message" => "Prosím vyplňte Vaše příjmení"]), + ] + ])->add("query", TextType::class, [ + "label" => "Dotaz", + "attr" => [ + "class" => "form-control", + ], + "constraints" => [ + new NotBlank(["message" => "Prosím vyplňte Váš dotaz"]), + ] + ]); + } +} \ No newline at end of file diff --git a/src/AppBundle/Repository/ContactRepository.php b/src/AppBundle/Repository/ContactRepository.php new file mode 100644 index 0000000..aeda507 --- /dev/null +++ b/src/AppBundle/Repository/ContactRepository.php @@ -0,0 +1,9 @@ + Date: Mon, 31 Oct 2016 16:42:48 +0100 Subject: [PATCH 3/3] - oprava route u action --- src/AppBundle/Controller/ContactController.php | 2 +- src/AppBundle/Controller/FaqController.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/AppBundle/Controller/ContactController.php b/src/AppBundle/Controller/ContactController.php index 6d7d187..a37410d 100644 --- a/src/AppBundle/Controller/ContactController.php +++ b/src/AppBundle/Controller/ContactController.php @@ -31,7 +31,7 @@ public function __construct(ContactFacade $contactFacade, FormFactory $formFacto } /** - * @Route("/", name="contact") + * @Route("/contact", name="contact") * @Template("contact/contact.html.twig") * * @param Request $request diff --git a/src/AppBundle/Controller/FaqController.php b/src/AppBundle/Controller/FaqController.php index b940db5..7879afa 100644 --- a/src/AppBundle/Controller/FaqController.php +++ b/src/AppBundle/Controller/FaqController.php @@ -20,7 +20,7 @@ public function __construct(FaqFacade $faqFacade) { } /** - * @Route("/", name="faq") + * @Route("/faq", name="faq") * @Template("faq/faq.html.twig") */ public function faqAction() {