From b173b9a9bb15c1d94c738d5b51c680041f41a3d6 Mon Sep 17 00:00:00 2001 From: Polonkai Gergely Date: Tue, 17 Jul 2012 09:21:33 +0200 Subject: [PATCH] Added document view support --- .../Controller/DefaultController.php | 15 ++++++++++ src/KekRozsak/FrontBundle/Entity/Document.php | 7 ++++- src/KekRozsak/FrontBundle/Entity/Group.php | 30 +++++++++++++++++++ .../views/Default/documentView.html.twig | 7 +++++ .../views/Default/groupDocuments.html.twig | 9 ++++-- 5 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 src/KekRozsak/FrontBundle/Resources/views/Default/documentView.html.twig diff --git a/src/KekRozsak/FrontBundle/Controller/DefaultController.php b/src/KekRozsak/FrontBundle/Controller/DefaultController.php index fe1d8d5..4aad5c6 100644 --- a/src/KekRozsak/FrontBundle/Controller/DefaultController.php +++ b/src/KekRozsak/FrontBundle/Controller/DefaultController.php @@ -195,4 +195,19 @@ class DefaultController extends Controller ); } } + + /** + * @Route("/dokumentum/{documentSlug}", name="KekRozsakFrontBundle_documentView") + * @Template() + */ + public function documentViewAction($documentSlug) + { + $docRepo = $this->getDoctrine()->getRepository('KekRozsakFrontBundle:Document'); + if (!($document = $docRepo->findOneBySlug($documentSlug))) + throw $this->createNotFoundException('A kért dokumentum nem létezik!'); + + return array( + 'document' => $document, + ); + } } diff --git a/src/KekRozsak/FrontBundle/Entity/Document.php b/src/KekRozsak/FrontBundle/Entity/Document.php index fc7905e..dbfc9f8 100644 --- a/src/KekRozsak/FrontBundle/Entity/Document.php +++ b/src/KekRozsak/FrontBundle/Entity/Document.php @@ -182,7 +182,12 @@ class Document /** * @var Doctrine\Common\Collections\ArrayCollection $groups - * @ORM\ManyToMany(targetEntity="KekRozsak\FrontBundle\Entity\Group", mappedBy="documents") + * @ORM\ManyToMany(targetEntity="KekRozsak\FrontBundle\Entity\Group") + * @ORM\JoinTable(name="group_document", joinColumns={ + * @ORM\JoinColumn(name="document_id", referencedColumnName="id"), + * }, inverseJoinColumns={ + * @ORM\JoinColumn(name="group_id", referencedColumnName="id") + * }) */ protected $groups; diff --git a/src/KekRozsak/FrontBundle/Entity/Group.php b/src/KekRozsak/FrontBundle/Entity/Group.php index 3658733..b178e22 100644 --- a/src/KekRozsak/FrontBundle/Entity/Group.php +++ b/src/KekRozsak/FrontBundle/Entity/Group.php @@ -6,6 +6,7 @@ use Doctrine\ORM\Mapping as ORM; use Doctrine\Common\Collections\ArrayCollection; use KekRozsak\SecurityBundle\Entity\User; +use KekRozsak\FrontBundle\Entity\Document; /** * KekRozsak\FrontBundle\Entity\Group @@ -17,6 +18,7 @@ class Group public function __construct() { $this->members = new ArrayCollection(); + $this->documents = new ArrayCollection(); } /** @@ -300,4 +302,32 @@ class Group { return $this->open; } + + /** + * @var Doctrine\Common\Collections\ArrayCollection $documents + * @ORM\ManyToMany(targetEntity="Document") + */ + protected $documents; + + /** + * Add document + * + * @param KekRozsak\FrontBundle\Entity\Document $document + * @return Group + */ + public function addDocument(\KekRozsak\FrontBundle\Entity\Document $document) + { + $this->documents[] = $document; + return $this; + } + + /** + * Get all documents + * + * @return Doctrine\Common\Collections\ArrayCollection + */ + public function getDocuments() + { + return $this->documents; + } } diff --git a/src/KekRozsak/FrontBundle/Resources/views/Default/documentView.html.twig b/src/KekRozsak/FrontBundle/Resources/views/Default/documentView.html.twig new file mode 100644 index 0000000..a162a2d --- /dev/null +++ b/src/KekRozsak/FrontBundle/Resources/views/Default/documentView.html.twig @@ -0,0 +1,7 @@ +{% extends '::main_template.html.twig' %} +{% block title %} - Dokumentum - {{ document.title }}{% endblock %} +{% block content %} +

{{ document.title }}

+{{ document.content }} +
{{ document.createdBy.displayName }}
+{% endblock content %} diff --git a/src/KekRozsak/FrontBundle/Resources/views/Default/groupDocuments.html.twig b/src/KekRozsak/FrontBundle/Resources/views/Default/groupDocuments.html.twig index 3bebdff..2b9651e 100644 --- a/src/KekRozsak/FrontBundle/Resources/views/Default/groupDocuments.html.twig +++ b/src/KekRozsak/FrontBundle/Resources/views/Default/groupDocuments.html.twig @@ -5,8 +5,13 @@ {% endblock additional_css %} {% block content %}

{{ group.name }} - Dokumentumok

+ {% endblock %}