From b82b4ffd34e55d272e58a7d81f607dab1745b7f9 Mon Sep 17 00:00:00 2001 From: Polonkai Gergely Date: Sun, 22 Jul 2012 19:38:00 +0200 Subject: [PATCH] Made document editing possible --- .../Controller/DocumentController.php | 88 ++- src/KekRozsak/FrontBundle/Entity/Document.php | 90 ++++ .../FrontBundle/Form/Type/DocumentType.php | 27 + .../Resources/views/Document/create.html.twig | 9 + .../views/Document/documentView.html.twig | 7 - .../Resources/views/Document/edit.html.twig | 9 + .../Resources/views/Document/view.html.twig | 9 + .../views/Group/groupDocuments.html.twig | 22 +- vendor/composer/installed.json | 502 +++++++++--------- vendor/kriswallsmith/assetic/.gitignore | 4 + vendor/kriswallsmith/assetic/composer.json | 2 + .../src/Assetic/Filter/CompassFilter.php | 22 +- .../src/Assetic/Filter/Sass/SassFilter.php | 11 +- .../src/Assetic/Filter/Sass/ScssFilter.php | 4 +- .../Filter/Yui/BaseCompressorFilter.php | 7 +- .../kriswallsmith/assetic/tests/bootstrap.php | 4 +- .../AsseticBundle/Command/DumpCommand.php | 2 +- .../Resources/config/filters/compass.xml | 1 + .../Resources/config/filters/sass.xml | 1 + .../Resources/config/filters/scss.xml | 1 + .../views/Collector/swiftmailer.html.twig | 8 +- vendor/symfony/symfony/UPGRADE-2.1.md | 36 +- .../src/Symfony/Bridge/Doctrine/CHANGELOG.md | 1 + .../Doctrine/Form/DoctrineOrmTypeGuesser.php | 5 +- .../Doctrine/Form/Type/DoctrineType.php | 6 +- .../Constraints/UniqueValidatorTest.php | 71 ++- .../Validator/Constraints/UniqueEntity.php | 1 + .../Constraints/UniqueEntityValidator.php | 2 +- .../Bridge/Twig/Extension/FormExtension.php | 346 ++---------- .../Symfony/Bridge/Twig/Form/TwigRenderer.php | 41 ++ .../Bridge/Twig/Form/TwigRendererEngine.php | 183 +++++++ .../Twig/Form/TwigRendererEngineInterface.php | 27 + .../Twig/Form/TwigRendererInterface.php | 27 + .../Bridge/Twig/Node/FormThemeNode.php | 2 +- .../Extension/FormExtensionDivLayoutTest.php | 36 +- .../FormExtensionTableLayoutTest.php | 36 +- .../Bridge/Twig/Tests/Node/FormThemeTest.php | 4 +- .../DataCollector/RequestDataCollector.php | 89 ---- .../Resources/config/collectors.xml | 4 +- .../Resources/config/templating_php.xml | 12 +- .../Resources/views/Form/attributes.html.php | 2 +- .../views/Form/checkbox_widget.html.php | 2 +- .../views/Form/choice_options.html.php | 2 +- .../views/Form/choice_widget.html.php | 4 +- .../Form/choice_widget_collapsed.html.php | 6 +- .../Form/choice_widget_expanded.html.php | 2 +- .../views/Form/container_attributes.html.php | 2 +- .../Resources/views/Form/date_widget.html.php | 4 +- .../views/Form/datetime_widget.html.php | 4 +- .../views/Form/email_widget.html.php | 2 +- .../views/Form/field_enctype.html.php | 2 +- .../views/Form/field_errors.html.php | 2 +- .../Resources/views/Form/field_label.html.php | 2 +- .../Resources/views/Form/field_rest.html.php | 2 +- .../Resources/views/Form/field_row.html.php | 2 +- .../Resources/views/Form/field_rows.html.php | 2 +- .../views/Form/field_widget.html.php | 2 +- .../Resources/views/Form/form_widget.html.php | 4 +- .../views/Form/form_widget_compound.html.php | 4 +- .../views/Form/form_widget_simple.html.php | 2 +- .../views/Form/hidden_widget.html.php | 2 +- .../views/Form/integer_widget.html.php | 2 +- .../views/Form/money_widget.html.php | 2 +- .../views/Form/number_widget.html.php | 2 +- .../views/Form/password_widget.html.php | 2 +- .../views/Form/percent_widget.html.php | 2 +- .../views/Form/radio_widget.html.php | 2 +- .../views/Form/repeated_row.html.php | 2 +- .../views/Form/search_widget.html.php | 2 +- .../views/Form/textarea_widget.html.php | 2 +- .../Resources/views/Form/time_widget.html.php | 4 +- .../Resources/views/Form/url_widget.html.php | 2 +- .../FormTable/form_widget_compound.html.php | 4 +- .../Templating/Helper/FormHelper.php | 306 +++-------- .../Helper/FormHelperDivLayoutTest.php | 10 +- .../Helper/FormHelperTableLayoutTest.php | 10 +- .../Security/Factory/AbstractFactory.php | 4 +- .../Security/Factory/AbstractFactoryTest.php | 9 +- .../TwigBundle/Resources/config/twig.xml | 12 +- .../views/Profiler/toolbar_style.html.twig | 6 +- .../Component/EventDispatcher/CHANGELOG.md | 2 +- ...tcher.php => ImmutableEventDispatcher.php} | 2 +- ...t.php => ImmutableEventDispatcherTest.php} | 8 +- .../src/Symfony/Component/Finder/Finder.php | 2 +- .../Component/Form/AbstractRendererEngine.php | 206 +++++++ .../src/Symfony/Component/Form/CHANGELOG.md | 12 +- .../Form/Extension/Core/Type/ChoiceType.php | 6 +- .../Extension/Core/Type/CollectionType.php | 6 +- .../Form/Extension/Core/Type/DateType.php | 6 +- .../Form/Extension/Core/Type/TimeType.php | 6 +- .../DependencyInjectionExtension.php | 7 +- .../Templating/TemplatingRendererEngine.php | 125 +++++ .../Type/FormTypeValidatorExtension.php | 10 +- .../src/Symfony/Component/Form/Form.php | 113 +++- .../Symfony/Component/Form/FormRenderer.php | 350 ++++++++++++ .../Form/FormRendererEngineInterface.php | 146 +++++ .../Component/Form/FormRendererInterface.php | 180 +++++++ ...FormConfig.php => ImmutableFormConfig.php} | 8 +- .../Form/Tests/AbstractDivLayoutTest.php | 2 +- .../Component/Form/Tests/CompoundFormTest.php | 2 +- .../Extension/Core/Type/DateTimeTypeTest.php | 2 +- .../Extension/Core/Type/DateTypeTest.php | 2 +- .../Extension/Core/Type/TimeTypeTest.php | 2 +- .../Component/Form/Tests/FormRendererTest.php | 105 ++++ .../Component/Form/Tests/SimpleFormTest.php | 19 +- .../Form/Tests/Util/FormUtilTest.php | 59 -- .../Symfony/Component/Form/Util/FormUtil.php | 29 - .../Component/HttpFoundation/Response.php | 21 +- .../HttpFoundation/ResponseHeaderBag.php | 10 +- .../HttpFoundation/Tests/ResponseTest.php | 27 + .../DataCollector/RequestDataCollector.php | 56 +- .../EventListener/ProfilerListener.php | 10 +- .../Tests/Stub/StubIntlDateFormatterTest.php | 2 +- .../Component/OptionsResolver/LazyOption.php | 22 +- .../Component/OptionsResolver/Options.php | 98 ++-- .../OptionsResolver/OptionsResolver.php | 12 +- .../OptionsResolverInterface.php | 10 +- .../OptionsResolver/Tests/LazyOptionTest.php | 44 ++ .../Tests/OptionsResolverTest.php | 4 +- .../src/Symfony/Component/Process/Process.php | 4 +- .../src/Symfony/Component/Routing/Route.php | 4 +- .../AbstractAuthenticationListener.php | 2 +- .../Component/Templating/PhpEngine.php | 14 + .../Validator/Constraints/TrueValidator.php | 10 +- .../constraint-mapping-1.0.xsd | 6 +- vendor/twig/twig/CHANGELOG | 3 +- .../twig/twig/doc/filters/number_format.rst | 4 +- vendor/twig/twig/doc/recipes.rst | 2 +- vendor/twig/twig/doc/templates.rst | 9 + vendor/twig/twig/doc/tests/empty.rst | 2 +- vendor/twig/twig/lib/Twig/Extension/Debug.php | 2 +- vendor/twig/twig/lib/Twig/Loader/Chain.php | 12 +- vendor/twig/twig/lib/Twig/Template.php | 2 +- .../twig/test/Twig/Tests/escapingTest.php | 4 - web/bundles/ivoryckeditor/ckeditor.js | 2 +- web/bundles/ivoryckeditor/config.js | 8 +- 136 files changed, 2734 insertions(+), 1289 deletions(-) create mode 100644 src/KekRozsak/FrontBundle/Form/Type/DocumentType.php create mode 100644 src/KekRozsak/FrontBundle/Resources/views/Document/create.html.twig delete mode 100644 src/KekRozsak/FrontBundle/Resources/views/Document/documentView.html.twig create mode 100644 src/KekRozsak/FrontBundle/Resources/views/Document/edit.html.twig create mode 100644 src/KekRozsak/FrontBundle/Resources/views/Document/view.html.twig create mode 100644 vendor/kriswallsmith/assetic/.gitignore create mode 100644 vendor/symfony/symfony/src/Symfony/Bridge/Twig/Form/TwigRenderer.php create mode 100644 vendor/symfony/symfony/src/Symfony/Bridge/Twig/Form/TwigRendererEngine.php create mode 100644 vendor/symfony/symfony/src/Symfony/Bridge/Twig/Form/TwigRendererEngineInterface.php create mode 100644 vendor/symfony/symfony/src/Symfony/Bridge/Twig/Form/TwigRendererInterface.php delete mode 100644 vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/DataCollector/RequestDataCollector.php rename vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/{UnmodifiableEventDispatcher.php => ImmutableEventDispatcher.php} (96%) rename vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/Tests/{UnmodifiableEventDispatcherTest.php => ImmutableEventDispatcherTest.php} (91%) create mode 100644 vendor/symfony/symfony/src/Symfony/Component/Form/AbstractRendererEngine.php create mode 100644 vendor/symfony/symfony/src/Symfony/Component/Form/Extension/Templating/TemplatingRendererEngine.php create mode 100644 vendor/symfony/symfony/src/Symfony/Component/Form/FormRenderer.php create mode 100644 vendor/symfony/symfony/src/Symfony/Component/Form/FormRendererEngineInterface.php create mode 100644 vendor/symfony/symfony/src/Symfony/Component/Form/FormRendererInterface.php rename vendor/symfony/symfony/src/Symfony/Component/Form/{UnmodifiableFormConfig.php => ImmutableFormConfig.php} (96%) create mode 100644 vendor/symfony/symfony/src/Symfony/Component/Form/Tests/FormRendererTest.php create mode 100644 vendor/symfony/symfony/src/Symfony/Component/OptionsResolver/Tests/LazyOptionTest.php diff --git a/src/KekRozsak/FrontBundle/Controller/DocumentController.php b/src/KekRozsak/FrontBundle/Controller/DocumentController.php index 48ac6c0..ed543f2 100644 --- a/src/KekRozsak/FrontBundle/Controller/DocumentController.php +++ b/src/KekRozsak/FrontBundle/Controller/DocumentController.php @@ -6,13 +6,17 @@ use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; +use KekRozsak\FrontBundle\Entity\Document; +use KekRozsak\FrontBundle\Form\Type\DocumentType; +use KekRozsak\FrontBundle\Extensions\Slugifier; + class DocumentController extends Controller { /** * @Route("/dokumentum/{documentSlug}", name="KekRozsakFrontBundle_documentView") * @Template() */ - public function documentViewAction($documentSlug) + public function viewAction($documentSlug) { $docRepo = $this->getDoctrine()->getRepository('KekRozsakFrontBundle:Document'); if (!($document = $docRepo->findOneBySlug($documentSlug))) @@ -22,4 +26,86 @@ class DocumentController extends Controller 'document' => $document, ); } + + /** + * @Route("/dokumentumok/uj/{groupSlug}", name="KekRozsakFrontBundle_documentCreate", defaults={"groupslug"=""}) + * @Template() + */ + public function createAction($groupSlug = '') + { + $groupRepo = $this->getDoctrine()->getRepository('KekRozsakFrontBundle:Group'); + $group = $groupRepo->findOneBySlug($groupSlug); + /* TODO: make group fully optional */ + + $document = new Document(); + $document->setSlug('n-a'); + $form = $this->createForm(new DocumentType(), $document); + $request = $this->getRequest(); + + if ($request->getMethod() == 'POST') + { + $form->bindRequest($request); + + if ($form->isValid()) + { + $slugifier = new Slugifier(); + $document->setSlug($slugifier->slugify($document->getTitle())); + $document->setCreatedAt(new \DateTime('now')); + $document->setCreatedBy($this->get('security.context')->getToken()->getUser()); + + if ($group) + { + $group->addDocument($document); + $document->addGroup($group); + } + + $em = $this->getDoctrine()->getEntityManager(); + $em->persist($document); + $em->flush(); + + /* TODO: return to group list if groupSlug is empty! */ + return $this->redirect($this->generateUrl('KekRozsakFrontBundle_groupDocuments', array('groupSlug' => $group->getSlug()))); + } + } + + return array( + 'defaultGroup' => $groupSlug, + 'form' => $form->createView(), + ); + } + + /** + * @Route("/dokumentum/{documentSlug}/szerkesztes", name="KekRozsakFrontBundle_documentEdit") + * @Template() + */ + public function editAction($documentSlug) + { + $documentRepo = $this->getDoctrine()->getRepository('KekRozsakFrontBundle:Document'); + if (!($document = $documentRepo->findOneBySlug($documentSlug))) + throw $this->createNotFoundException('A kért dokumentum nem létezik!'); + $form = $this->createForm(new DocumentType(), $document); + $request = $this->getRequest(); + + if ($request->getMethod() == 'POST') + { + $form->bindRequest($request); + if ($form->isValid()) + { + $slugifier = new Slugifier(); + $document->setSlug($slugifier->slugify($document->getTitle())); + // TODO: add updatedAt, updatedBy, updateReason, etc. + + $em = $this->getDoctrine()->getEntityManager(); + $em->persist($document); + $em->flush(); + + return $this->redirect($this->generateUrl('KekRozsakFrontBundle_documentView', array('documentSlug' => $document->getSlug()))); + } + } + + return array( + 'document' => $document, + 'form' => $form->createView(), + ); + } } diff --git a/src/KekRozsak/FrontBundle/Entity/Document.php b/src/KekRozsak/FrontBundle/Entity/Document.php index fc7905e..9026d3b 100644 --- a/src/KekRozsak/FrontBundle/Entity/Document.php +++ b/src/KekRozsak/FrontBundle/Entity/Document.php @@ -4,6 +4,8 @@ namespace KekRozsak\FrontBundle\Entity; use Doctrine\ORM\Mapping as ORM; use Doctrine\Common\Collections\ArrayCollection; +use Symfony\Component\Validator\Constraints as Assert; +use Symfony\Bridge\Doctrine\Validator\Constraints as DoctrineAssert; use KekRozsak\SecurityBundle\Entity\User; use KekRozsak\FrontBundle\Entity\Group; @@ -12,6 +14,8 @@ use KekRozsak\FrontBundle\Entity\Group; * KekRozsak\FrontBundle\Entity\Document * @ORM\Entity * @ORM\Table(name="documents") + * @DoctrineAssert\UniqueEntity(fields={"title"}, message="Ilyen című dokumentum már létezik. Kérlek válassz másikat!") + * @DoctrineAssert\UniqueEntity(fields={"slug"}, message="Ilyen című dokumentum már létezik. Kérlek válassz másikat!") */ class Document { @@ -41,6 +45,7 @@ class Document /** * @var string $title * @ORM\Column(type="string", length=150, unique=true, nullable=false) + * @Assert\NotBlank() */ protected $title; @@ -69,6 +74,7 @@ class Document /** * @var string $slug * @ORM\Column(type="string", length=150, unique=true, nullable=false) + * @Assert\NotBlank() */ protected $slug; @@ -207,4 +213,88 @@ class Document { return $this->group; } + + /** + * @var KekRozsak\SecurityBundle\Entity\User $updatedBy + * @ORM\ManyToOne(targetEntity="KekRozsak\SecurityBundle\Entity\User") + */ + protected $updatedBy; + + /** + * Set updatedBy + * + * @param KekRozsak\SecurityBundle\Entity\User $updatedBy + * @return Document + */ + public function setUpdatedBy(\KekRozsak\SecurityBundle\Entity\User $updatedBy = null) + { + $this->updatedBy = $updatedBy; + return $this; + } + + /** + * Get updatedBy + * + * @return KekRozsak\SecurityBundle\Entity\User + */ + public function getUpdatedBy() + { + return $this->updatedBy; + } + + /** + * @var DateTime $updatedAt + * @ORM\Column(type="datetime", nullable=true) + */ + protected $updatedAt; + + /** + * Set updatedAt + * + * @param DateTime $updatedAt + * @return Document + */ + public function setUpdatedAt(\DateTime $updatedAt = null) + { + $this->updatedAt = $updatedAt; + return $this; + } + + /** + * Get updatedAt + * + * @return DateTime + */ + public function getUpdatedAt() + { + return $this->updatedAt; + } + + /** + * @var string updateReason + * @ORM\Column(type="text", nullable=true) + */ + protected $updateReason; + + /** + * Set updateReason + * + * @param string $updateReason + * @return Document + */ + public function setUpdateReason($updateReason = null) + { + $this->updateReason = $updateReason; + return $this; + } + + /** + * Get updateReason + * + * @return string + */ + public function getUpdateReason() + { + return $this->updateReason; + } } diff --git a/src/KekRozsak/FrontBundle/Form/Type/DocumentType.php b/src/KekRozsak/FrontBundle/Form/Type/DocumentType.php new file mode 100644 index 0000000..d7c3068 --- /dev/null +++ b/src/KekRozsak/FrontBundle/Form/Type/DocumentType.php @@ -0,0 +1,27 @@ +add('title', null, array( + 'label' => 'A dokumentum címe', + )); + + $builder->add('content', 'ckeditor', array( + 'label' => ' ', + )); + + /* TODO: possibility to add to other groups! */ + } + + public function getName() + { + return 'document'; + } +} diff --git a/src/KekRozsak/FrontBundle/Resources/views/Document/create.html.twig b/src/KekRozsak/FrontBundle/Resources/views/Document/create.html.twig new file mode 100644 index 0000000..52299ff --- /dev/null +++ b/src/KekRozsak/FrontBundle/Resources/views/Document/create.html.twig @@ -0,0 +1,9 @@ +{% extends '::main_template.html.twig' %} +{% block title %} - Dokumentum létrehozása{% endblock %} +{% block content %} +

Új dokumentum létrehozása

+
+ {{ form_widget(form) }} + +
+{% endblock content %} diff --git a/src/KekRozsak/FrontBundle/Resources/views/Document/documentView.html.twig b/src/KekRozsak/FrontBundle/Resources/views/Document/documentView.html.twig deleted file mode 100644 index a162a2d..0000000 --- a/src/KekRozsak/FrontBundle/Resources/views/Document/documentView.html.twig +++ /dev/null @@ -1,7 +0,0 @@ -{% 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/Document/edit.html.twig b/src/KekRozsak/FrontBundle/Resources/views/Document/edit.html.twig new file mode 100644 index 0000000..895bb5c --- /dev/null +++ b/src/KekRozsak/FrontBundle/Resources/views/Document/edit.html.twig @@ -0,0 +1,9 @@ +{% extends '::main_template.html.twig' %} +{% block title %} - Dokumentum szerkesztése - {{ document.title }}{% endblock %} +{% block content %} +

Dokumentum szerkesztése - {{ document.title }}

+
+ {{ form_widget(form) }} + +
+{% endblock content %} diff --git a/src/KekRozsak/FrontBundle/Resources/views/Document/view.html.twig b/src/KekRozsak/FrontBundle/Resources/views/Document/view.html.twig new file mode 100644 index 0000000..dcac593 --- /dev/null +++ b/src/KekRozsak/FrontBundle/Resources/views/Document/view.html.twig @@ -0,0 +1,9 @@ +{% extends '::main_template.html.twig' %} +{% block title %} - Dokumentum - {{ document.title }}{% endblock %} +{% block content %} +

+ {{ document.title }}{% if document.createdBy == app.user %} [ Szerkesztés ] {% endif %} +

+{{ document.content|raw }} +
{{ document.createdBy.displayName }}
+{% endblock content %} diff --git a/src/KekRozsak/FrontBundle/Resources/views/Group/groupDocuments.html.twig b/src/KekRozsak/FrontBundle/Resources/views/Group/groupDocuments.html.twig index 2b9651e..0d85ec9 100644 --- a/src/KekRozsak/FrontBundle/Resources/views/Group/groupDocuments.html.twig +++ b/src/KekRozsak/FrontBundle/Resources/views/Group/groupDocuments.html.twig @@ -9,9 +9,25 @@
  • Tagok
  • {{ group.name }} - Dokumentumok

    -