Skip to content

Ukol 4 - Lukáš Vraný #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/Resources/views/base.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@
<li>
<a href="{{ path("homepage") }}">Domů</a>
</li>
<li>
<a href="{{ path("faq") }}">FAQ</a>
</li>
<li>
<a href="{{ path("contact") }}">Kontakty</a>
</li>
</ul>
<p class="navbar-text navbar-right">
{% if user is defined and user %}
Expand Down
12 changes: 12 additions & 0 deletions app/Resources/views/contact/contact.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% extends 'base.html.twig' %}

{% block body %}
{{ form_start(form) }}
{{ form_row(form.name) }}
{{ form_row(form.email) }}
{{ form_row(form.subject) }}
{{ form_row(form.msg) }}
<br />
<button class="btn btn-lg btn-primary btn-block" type="submit">Odeslat!</button>
{{ form_end(form) }}
{% endblock %}
13 changes: 13 additions & 0 deletions app/Resources/views/faq/faq.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% extends 'base.html.twig' %}

{% block body %}
{% if faqs is null or faqs is empty %}
<h2>Žádné zajímevé otázky a odpovědi</h2>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super, že myslíš i na tyto případy

{% else %}
{% for faq in faqs %}
<h2>{{ faq.question|raw }}</h2>
<p>{{ faq.answer|raw }}</p>
<hr>
{% endfor %}
{% endif %}
{% endblock %}
26 changes: 26 additions & 0 deletions app/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ services:
app.controller.user_controller:
class: AppBundle\Controller\UserController
autowire: true

app.controller.faq_controller:
class: AppBundle\Controller\FaqController
autowire: true

app.controller.contact_controller:
class: AppBundle\Controller\ContactController
autowire: true

app.facade.category_facade:
class: AppBundle\Facade\CategoryFacade
Expand All @@ -31,11 +39,29 @@ services:
app.facade.user_facade:
class: AppBundle\Facade\UserFacade
autowire: true

app.facade.faq_facade:
class: AppBundle\Facade\FaqFacade
autowire: true

app.facade.contact_facade:
class: AppBundle\Facade\ContactFacade
autowire: true

app.repository.category_repository:
class: AppBundle\Repository\CategoryRepository
factory: ['@doctrine.orm.default_entity_manager', getRepository]
arguments: ['AppBundle\Entity\Category']

app.repository.faq_repository:
class: AppBundle\Repository\FaqRepository
factory: ['@doctrine.orm.default_entity_manager', getRepository]
arguments: ['AppBundle\Entity\Faq']

app.repository.contact_msg_repository:
class: AppBundle\Repository\ContactMsgRepository
factory: ['@doctrine.orm.default_entity_manager', getRepository]
arguments: ['AppBundle\Entity\ContactMsg']

app.repository.product_repository:
class: AppBundle\Repository\ProductRepository
Expand Down
63 changes: 63 additions & 0 deletions src/AppBundle/Controller/ContactController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

namespace AppBundle\Controller;

use AppBundle\Entity\ContactMsg;
use AppBundle\Facade\ContactFacade;
use AppBundle\FormType\ContactFormType;
use AppBundle\Facade\UserFacade;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Form\FormFactory;
use Symfony\Component\Routing\RouterInterface;

/**
* * @Route(service="app.controller.contact_controller")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

asi překlep

*/
class ContactController
{

private $contactFacade;
private $userFacade;
private $formFactory;
private $router;

public function __construct(
ContactFacade $contactFacade, UserFacade $userFacade, FormFactory $formFactory, RouterInterface $router
)
{
$this->contactFacade = $contactFacade;
$this->userFacade = $userFacade;
$this->formFactory = $formFactory;
$this->router = $router;
}

/**
* @Route("/kontakty", name="contact")
* @Template("contact/contact.html.twig")
*
* @param Request $request
* @return RedirectResponse|array
*/
public function contactAction(Request $request)
{
$msg = new ContactMsg();
$msg->setUser($this->userFacade->getUser());
$form = $this->formFactory->create(ContactFormType::class, $msg);

$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid())
{
$this->contactFacade->save($msg);

return RedirectResponse::create($this->router->generate("homepage"));
}

return [
"form" => $form->createView(),
];
}

}
46 changes: 46 additions & 0 deletions src/AppBundle/Controller/FaqController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace AppBundle\Controller;

use AppBundle\Entity\Faq;
use AppBundle\Facade\FaqFacade;
use Doctrine\ORM\EntityManager;
use AppBundle\Facade\CategoryFacade;
use AppBundle\Facade\UserFacade;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

/**
* * @Route(service="app.controller.faq_controller")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tady taky, možná to tak máš nastaveno...

*/
class FaqController
{

private $faqFacade;
private $userFacade;

public function __construct(
FaqFacade $faqFacade, UserFacade $userFacade
)
{

$this->faqFacade = $faqFacade;
$this->userFacade = $userFacade;
}

/**
* @Route("/faq", name="faq")
* @Template("faq/faq.html.twig")
*/
public function faqAction()
{
$faqs = $this->faqFacade->getAll();

return [
"faqs" => $faqs,
"user" => $this->userFacade->getUser(),
];
}

}
Loading