From 958aa913be34549f48464f1322c5c0c370188af8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vojt=C4=9Bch=20Barto=C5=A1?= Date: Sat, 29 Oct 2016 17:31:43 +0200 Subject: [PATCH 1/5] Add FAQ list --- app/Resources/views/base.html.twig | 3 + app/Resources/views/faq/faq.html.twig | 12 +++ app/config/services.yml | 22 ++++++ src/AppBundle/Controller/FaqController.php | 46 ++++++++++++ src/AppBundle/Entity/Answer.php | 73 +++++++++++++++++++ src/AppBundle/Entity/Question.php | 51 +++++++++++++ src/AppBundle/Facade/AnswerFacade.php | 51 +++++++++++++ src/AppBundle/Facade/QuestionFacade.php | 28 +++++++ src/AppBundle/Repository/AnswerRepository.php | 21 ++++++ .../Repository/QuestionRepository.php | 9 +++ 10 files changed, 316 insertions(+) create mode 100644 app/Resources/views/faq/faq.html.twig create mode 100644 src/AppBundle/Controller/FaqController.php create mode 100644 src/AppBundle/Entity/Answer.php create mode 100644 src/AppBundle/Entity/Question.php create mode 100644 src/AppBundle/Facade/AnswerFacade.php create mode 100644 src/AppBundle/Facade/QuestionFacade.php create mode 100644 src/AppBundle/Repository/AnswerRepository.php create mode 100644 src/AppBundle/Repository/QuestionRepository.php diff --git a/app/Resources/views/base.html.twig b/app/Resources/views/base.html.twig index 4f5d87e..14cc99c 100644 --- a/app/Resources/views/base.html.twig +++ b/app/Resources/views/base.html.twig @@ -46,6 +46,9 @@
  • Domů
  • +
  • + FAQ +
  • +

    {{ question.text }}

    + + {{ answers[question.id].text }} +
    + {% endfor %} +{% endblock %} + diff --git a/app/config/services.yml b/app/config/services.yml index 59f9fb4..e1653e4 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,14 @@ services: class: AppBundle\Facade\UserFacade autowire: true + app.facade.answer_facade: + class: AppBundle\Facade\AnswerFacade + autowire: true + + app.facade.question_facade: + class: AppBundle\Facade\QuestionFacade + autowire: true + app.repository.category_repository: class: AppBundle\Repository\CategoryRepository factory: ['@doctrine.orm.default_entity_manager', getRepository] @@ -42,6 +54,16 @@ services: factory: ['@doctrine.orm.default_entity_manager', getRepository] arguments: ['AppBundle\Entity\Product'] + app.repository.answer_repository: + class: AppBundle\Repository\AnswerRepository + factory: ['@doctrine.orm.default_entity_manager', getRepository] + arguments: ['AppBundle\Entity\Answer'] + + app.repository.question_repository: + class: AppBundle\Repository\QuestionRepository + factory: ['@doctrine.orm.default_entity_manager', getRepository] + arguments: ['AppBundle\Entity\Question'] + 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..7c17f2f --- /dev/null +++ b/src/AppBundle/Controller/FaqController.php @@ -0,0 +1,46 @@ +questionFacade = $questionFacade; + $this->answerFacade = $answerFacade; + } + + /** + * @Route("/faq", name="faq") + * @Template("faq/faq.html.twig") + */ + public function faqAction(Request $request) + { + $questions = $this->questionFacade->findAll(); + $answers = $this->answerFacade->findByQuestions($questions); + + return [ + "questions" => $questions, + "answers" => $answers, + ]; + } +} \ No newline at end of file diff --git a/src/AppBundle/Entity/Answer.php b/src/AppBundle/Entity/Answer.php new file mode 100644 index 0000000..29c2a1f --- /dev/null +++ b/src/AppBundle/Entity/Answer.php @@ -0,0 +1,73 @@ +id; + } + + /** + * @return Question + */ + public function getQuestion() : Question + { + return $this->question; + } + + /** + * @param Question $question + */ + public function setQuestion(Question $question) + { + $this->question = $question; + } + + /** + * @return string + */ + public function getText() : string + { + return $this->text; + } + + /** + * @param string $text + */ + public function setText(string $text) + { + $this->text = $text; + } +} \ No newline at end of file diff --git a/src/AppBundle/Entity/Question.php b/src/AppBundle/Entity/Question.php new file mode 100644 index 0000000..f3b5d9d --- /dev/null +++ b/src/AppBundle/Entity/Question.php @@ -0,0 +1,51 @@ +id; + } + + /** + * @return string + */ + public function getText() : string + { + return $this->text; + } + + /** + * @param string $text + */ + public function setText(string $text) + { + $this->text = $text; + } +} \ No newline at end of file diff --git a/src/AppBundle/Facade/AnswerFacade.php b/src/AppBundle/Facade/AnswerFacade.php new file mode 100644 index 0000000..628a89b --- /dev/null +++ b/src/AppBundle/Facade/AnswerFacade.php @@ -0,0 +1,51 @@ +answerRepository = $answerRepository; + } + + /** + * @param Question $question + * @return Answer|null + */ + public function findByQuestion(Question $question) + { + return $this->answerRepository->findOneBy([ + "question" => $question, + ]); + } + + /** + * @param Question[] $questions + * @return Answer[]|null + */ + public function findByQuestions($questions) + { + /** @var Answer[] $answers */ + $answers = $this->answerRepository->findBy([ + "question" => $questions, + ]); + + $result = []; + foreach ($answers as $answer) { + $result[$answer->getQuestion()->getId()] = $answer; + } + + return $result; + } +} \ No newline at end of file diff --git a/src/AppBundle/Facade/QuestionFacade.php b/src/AppBundle/Facade/QuestionFacade.php new file mode 100644 index 0000000..b44701e --- /dev/null +++ b/src/AppBundle/Facade/QuestionFacade.php @@ -0,0 +1,28 @@ +questionRepository = $questionRepository; + } + + /** + * @return Question[] + */ + public function findAll() + { + return $this->questionRepository->findAll(); + } +} \ No newline at end of file diff --git a/src/AppBundle/Repository/AnswerRepository.php b/src/AppBundle/Repository/AnswerRepository.php new file mode 100644 index 0000000..76118cd --- /dev/null +++ b/src/AppBundle/Repository/AnswerRepository.php @@ -0,0 +1,21 @@ +_em->createQueryBuilder() + ->select('*') + ->from(Answer::class, 'a') + ->where('a.question = :question') + ->setParameter("question", $question) + ->getQuery() + ->getResult(); + } +} \ No newline at end of file diff --git a/src/AppBundle/Repository/QuestionRepository.php b/src/AppBundle/Repository/QuestionRepository.php new file mode 100644 index 0000000..f95054f --- /dev/null +++ b/src/AppBundle/Repository/QuestionRepository.php @@ -0,0 +1,9 @@ + Date: Sat, 29 Oct 2016 17:59:51 +0200 Subject: [PATCH 2/5] Add contact form --- app/Resources/views/base.html.twig | 3 + app/Resources/views/contact/contact.html.twig | 11 +++ app/config/services.yml | 8 ++ .../Controller/ContactController.php | 52 +++++++++++++ src/AppBundle/Entity/Message.php | 74 +++++++++++++++++++ src/AppBundle/Facade/MessageFacade.php | 35 +++++++++ src/AppBundle/FormType/ContactFormType.php | 33 +++++++++ src/AppBundle/FormType/VO/MessageVO.php | 44 +++++++++++ 8 files changed, 260 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/Message.php create mode 100644 src/AppBundle/Facade/MessageFacade.php create mode 100644 src/AppBundle/FormType/ContactFormType.php create mode 100644 src/AppBundle/FormType/VO/MessageVO.php diff --git a/app/Resources/views/base.html.twig b/app/Resources/views/base.html.twig index 14cc99c..f0ba10b 100644 --- a/app/Resources/views/base.html.twig +++ b/app/Resources/views/base.html.twig @@ -49,6 +49,9 @@
  • FAQ
  • +
  • + Kontakt +
  • +

    {{ question.text }} Upravit

    + + {{ answers[question.id].text }} +
    + {% endfor %} +{% endblock %} + diff --git a/app/config/security.yml b/app/config/security.yml index 82c6691..35297d9 100644 --- a/app/config/security.yml +++ b/app/config/security.yml @@ -1,10 +1,22 @@ security: + role_hierarchy: + ROLE_ADMIN: ROLE_USER + encoders: + Symfony\Component\Security\Core\User\User: plaintext AppBundle\Entity\User: algorithm: bcrypt cost: 13 #cost is 13 by default, just so you know why and how to set it providers: + chain_provider: + chain: + providers: [in_memory, database_users] + in_memory: + memory: + users: + - { name: admin@shop.cz, password: admin, roles: 'ROLE_ADMIN' } + database_users: entity: { class: AppBundle:User, property: username } @@ -24,4 +36,6 @@ security: # The route name the user can go to in order to logout path: user_logout # The name of the route to redirect to after logging out - target: homepage \ No newline at end of file + target: homepage + access_control: + - { path: ^/faq/, roles: ROLE_ADMIN } \ No newline at end of file diff --git a/app/config/services.yml b/app/config/services.yml index 9a346b5..06903a8 100644 --- a/app/config/services.yml +++ b/app/config/services.yml @@ -52,6 +52,10 @@ services: class: AppBundle\Facade\MessageFacade 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] diff --git a/src/AppBundle/Controller/FaqController.php b/src/AppBundle/Controller/FaqController.php index 7c17f2f..aff8bab 100644 --- a/src/AppBundle/Controller/FaqController.php +++ b/src/AppBundle/Controller/FaqController.php @@ -3,9 +3,13 @@ namespace AppBundle\Controller; use AppBundle\Facade\AnswerFacade; +use AppBundle\Facade\FaqFacade; use AppBundle\Facade\QuestionFacade; +use AppBundle\FormType\FaqFormType; +use AppBundle\FormType\VO\FaqVO; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; +use Symfony\Component\Form\FormFactory; use Symfony\Component\HttpFoundation\Request; /** @@ -13,20 +17,30 @@ */ class FaqController { + /** @var FormFactory */ + private $formFactory; + /** @var QuestionFacade */ private $questionFacade; /** @var AnswerFacade */ private $answerFacade; + /** @var FaqFacade */ + private $faqFacade; + /** + * @param FormFactory $formFactory * @param QuestionFacade $questionFacade * @param AnswerFacade $answerFacade + * @param FaqFacade $faqFacade */ - public function __construct(QuestionFacade $questionFacade, AnswerFacade $answerFacade) + public function __construct(FormFactory $formFactory, QuestionFacade $questionFacade, AnswerFacade $answerFacade, FaqFacade $faqFacade) { + $this->formFactory = $formFactory; $this->questionFacade = $questionFacade; $this->answerFacade = $answerFacade; + $this->faqFacade = $faqFacade; } /** @@ -43,4 +57,65 @@ public function faqAction(Request $request) "answers" => $answers, ]; } + + /** + * @Route("/faq/list", name="faq_list") + * @Template("faq/list.html.twig") + */ + public function listAction() + { + $questions = $this->questionFacade->findAll(); + $answers = $this->answerFacade->findByQuestions($questions); + + return [ + "questions" => $questions, + "answers" => $answers, + ]; + } + + /** + * @Route("/faq/add", name="faq_add") + * @Template("faq/add.html.twig") + * @param Request $request + * @return array + */ + public function addAction(Request $request) + { + $faqVO = new FaqVO(); + $form = $this->formFactory->create(FaqFormType::class, $faqVO); + + $form->handleRequest($request); + if ($form->isSubmitted() && $form->isValid()) { + $this->faqFacade->insert($faqVO); + } + + return [ + "form" => $form->createView() + ]; + } + + /** + * @Route("/faq/edit/{id}", name="faq_edit", requirements={"id": "\d+"}) + * @Template("faq/edit.html.twig") + * @param int $id + * @param Request $request + * @return array + */ + public function editAction($id, Request $request) + { + $question = $this->questionFacade->findById($id); + $answer = $this->answerFacade->findByQuestion($question); + + $faqVO = FaqVO::fromEntity($question, $answer); + $form = $this->formFactory->create(FaqFormType::class, $faqVO); + + $form->handleRequest($request); + if ($form->isSubmitted() && $form->isValid()) { + $this->faqFacade->update($question, $answer, $faqVO); + } + + return [ + "form" => $form->createView() + ]; + } } \ No newline at end of file diff --git a/src/AppBundle/Facade/AnswerFacade.php b/src/AppBundle/Facade/AnswerFacade.php index 628a89b..8555a27 100644 --- a/src/AppBundle/Facade/AnswerFacade.php +++ b/src/AppBundle/Facade/AnswerFacade.php @@ -5,18 +5,24 @@ use AppBundle\Entity\Answer; use AppBundle\Entity\Question; use AppBundle\Repository\AnswerRepository; +use Doctrine\ORM\EntityManager; class AnswerFacade { /** @var AnswerRepository */ private $answerRepository; + /** @var EntityManager */ + private $entityManager; + /** * @param AnswerRepository $answerRepository + * @param EntityManager $entityManager */ - public function __construct(AnswerRepository $answerRepository) + public function __construct(AnswerRepository $answerRepository, EntityManager $entityManager) { $this->answerRepository = $answerRepository; + $this->entityManager = $entityManager; } /** @@ -48,4 +54,13 @@ public function findByQuestions($questions) return $result; } + + /** + * @param Answer $answer + */ + public function save(Answer $answer) + { + $this->entityManager->persist($answer); + $this->entityManager->flush($answer); + } } \ 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..47cb79d --- /dev/null +++ b/src/AppBundle/Facade/FaqFacade.php @@ -0,0 +1,56 @@ +questionFacade = $questionFacade; + $this->answerFacade = $answerFacade; + } + + /** + * @param FaqVO $faqVO + */ + public function insert(FaqVO $faqVO) + { + $question = new Question(); + $answer = new Answer(); + $answer->setQuestion($question); + + $question->setText($faqVO->getQuestion()); + $answer->setText($faqVO->getAnswer()); + + $this->questionFacade->save($question); + $this->answerFacade->save($answer); + } + + /** + * @param Question $question + * @param Answer $answer + * @param FaqVO $faqVO + */ + public function update(Question $question, Answer $answer, FaqVO $faqVO) + { + $question->setText($faqVO->getQuestion()); + $answer->setText($faqVO->getAnswer()); + + $this->questionFacade->save($question); + $this->answerFacade->save($answer); + } +} \ No newline at end of file diff --git a/src/AppBundle/Facade/QuestionFacade.php b/src/AppBundle/Facade/QuestionFacade.php index b44701e..660095d 100644 --- a/src/AppBundle/Facade/QuestionFacade.php +++ b/src/AppBundle/Facade/QuestionFacade.php @@ -4,18 +4,34 @@ use AppBundle\Entity\Question; use AppBundle\Repository\QuestionRepository; +use Doctrine\ORM\EntityManager; class QuestionFacade { /** @var QuestionRepository */ private $questionRepository; + /** @var EntityManager */ + private $entityManager; + /** * @param QuestionRepository $questionRepository + * @param EntityManager $entityManager */ - public function __construct(QuestionRepository $questionRepository) + public function __construct(QuestionRepository $questionRepository, EntityManager $entityManager) { $this->questionRepository = $questionRepository; + $this->entityManager = $entityManager; + } + + /** + * @return Question + */ + public function findById($id) + { + return $this->questionRepository->findOneBy([ + 'id' => $id, + ]); } /** @@ -25,4 +41,13 @@ public function findAll() { return $this->questionRepository->findAll(); } + + /** + * @param Question $question + */ + public function save(Question $question) + { + $this->entityManager->persist($question); + $this->entityManager->flush($question); + } } \ 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..1dcb149 --- /dev/null +++ b/src/AppBundle/FormType/FaqFormType.php @@ -0,0 +1,32 @@ +add("question", TextareaType::class, [ + "label" => "Otázka", + "attr" => [ + "class" => "form-control", + ], + "constraints" => [ + new NotBlank(["message" => "Prosím napište text otázky."]), + ], + ])->add("answer", TextareaType::class, [ + "label" => "Odpověď", + "attr" => [ + "class" => "form-control", + ], + "constraints" => [ + new NotBlank(["message" => "Prosím napište text odpovědi."]), + ], + ]); + } +} \ No newline at end of file diff --git a/src/AppBundle/FormType/VO/FaqVO.php b/src/AppBundle/FormType/VO/FaqVO.php new file mode 100644 index 0000000..efed62b --- /dev/null +++ b/src/AppBundle/FormType/VO/FaqVO.php @@ -0,0 +1,61 @@ +question; + } + + /** + * @param null|string $question + */ + public function setQuestion($question) + { + $this->question = $question; + } + + /** + * @return null|string + */ + public function getAnswer() + { + return $this->answer; + } + + /** + * @param null|string $answer + */ + public function setAnswer($answer) + { + $this->answer = $answer; + } + + /** + * @param Question $question + * @param Answer $answer + * @return FaqVO + */ + public static function fromEntity(Question $question, Answer $answer) + { + $faqVO = new FaqVO(); + $faqVO->setQuestion($question->getText()); + $faqVO->setAnswer($answer->getText()); + + return $faqVO; + } +} \ No newline at end of file From 1220423eedd2c216f2b74e21875eb7208b12b0a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vojt=C4=9Bch=20Barto=C5=A1?= Date: Sun, 30 Oct 2016 00:46:25 +0200 Subject: [PATCH 4/5] Redirect after form submit --- src/AppBundle/Controller/ContactController.php | 11 ++++++++++- src/AppBundle/Controller/FaqController.php | 13 ++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/AppBundle/Controller/ContactController.php b/src/AppBundle/Controller/ContactController.php index 6b0d3ae..6862859 100644 --- a/src/AppBundle/Controller/ContactController.php +++ b/src/AppBundle/Controller/ContactController.php @@ -8,7 +8,9 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; use Symfony\Component\Form\FormFactory; +use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\Routing\RouterInterface; /** * @Route(service="app.controller.contact_controller") @@ -21,14 +23,19 @@ class ContactController /** @var MessageFacade */ private $messageFacade; + /** @var RouterInterface */ + private $router; + /** * @param FormFactory $formFactory * @param MessageFacade $messageFacade + * @param RouterInterface $router */ - public function __construct(FormFactory $formFactory, MessageFacade $messageFacade) + public function __construct(FormFactory $formFactory, MessageFacade $messageFacade, RouterInterface $router) { $this->formFactory = $formFactory; $this->messageFacade = $messageFacade; + $this->router = $router; } /** @@ -43,6 +50,8 @@ public function contactAction(Request $request) $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $this->messageFacade->save($messageVO); + + return RedirectResponse::create($this->router->generate("contact")); } return [ diff --git a/src/AppBundle/Controller/FaqController.php b/src/AppBundle/Controller/FaqController.php index aff8bab..7614ee3 100644 --- a/src/AppBundle/Controller/FaqController.php +++ b/src/AppBundle/Controller/FaqController.php @@ -10,7 +10,9 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; use Symfony\Component\Form\FormFactory; +use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\Routing\RouterInterface; /** * @Route(service="app.controller.faq_controller") @@ -29,18 +31,23 @@ class FaqController /** @var FaqFacade */ private $faqFacade; + /** @var RouterInterface */ + private $router; + /** * @param FormFactory $formFactory * @param QuestionFacade $questionFacade * @param AnswerFacade $answerFacade * @param FaqFacade $faqFacade + * @param RouterInterface $router */ - public function __construct(FormFactory $formFactory, QuestionFacade $questionFacade, AnswerFacade $answerFacade, FaqFacade $faqFacade) + public function __construct(FormFactory $formFactory, QuestionFacade $questionFacade, AnswerFacade $answerFacade, FaqFacade $faqFacade, RouterInterface $router) { $this->formFactory = $formFactory; $this->questionFacade = $questionFacade; $this->answerFacade = $answerFacade; $this->faqFacade = $faqFacade; + $this->router = $router; } /** @@ -87,6 +94,8 @@ public function addAction(Request $request) $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $this->faqFacade->insert($faqVO); + + return RedirectResponse::create($this->router->generate("faq_list")); } return [ @@ -112,6 +121,8 @@ public function editAction($id, Request $request) $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $this->faqFacade->update($question, $answer, $faqVO); + + return RedirectResponse::create($this->router->generate("faq_list")); } return [ From fcb4e1ad161286da694d0418333e5c7abe70d22a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vojt=C4=9Bch=20Barto=C5=A1?= Date: Sun, 30 Oct 2016 00:53:30 +0200 Subject: [PATCH 5/5] Add flash messages --- app/Resources/views/base.html.twig | 9 +++++++++ src/AppBundle/Controller/ContactController.php | 10 +++++++++- src/AppBundle/Controller/FaqController.php | 14 ++++++++++++-- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/app/Resources/views/base.html.twig b/app/Resources/views/base.html.twig index f0ba10b..08efa74 100644 --- a/app/Resources/views/base.html.twig +++ b/app/Resources/views/base.html.twig @@ -78,6 +78,15 @@
    + + {% for flash_message in app.session.flashBag.get('notice') %} + + +
    + {{ flash_message }} +
    + {% endfor %} + {% block body %} {% endblock %}
    diff --git a/src/AppBundle/Controller/ContactController.php b/src/AppBundle/Controller/ContactController.php index 6862859..4d341c0 100644 --- a/src/AppBundle/Controller/ContactController.php +++ b/src/AppBundle/Controller/ContactController.php @@ -10,6 +10,7 @@ use Symfony\Component\Form\FormFactory; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Session\Flash\FlashBag; use Symfony\Component\Routing\RouterInterface; /** @@ -26,16 +27,21 @@ class ContactController /** @var RouterInterface */ private $router; + /** @var FlashBag */ + private $flashBag; + /** * @param FormFactory $formFactory * @param MessageFacade $messageFacade * @param RouterInterface $router + * @param FlashBag $flashBag */ - public function __construct(FormFactory $formFactory, MessageFacade $messageFacade, RouterInterface $router) + public function __construct(FormFactory $formFactory, MessageFacade $messageFacade, RouterInterface $router, FlashBag $flashBag) { $this->formFactory = $formFactory; $this->messageFacade = $messageFacade; $this->router = $router; + $this->flashBag = $flashBag; } /** @@ -51,6 +57,8 @@ public function contactAction(Request $request) if ($form->isSubmitted() && $form->isValid()) { $this->messageFacade->save($messageVO); + $this->flashBag->add('notice', 'Message send.'); + return RedirectResponse::create($this->router->generate("contact")); } diff --git a/src/AppBundle/Controller/FaqController.php b/src/AppBundle/Controller/FaqController.php index 7614ee3..01e14c2 100644 --- a/src/AppBundle/Controller/FaqController.php +++ b/src/AppBundle/Controller/FaqController.php @@ -12,6 +12,7 @@ use Symfony\Component\Form\FormFactory; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Session\Flash\FlashBag; use Symfony\Component\Routing\RouterInterface; /** @@ -34,20 +35,25 @@ class FaqController /** @var RouterInterface */ private $router; + /** @var FlashBag */ + private $flashBag; + /** * @param FormFactory $formFactory * @param QuestionFacade $questionFacade * @param AnswerFacade $answerFacade * @param FaqFacade $faqFacade * @param RouterInterface $router + * @param FlashBag $flashBag */ - public function __construct(FormFactory $formFactory, QuestionFacade $questionFacade, AnswerFacade $answerFacade, FaqFacade $faqFacade, RouterInterface $router) + public function __construct(FormFactory $formFactory, QuestionFacade $questionFacade, AnswerFacade $answerFacade, FaqFacade $faqFacade, RouterInterface $router, FlashBag $flashBag) { $this->formFactory = $formFactory; $this->questionFacade = $questionFacade; $this->answerFacade = $answerFacade; $this->faqFacade = $faqFacade; $this->router = $router; + $this->flashBag = $flashBag; } /** @@ -95,6 +101,8 @@ public function addAction(Request $request) if ($form->isSubmitted() && $form->isValid()) { $this->faqFacade->insert($faqVO); + $this->flashBag->add('notice', 'Question added.'); + return RedirectResponse::create($this->router->generate("faq_list")); } @@ -122,6 +130,8 @@ public function editAction($id, Request $request) if ($form->isSubmitted() && $form->isValid()) { $this->faqFacade->update($question, $answer, $faqVO); + $this->flashBag->add('notice', 'Question uppdated.'); + return RedirectResponse::create($this->router->generate("faq_list")); } @@ -129,4 +139,4 @@ public function editAction($id, Request $request) "form" => $form->createView() ]; } -} \ No newline at end of file +}