Skip to content
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

Ukol 4 - Lubomír Jiřišta #39

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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@
/vendor/
/web/bundles/
composer.lock
composer.phar
10 changes: 10 additions & 0 deletions app/Resources/views/Contact/contact.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% extends "::base.html.twig" %}

{% block body %}
{{ include('::alert.html.twig') }}
<h1>Kontaktujte nás</h1>
{{ form_start(form) }}
{{ form_widget(form) }}
<button class="btn btn-lg btn-primary btn-block" type="submit">Odeslat!</button>
{{ form_end(form) }}
{% endblock %}
26 changes: 26 additions & 0 deletions app/Resources/views/Faq/faqs.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{% extends "::base.html.twig" %}

{% block body %}
<h1>Frequently Asked Questions</h1>
<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
{% for faq in allFaqs %}
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="heading{{ loop.index }}">
<h4 class="panel-title">
<a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapse{{ loop.index }}"
aria-expanded="true" aria-controls="collapse{{ loop.index }}">
{{ faq.question }}
</a>
</h4>
</div>
<div id="collapse{{ loop.index }}" class="panel-collapse collapse {% if loop.first %}in{% endif %}"
role="tabpanel"
aria-labelledby="heading{{ loop.index }}">
<div class="panel-body">
{{ faq.response }}
</div>
</div>
</div>
{% endfor %}
</div>
{% endblock %}
7 changes: 7 additions & 0 deletions app/Resources/views/alert.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% for type, flashes in app.session.flashbag.all %}
{% for flash in flashes %}
<div class="alert alert-{{ type }} fade in">
{{ flash }}
</div>
{% endfor %}
{% endfor %}
4 changes: 4 additions & 0 deletions app/Resources/views/base.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@
| <a href="{{ path("user_registration") }}" class="navbar-link">Registrovat</a>
{% endif %}
</p>
<p class="navbar-text navbar-right margin-left">
<a href="{{ path("contact") }}" class="navbar-link">Kontakt</a>
| <a href="{{ path("faqs") }}" class="navbar-link">FAQ</a>
</p>
</div>
<!-- /.navbar-collapse -->
</div>
Expand Down
26 changes: 26 additions & 0 deletions app/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ services:
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
autowire: true
Expand All @@ -32,6 +40,14 @@ services:
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]
Expand All @@ -42,6 +58,16 @@ 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']

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:
Expand Down
74 changes: 74 additions & 0 deletions src/AppBundle/Controller/ContactController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

namespace AppBundle\Controller;

use AppBundle\Entity\Contact;
use AppBundle\Facade\ContactFacade;
use AppBundle\FormType\ContactFormType;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
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")
*/
class ContactController extends Controller
{

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

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

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

$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {

$contact = $this->contactFacade->setNewContactMessage($contact);
if(null != $contact->getId()) {
$request->getSession()->getFlashBag()->add(
'success',
'Vaše zpráva byla odeslána'
);
} else {
$request->getSession()->getFlashBag()->add(
'error',
'Vaše nebyla odeslána. Zkuste to prosím znovu.'
);
}

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


}

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

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

namespace AppBundle\Controller;

use AppBundle\Facade\FaqFacade;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;

/**
* @Route(service="app.controller.faq_controller")
*/
class FaqController extends Controller
{
private $faqFacade;

public function __construct(FaqFacade $faqFacade)
{
$this->faqFacade = $faqFacade;
}

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

return [
"allFaqs" => $allFaqs
Copy link
Member

Choose a reason for hiding this comment

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

jeden tab navíc :)

];
}

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

namespace AppBundle\Entity;
use Symfony\Component\Validator\Constraints as Assert;

use Doctrine\ORM\Mapping as ORM;

/**
* Faq
*
* @ORM\Table(name="contact")
* @ORM\Entity(repositoryClass="AppBundle\Repository\ContactRepository")
*/
class Contact
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;

/**
* @ORM\Column(type="string")
*/
private $name;

/**
* @ORM\Column(type="string", length=255, name="email")
* @Assert\NotBlank()
* @Assert\Email()
*/
private $email;

/**
* @ORM\Column(type="text")
* @Assert\NotBlank()
*/
private $message;

/**
* @return int
*/
public function getId()
{
return $this->id;
}

/**
* @param int $id
* @return Contact
*/
public function setId($id)
{
$this->id = $id;
return $this;
}

/**
* @return mixed
*/
public function getName()
{
return $this->name;
}

/**
* @param mixed $name
* @return Contact
*/
public function setName($name)
{
$this->name = $name;
return $this;
}

/**
* @return mixed
*/
public function getEmail()
{
return $this->email;
}

/**
* @param mixed $email
* @return Contact
*/
public function setEmail($email)
{
$this->email = $email;
return $this;
}

/**
* @return mixed
*/
public function getMessage()
{
return $this->message;
}

/**
* @param mixed $message
* @return Contact
*/
public function setMessage($message)
{
$this->message = $message;
return $this;
}


}

Loading