deblan.io-murph/src/Controller/Blog/CommentAdminController.php
2022-11-19 20:42:30 +01:00

109 lines
4.1 KiB
PHP

<?php
namespace App\Controller\Blog;
use App\Core\Controller\Admin\Crud\CrudController;
use App\Core\Crud\CrudConfiguration;
use App\Core\Crud\Field\DatetimeField;
use App\Core\Crud\Field\TextField;
use App\Core\Entity\EntityInterface;
use App\Core\Manager\EntityManager;
use App\Entity\Blog\Comment as Entity;
use App\Form\Blog\CommentType;
use App\Form\Blog\Filter\CommentFilterType;
use App\Repository\Blog\CommentRepositoryQuery as RepositoryQuery;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\Routing\Annotation\Route;
#[Route(path: '/admin/blog/comment')]
class CommentAdminController extends CrudController
{
public function getConfiguration(): CrudConfiguration
{
return CrudConfiguration::create()
->setPageTitle('index', 'Commentaire')
->setPageTitle('edit', 'Par {author}')
->setPageTitle('show', 'Par {author}')
->setPageRoute('index', 'admin_blog_comment_index')
->setPageRoute('edit', 'admin_blog_comment_edit')
->setPageRoute('show', 'admin_blog_comment_show')
->setPageRoute('delete', 'admin_blog_comment_delete')
->setPageRoute('filter', 'admin_blog_comment_filter')
->setPageRoute('batch', 'admin_blog_comment_batch')
->setForm('edit', CommentType::class, [])
->setForm('filter', CommentFilterType::class, [])
->setAction('index', 'new', false)
->setView('show_entity', 'blog/comment_admin/_show.html.twig')
->setView('form', 'blog/comment_admin/_form.html.twig')
->setDefaultSort('index', 'createdAt', 'desc')
->setField('index', 'Auteur', TextField::class, [
'view' => 'blog/comment_admin/field/author.html.twig',
'sort' => ['author', '.author'],
'attr' => ['class' => 'miw-300'],
])
->setField('index', 'Date', DatetimeField::class, [
'property' => 'createdAt',
'sort' => ['createdAt', '.createdAt'],
'attr' => ['class' => 'miw-200'],
])
->setField('index', 'Status', TextField::class, [
'view' => 'blog/comment_admin/field/status.html.twig',
'attr' => ['class' => 'miw-100'],
])
->setBatchAction('index', 'delete', 'Delete', function (EntityInterface $entity, EntityManager $manager) {
$manager->delete($entity);
})
;
}
#[Route(path: '/{page}', name: 'admin_blog_comment_index', requirements: ['page' => '\d+'])]
public function index(RepositoryQuery $query, Request $request, Session $session, int $page = 1): Response
{
return $this->doIndex($page, $query, $request, $session);
}
#[Route(path: '/edit/{entity}', name: 'admin_blog_comment_edit')]
public function edit(Entity $entity, EntityManager $entityManager, Request $request): Response
{
return $this->doEdit($entity, $entityManager, $request);
}
#[Route(path: '/show/{entity}', name: 'admin_blog_comment_show')]
public function show(Entity $entity): Response
{
return $this->doShow($entity);
}
#[Route(path: '/filters', name: 'admin_blog_comment_filter')]
public function filter(Session $session): Response
{
return $this->doFilter($session);
}
#[Route(path: '/delete/{entity}', name: 'admin_blog_comment_delete', methods: ['DELETE'])]
public function delete(Entity $entity, EntityManager $entityManager, Request $request): Response
{
return $this->doDelete($entity, $entityManager, $request);
}
#[Route(path: '/admin/blog_comment/batch/{page}', name: 'admin_blog_comment_batch', methods: ['POST'], requirements: ['page' => '\d+'])]
public function batch(RepositoryQuery $query, EntityManager $entityManager, Request $request, Session $session, int $page = 1): Response
{
return $this->doBatch($page, $query, $entityManager, $request, $session);
}
public function getSection(): string
{
return 'blog_comment';
}
}