Refactored code to comply with PSR-*
Signed-off-by: Gergely POLONKAI <polesz@w00d5t0ck.info>
This commit is contained in:
@@ -13,93 +13,101 @@ use KekRozsak\FrontBundle\Extensions\Slugifier;
|
||||
|
||||
class DocumentController extends Controller
|
||||
{
|
||||
/**
|
||||
* @Route("/dokumentum/{slug}.{_format}", name="KekRozsakFrontBundle_documentView", defaults={"_format": "html"}, requirements={"_format": "html|pdf"})
|
||||
* @Template()
|
||||
* @ParamConverter("document")
|
||||
*/
|
||||
public function viewAction(Document $document, $_format)
|
||||
{
|
||||
$templateParams = array(
|
||||
'document' => $document,
|
||||
);
|
||||
/**
|
||||
* @Route("/dokumentum/{slug}.{_format}", name="KekRozsakFrontBundle_documentView", defaults={"_format": "html"}, requirements={"_format": "html|pdf"})
|
||||
* @Template()
|
||||
* @ParamConverter("document")
|
||||
*/
|
||||
public function viewAction(Document $document, $_format)
|
||||
{
|
||||
$templateParams = array(
|
||||
'document' => $document,
|
||||
);
|
||||
|
||||
if ($_format == 'pdf')
|
||||
{
|
||||
$html = $this->renderView('KekRozsakFrontBundle:Document:pdfView.html.twig', $templateParams);
|
||||
return $this->get('io_tcpdf')->quick_pdf($html);
|
||||
}
|
||||
if ($_format == 'pdf') {
|
||||
$html = $this->renderView(
|
||||
'KekRozsakFrontBundle:Document:pdfView.html.twig',
|
||||
$templateParams
|
||||
);
|
||||
return $this->get('io_tcpdf')->quick_pdf($html);
|
||||
}
|
||||
|
||||
return $templateParams;
|
||||
}
|
||||
return $templateParams;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/dokumentumok/uj/", name="KekRozsakFrontBundle_documentCreate")
|
||||
* @Template()
|
||||
*/
|
||||
public function createAction()
|
||||
{
|
||||
$document = new Document();
|
||||
$document->setSlug('n-a');
|
||||
$form = $this->createForm(new DocumentType(), $document);
|
||||
$request = $this->getRequest();
|
||||
/**
|
||||
* @Route("/dokumentumok/uj/", name="KekRozsakFrontBundle_documentCreate")
|
||||
* @Template()
|
||||
*/
|
||||
public function createAction()
|
||||
{
|
||||
$document = new Document();
|
||||
$document->setSlug('n-a');
|
||||
$form = $this->createForm(new DocumentType(), $document);
|
||||
$request = $this->getRequest();
|
||||
|
||||
if ($request->getMethod() == 'POST')
|
||||
{
|
||||
$form->bind($request);
|
||||
if ($request->getMethod() == 'POST') {
|
||||
$form->bind($request);
|
||||
|
||||
if ($form->isValid())
|
||||
{
|
||||
/* TODO: move these lines into life cycle events */
|
||||
$slugifier = new Slugifier();
|
||||
$document->setSlug($slugifier->slugify($document->getTitle()));
|
||||
$document->setCreatedAt(new \DateTime('now'));
|
||||
$document->setCreatedBy($this->get('security.context')->getToken()->getUser());
|
||||
if ($form->isValid()) {
|
||||
// TODO: move these lines into life cycle events
|
||||
$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();
|
||||
$em = $this->getDoctrine()->getEntityManager();
|
||||
$em->persist($document);
|
||||
$em->flush();
|
||||
|
||||
return $this->redirect($this->generateUrl('KekRozsakFrontBundle_documentView', array('slug' => $document->getSlug())));
|
||||
}
|
||||
}
|
||||
return $this->redirect(
|
||||
$this->generateUrl(
|
||||
'KekRozsakFrontBundle_documentView',
|
||||
array('slug' => $document->getSlug())
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return array(
|
||||
'form' => $form->createView(),
|
||||
);
|
||||
}
|
||||
return array(
|
||||
'form' => $form->createView(),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/dokumentum/{slug}/szerkesztes", name="KekRozsakFrontBundle_documentEdit")
|
||||
* @Template()
|
||||
* @ParamConverter("document")
|
||||
*/
|
||||
public function editAction(Document $document)
|
||||
{
|
||||
$form = $this->createForm(new DocumentType(), $document);
|
||||
$request = $this->getRequest();
|
||||
/**
|
||||
* @Route("/dokumentum/{slug}/szerkesztes", name="KekRozsakFrontBundle_documentEdit")
|
||||
* @Template()
|
||||
* @ParamConverter("document")
|
||||
*/
|
||||
public function editAction(Document $document)
|
||||
{
|
||||
$form = $this->createForm(new DocumentType(), $document);
|
||||
$request = $this->getRequest();
|
||||
|
||||
if ($request->getMethod() == 'POST')
|
||||
{
|
||||
$form->bind($request);
|
||||
if ($form->isValid())
|
||||
{
|
||||
/* TODO: move these lines into life cycle events */
|
||||
$slugifier = new Slugifier();
|
||||
$document->setSlug($slugifier->slugify($document->getTitle()));
|
||||
// TODO: add updatedAt, updatedBy, updateReason, etc.
|
||||
if ($request->getMethod() == 'POST') {
|
||||
$form->bind($request);
|
||||
if ($form->isValid()) {
|
||||
// TODO: move these lines into life cycle events
|
||||
$slugifier = new Slugifier();
|
||||
$document->setSlug($slugifier->slugify($document->getTitle()));
|
||||
// TODO: add updatedAt, updatedBy, updateReason, etc.
|
||||
|
||||
$em = $this->getDoctrine()->getEntityManager();
|
||||
$em->persist($document);
|
||||
$em->flush();
|
||||
$em = $this->getDoctrine()->getEntityManager();
|
||||
$em->persist($document);
|
||||
$em->flush();
|
||||
|
||||
return $this->redirect($this->generateUrl('KekRozsakFrontBundle_documentView', array('slug' => $document->getSlug())));
|
||||
}
|
||||
}
|
||||
return $this->redirect(
|
||||
$this->generateUrl(
|
||||
'KekRozsakFrontBundle_documentView',
|
||||
array('slug' => $document->getSlug())
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return array(
|
||||
'document' => $document,
|
||||
'form' => $form->createView(),
|
||||
);
|
||||
}
|
||||
return array(
|
||||
'document' => $document,
|
||||
'form' => $form->createView(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user