Added chunk editor
Signed-off-by: Gergely Polonkai (W00d5t0ck) <polesz@w00d5t0ck.info>
This commit is contained in:
parent
f16e4c4244
commit
7a254af1a9
@ -16,7 +16,7 @@ class Version20120905131921 extends AbstractMigration
|
||||
$this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql");
|
||||
|
||||
$this->addSql("ALTER TABLE blog_posts ADD draft TINYINT(1) NOT NULL");
|
||||
$this->addSql("UPDATE blog_posts SET draft = 0");
|
||||
$this->addSql("UPDATE blog_posts SET draft = 0");
|
||||
}
|
||||
|
||||
public function down(Schema $schema)
|
||||
|
@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
32
src/GergelyPolonkai/FrontBundle/Form/CodeChunkType.php
Normal file
32
src/GergelyPolonkai/FrontBundle/Form/CodeChunkType.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace GergelyPolonkai\FrontBundle\Form;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
|
||||
|
||||
class CodeChunkType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
->add('language')
|
||||
->add('title')
|
||||
->add('content')
|
||||
->add('description', 'ckeditor')
|
||||
;
|
||||
}
|
||||
|
||||
public function setDefaultOptions(OptionsResolverInterface $resolver)
|
||||
{
|
||||
$resolver->setDefaults(array(
|
||||
'data_class' => 'GergelyPolonkai\FrontBundle\Entity\CodeChunk'
|
||||
));
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return 'gergelypolonkai_frontbundle_codechunktype';
|
||||
}
|
||||
}
|
@ -12,7 +12,7 @@ class PostType extends AbstractType
|
||||
{
|
||||
$builder
|
||||
->add('title')
|
||||
->add('draft')
|
||||
->add('draft', null, array('required' => false))
|
||||
->add('content', 'ckeditor')
|
||||
;
|
||||
}
|
||||
|
@ -0,0 +1,14 @@
|
||||
{% extends 'GergelyPolonkaiFrontBundle:Default:front_base.html.twig' %}
|
||||
|
||||
{% block content %}
|
||||
{% if chunk.id is not null %}
|
||||
<h3>Edit Code Chunk - {{ chunk.title }}</h3>
|
||||
{% else %}
|
||||
<h3>Create Code Chunk</h3>
|
||||
{% endif %}
|
||||
<form method="post" action="">
|
||||
{{ form_widget(form) }}
|
||||
<button type="submit">Save</button>
|
||||
<a href="{{ path('GergelyPolonkaiFrontBundle_adminListChunk') }}">Cancel</a>
|
||||
</form>
|
||||
{% endblock content %}
|
@ -0,0 +1,27 @@
|
||||
{% extends 'GergelyPolonkaiFrontBundle:Default:front_base.html.twig' %}
|
||||
|
||||
{% block content %}
|
||||
<h3>Code chunks</h3>
|
||||
<a href="{{ path('GergelyPolonkaiFrontBundle_adminEditChunk') }}">New Code Chunk</a>
|
||||
{% if chunks %}
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<td>Title</td>
|
||||
<td>Language</td>
|
||||
<td>Code</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for chunk in chunks %}
|
||||
<tr>
|
||||
<td><a href="{{ path('GergelyPolonkaiFrontBundle_adminEditChunk', {id: chunk.id}) }}">{{ chunk.title }}</a></td>
|
||||
<td>{{ chunk.language }}</td>
|
||||
<td><input type="text" value="[$ code:{{ chunk.language }}:{{ chunk.slug }} $]" /></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% endif %}
|
||||
<a href="{{ path('GergelyPolonkaiFrontBundle_adminEditChunk') }}">New Code Chunk</a>
|
||||
{% endblock content %}
|
Loading…
Reference in New Issue
Block a user