-
Notifications
You must be signed in to change notification settings - Fork 13
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
lumitor2
wants to merge
4
commits into
czcodecamp:master
Choose a base branch
from
lumitor2:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+791
−8
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,4 @@ | |
/vendor/ | ||
/web/bundles/ | ||
composer.lock | ||
composer.phar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(), | ||
]; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
]; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<?php | ||
|
||
namespace AppBundle\Entity; | ||
use Symfony\Component\Validator\Constraints as Assert; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
/** | ||
* Faq | ||
* | ||
* @ORM\Table(name="faq") | ||
* @ORM\Entity(repositoryClass="AppBundle\Repository\FaqRepository") | ||
*/ | ||
class Faq | ||
{ | ||
/** | ||
* @var int | ||
* | ||
* @ORM\Column(name="id", type="integer") | ||
* @ORM\Id | ||
* @ORM\GeneratedValue(strategy="AUTO") | ||
*/ | ||
private $id; | ||
|
||
/** | ||
* @var string | ||
* | ||
* @ORM\Column(name="question", type="text") | ||
* @Assert\NotBlank() | ||
*/ | ||
private $question; | ||
|
||
/** | ||
* @var string | ||
* @Assert\NotBlank() | ||
* @ORM\Column(name="response", type="text") | ||
*/ | ||
private $response; | ||
|
||
|
||
/** | ||
* Get id | ||
* | ||
* @return int | ||
*/ | ||
public function getId() | ||
{ | ||
return $this->id; | ||
} | ||
|
||
/** | ||
* Set question | ||
* | ||
* @param string $question | ||
* | ||
* @return Faq | ||
*/ | ||
public function setQuestion($question) | ||
{ | ||
$this->question = $question; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Get question | ||
* | ||
* @return string | ||
*/ | ||
public function getQuestion() | ||
{ | ||
return $this->question; | ||
} | ||
|
||
/** | ||
* Set response | ||
* | ||
* @param string $response | ||
* | ||
* @return Faq | ||
*/ | ||
public function setResponse($response) | ||
{ | ||
$this->response = $response; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Get response | ||
* | ||
* @return string | ||
*/ | ||
public function getResponse() | ||
{ | ||
return $this->response; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace AppBundle\Facade; | ||
|
||
use AppBundle\Repository\ContactRepository; | ||
use Doctrine\ORM\EntityManager; | ||
|
||
class ContactFacade { | ||
|
||
private $contactRepository; | ||
private $entityManager; | ||
|
||
public function __construct( | ||
ContactRepository $contactRepository, | ||
EntityManager $entityManager | ||
) { | ||
$this->contactRepository = $contactRepository; | ||
$this->entityManager = $entityManager; | ||
} | ||
|
||
public function setNewContactMessage($contact) { | ||
$this->entityManager->persist($contact); | ||
$this->entityManager->flush([$contact]); | ||
return $contact; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace AppBundle\Facade; | ||
|
||
use AppBundle\Entity\Faq; | ||
use AppBundle\Repository\FaqRepository; | ||
|
||
class FaqFacade { | ||
|
||
private $faqRepository; | ||
|
||
public function __construct(FaqRepository $faqRepository) { | ||
$this->faqRepository = $faqRepository; | ||
} | ||
|
||
/** @return Faq[] */ | ||
public function getAllFaqs() { | ||
return $this->faqRepository->findAll(); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
namespace AppBundle\FormType; | ||
|
||
use Symfony\Component\Form\AbstractType; | ||
use Symfony\Component\Form\Extension\Core\Type\TextareaType; | ||
use Symfony\Component\Form\Extension\Core\Type\TextType; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
use Symfony\Component\Validator\Constraints\NotBlank; | ||
|
||
class ContactFormType extends AbstractType | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function buildForm(FormBuilderInterface $builder, array $options) | ||
{ | ||
$builder->add("name", TextType::class, [ | ||
"label" => "Jméno", | ||
"attr" => [ | ||
"class" => "form-control", | ||
], | ||
"constraints" => [ | ||
new NotBlank(["message" => "Prosím vyplňte Vaše jméno"]), | ||
], | ||
])->add("email", TextType::class, [ | ||
"label" => "Email", | ||
"attr" => [ | ||
"class" => "form-control", | ||
], | ||
"constraints" => [ | ||
new NotBlank(["message" => "Prosím vyplňte Váš email"]), | ||
], | ||
])->add("message", TextareaType::class, [ | ||
"label" => "Zpráva", | ||
"attr" => [ | ||
"class" => "form-control", | ||
], | ||
"constraints" => [ | ||
new NotBlank(["message" => "Prosím vyplňte Vaši zprávu"]), | ||
], | ||
]); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function configureOptions(OptionsResolver $resolver) | ||
{ | ||
$resolver->setDefaults(array( | ||
'data_class' => 'AppBundle\Entity\Contact' | ||
)); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getBlockPrefix() | ||
{ | ||
return 'appbundle_contact'; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace AppBundle\Repository; | ||
|
||
use Doctrine\ORM\EntityRepository; | ||
|
||
/** | ||
* ContactRepository | ||
* | ||
* This class was generated by the Doctrine ORM. Add your own custom | ||
* repository methods below. | ||
*/ | ||
class ContactRepository extends EntityRepository | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace AppBundle\Repository; | ||
|
||
use Doctrine\ORM\EntityRepository; | ||
|
||
/** | ||
* FaqRepository | ||
* | ||
* This class was generated by the Doctrine ORM. Add your own custom | ||
* repository methods below. | ||
*/ | ||
class FaqRepository extends EntityRepository | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace AppBundle\Tests\Controller; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; | ||
|
||
class ContactControllerTest extends WebTestCase | ||
{ | ||
public function testContact() | ||
{ | ||
$client = static::createClient(); | ||
|
||
$crawler = $client->request('GET', '/contact'); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace AppBundle\Tests\Controller; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; | ||
|
||
class FaqControllerTest extends WebTestCase | ||
{ | ||
public function testReadfaqs() | ||
{ | ||
$client = static::createClient(); | ||
|
||
$crawler = $client->request('GET', '/faqs'); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jeden tab navíc :)