merge calendar/finalization into testing: fix conflicts

This commit is contained in:
2022-11-28 09:33:24 +01:00
12 changed files with 149 additions and 32 deletions

View File

@@ -16,6 +16,7 @@ use Chill\CalendarBundle\Security\Voter\CalendarVoter;
use Chill\DocGeneratorBundle\Repository\DocGeneratorTemplateRepository;
use RuntimeException;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
@@ -23,6 +24,7 @@ use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Serializer\SerializerInterface;
use Symfony\Component\Templating\EngineInterface;
use UnexpectedValueException;
class CalendarDocController
{
@@ -47,7 +49,7 @@ class CalendarDocController
/**
* @Route("/{_locale}/calendar/docgen/pick/{id}", name="chill_calendar_calendardoc_pick_template")
*/
public function pickTemplate(Calendar $calendar): Response
public function pickTemplate(Calendar $calendar, Request $request): Response
{
if (!$this->security->isGranted(CalendarVoter::SEE, $calendar)) {
throw new AccessDeniedException('Not authorized to see this calendar');
@@ -60,23 +62,42 @@ class CalendarDocController
if (1 === $number) {
$templates = $this->docGeneratorTemplateRepository->findByEntity(Calendar::class);
if ($request->query->has('returnPath')) {
$returnPathParam = ['returnPath' => $request->query->get('returnPath')];
}
return new RedirectResponse(
$this->urlGenerator->generate(
'chill_docgenerator_generate_from_template',
[
'template' => $templates[0]->getId(),
'entityClassName' => Calendar::class,
'entityId' => $calendar->getId(),
]
array_merge(
$returnPathParam ?? [],
[
'template' => $templates[0]->getId(),
'entityClassName' => Calendar::class,
'entityId' => $calendar->getId(),
]
)
)
);
}
return new Response(
$this->engine->render('@ChillCalendar/CalendarDoc/pick_template.html.twig', [
'calendar' => $calendar,
'accompanyingCourse' => $calendar->getAccompanyingPeriod(),
])
);
switch ($calendar->getContext()) {
case 'person':
return new Response(
$this->engine->render('@ChillCalendar/CalendarDoc/pick_template_person.html.twig', [
'calendar' => $calendar,
])
);
case 'accompanying_period':
return new Response(
$this->engine->render('@ChillCalendar/CalendarDoc/pick_template_accompanying_period.html.twig', [
'calendar' => $calendar,
])
);
default:
throw new UnexpectedValueException('calendar context not expected : ' . $calendar->getContext());
}
}
}