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 - Aleš Kůdela #42

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
12 changes: 12 additions & 0 deletions app/Resources/views/contact/contact.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% extends 'base.html.twig' %}

{% block body %}
{{ form_start(form) }}
{{ form_row(form.firstName) }}
{{ form_row(form.surname) }}
{{ form_row(form.email) }}
{{ form_row(form.query) }}
<br />
<button class="btn btn-lg btn-primary btn-block" type="submit">Odeslat</button>
{{ form_end(form) }}
{% endblock %}
20 changes: 20 additions & 0 deletions app/Resources/views/faq/faq.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{% extends 'base.html.twig' %}

{% block body %}
<div class="accordion" id="accordion2">
{% for f in faq %}
<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapse{{ f.id }}">
{{ f.question }}
</a>
</div>
<div id="collapse{{ f.id }}" class="accordion-body collapse">
<div class="accordion-inner">
{{ f.reply }}
</div>
</div>
</div>
{% endfor %}
</div>
{% endblock %}
28 changes: 27 additions & 1 deletion 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 @@ -31,7 +39,15 @@ services:
app.facade.user_facade:
class: AppBundle\Facade\UserFacade
autowire: true


app.facade.faq_facade:
class: AppBundle\Facade\FaqFacade
autowire: true

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

namespace AppBundle\Controller;

use AppBundle\Entity\Contact;
use AppBundle\Facade\ContactFacade;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use AppBundle\FormType\ContactFormType;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Form\FormFactory;
use Doctrine\ORM\EntityManager;

/**
* @author Aleš
* @Route(service="app.controller.contact_controller")
*/
class ContactController {

private $contactFacade;

private $formFactory;

private $entityManager;

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

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

$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->entityManager->persist($contact);
$this->entityManager->flush([$contact]);
}

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

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

namespace AppBundle\Controller;

use AppBundle\Facade\FaqFacade;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;

/**
* @author Aleš
* @Route(service="app.controller.faq_controller")
*/
class FaqController {

private $faqFacade;

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

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

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

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
*
* @ORM\Entity(repositoryClass="AppBundle\Repository\ContactRepository")
*/
class Contact {

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

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

/**
* @var string
* @ORM\Column(type="string", length=64)
*/
private $firstName;

/**
* @var string
* @ORM\Column(type="string", length=64)
*/
private $surname;

/**
* @var string
* @ORM\Column(type="string", length=65535)
*/
private $query;

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

/**
* @param int $id
* @return self
*/
public function setId($id) {
$this->id = $id;
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 getFirstName() {
return $this->firstName;
}

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

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

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

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

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

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
*
* @ORM\Entity(repositoryClass="AppBundle\Repository\FaqRepository")
*/
class Faq {

/**
* @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", length=65535)
*/
private $reply;

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

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

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

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

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

namespace AppBundle\Facade;

use AppBundle\Entity\Contact;
use AppBundle\Repository\ContactRepository;
/**
* @author Aleš Kůdela
*/
class ContactFacade {

private $contactRepository;

public function __construct(ContactRepository $contactRepository) {
$this->contactRepository = $contactRepository;
}

}
Loading