Made document editing possible

This commit is contained in:
Polonkai Gergely
2012-07-22 19:38:00 +02:00
parent 1b55b079f4
commit b82b4ffd34
136 changed files with 2734 additions and 1289 deletions

View File

@@ -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(),
);
}
}

View File

@@ -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;
}
}

View File

@@ -0,0 +1,27 @@
<?php
namespace KekRozsak\FrontBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
class DocumentType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->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';
}
}

View File

@@ -0,0 +1,9 @@
{% extends '::main_template.html.twig' %}
{% block title %} - Dokumentum létrehozása{% endblock %}
{% block content %}
<h3>Új dokumentum létrehozása</h3>
<form method="post" action="{{ path('KekRozsakFrontBundle_documentCreate', { groupSlug: defaultGroup }) }}">
{{ form_widget(form) }}
<button type="submit">Mentés</button>
</form>
{% endblock content %}

View File

@@ -1,7 +0,0 @@
{% extends '::main_template.html.twig' %}
{% block title %} - Dokumentum - {{ document.title }}{% endblock %}
{% block content %}
<h3>{{ document.title }}</h3>
{{ document.content }}
<div class="szerzo">{{ document.createdBy.displayName }}</div>
{% endblock content %}

View File

@@ -0,0 +1,9 @@
{% extends '::main_template.html.twig' %}
{% block title %} - Dokumentum szerkesztése - {{ document.title }}{% endblock %}
{% block content %}
<h3>Dokumentum szerkesztése - {{ document.title }}</h3>
<form method="post" action="{{ path('KekRozsakFrontBundle_documentEdit', { documentSlug: document.slug }) }}">
{{ form_widget(form) }}
<button type="submit">Mentés</button>
</form>
{% endblock content %}

View File

@@ -0,0 +1,9 @@
{% extends '::main_template.html.twig' %}
{% block title %} - Dokumentum - {{ document.title }}{% endblock %}
{% block content %}
<h3>
{{ document.title }}{% if document.createdBy == app.user %} [ <a href="{{ path('KekRozsakFrontBundle_documentEdit', { documentSlug: document.slug }) }}">Szerkesztés</a> ] {% endif %}
</h3>
{{ document.content|raw }}
<div class="szerzo">{{ document.createdBy.displayName }}</div>
{% endblock content %}

View File

@@ -9,9 +9,25 @@
<li><a href="{{ path('KekRozsakFrontBundle_groupMembers', { groupSlug: group.slug }) }}">Tagok</a></li>
</ul>
<h3>{{ group.name }} - Dokumentumok</h3>
<ul>
<table>
<thead>
<tr>
<td colspan="2">Cím</td>
<td>Készítette</td>
</tr>
</thead>
<tbody>
{% for document in group.documents %}
<li><a href="{{ path('KekRozsakFrontBundle_documentView', { documentSlug: document.slug }) }}">{{ document.title }}</a></li>
<tr>
<td>[ikon]</td>
<td><a href="{{ path('KekRozsakFrontBundle_documentView', { documentSlug: document.slug }) }}">{{ document.title }}</a></td>
<td>
{{ document.createdBy.displayName }}<br />
{{ document.createdAt|date('Y-m-d H:i') }}
</td>
</tr>
{% endfor %}
</ul>
</tbody>
</table>
<a href="{{ path('KekRozsakFrontBundle_documentCreate', { groupSlug: group.slug }) }}">Új dokumentum</a>
{% endblock %}