mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
Feature: [CalendarDoc] pick template for generating calendar directly in list
This commit is contained in:
@@ -16,10 +16,8 @@ use Chill\CalendarBundle\Entity\CalendarDoc;
|
||||
use Chill\CalendarBundle\Form\CalendarDocCreateType;
|
||||
use Chill\CalendarBundle\Form\CalendarDocEditType;
|
||||
use Chill\CalendarBundle\Security\Voter\CalendarDocVoter;
|
||||
use Chill\CalendarBundle\Security\Voter\CalendarVoter;
|
||||
use Chill\DocGeneratorBundle\Repository\DocGeneratorTemplateRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use RuntimeException;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
use Symfony\Component\Form\FormFactoryInterface;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
@@ -28,7 +26,6 @@ use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
use Symfony\Component\Serializer\SerializerInterface;
|
||||
use Symfony\Component\Templating\EngineInterface;
|
||||
@@ -237,59 +234,4 @@ class CalendarDocController
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/{_locale}/calendar/docgen/pick/{id}", name="chill_calendar_calendardoc_pick_template")
|
||||
*/
|
||||
public function pickTemplate(Calendar $calendar, Request $request): Response
|
||||
{
|
||||
if (!$this->security->isGranted(CalendarVoter::SEE, $calendar)) {
|
||||
throw new AccessDeniedException('Not authorized to see this calendar');
|
||||
}
|
||||
|
||||
if (0 === $number = $this->docGeneratorTemplateRepository->countByEntity(Calendar::class)) {
|
||||
throw new RuntimeException('should not be redirected to this page if no template');
|
||||
}
|
||||
|
||||
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',
|
||||
array_merge(
|
||||
$returnPathParam ?? [],
|
||||
[
|
||||
'template' => $templates[0]->getId(),
|
||||
'entityClassName' => Calendar::class,
|
||||
'entityId' => $calendar->getId(),
|
||||
]
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user