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 - Jozef Liška #35

Open
wants to merge 3 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
14 changes: 14 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("message_add") }}">Kontakt</a>
</li>
</ul>
<p class="navbar-text navbar-right">
{% if user is defined and user %}
Expand All @@ -72,6 +78,14 @@
</div>

<div class="col-md-9">
{% if app.session.flashBag.has('success') %}
<div class="alert alert-success">
{% for msg in app.session.flashBag.get('success') %}
{{ msg }}
{% endfor %}
</div>
{% endif %}

{% block body %}
{% endblock %}
</div>
Expand Down
23 changes: 23 additions & 0 deletions app/Resources/views/faq/faq.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{% extends 'base.html.twig' %}

{% block body %}
<h1>FAQ</h1>
<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
{% for item in faq %}
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="heading{{ item.id }}">
<h4 class="panel-title">
<a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapse{{ item.id }}" aria-expanded="false" aria-controls="collapse{{ item.id }}">
{{ item.question }}
</a>
</h4>
</div>
<div id="collapse{{ item.id }}" class="panel-collapse collapse" role="tabpanel" aria-labelledby="heading{{ item.id }}">
<div class="panel-body">
{{ item.answer }}
</div>
</div>
</div>
{% endfor %}
</div>
{% endblock %}
6 changes: 6 additions & 0 deletions app/Resources/views/message/add.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{% extends 'base.html.twig' %}

{% block body %}
<h1>Kontakt</h1>
{{ form(form) }}
{% endblock %}
22 changes: 22 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.message_controller:
class: AppBundle\Controller\MessageController
autowire: true

app.facade.category_facade:
class: AppBundle\Facade\CategoryFacade
autowire: true
Expand All @@ -32,6 +40,10 @@ services:
class: AppBundle\Facade\UserFacade
autowire: true

app.facade.message_facade:
class: AppBundle\Facade\MessageFacade
autowire: true

app.repository.category_repository:
class: AppBundle\Repository\CategoryRepository
factory: ['@doctrine.orm.default_entity_manager', getRepository]
Expand All @@ -42,6 +54,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.message_repository:
class: AppBundle\Repository\MessageRepository
factory: ['@doctrine.orm.default_entity_manager', getRepository]
arguments: ['AppBundle\Entity\Message']

encoder:
class: Symfony\Component\Security\Core\Encoder\BCryptPasswordEncoder
arguments:
Expand Down
36 changes: 36 additions & 0 deletions src/AppBundle/Controller/FaqController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace AppBundle\Controller;

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

/**
* @author Jozef Liška <jfox@jfox.sk>
* @Route(service="app.controller.faq_controller")
*/
class FaqController
{
/**
* @var FaqFacade
*/
private $faqFacade;

public function __construct(FaqFacade $faqFacade)
{
Copy link
Member

Choose a reason for hiding this comment

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

indent

$this->faqFacade = $faqFacade;
}

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

}
61 changes: 61 additions & 0 deletions src/AppBundle/Controller/MessageController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
namespace AppBundle\Controller;

use AppBundle\Entity\Message;
use AppBundle\Facade\MessageFacade;
use AppBundle\FormType\MessageFormType;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\Form\FormFactory;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\RouterInterface;


/**
* @author Jozef Liška <jfox@jfox.sk>
* @Route(service="app.controller.message_controller")
*/
class MessageController
{
private $messageFacade;
private $formFactory;
private $router;

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

/**
* @Route("/kontakt", name="message_add")
* @Template("message/add.html.twig")
*
* @param Request $request
* @return RedirectResponse|array
*/
public function addAction(Request $request)
{
$message = new Message();
$form = $this->formFactory->create(MessageFormType::class, $message);

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

$this->messageFacade->saveMessage($message);

$request->getSession()->getFlashBag()->add('success', 'Vaša správa bola odoslaná');

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

return [
"form" => $form->createView(),
];
}
}
78 changes: 78 additions & 0 deletions src/AppBundle/Entity/Faq.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
* @author Jozef Liška <jfox@jfox.sk>
*
* @ORM\Entity(repositoryClass="AppBundle\Repository\FaqRepository")
*/
class Faq
{

/**
Copy link
Member

Choose a reason for hiding this comment

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

indent

* @var int
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;

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

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

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

/**
* @return string
*/
public function getQuestion()
{
return $this->question;
}

/**
* @param string $question
* @return self
*/
public function setQuestion($question)
{
$this->question = $question;
return $this;
}

/**
* @return string
*/
public function getAnswer()
{
return $this->answer;
}

/**
* @param string $answer
* @return self
*/
public function setAnswer($answer)
{
$this->answer = $answer;
return $this;
}
}
107 changes: 107 additions & 0 deletions src/AppBundle/Entity/Message.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;

/**
* @author Jozef Liška <jfox@jfox.sk>
*
* @ORM\Entity(repositoryClass="AppBundle\Repository\MessageRepository")
*/
class Message
Copy link
Member

Choose a reason for hiding this comment

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

Byl bych možná opatrný s použitím takto obecných slov...

{

/**
Copy link
Member

Choose a reason for hiding this comment

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

indent :)

* @var int
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;

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

/**
* @var string
* @ORM\Column(type="string")
* @Assert\NotBlank()
* @Assert\Email()
*/
private $email;

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

/**
Copy link
Member

Choose a reason for hiding this comment

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

indent

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

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

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

/**
* @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 getMessage()
{
return $this->message;
}

/**
* @param string $message
* @return self
*/
public function setMessage($message)
{
$this->message = $message;
return $this;
}
}
Loading