Added chunk editor

Signed-off-by: Gergely Polonkai (W00d5t0ck) <polesz@w00d5t0ck.info>
This commit is contained in:
Gergely Polonkai (W00d5t0ck)
2012-09-05 15:14:01 +02:00
parent f16e4c4244
commit 7a254af1a9
6 changed files with 127 additions and 2 deletions

View File

@@ -7,7 +7,9 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\Security\Core\SecurityContext;
use GergelyPolonkai\FrontBundle\Form\PostType;
use GergelyPolonkai\FrontBundle\Form\CodeChunkType;
use GergelyPolonkai\FrontBundle\Entity\Post;
use GergelyPolonkai\FrontBundle\Entity\CodeChunk;
/**
* Description of AdminController
@@ -100,4 +102,54 @@ class AdminController extends Controller
'posts' => $posts,
);
}
/**
* @Route("/code-chunk/", name="GergelyPolonkaiFrontBundle_adminListChunk")
* @Template
*/
public function listCodeChunkAction()
{
$chunkRepo = $this->getDoctrine()->getRepository('GergelyPolonkaiFrontBundle:CodeChunk');
$chunks = $chunkRepo->findBy(array(), array('title' => 'ASC'));
return array(
'chunks' => $chunks,
);
}
/**
* @Route("/code-chunk/edit/{id}", name="GergelyPolonkaiFrontBundle_adminEditChunk", defaults={"id": null})
* @Template
*/
public function editChunkAction($id)
{
if (is_numeric($id)) {
$chunk = $this->getDoctrine()->getRepository('GergelyPolonkaiFrontBundle:CodeChunk')->findOneById($id);
if ($chunk === null) {
throw $this->createNotFoundException();
}
} else {
$chunk = new CodeChunk();
}
$form = $this->createForm(new CodeChunkType(), $chunk);
$request = $this->getRequest();
$user = $this->get('security.context')->getToken()->getUser();
if ($request->getMethod() === 'POST') {
$form->bind($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getEntityManager();
$em->persist($chunk);
$em->flush();
return $this->redirect($this->generateUrl('GergelyPolonkaiFrontBundle_adminListChunk'));
}
}
return array(
'form' => $form->createView(),
'chunk' => $chunk,
);
}
}