From 7824153836a9460f469d678e8238f6ed055b39e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Wed, 6 Dec 2023 18:14:49 +0100 Subject: [PATCH] feat: display new and pending feedbacks on admin dashboard --- src/Controller/Admin/IndexController.php | 8 +++++++ src/Repository/FeedbackRepository.php | 29 ++++++++++++++++-------- templates/admin/index.html.twig | 26 +++++++++++++++++++++ 3 files changed, 53 insertions(+), 10 deletions(-) diff --git a/src/Controller/Admin/IndexController.php b/src/Controller/Admin/IndexController.php index d1fa2bf..1bd3884 100644 --- a/src/Controller/Admin/IndexController.php +++ b/src/Controller/Admin/IndexController.php @@ -3,10 +3,12 @@ namespace App\Controller\Admin; use App\Entity\Application; +use App\Entity\Feedback; use App\Entity\Upload; use App\Repository\ApplicationRepository; use App\Repository\AssignmentRepository; use App\Repository\AvailabilityRepository; +use App\Repository\FeedbackRepository; use App\Repository\UploadRepository; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Response; @@ -17,6 +19,7 @@ class IndexController extends AbstractController { public function __construct( private readonly ApplicationRepository $applicationRepository, + private readonly FeedbackRepository $feedbackRepository, private readonly AssignmentRepository $assignmentRepository, private readonly AvailabilityRepository $availabilityRepository, private readonly UploadRepository $uploadRepository @@ -31,6 +34,9 @@ class IndexController extends AbstractController $newApplicationsCount = $this->applicationRepository->getCountByStatus(Application::STATUS_NEW); $pendingApplicationsCount = $this->applicationRepository->getCountByStatus(Application::STATUS_PENDING); + $feedbacks = $this->feedbackRepository->getNew(); + $pendingFeedbacksCount = $this->feedbackRepository->getCountByStatus(Feedback::STATUS_NEW); + $assignments = $this->assignmentRepository->getNew(); $availabilities = $this->availabilityRepository->getNew(); @@ -43,6 +49,8 @@ class IndexController extends AbstractController 'applications' => $applications, 'newApplicationsCount' => $newApplicationsCount, 'pendingApplicationsCount' => $pendingApplicationsCount, + 'feedbacks' => $feedbacks, + 'pendingFeedbacksCount' => $pendingFeedbacksCount, 'assignments' => $assignments, 'availabilities' => $availabilities, 'documents' => $documents, diff --git a/src/Repository/FeedbackRepository.php b/src/Repository/FeedbackRepository.php index 47ab496..aff79ed 100644 --- a/src/Repository/FeedbackRepository.php +++ b/src/Repository/FeedbackRepository.php @@ -21,21 +21,30 @@ class FeedbackRepository extends ServiceEntityRepository parent::__construct($registry, Feedback::class); } - public function save(Feedback $entity, bool $flush = false): void + public function getNew(int $limit = 5): array { - $this->getEntityManager()->persist($entity); + $qb = $this->createQueryBuilder('feedback'); - if ($flush) { - $this->getEntityManager()->flush(); - } + return $qb + ->select('feedback', 'teamer') + ->innerJoin('feedback.teamer', 'teamer') + ->orderBy('feedback.createdAt', 'DESC') + ->setMaxResults($limit) + ->getQuery() + ->getResult() + ; } - public function remove(Feedback $entity, bool $flush = false): void + public function getCountByStatus(string $status): int { - $this->getEntityManager()->remove($entity); + $qb = $this->createQueryBuilder('feedback'); - if ($flush) { - $this->getEntityManager()->flush(); - } + return $qb + ->select($qb->expr()->count('feedback')) + ->where($qb->expr()->eq('feedback.status', ':status')) + ->setParameter('status', $status) + ->getQuery() + ->getSingleScalarResult() + ; } } diff --git a/templates/admin/index.html.twig b/templates/admin/index.html.twig index f5d4644..7273023 100644 --- a/templates/admin/index.html.twig +++ b/templates/admin/index.html.twig @@ -110,5 +110,31 @@ {% endfor %} +
+

+ Neue Feedbacks +

+

+ {{ pendingFeedbacksCount }} freizugeben +

+ +
{% endblock %} \ No newline at end of file