-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
260 additions
and
0 deletions.
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
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,11 @@ | ||
{% extends 'base.html.twig' %} | ||
|
||
{% block body %} | ||
{{ form_start(form) }} | ||
{{ form_row(form.email) }} | ||
{{ form_row(form.text) }} | ||
<br /> | ||
<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
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,52 @@ | ||
<?php | ||
|
||
namespace AppBundle\Controller; | ||
|
||
use AppBundle\Facade\MessageFacade; | ||
use AppBundle\FormType\ContactFormType; | ||
use AppBundle\FormType\VO\MessageVO; | ||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | ||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; | ||
use Symfony\Component\Form\FormFactory; | ||
use Symfony\Component\HttpFoundation\Request; | ||
|
||
/** | ||
* @Route(service="app.controller.contact_controller") | ||
*/ | ||
class ContactController | ||
{ | ||
/** @var FormFactory */ | ||
private $formFactory; | ||
|
||
/** @var MessageFacade */ | ||
private $messageFacade; | ||
|
||
/** | ||
* @param FormFactory $formFactory | ||
* @param MessageFacade $messageFacade | ||
*/ | ||
public function __construct(FormFactory $formFactory, MessageFacade $messageFacade) | ||
{ | ||
$this->formFactory = $formFactory; | ||
$this->messageFacade = $messageFacade; | ||
} | ||
|
||
/** | ||
* @Route("/contact", name="contact") | ||
* @Template("contact/contact.html.twig") | ||
*/ | ||
public function contactAction(Request $request) | ||
{ | ||
$messageVO = new MessageVO(); | ||
$form = $this->formFactory->create(ContactFormType::class, $messageVO); | ||
|
||
$form->handleRequest($request); | ||
if ($form->isSubmitted() && $form->isValid()) { | ||
$this->messageFacade->save($messageVO); | ||
} | ||
|
||
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,74 @@ | ||
<?php | ||
|
||
namespace AppBundle\Entity; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
use Symfony\Component\Validator\Constraints as Assert; | ||
|
||
/** | ||
* @ORM\Entity | ||
*/ | ||
class Message | ||
{ | ||
/** | ||
* @ORM\Id | ||
* @ORM\GeneratedValue | ||
* @ORM\Column(type="integer") | ||
* @var int | ||
*/ | ||
private $id; | ||
|
||
/** | ||
* @ORM\Column(type="string", length=255, unique=true, name="email") | ||
* @Assert\NotBlank() | ||
* @Assert\Email() | ||
* @var string | ||
*/ | ||
private $email; | ||
|
||
/** | ||
* @ORM\Column(type="string") | ||
* @var string | ||
*/ | ||
private $text; | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getId(): int | ||
{ | ||
return $this->id; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getEmail() : string | ||
{ | ||
return $this->email; | ||
} | ||
|
||
/** | ||
* @param string $email | ||
*/ | ||
public function setEmail(string $email) | ||
{ | ||
$this->email = $email; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getText(): string | ||
{ | ||
return $this->text; | ||
} | ||
|
||
/** | ||
* @param string $text | ||
*/ | ||
public function setText(string $text) | ||
{ | ||
$this->text = $text; | ||
} | ||
} |
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\Facade; | ||
|
||
use AppBundle\Entity\Message; | ||
use AppBundle\FormType\VO\MessageVO; | ||
use Doctrine\ORM\EntityManager; | ||
|
||
class MessageFacade | ||
{ | ||
/** @var EntityManager */ | ||
private $entityManager; | ||
|
||
/** | ||
* @param EntityManager $entityManager | ||
*/ | ||
public function __construct(EntityManager $entityManager) | ||
{ | ||
$this->entityManager = $entityManager; | ||
} | ||
|
||
/** | ||
* @param MessageVO $messageVO | ||
*/ | ||
public function save(MessageVO $messageVO) | ||
{ | ||
$message = new Message(); | ||
|
||
$message->setEmail($messageVO->getEmail()); | ||
$message->setText($messageVO->getText()); | ||
|
||
$this->entityManager->persist($message); | ||
$this->entityManager->flush($message); | ||
} | ||
} |
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,33 @@ | ||
<?php | ||
|
||
namespace AppBundle\FormType; | ||
|
||
use Symfony\Component\Form\AbstractType; | ||
use Symfony\Component\Form\Extension\Core\Type\EmailType; | ||
use Symfony\Component\Form\Extension\Core\Type\TextareaType; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
use Symfony\Component\Validator\Constraints\NotBlank; | ||
|
||
class ContactFormType extends AbstractType | ||
{ | ||
public function buildForm(FormBuilderInterface $builder, array $options) | ||
{ | ||
$builder->add("email", EmailType::class, [ | ||
"label" => "E-mail", | ||
"attr" => [ | ||
"class" => "form-control", | ||
], | ||
"constraints" => [ | ||
new NotBlank(["message" => "Prosím vyplňte Váš e-mail"]), | ||
], | ||
])->add("text", TextareaType::class, [ | ||
"label" => "Zpráva", | ||
"attr" => [ | ||
"class" => "form-control", | ||
], | ||
"constraints" => [ | ||
new NotBlank(["message" => "Prosím napište text zprávy"]), | ||
], | ||
]); | ||
} | ||
} |
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,44 @@ | ||
<?php | ||
|
||
namespace AppBundle\FormType\VO; | ||
|
||
class MessageVO | ||
{ | ||
/** @var string */ | ||
private $email; | ||
|
||
/** @var string */ | ||
private $text; | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getEmail() | ||
{ | ||
return $this->email; | ||
} | ||
|
||
/** | ||
* @param string $email | ||
*/ | ||
public function setEmail(string $email) | ||
{ | ||
$this->email = $email; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getText() | ||
{ | ||
return $this->text; | ||
} | ||
|
||
/** | ||
* @param string $text | ||
*/ | ||
public function setText(string $text) | ||
{ | ||
$this->text = $text; | ||
} | ||
} |