merge calendar/finalization into testing: fix conflicts

This commit is contained in:
Julie Lenaerts 2022-11-28 09:33:24 +01:00
commit 72ae6fb2cd
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 Chill\DocGeneratorBundle\Repository\DocGeneratorTemplateRepository;
use RuntimeException; use RuntimeException;
use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; 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\Security\Core\Security;
use Symfony\Component\Serializer\SerializerInterface; use Symfony\Component\Serializer\SerializerInterface;
use Symfony\Component\Templating\EngineInterface; use Symfony\Component\Templating\EngineInterface;
use UnexpectedValueException;
class CalendarDocController class CalendarDocController
{ {
@ -47,7 +49,7 @@ class CalendarDocController
/** /**
* @Route("/{_locale}/calendar/docgen/pick/{id}", name="chill_calendar_calendardoc_pick_template") * @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)) { if (!$this->security->isGranted(CalendarVoter::SEE, $calendar)) {
throw new AccessDeniedException('Not authorized to see this calendar'); throw new AccessDeniedException('Not authorized to see this calendar');
@ -60,23 +62,42 @@ class CalendarDocController
if (1 === $number) { if (1 === $number) {
$templates = $this->docGeneratorTemplateRepository->findByEntity(Calendar::class); $templates = $this->docGeneratorTemplateRepository->findByEntity(Calendar::class);
if ($request->query->has('returnPath')) {
$returnPathParam = ['returnPath' => $request->query->get('returnPath')];
}
return new RedirectResponse( return new RedirectResponse(
$this->urlGenerator->generate( $this->urlGenerator->generate(
'chill_docgenerator_generate_from_template', 'chill_docgenerator_generate_from_template',
[ array_merge(
'template' => $templates[0]->getId(), $returnPathParam ?? [],
'entityClassName' => Calendar::class, [
'entityId' => $calendar->getId(), 'template' => $templates[0]->getId(),
] 'entityClassName' => Calendar::class,
'entityId' => $calendar->getId(),
]
)
) )
); );
} }
return new Response( switch ($calendar->getContext()) {
$this->engine->render('@ChillCalendar/CalendarDoc/pick_template.html.twig', [ case 'person':
'calendar' => $calendar, return new Response(
'accompanyingCourse' => $calendar->getAccompanyingPeriod(), $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());
}
} }
} }

View File

@ -16,7 +16,6 @@ use Chill\MainBundle\Export\FilterInterface;
use Chill\MainBundle\Form\Type\PickRollingDateType; use Chill\MainBundle\Form\Type\PickRollingDateType;
use Chill\MainBundle\Service\RollingDate\RollingDate; use Chill\MainBundle\Service\RollingDate\RollingDate;
use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface;
use Doctrine\ORM\Query\Expr\Andx;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
@ -36,20 +35,12 @@ class BetweenDatesFilter implements FilterInterface
public function alterQuery(QueryBuilder $qb, $data) public function alterQuery(QueryBuilder $qb, $data)
{ {
$where = $qb->getDQLPart('where');
$clause = $qb->expr()->andX( $clause = $qb->expr()->andX(
$qb->expr()->gte('cal.startDate', ':dateFrom'), $qb->expr()->gte('cal.startDate', ':dateFrom'),
$qb->expr()->lte('cal.endDate', ':dateTo') $qb->expr()->lte('cal.endDate', ':dateTo')
); );
if ($where instanceof Andx) { $qb->andWhere($clause);
$where->add($clause);
} else {
$where = $qb->expr()->andX($clause);
}
$qb->add('where', $where);
$qb->setParameter( $qb->setParameter(
'dateFrom', 'dateFrom',
$this->rollingDateConverter->convert($data['date_from']) $this->rollingDateConverter->convert($data['date_from'])
@ -79,7 +70,7 @@ class BetweenDatesFilter implements FilterInterface
public function describeAction($data, $format = 'string'): array public function describeAction($data, $format = 'string'): array
{ {
return ['Filtered by appointments between %dateFrom% and %dateTo%', [ return ['Filtered by calendars between %dateFrom% and %dateTo%', [
'%dateFrom%' => $this->rollingDateConverter->convert($data['date_from'])->format('d-m-Y'), '%dateFrom%' => $this->rollingDateConverter->convert($data['date_from'])->format('d-m-Y'),
'%dateTo%' => $this->rollingDateConverter->convert($data['date_to'])->format('d-m-Y'), '%dateTo%' => $this->rollingDateConverter->convert($data['date_to'])->format('d-m-Y'),
]]; ]];

View File

@ -1,7 +1,5 @@
{# list used in context of person or accompanyingPeriod #} {# list used in context of person or accompanyingPeriod #}
{{ filterOrder|chill_render_filter_order_helper }}
{% if calendarItems|length > 0 %} {% if calendarItems|length > 0 %}
<div class="flex-table list-records context-accompanyingCourse"> <div class="flex-table list-records context-accompanyingCourse">

View File

@ -23,6 +23,8 @@
<h1>{{ 'Calendar list' |trans }}</h1> <h1>{{ 'Calendar list' |trans }}</h1>
{{ filterOrder|chill_render_filter_order_helper }}
{% if calendarItems|length == 0 %} {% if calendarItems|length == 0 %}
<p class="chill-no-data-statement"> <p class="chill-no-data-statement">
{{ "There is no calendar items."|trans }} {{ "There is no calendar items."|trans }}

View File

@ -22,6 +22,8 @@
<h1>{{ 'Calendar list' |trans }}</h1> <h1>{{ 'Calendar list' |trans }}</h1>
{{ filterOrder|chill_render_filter_order_helper }}
{% if calendarItems|length == 0 %} {% if calendarItems|length == 0 %}
<p class="chill-no-data-statement"> <p class="chill-no-data-statement">
{{ "There is no calendar items."|trans }} {{ "There is no calendar items."|trans }}

View File

@ -5,6 +5,7 @@
{% block title %}{{ 'chill_calendar.Add a document' |trans }}{% endblock title %} {% block title %}{{ 'chill_calendar.Add a document' |trans }}{% endblock title %}
{% set user_id = null %} {% set user_id = null %}
{% set accompanyingCourse = calendar.accompanyingPeriod %}
{% set accompanying_course_id = accompanyingCourse.id %} {% set accompanying_course_id = accompanyingCourse.id %}
{% block js %} {% block js %}
@ -19,6 +20,18 @@
{% block content %} {% block content %}
<h1>{{ 'chill_calendar.Add a document'|trans }}</h1>
<p>
{% if calendar.endDate.diff(calendar.startDate).days >= 1 %}
{{ calendar.startDate|format_datetime('short', 'short') }}
- {{ calendar.endDate|format_datetime('short', 'short') }}
{% else %}
{{ calendar.startDate|format_datetime('short', 'short') }}
- {{ calendar.endDate|format_datetime('none', 'short') }}
{% endif %}
</p>
<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> <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 %} {% endblock %}

View File

@ -0,0 +1,35 @@
{% extends "@ChillPerson/Person/layout.html.twig" %}
{% set activeRouteKey = 'chill_calendar_calendar_list' %}
{% block title %}{{ 'chill_calendar.Add a document' |trans }}{% endblock title %}
{% set person = calendar.person %}
{% block js %}
{{ parent() }}
{{ encore_entry_script_tags('mod_docgen_picktemplate') }}
{% endblock %}
{% block css %}
{{ parent() }}
{{ encore_entry_link_tags('mod_docgen_picktemplate') }}
{% endblock %}
{% block content %}
<h1>{{ 'chill_calendar.Add a document'|trans }}</h1>
<p>
{% if calendar.endDate.diff(calendar.startDate).days >= 1 %}
{{ calendar.startDate|format_datetime('short', 'short') }}
- {{ calendar.endDate|format_datetime('short', 'short') }}
{% else %}
{{ calendar.startDate|format_datetime('short', 'short') }}
- {{ calendar.endDate|format_datetime('none', 'short') }}
{% endif %}
</p>
<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 %}

View File

@ -1 +1 @@
Votre travailleur social {{ calendar.mainUser.label }} vous rencontrera le {{ calendar.startDate|format_date('short', locale='fr') }} à {{ calendar.startDate|format_time('short', locale='fr') }} - LIEU.{% if calendar.mainUser.mainLocation is not null and calendar.mainUser.mainLocation.phonenumber1 is not null %} En cas d'indisponibilité, appelez-nous au {{ calendar.mainUser.mainLocation.phonenumber1|chill_format_phonenumber }}.{% endif %} Votre travailleur social {{ calendar.mainUser.label }} vous rencontrera le {{ calendar.startDate|format_date('short', locale='fr') }} à {{ calendar.startDate|format_time('short', locale='fr') }} - {% if calendar.location is not null%}{{ calendar.location.name }}{% endif %}{% if calendar.mainUser.mainLocation is not null and calendar.mainUser.mainLocation.phonenumber1 is not null %} En cas d'indisponibilité, appelez-nous au {{ calendar.mainUser.mainLocation.phonenumber1|chill_format_phonenumber }}.{% endif %}

View File

@ -61,6 +61,9 @@ class CalendarVoter extends AbstractChillVoter implements ProvideRoleHierarchyIn
public function getRoles(): array public function getRoles(): array
{ {
return [ return [
self::CREATE,
self::DELETE,
self::EDIT,
self::SEE, self::SEE,
]; ];
} }
@ -72,7 +75,12 @@ class CalendarVoter extends AbstractChillVoter implements ProvideRoleHierarchyIn
public function getRolesWithoutScope(): array public function getRolesWithoutScope(): array
{ {
return []; return [
self::CREATE,
self::DELETE,
self::EDIT,
self::SEE,
];
} }
protected function supports($attribute, $subject): bool protected function supports($attribute, $subject): bool

View File

@ -0,0 +1,41 @@
<?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\Migrations\Calendar;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20221125144205 extends AbstractMigration
{
public function down(Schema $schema): void
{
$this->throwIrreversibleMigrationException();
}
public function getDescription(): string
{
return 'Calendar: remove association between scope and calendar';
}
public function up(Schema $schema): void
{
$this->addSql(
sprintf(
'UPDATE role_scopes SET scope_id=NULL WHERE role IN (\'%s\', \'%s\', \'%s\', \'%s\')',
'CHILL_CALENDAR_CALENDAR_CREATE',
'CHILL_CALENDAR_CALENDAR_DELETE',
'CHILL_CALENDAR_CALENDAR_EDIT',
'CHILL_CALENDAR_CALENDAR_SEE'
)
);
}
}

View File

@ -131,3 +131,9 @@ docgen:
Destinee: Destinataire Destinee: Destinataire
None: Aucun choix None: Aucun choix
title of the generated document: Titre du document généré title of the generated document: Titre du document généré
CHILL_CALENDAR_CALENDAR_CREATE: Créer les rendez-vous
CHILL_CALENDAR_CALENDAR_EDIT: Modifier les rendez-vous
CHILL_CALENDAR_CALENDAR_DELETE: Supprimer les rendez-vous
CHILL_CALENDAR_CALENDAR_SEE: Voir les rendez-vous

View File

@ -44,6 +44,11 @@ class PickRollingDateType extends AbstractType
$builder->setDataMapper(new RollingDateDataMapper()); $builder->setDataMapper(new RollingDateDataMapper());
} }
public function buildView(FormView $view, FormInterface $form, array $options)
{
$view->vars['uniqid'] = uniqid('rollingdate-');
}
public function configureOptions(OptionsResolver $resolver) public function configureOptions(OptionsResolver $resolver)
{ {
$resolver->setDefaults([ $resolver->setDefaults([
@ -65,9 +70,4 @@ class PickRollingDateType extends AbstractType
->addViolation(); ->addViolation();
} }
} }
public function buildView(FormView $view, FormInterface $form, array $options)
{
$view->vars['uniqid'] = uniqid('rollingdate-');
}
} }