mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Feature: [calendar][docgen] controller and UI to generate a document from a calendar
This commit is contained in:
parent
e107e39ffd
commit
6ae03806b4
@ -15,7 +15,7 @@ use Chill\CalendarBundle\Entity\Calendar;
|
||||
use Chill\CalendarBundle\Form\CalendarType;
|
||||
use Chill\CalendarBundle\RemoteCalendar\Connector\RemoteCalendarConnectorInterface;
|
||||
use Chill\CalendarBundle\Repository\CalendarACLAwareRepositoryInterface;
|
||||
use Chill\CalendarBundle\Repository\CalendarRepository;
|
||||
use Chill\DocGeneratorBundle\Repository\DocGeneratorTemplateRepository;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Pagination\PaginatorFactory;
|
||||
use Chill\MainBundle\Repository\UserRepository;
|
||||
@ -42,7 +42,7 @@ class CalendarController extends AbstractController
|
||||
{
|
||||
private CalendarACLAwareRepositoryInterface $calendarACLAwareRepository;
|
||||
|
||||
private CalendarRepository $calendarRepository;
|
||||
private DocGeneratorTemplateRepository $docGeneratorTemplateRepository;
|
||||
|
||||
private FilterOrderHelperFactoryInterface $filterOrderHelperFactory;
|
||||
|
||||
@ -57,8 +57,8 @@ class CalendarController extends AbstractController
|
||||
private UserRepository $userRepository;
|
||||
|
||||
public function __construct(
|
||||
CalendarRepository $calendarRepository,
|
||||
CalendarACLAwareRepositoryInterface $calendarACLAwareRepository,
|
||||
DocGeneratorTemplateRepository $docGeneratorTemplateRepository,
|
||||
FilterOrderHelperFactoryInterface $filterOrderHelperFactory,
|
||||
LoggerInterface $logger,
|
||||
PaginatorFactory $paginator,
|
||||
@ -66,8 +66,8 @@ class CalendarController extends AbstractController
|
||||
SerializerInterface $serializer,
|
||||
UserRepository $userRepository
|
||||
) {
|
||||
$this->calendarRepository = $calendarRepository;
|
||||
$this->calendarACLAwareRepository = $calendarACLAwareRepository;
|
||||
$this->docGeneratorTemplateRepository = $docGeneratorTemplateRepository;
|
||||
$this->filterOrderHelperFactory = $filterOrderHelperFactory;
|
||||
$this->logger = $logger;
|
||||
$this->paginator = $paginator;
|
||||
@ -214,6 +214,7 @@ class CalendarController extends AbstractController
|
||||
'accompanyingCourse' => $accompanyingPeriod,
|
||||
'paginator' => $paginator,
|
||||
'filterOrder' => $filterOrder,
|
||||
'hasDocs' => 0 < $this->docGeneratorTemplateRepository->countByEntity(Calendar::class),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\CalendarBundle\Controller;
|
||||
|
||||
use Chill\CalendarBundle\Entity\Calendar;
|
||||
use Chill\CalendarBundle\Security\Voter\CalendarVoter;
|
||||
use Chill\DocGeneratorBundle\Repository\DocGeneratorTemplateRepository;
|
||||
use RuntimeException;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
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;
|
||||
|
||||
class CalendarDocController
|
||||
{
|
||||
private DocGeneratorTemplateRepository $docGeneratorTemplateRepository;
|
||||
|
||||
private EngineInterface $engine;
|
||||
|
||||
private Security $security;
|
||||
|
||||
private SerializerInterface $serializer;
|
||||
|
||||
private UrlGeneratorInterface $urlGenerator;
|
||||
|
||||
public function __construct(Security $security, DocGeneratorTemplateRepository $docGeneratorTemplateRepository, UrlGeneratorInterface $urlGenerator, EngineInterface $engine)
|
||||
{
|
||||
$this->security = $security;
|
||||
$this->docGeneratorTemplateRepository = $docGeneratorTemplateRepository;
|
||||
$this->urlGenerator = $urlGenerator;
|
||||
$this->engine = $engine;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/{_locale}/calendar/docgen/pick/{id}", name="chill_calendar_calendardoc_pick_template")
|
||||
*/
|
||||
public function pickTemplate(Calendar $calendar): 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);
|
||||
|
||||
return new RedirectResponse(
|
||||
$this->urlGenerator->generate(
|
||||
'chill_docgenerator_generate_from_template',
|
||||
[
|
||||
'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(),
|
||||
])
|
||||
);
|
||||
}
|
||||
}
|
@ -128,7 +128,14 @@
|
||||
</div>
|
||||
|
||||
<ul class="record_actions">
|
||||
{% if is_granted('CHILL_ACTIVITY_CREATE', accompanyingCourse) %}
|
||||
{% if is_granted('CHILL_CALENDAR_CALENDAR_SEE', calendar) and hasDocs %}
|
||||
<li>
|
||||
<a class="btn btn-create" href="{{ chill_path_add_return_path('chill_calendar_calendardoc_pick_template', {'id': calendar.id }) }}">
|
||||
{{ 'chill_calendar.Add a document'|trans }}
|
||||
</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% if is_granted('CHILL_ACTIVITY_CREATE', accompanyingCourse) and calendar.activity is null %}
|
||||
<li>
|
||||
<a class="btn btn-create" href="{{ chill_path_add_return_path('chill_calendar_calendar_to_activity', { 'id': calendar.id }) }}">
|
||||
{{ 'Transform to activity'|trans }}
|
||||
|
@ -0,0 +1,24 @@
|
||||
{% extends "@ChillPerson/AccompanyingCourse/layout.html.twig" %}
|
||||
|
||||
{% set activeRouteKey = 'chill_calendar_calendar_list' %}
|
||||
|
||||
{% block title %}{{ 'chill_calendar.Add a document' |trans }}{% endblock title %}
|
||||
|
||||
{% set user_id = null %}
|
||||
{% set accompanying_course_id = accompanyingCourse.id %}
|
||||
|
||||
{% block js %}
|
||||
{{ parent() }}
|
||||
{{ encore_entry_script_tags('mod_docgen_picktemplate') }}
|
||||
{% endblock %}
|
||||
|
||||
{% block css %}
|
||||
{{ parent() }}
|
||||
{{ encore_entry_link_tags('mod_docgen_picktemplate') }}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<div data-docgen-template-picker="data-docgen-template-picker" data-entity-id="{{ calendar.id }}" data-entity-class="{{ 'Chill\\CalendarBundle\\Entity\\Calendar'|e('html_attr') }}"></div>
|
||||
|
||||
{% endblock %}
|
@ -50,6 +50,8 @@ chill_calendar:
|
||||
From: Du
|
||||
To: Au
|
||||
Next calendars: Prochains rendez-vous
|
||||
Add a document: Ajouter un document
|
||||
|
||||
|
||||
remote_ms_graph:
|
||||
freebusy_statuses:
|
||||
|
Loading…
x
Reference in New Issue
Block a user