2012-07-17 21:33:31 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace KekRozsak\FrontBundle\Controller;
|
|
|
|
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
|
2012-07-31 07:47:50 +00:00
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
2012-07-17 21:33:31 +00:00
|
|
|
|
2012-07-22 17:38:00 +00:00
|
|
|
use KekRozsak\FrontBundle\Entity\Document;
|
|
|
|
use KekRozsak\FrontBundle\Form\Type\DocumentType;
|
|
|
|
use KekRozsak\FrontBundle\Extensions\Slugifier;
|
|
|
|
|
2012-07-17 21:33:31 +00:00
|
|
|
class DocumentController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
2012-08-03 15:56:21 +00:00
|
|
|
* @Route("/dokumentum/{slug}.{_format}", name="KekRozsakFrontBundle_documentView", defaults={"_format": "html"}, requirements={"_format": "html|pdf"})
|
2012-07-17 21:33:31 +00:00
|
|
|
* @Template()
|
2012-07-31 07:47:50 +00:00
|
|
|
* @ParamConverter("document")
|
2012-07-17 21:33:31 +00:00
|
|
|
*/
|
2012-08-03 15:56:21 +00:00
|
|
|
public function viewAction(Document $document, $_format)
|
2012-07-17 21:33:31 +00:00
|
|
|
{
|
2012-08-03 15:56:21 +00:00
|
|
|
$templateParams = array(
|
2012-07-17 21:33:31 +00:00
|
|
|
'document' => $document,
|
|
|
|
);
|
2012-08-03 15:56:21 +00:00
|
|
|
|
|
|
|
if ($_format == 'pdf')
|
|
|
|
{
|
|
|
|
$html = $this->renderView('KekRozsakFrontBundle:Document:pdfView.html.twig', $templateParams);
|
|
|
|
return $this->get('io_tcpdf')->quick_pdf($html);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $templateParams;
|
2012-07-17 21:33:31 +00:00
|
|
|
}
|
2012-07-22 17:38:00 +00:00
|
|
|
|
|
|
|
/**
|
2012-07-31 07:47:50 +00:00
|
|
|
* @Route("/dokumentumok/uj/", name="KekRozsakFrontBundle_documentCreate")
|
2012-07-22 17:38:00 +00:00
|
|
|
* @Template()
|
|
|
|
*/
|
2012-07-31 07:47:50 +00:00
|
|
|
public function createAction()
|
2012-07-22 17:38:00 +00:00
|
|
|
{
|
|
|
|
$document = new Document();
|
|
|
|
$document->setSlug('n-a');
|
|
|
|
$form = $this->createForm(new DocumentType(), $document);
|
|
|
|
$request = $this->getRequest();
|
|
|
|
|
|
|
|
if ($request->getMethod() == 'POST')
|
|
|
|
{
|
2012-08-08 20:18:33 +00:00
|
|
|
$form->bind($request);
|
2012-07-22 17:38:00 +00:00
|
|
|
|
|
|
|
if ($form->isValid())
|
|
|
|
{
|
2012-07-31 07:47:50 +00:00
|
|
|
/* TODO: move these lines into life cycle events */
|
2012-07-22 17:38:00 +00:00
|
|
|
$slugifier = new Slugifier();
|
|
|
|
$document->setSlug($slugifier->slugify($document->getTitle()));
|
|
|
|
$document->setCreatedAt(new \DateTime('now'));
|
|
|
|
$document->setCreatedBy($this->get('security.context')->getToken()->getUser());
|
|
|
|
|
|
|
|
$em = $this->getDoctrine()->getEntityManager();
|
|
|
|
$em->persist($document);
|
|
|
|
$em->flush();
|
|
|
|
|
2012-07-31 07:47:50 +00:00
|
|
|
return $this->redirect($this->generateUrl('KekRozsakFrontBundle_documentView', array('slug' => $document->getSlug())));
|
2012-07-22 17:38:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return array(
|
|
|
|
'form' => $form->createView(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-07-31 07:47:50 +00:00
|
|
|
* @Route("/dokumentum/{slug}/szerkesztes", name="KekRozsakFrontBundle_documentEdit")
|
2012-07-22 17:38:00 +00:00
|
|
|
* @Template()
|
2012-07-31 07:47:50 +00:00
|
|
|
* @ParamConverter("document")
|
2012-07-22 17:38:00 +00:00
|
|
|
*/
|
2012-07-31 07:47:50 +00:00
|
|
|
public function editAction(Document $document)
|
2012-07-22 17:38:00 +00:00
|
|
|
{
|
|
|
|
$form = $this->createForm(new DocumentType(), $document);
|
|
|
|
$request = $this->getRequest();
|
|
|
|
|
|
|
|
if ($request->getMethod() == 'POST')
|
|
|
|
{
|
2012-08-08 20:18:33 +00:00
|
|
|
$form->bind($request);
|
2012-07-22 17:38:00 +00:00
|
|
|
if ($form->isValid())
|
|
|
|
{
|
2012-07-31 07:47:50 +00:00
|
|
|
/* TODO: move these lines into life cycle events */
|
2012-07-22 17:38:00 +00:00
|
|
|
$slugifier = new Slugifier();
|
|
|
|
$document->setSlug($slugifier->slugify($document->getTitle()));
|
|
|
|
// TODO: add updatedAt, updatedBy, updateReason, etc.
|
|
|
|
|
|
|
|
$em = $this->getDoctrine()->getEntityManager();
|
|
|
|
$em->persist($document);
|
|
|
|
$em->flush();
|
|
|
|
|
2012-07-31 07:47:50 +00:00
|
|
|
return $this->redirect($this->generateUrl('KekRozsakFrontBundle_documentView', array('slug' => $document->getSlug())));
|
2012-07-22 17:38:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return array(
|
|
|
|
'document' => $document,
|
|
|
|
'form' => $form->createView(),
|
|
|
|
);
|
|
|
|
}
|
2012-07-17 21:33:31 +00:00
|
|
|
}
|