-
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 - Jan Suchánek #40
Open
JanSuchanek
wants to merge
2
commits into
czcodecamp:master
Choose a base branch
from
JanSuchanek: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.
Open
Changes from 1 commit
Commits
Show all changes
2 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
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,7 @@ | ||
<div class="col-sm-4 col-lg-4 col-md-4"> | ||
<ul> | ||
{% for faq in faqs %} | ||
<li>{{ faq.email }}<br>{{ faq.question }}</li> | ||
{% endfor %} | ||
</ul> | ||
</div> |
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,17 @@ | ||
{% extends 'base.html.twig' %} | ||
|
||
{% block body %} | ||
<h1>Faq - Časté dotazy</h1> | ||
|
||
{{ form_start(form) }} | ||
{{ form_row(form.email) }} | ||
{{ form_row(form.question) }} | ||
<br /> | ||
<button class="btn btn-lg btn-primary btn-block" type="submit">Vložit dotaz</button> | ||
{{ form_end(form) }} | ||
|
||
<div class="row"> | ||
{% include 'components/list_faq.html.twig' %} | ||
</div> | ||
{% include ":components:paginator.html.twig" %} | ||
{% 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,80 @@ | ||
<?php | ||
|
||
namespace AppBundle\Controller; | ||
|
||
use AppBundle\Entity\Faq; | ||
use AppBundle\Facade\FaqFacade; | ||
use AppBundle\Service\Paginator; | ||
use Doctrine\ORM\EntityManager; | ||
use Symfony\Component\Form\FormFactory; | ||
use Symfony\Component\HttpFoundation\RedirectResponse; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | ||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; | ||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; | ||
use AppBundle\FormType\FaqFormType; | ||
use Symfony\Component\Routing\RouterInterface; | ||
|
||
/** | ||
* @author Vašek Boch <[email protected]> | ||
* @author Jan Klat <[email protected]> | ||
* @Route(service="app.controller.faq_controller") | ||
*/ | ||
class FaqController | ||
{ | ||
private $faqFacade; | ||
private $entityManager; | ||
private $formFactory; | ||
private $router; | ||
|
||
public function __construct( | ||
FaqFacade $faqFacade, | ||
FormFactory $formFactory, | ||
RouterInterface $router, | ||
EntityManager $entityManager | ||
) { | ||
$this->faqFacade = $faqFacade; | ||
$this->entityManager = $entityManager; | ||
$this->formFactory = $formFactory; | ||
$this->router = $router; | ||
} | ||
/** | ||
* @Route("/faq", name="faq_list") | ||
* @Template("faq/list.html.twig") | ||
* | ||
* @param Request $request | ||
* @return RedirectResponse|array | ||
*/ | ||
public function listAction(Request $request) | ||
{ | ||
if(!$page = $request->query->get("page")){ | ||
$page = 1; | ||
} | ||
|
||
|
||
$faq = new Faq(); | ||
$form = $this->formFactory->create(FaqFormType::class, $faq); | ||
|
||
$form->handleRequest($request); | ||
if ($form->isSubmitted() && $form->isValid()) { | ||
|
||
$this->entityManager->persist($faq); | ||
$this->entityManager->flush([$faq]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pryč z controlleru |
||
|
||
return RedirectResponse::create($this->router->generate("faq_list")); | ||
} | ||
|
||
$countByFaq = $this->faqFacade->countAll(); | ||
$paginator = new Paginator($countByFaq, 10); | ||
$paginator->setCurrentPage($page); | ||
|
||
return [ | ||
"faqs" => $this->faqFacade->getAll($paginator->getLimit(), $paginator->getOffset()), | ||
"form" => $form->createView(), | ||
"currentPage" => $page, | ||
"totalPages" => $paginator->getTotalPageCount(), | ||
"pageRange" => $paginator->getPageRange(5), | ||
]; | ||
} | ||
|
||
} |
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,82 @@ | ||
<?php | ||
|
||
namespace AppBundle\Entity; | ||
|
||
use Doctrine\Common\Collections\ArrayCollection; | ||
use Doctrine\ORM\Mapping as ORM; | ||
use Symfony\Component\Validator\Constraints as Assert; | ||
|
||
/** | ||
* @author Vašek Boch <[email protected]> | ||
* @author Jan Klat <[email protected]> | ||
* | ||
* @ORM\Entity(repositoryClass="AppBundle\Repository\FaqRepository") | ||
*/ | ||
class Faq | ||
{ | ||
|
||
/** | ||
* @var int | ||
* @ORM\Id | ||
* @ORM\GeneratedValue | ||
* @ORM\Column(type="integer") | ||
*/ | ||
private $id; | ||
|
||
/** | ||
* @ORM\Column(type="string", length=255, name="email") | ||
* @Assert\NotBlank() | ||
* @Assert\Email() | ||
*/ | ||
private $email; | ||
|
||
/** | ||
* @var string | ||
* @ORM\Column(type="text", length=255) | ||
*/ | ||
private $question; | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getId() | ||
{ | ||
return $this->id; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getEmail() | ||
{ | ||
return $this->email; | ||
} | ||
|
||
/** | ||
* @param string $email | ||
* @return self | ||
*/ | ||
public function setEmail($email) | ||
{ | ||
$this->email = $email; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getQuestion() | ||
{ | ||
return $this->question; | ||
} | ||
|
||
/** | ||
* @param string $description | ||
* @return self | ||
*/ | ||
public function setQuestion($question) | ||
{ | ||
$this->question = $question; | ||
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,34 @@ | ||
<?php | ||
|
||
namespace AppBundle\Facade; | ||
|
||
use AppBundle\Entity\Faq; | ||
use AppBundle\Repository\FaqRepository; | ||
|
||
/** | ||
* @author Vašek Boch <[email protected]> | ||
* @author Jan Klat <[email protected]> | ||
*/ | ||
class FaqFacade { | ||
|
||
private $faqRepository; | ||
|
||
public function __construct(FaqRepository $faqRepository) { | ||
$this->faqRepository = $faqRepository; | ||
} | ||
|
||
public function getAll($limit, $offset) { | ||
return $this->faqRepository->findBy( | ||
[], | ||
[ | ||
"id" => "desc" | ||
], | ||
$limit, | ||
$offset | ||
); | ||
} | ||
|
||
public function countAll() { | ||
return $this->faqRepository->countAll(); | ||
} | ||
} |
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,45 @@ | ||
<?php | ||
namespace AppBundle\FormType; | ||
|
||
use AppBundle\Entity\Faq; | ||
use Symfony\Component\Form\AbstractType; | ||
use Symfony\Component\Form\Extension\Core\Type\EmailType; | ||
use Symfony\Component\Form\Extension\Core\Type\TextareaType; | ||
use Symfony\Component\Validator\Constraints\NotBlank; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
|
||
/** | ||
* @author Vašek Boch <[email protected]> | ||
* @author Jan Klat <[email protected]> | ||
*/ | ||
class FaqFormType extends AbstractType | ||
{ | ||
public function buildForm(FormBuilderInterface $builder, array $options) | ||
{ | ||
$builder | ||
->add("email", EmailType::class, [ | ||
"label" => "E-mail", | ||
"attr" => [ | ||
"class" => "form-control", | ||
], | ||
])->add("question", TextareaType::class, [ | ||
"label" => "Question", | ||
"attr" => [ | ||
"class" => "form-control", | ||
], | ||
"constraints" => [ | ||
new NotBlank(["message" => "Prosím vyplňte Váš dotaz"]), | ||
], | ||
]); | ||
} | ||
|
||
public function configureOptions(OptionsResolver $resolver) | ||
{ | ||
|
||
$resolver->setDefaults(array( | ||
"data_class" => Faq::class, | ||
)); | ||
|
||
} | ||
} |
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,32 @@ | ||
<?php | ||
|
||
namespace AppBundle\Repository; | ||
|
||
use AppBundle\Entity\Faq; | ||
use Doctrine\ORM\EntityRepository; | ||
|
||
/** | ||
* @author Vašek Boch <[email protected]> | ||
* @author Jan Klat <[email protected]> | ||
*/ | ||
class FaqRepository extends EntityRepository | ||
{ | ||
/** | ||
* @param Faq $faq | ||
* @return QueryBuilder | ||
*/ | ||
public function findByFaq(Faq $faq) | ||
{ | ||
$builder = $this->_em->createQueryBuilder() | ||
->select('f') | ||
->from('AppBundle\Entity\Faq', 'f'); | ||
return $builder; | ||
} | ||
|
||
public function countAll() { | ||
return $this->_em->createQueryBuilder() | ||
->select('COUNT(f.id)') | ||
->from('AppBundle\Entity\Faq', 'f') | ||
->getQuery()->getSingleScalarResult(); | ||
} | ||
} |
Oops, something went wrong.
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.
a
?