WIP: Implement role house manager and feedback providing
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\HouseManager\Feedback;
|
||||
|
||||
use App\BusProNet\DataProvider\HotelDataProvider;
|
||||
use App\BusProNet\Model\Hotel;
|
||||
use App\Entity\User;
|
||||
use App\Repository\DispositionRepository;
|
||||
use Knp\Component\Pager\PaginatorInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
class IndexController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly DispositionRepository $dispositionRepository,
|
||||
private readonly HotelDataProvider $hotelDataProvider,
|
||||
private readonly PaginatorInterface $paginator
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route('/house-manager/pending-feedback', name: 'app_house_manager_feedback_index')]
|
||||
#[IsGranted('ROLE_HOUSE_MANAGER')]
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = $this->getUser();
|
||||
$hotels = $this
|
||||
->hotelDataProvider
|
||||
->findByCode($user->getHotelCode())
|
||||
;
|
||||
$hotelBusProIds = array_map(function (Hotel $hotel) {
|
||||
return $hotel->getBusProId();
|
||||
}, $hotels);
|
||||
|
||||
$query = $this
|
||||
->dispositionRepository
|
||||
->getPendingFeedbackQuery($hotelBusProIds)
|
||||
;
|
||||
|
||||
$pagination = $this->paginator->paginate(
|
||||
$query,
|
||||
$request->query->getInt('page', 1),
|
||||
10,
|
||||
[
|
||||
'defaultSortFieldName' => 'assignment.dateFrom',
|
||||
'defaultSortDirection' => 'asc',
|
||||
]
|
||||
);
|
||||
|
||||
return $this->render('house_manager/feedback/index.html.twig', [
|
||||
'pagination' => $pagination,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\HouseManager\Feedback;
|
||||
|
||||
use App\Entity\Disposition;
|
||||
use App\Entity\Feedback;
|
||||
use App\Event\FeedbackProvidedEvent;
|
||||
use App\Form\FeedbackType;
|
||||
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\Annotation\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
|
||||
|
||||
class ProvideController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private readonly EventDispatcherInterface $eventDispatcher,
|
||||
private readonly LoggerInterface $logger
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route('/house-manager/feedback/provide/{uuid}', name: 'app_house_manager_feedback_provide')]
|
||||
#[IsGranted('FEEDBACK', subject: 'disposition')]
|
||||
public function index(Disposition $disposition, Request $request): Response
|
||||
{
|
||||
$assignment = $disposition->getAssignment();
|
||||
$destination = $assignment->getDestination();
|
||||
$feebackSet = $assignment
|
||||
->getJobProfile()
|
||||
->getFeedbackSet()
|
||||
;
|
||||
$feedback = new Feedback();
|
||||
|
||||
$form = $this->createForm(FeedbackType::class, $feedback, ['feedback_set' => $feebackSet]);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$feedback
|
||||
->setAssignmentDestination($destination)
|
||||
->setAssignmentDate($assignment->getEffectivePeriod()->start->toDateTimeImmutable())
|
||||
;
|
||||
$teamer = $disposition->getTeamer();
|
||||
$teamer->addFeedback($feedback);
|
||||
$disposition->setFeedback($feedback);
|
||||
|
||||
$this->entityManager->persist($feedback);
|
||||
$this->entityManager->flush();
|
||||
|
||||
$this->eventDispatcher->dispatch(new FeedbackProvidedEvent($feedback), FeedbackProvidedEvent::NAME);
|
||||
$this->logger->info('Feedback provided', [
|
||||
'feedback_id' => $feedback->getId(),
|
||||
'teamer' => (string) $teamer,
|
||||
'destination' => (string) $destination,
|
||||
]);
|
||||
|
||||
$this->addFlash('success', 'Das Feedback wurde entgegengenommen');
|
||||
|
||||
return $this->redirectToRoute('app_house_manager_feedback_index');
|
||||
}
|
||||
|
||||
return $this->render('house_manager/feedback/provide.html.twig', [
|
||||
'form' => $form,
|
||||
'disposition' => $disposition,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,6 @@ class IndexController extends AbstractController
|
||||
#[Route('/house-manager', name: 'app_house_manager_index')]
|
||||
public function index(): Response
|
||||
{
|
||||
return $this->render('');
|
||||
return $this->render('house_manager/index.html.twig');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user