72 lines
2.6 KiB
PHP
72 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Controller\Administrative\Questionnaire;
|
|
|
|
use App\Config\QuestionnaireCatalog;
|
|
use App\Controller\Traits\ReturnUrlTrait;
|
|
use App\Entity\Assignment;
|
|
use App\Enum\QuestionnaireFlag;
|
|
use App\Form\QuestionnaireType;
|
|
use Symfony\Bridge\Doctrine\Attribute\MapEntity;
|
|
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;
|
|
|
|
/**
|
|
* The teamer questionnaire as a teamer gets it, for trying out on any assignment - before or after
|
|
* the trip, placed or not. It shows the assignment's own variant, with or without the bus
|
|
* sections; ?bus_escort=1 or 0 tries the other one. Nothing is saved: "Absenden" shows the answers
|
|
* as they would be stored, "Entwurf speichern" just keeps them in the form.
|
|
*/
|
|
class TestController extends AbstractController
|
|
{
|
|
use ReturnUrlTrait;
|
|
|
|
public function __construct(
|
|
private readonly QuestionnaireCatalog $catalog,
|
|
) {
|
|
}
|
|
|
|
#[Route('/administrative/questionnaire/test/{uuid}', name: 'app_administrative_questionnaire_test')]
|
|
#[IsGranted('ROLE_ADMINISTRATIVE')]
|
|
public function index(
|
|
#[MapEntity(mapping: ['uuid' => 'uuid'])]
|
|
Assignment $assignment,
|
|
Request $request,
|
|
): Response {
|
|
$busEscort = $request->query->has('bus_escort')
|
|
? $request->query->getBoolean('bus_escort')
|
|
: $assignment->hasBusEscort();
|
|
$definition = $this->catalog
|
|
->get(QuestionnaireCatalog::TEAMER_ASSIGNMENT)
|
|
->forFlags($busEscort ? [QuestionnaireFlag::BUS_ESCORT] : [])
|
|
;
|
|
|
|
$form = $this->createForm(QuestionnaireType::class, [], ['definition' => $definition]);
|
|
$form->handleRequest($request);
|
|
|
|
$submitted = null;
|
|
$draft = false;
|
|
|
|
if ($form->isSubmitted() && $form->isValid()) {
|
|
if (QuestionnaireType::isFinal($form)) {
|
|
$submitted = $definition->withoutHiddenAnswers($form->getData());
|
|
} else {
|
|
$draft = true;
|
|
}
|
|
}
|
|
|
|
return $this->render('administrative/questionnaire/test.html.twig', [
|
|
'assignment' => $assignment,
|
|
'definition' => $definition,
|
|
'form' => $form,
|
|
'submitted' => $submitted,
|
|
'draft' => $draft,
|
|
'busEscort' => $busEscort,
|
|
'returnUrl' => $this->getReturnUrl($request, 'app_administrative_assignment_detail', ['uuid' => $assignment->getUuid()]),
|
|
]);
|
|
}
|
|
}
|