2021-03-29 13:58:05 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Controller\Blog;
|
|
|
|
|
2021-05-12 15:24:43 +02:00
|
|
|
use App\Core\Controller\Admin\Crud\CrudController;
|
|
|
|
use App\Core\Crud\CrudConfiguration;
|
|
|
|
use App\Core\Crud\Field\ButtonField;
|
|
|
|
use App\Core\Crud\Field\TextField;
|
|
|
|
use App\Core\Entity\EntityInterface;
|
2021-03-29 13:58:05 +02:00
|
|
|
use App\Core\Manager\EntityManager;
|
|
|
|
use App\Entity\Blog\Category as Entity;
|
|
|
|
use App\Factory\Blog\CategoryFactory as EntityFactory;
|
2021-05-12 15:24:43 +02:00
|
|
|
use App\Form\Blog\CategoryType;
|
2021-03-29 13:58:05 +02:00
|
|
|
use App\Repository\Blog\CategoryRepositoryQuery as RepositoryQuery;
|
|
|
|
use App\Repository\Blog\PostRepositoryQuery;
|
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
2021-05-12 12:45:09 +02:00
|
|
|
use Symfony\Component\HttpFoundation\Session\Session;
|
2021-05-12 15:24:43 +02:00
|
|
|
use Symfony\Component\Routing\Annotation\Route;
|
2021-03-29 13:58:05 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @Route("/admin/blog/category")
|
|
|
|
*/
|
2021-05-12 12:45:09 +02:00
|
|
|
class CategoryAdminController extends CrudController
|
2021-03-29 13:58:05 +02:00
|
|
|
{
|
2021-05-12 12:45:09 +02:00
|
|
|
public function getConfiguration(): CrudConfiguration
|
|
|
|
{
|
|
|
|
return CrudConfiguration::create()
|
|
|
|
->setPageTitle('index', 'Catégories')
|
|
|
|
->setPageTitle('edit', '{title}')
|
|
|
|
->setPageTitle('new', 'Nouvelle catégorie')
|
|
|
|
->setPageTitle('show', '{title}')
|
|
|
|
|
|
|
|
->setPageRoute('index', 'admin_blog_category_index')
|
|
|
|
->setPageRoute('new', 'admin_blog_category_new')
|
|
|
|
->setPageRoute('edit', 'admin_blog_category_edit')
|
|
|
|
->setPageRoute('show', 'admin_blog_category_show')
|
|
|
|
->setPageRoute('delete', 'admin_blog_category_delete')
|
|
|
|
->setPageRoute('filter', 'admin_blog_category_filter')
|
2021-06-03 13:57:57 +02:00
|
|
|
->setPageRoute('batch', 'admin_blog_category_batch')
|
|
|
|
|
2021-05-12 12:45:09 +02:00
|
|
|
|
|
|
|
->setForm('edit', CategoryType::class, [])
|
|
|
|
->setForm('new', CategoryType::class)
|
|
|
|
|
|
|
|
->setMaxPerPage('index', 100)
|
|
|
|
|
2021-05-13 17:33:09 +02:00
|
|
|
->setView('form', 'blog/category_admin/_form.html.twig')
|
2021-05-12 12:45:09 +02:00
|
|
|
|
2021-05-15 18:36:05 +02:00
|
|
|
->setDefaultSort('index', 'title', 'asc')
|
|
|
|
|
2021-05-12 12:45:09 +02:00
|
|
|
->setField('index', 'Titre', TextField::class, [
|
|
|
|
'property' => 'title',
|
2021-05-15 18:36:05 +02:00
|
|
|
'sort' => ['title', '.title'],
|
2021-05-12 12:45:09 +02:00
|
|
|
])
|
|
|
|
->setField('index', 'Articles', ButtonField::class, [
|
2021-05-12 15:24:43 +02:00
|
|
|
'property_builder' => function (EntityInterface $entity) {
|
2021-05-12 12:45:09 +02:00
|
|
|
$count = $entity->getPosts()->count();
|
|
|
|
|
|
|
|
return '<strong>'.$count.'</strong> article'.($count > 1 ? 's' : '');
|
|
|
|
},
|
2021-05-12 15:29:34 +02:00
|
|
|
'button_attr' => ['class' => 'btn btn-sm btn-light'],
|
2021-05-12 12:45:09 +02:00
|
|
|
'raw' => true,
|
|
|
|
])
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
2021-03-29 13:58:05 +02:00
|
|
|
/**
|
|
|
|
* @Route("/{page}", name="admin_blog_category_index", requirements={"page": "\d+"})
|
|
|
|
*/
|
2022-01-23 17:22:59 +01:00
|
|
|
public function index(RepositoryQuery $query, Request $request, Session $session, int $page = 1): Response
|
2021-03-29 13:58:05 +02:00
|
|
|
{
|
2021-05-12 15:27:01 +02:00
|
|
|
return $this->doIndex($page, $query, $request, $session);
|
2021-03-29 13:58:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Route("/new", name="admin_blog_category_new")
|
|
|
|
*/
|
|
|
|
public function new(EntityFactory $factory, EntityManager $entityManager, Request $request): Response
|
|
|
|
{
|
2021-05-12 12:45:09 +02:00
|
|
|
return $this->doNew($factory->create(), $entityManager, $request);
|
2021-03-29 13:58:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Route("/edit/{entity}", name="admin_blog_category_edit")
|
|
|
|
*/
|
|
|
|
public function edit(Entity $entity, EntityManager $entityManager, Request $request): Response
|
|
|
|
{
|
2021-05-12 12:45:09 +02:00
|
|
|
return $this->doEdit($entity, $entityManager, $request);
|
2021-03-29 13:58:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Route("/show/{entity}", name="admin_blog_category_show")
|
|
|
|
*/
|
|
|
|
public function show(Entity $entity, PostRepositoryQuery $postQuery): Response
|
|
|
|
{
|
|
|
|
$posts = $postQuery->create()
|
|
|
|
->orderBy('.publishedAt', 'DESC')
|
|
|
|
->orderBy('.createdAt', 'DESC')
|
|
|
|
->inCategory($entity)
|
|
|
|
->paginate(1, 10)
|
|
|
|
;
|
|
|
|
|
2021-05-13 17:33:09 +02:00
|
|
|
$this->getConfiguration()->setView('show_entity', 'blog/category_admin/_show.html.twig');
|
2021-05-12 12:45:09 +02:00
|
|
|
$this->getConfiguration()->addViewData('show', 'posts', $posts);
|
|
|
|
|
|
|
|
return $this->doShow($entity);
|
2021-03-29 13:58:05 +02:00
|
|
|
}
|
|
|
|
|
2021-05-12 15:24:43 +02:00
|
|
|
/**
|
|
|
|
* @Route("/filter", name="admin_blog_category_filter", methods={"GET"})
|
|
|
|
*/
|
|
|
|
public function filter(Session $session): Response
|
|
|
|
{
|
|
|
|
return $this->doFilter($session);
|
|
|
|
}
|
|
|
|
|
2021-03-29 13:58:05 +02:00
|
|
|
/**
|
|
|
|
* @Route("/delete/{entity}", name="admin_blog_category_delete", methods={"DELETE"})
|
|
|
|
*/
|
|
|
|
public function delete(Entity $entity, EntityManager $entityManager, Request $request): Response
|
|
|
|
{
|
2021-05-12 12:45:09 +02:00
|
|
|
return $this->doDelete($entity, $entityManager, $request);
|
2021-03-29 13:58:05 +02:00
|
|
|
}
|
|
|
|
|
2021-06-03 13:57:57 +02:00
|
|
|
/**
|
|
|
|
* @Route("/admin/blog_category/batch/{page}", name="admin_blog_category_batch", methods={"POST"}, requirements={"page":"\d+"})
|
|
|
|
*/
|
2022-01-23 17:22:59 +01:00
|
|
|
public function batch(RepositoryQuery $query, EntityManager $entityManager, Request $request, Session $session, int $page = 1): Response
|
2021-06-03 13:57:57 +02:00
|
|
|
{
|
|
|
|
return $this->doBatch($page, $query, $entityManager, $request, $session);
|
|
|
|
}
|
|
|
|
|
2021-03-29 13:58:05 +02:00
|
|
|
public function getSection(): string
|
|
|
|
{
|
|
|
|
return 'blog_category';
|
|
|
|
}
|
|
|
|
}
|