feat: news messages to be displayed on teamers' dashboards

This commit is contained in:
Björn Fromme
2024-06-23 18:37:33 +02:00
parent b58bd9f34f
commit fbad0d4e06
18 changed files with 505 additions and 0 deletions
@@ -0,0 +1,50 @@
<?php
namespace App\Controller\Administrative\System\News;
use App\Entity\News;
use App\Form\NewsType;
use App\Htmx\HxRedirectResponse;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;
class CreateController extends AbstractController
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
private readonly LoggerInterface $logger
) {
}
#[Route('/administrative/system/news/create', name: 'app_administrative_system_news_create')]
#[IsGranted('ROLE_ADMINISTRATIVE')]
public function index(Request $request): Response
{
$news = new News();
$form = $this->createForm(NewsType::class, $news, [
'hx_post' => $request->getUri(),
]);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->entityManager->persist($news);
$this->entityManager->flush();
$this->addFlash('success', 'News wurden erstellt');
$this->logger->info('Create news', [
'news_id' => $news->getId(),
]);
return new HxRedirectResponse($this->generateUrl('app_administrative_system_news_index'));
}
return $this->render('administrative/system/news/modal_create.html.twig', [
'form' => $form->createView(),
]);
}
}
@@ -0,0 +1,43 @@
<?php
namespace App\Controller\Administrative\System\News;
use App\Entity\News;
use App\Htmx\HxRedirectResponse;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;
class DeleteController extends AbstractController
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
private readonly LoggerInterface $logger
) {
}
#[Route('/administrative/system/news/delete/{id}', name: 'app_administrative_system_news_delete')]
#[IsGranted('ROLE_ADMINISTRATIVE')]
public function index(News $news, Request $request): Response
{
if (true === $request->isMethod('POST')) {
$this->entityManager->remove($news);
$this->entityManager->flush();
$this->addFlash('success', 'Die Nachricht wurde gelöscht');
$this->logger->info('Delete news', [
'news' => $news->getMessage(),
]);
return new HxRedirectResponse($this->generateUrl('app_administrative_system_news_index'));
}
return $this->render('administrative/system/news/modal_delete.html.twig', [
'news' => $news,
]);
}
}
@@ -0,0 +1,49 @@
<?php
namespace App\Controller\Administrative\System\News;
use App\Entity\News;
use App\Form\NewsType;
use App\Htmx\HxRedirectResponse;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;
class EditController extends AbstractController
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
private readonly LoggerInterface $logger
) {
}
#[Route('/administrative/system/news/edit/{id}', name: 'app_administrative_system_news_edit')]
#[IsGranted('ROLE_ADMINISTRATIVE')]
public function index(News $news, Request $request): Response
{
$form = $this->createForm(NewsType::class, $news, [
'hx_post' => $request->getUri(),
]);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->entityManager->persist($news);
$this->entityManager->flush();
$this->addFlash('success', 'News wurden aktualisiert.');
$this->logger->info('Edit news', [
'news_id' => $news->getId(),
]);
return new HxRedirectResponse($this->generateUrl('app_administrative_system_news_index'));
}
return $this->render('administrative/system/news/modal_edit.html.twig', [
'form' => $form->createView(),
]);
}
}
@@ -0,0 +1,36 @@
<?php
namespace App\Controller\Administrative\System\News;
use App\Repository\NewsRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
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 NewsRepository $repository)
{
}
#[Route('/administrative/system/news', name: 'app_administrative_system_news_index')]
#[IsGranted('ROLE_ADMINISTRATIVE')]
public function index(): Response
{
$news = $this
->repository
->findBy([], ['createdAt' => 'DESC'])
;
$activeNews = $this
->repository
->getLatestForDashboard()
;
return $this->render('administrative/system/news/index.html.twig', [
'news' => $news,
'activeNews' => $activeNews,
]);
}
}
@@ -6,6 +6,7 @@ use App\Entity\Application;
use App\Entity\Assignment;
use App\Entity\Disposition;
use App\Entity\Feedback;
use App\Entity\News;
use App\Entity\User;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
@@ -27,6 +28,12 @@ class IndexController extends AbstractController
$user = $this->getUser();
$teamer = $user->getTeamer();
$news = $this
->entityManager
->getRepository(News::class)
->getLatestForDashboard()
;
$matchingAssignments = $this
->entityManager
->getRepository(Assignment::class)
@@ -60,6 +67,7 @@ class IndexController extends AbstractController
$dispositionDocuments = $this->processDocuments($upcomingDispositions);
return $this->render('teamer/index.html.twig', [
'news' => $news,
'teamer' => $teamer,
'matchingAssignments' => $matchingAssignments,
'recentFeedback' => $recentFeedback,