54 lines
1.6 KiB
PHP
54 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Controller\Admin\System\Faq;
|
|
|
|
use App\Entity\Faq;
|
|
use App\Repository\FaqRepository;
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\Routing\Attribute\Route;
|
|
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
|
|
|
class IndexController extends AbstractController
|
|
{
|
|
public function __construct(
|
|
private readonly FaqRepository $faqRepository,
|
|
private readonly EntityManagerInterface $entityManager
|
|
) {
|
|
}
|
|
|
|
#[Route('/admin/system/faq', name: 'app_admin_system_faq_index')]
|
|
#[IsGranted('ROLE_ADMIN')]
|
|
public function index(): Response
|
|
{
|
|
$faqs = $this->faqRepository->findBy([], ['sorting' => 'ASC']);
|
|
|
|
return $this->render('admin/system/faq/index.html.twig', [
|
|
'faqs' => $faqs,
|
|
]);
|
|
}
|
|
|
|
#[Route('/admin/system/faq/sort', name: 'app_admin_system_faq_sort', methods: ['POST'])]
|
|
public function sort(Request $request): JsonResponse
|
|
{
|
|
$data = json_decode($request->getContent(), true);
|
|
$ordering = $data['ordering'];
|
|
$faqIds = array_keys($ordering);
|
|
$faqs = $this
|
|
->faqRepository
|
|
->findBy(['id' => $faqIds])
|
|
;
|
|
foreach ($faqs as $faq) {
|
|
/* @var Faq $faq */
|
|
$faq->setSorting($ordering[$faq->getId()]);
|
|
}
|
|
$this->entityManager->flush();
|
|
|
|
return $this->json([
|
|
'success' => true,
|
|
]);
|
|
}
|
|
} |