feat: feedback approval by admins
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Admin\Feedback;
|
||||
|
||||
use App\Entity\Feedback;
|
||||
use App\Form\FeedbackApproveType;
|
||||
use App\Model\AjaxModalResponseDto;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
class ApproveController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private readonly LoggerInterface $logger
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route('/admin/feedback/approve/{uuid}', name: 'app_admin_feedback_approve')]
|
||||
#[IsGranted('ROLE_ADMIN')]
|
||||
public function index(Feedback $feedback, Request $request): JsonResponse
|
||||
{
|
||||
$response = new AjaxModalResponseDto();
|
||||
$action = $this->generateUrl('app_admin_feedback_approve', ['uuid' => $feedback->getUuid()]);
|
||||
$form = $this->createForm(FeedbackApproveType::class, $feedback, ['action' => $action, 'ajax_submit' => true]);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$feedback->setStatus(Feedback::STATUS_PUBLISHED);
|
||||
$this->entityManager->flush();
|
||||
|
||||
$this->addFlash('success', 'Das Feedback wurde freigegeben');
|
||||
$this->logger->info('Approve feedback', [
|
||||
'feedback_uuid' => $feedback->getUuid(),
|
||||
]);
|
||||
|
||||
$returnUrl = $this->generateUrl('app_admin_index');
|
||||
$response->setCloseAndRedirect($returnUrl);
|
||||
} else {
|
||||
$response->setContent($this->renderView('admin/feedback/approve.html.twig', [
|
||||
'feedback' => $feedback,
|
||||
'form' => $form->createView(),
|
||||
]));
|
||||
}
|
||||
|
||||
return $this->json($response);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user