Merge branch 'master' into calendar/docgen-add-generation

This commit is contained in:
2022-10-20 13:34:21 +02:00
56 changed files with 1728 additions and 100 deletions

View File

@@ -62,6 +62,7 @@ class UserRefEventSubscriber implements EventSubscriberInterface
&& $period->getUser() !== $this->security->getUser()
&& null !== $period->getUser()
&& $period->getStep() !== AccompanyingPeriod::STEP_DRAFT
&& !$period->isPreventUserIsChangedNotification()
) {
$this->generateNotificationToUser($period);
}

View File

@@ -11,7 +11,9 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Controller;
use Chill\MainBundle\Entity\PostalCode;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Form\Type\PickPostalCodeType;
use Chill\MainBundle\Form\Type\PickUserDynamicType;
use Chill\MainBundle\Pagination\PaginatorFactory;
use Chill\MainBundle\Repository\UserRepository;
@@ -92,12 +94,14 @@ class ReassignAccompanyingPeriodController extends AbstractController
$form->handleRequest($request);
$userFrom = $form['user']->getData();
$postalCodes = $form['postal_code']->getData() instanceof PostalCode ? [$form['postal_code']->getData()] : [];
$total = $this->accompanyingPeriodACLAwareRepository->countByUserOpenedAccompanyingPeriod($userFrom);
$paginator = $this->paginatorFactory->create($total);
$periods = $this->accompanyingPeriodACLAwareRepository
->findByUserOpenedAccompanyingPeriod(
->findByUserAndPostalCodesOpenedAccompanyingPeriod(
$userFrom,
$postalCodes,
['openingDate' => 'ASC'],
$paginator->getItemsPerPage(),
$paginator->getCurrentPageFirstItemNumber()
@@ -123,7 +127,7 @@ class ReassignAccompanyingPeriodController extends AbstractController
$period = $this->courseRepository->find($periodId);
if ($period->getUser() === $userFrom) {
$period->setUser($userTo);
$period->setUser($userTo, true);
}
}
@@ -148,7 +152,9 @@ class ReassignAccompanyingPeriodController extends AbstractController
{
$data = [
'user' => null,
'postal_code' => null,
];
$builder = $this->formFactory->createBuilder(FormType::class, $data, [
'method' => 'get', 'csrf_protection' => false, ]);
@@ -158,12 +164,17 @@ class ReassignAccompanyingPeriodController extends AbstractController
'label' => 'reassign.Current user',
'required' => false,
'help' => 'reassign.Choose a user and click on "Filter" to apply',
])
->add('postal_code', PickPostalCodeType::class, [
'label' => 'reassign.Filter by postal code',
'required' => false,
'help' => 'reassign.Filter course which are located inside a postal code',
]);
return $builder->getForm();
}
private function buildReassignForm(array $periodIds, ?User $userFrom): FormInterface
private function buildReassignForm(array $periodIds, ?User $userFrom = null): FormInterface
{
$defaultData = [
'userFrom' => $userFrom,

View File

@@ -270,6 +270,8 @@ class AccompanyingPeriod implements
*/
private ?Comment $pinnedComment = null;
private bool $preventUserIsChangedNotification = false;
/**
* @ORM\Column(type="text")
* @Groups({"read", "write"})
@@ -1077,6 +1079,11 @@ class AccompanyingPeriod implements
return false;
}
public function isPreventUserIsChangedNotification(): bool
{
return $this->preventUserIsChangedNotification;
}
public function isRequestorAnonymous(): bool
{
return $this->requestorAnonymous;
@@ -1372,11 +1379,12 @@ class AccompanyingPeriod implements
return $this;
}
public function setUser(?User $user): self
public function setUser(?User $user, bool $preventNotification = false): self
{
if ($this->user !== $user) {
$this->userPrevious = $this->user;
$this->userIsChanged = true;
$this->preventUserIsChangedNotification = $preventNotification;
foreach ($this->userHistories as $history) {
if (null === $history->getEndDate()) {

View File

@@ -35,6 +35,11 @@ class MaritalStatus
*/
private array $name;
public function __construct()
{
$this->id = substr(md5(uniqid()), 0, 7);
}
/**
* Get id.
*/

View File

@@ -72,6 +72,9 @@ class Evaluation
$this->socialActions = new ArrayCollection();
}
/**
* @internal do use @see{SocialAction::addEvaluation}
*/
public function addSocialAction(SocialAction $socialAction): self
{
if (!$this->socialActions->contains($socialAction)) {
@@ -111,6 +114,11 @@ class Evaluation
return $this->url;
}
/**
* @return $this
*
* @internal do use @see{SocialAction::removeEvaluation}
*/
public function removeSocialAction(SocialAction $socialAction): self
{
if ($this->socialActions->contains($socialAction)) {

View File

@@ -112,6 +112,7 @@ class SocialAction
{
if (!$this->evaluations->contains($evaluation)) {
$this->evaluations[] = $evaluation;
$evaluation->addSocialAction($this);
}
return $this;
@@ -310,6 +311,7 @@ class SocialAction
public function removeEvaluation(Evaluation $evaluation): self
{
$this->evaluations->removeElement($evaluation);
$evaluation->removeSocialAction($this);
return $this;
}

View File

@@ -14,7 +14,6 @@ namespace Chill\PersonBundle\Form;
use Chill\MainBundle\Form\Type\TranslatableStringFormType;
use Chill\PersonBundle\Entity\MaritalStatus;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
@@ -26,9 +25,6 @@ class MaritalStatusType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('id', TextType::class, [
'label' => 'Identifiant',
])
->add('name', TranslatableStringFormType::class, [
'label' => 'Nom',
]);

View File

@@ -11,7 +11,9 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Repository;
use Chill\MainBundle\Entity\Address;
use Chill\MainBundle\Entity\Location;
use Chill\MainBundle\Entity\PostalCode;
use Chill\MainBundle\Entity\Scope;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Entity\UserJob;
@@ -19,10 +21,14 @@ use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
use Chill\MainBundle\Security\Resolver\CenterResolverDispatcherInterface;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation;
use Chill\PersonBundle\Entity\Household\PersonHouseholdAddress;
use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
use DateTime;
use DateTimeImmutable;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Query\Expr\Join;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Security\Core\Security;
use function count;
@@ -49,7 +55,12 @@ final class AccompanyingPeriodACLAwareRepository implements AccompanyingPeriodAC
$this->centerResolverDispatcher = $centerResolverDispatcher;
}
public function buildQueryOpenedAccompanyingCourseByUser(?User $user)
/**
* @param array|PostalCode[]
*
* @return QueryBuilder
*/
public function buildQueryOpenedAccompanyingCourseByUser(?User $user, array $postalCodes = [])
{
$qb = $this->accompanyingPeriodRepository->createQueryBuilder('ap');
@@ -65,6 +76,37 @@ final class AccompanyingPeriodACLAwareRepository implements AccompanyingPeriodAC
->setParameter('now', new DateTime('now'))
->setParameter('draft', AccompanyingPeriod::STEP_DRAFT);
if ([] !== $postalCodes) {
$qb->join('ap.locationHistories', 'location_history')
->leftJoin(PersonHouseholdAddress::class, 'person_address', Join::WITH, 'IDENTITY(location_history.personLocation) = IDENTITY(person_address.person)')
->join(
Address::class,
'address',
Join::WITH,
'COALESCE(IDENTITY(location_history.addressLocation), IDENTITY(person_address.address)) = address.id'
)
->andWhere(
$qb->expr()->orX(
$qb->expr()->isNull('person_address'),
$qb->expr()->andX(
$qb->expr()->lte('person_address.validFrom', ':now'),
$qb->expr()->orX(
$qb->expr()->isNull('person_address.validTo'),
$qb->expr()->lt('person_address.validTo', ':now')
)
)
)
)
->andWhere(
$qb->expr()->isNull('location_history.endDate')
)
->andWhere(
$qb->expr()->in('address.postcode', ':postal_codes')
)
->setParameter('now', new DateTimeImmutable('now'), Types::DATE_IMMUTABLE)
->setParameter('postal_codes', $postalCodes);
}
return $qb;
}
@@ -77,6 +119,18 @@ final class AccompanyingPeriodACLAwareRepository implements AccompanyingPeriodAC
return $qb->getQuery()->getSingleScalarResult();
}
public function countByUserAndPostalCodesOpenedAccompanyingPeriod(?User $user, array $postalCodes): int
{
if (null === $user) {
return 0;
}
return $this->buildQueryOpenedAccompanyingCourseByUser($user, $postalCodes)
->select('COUNT(ap)')
->getQuery()
->getSingleScalarResult();
}
public function countByUserOpenedAccompanyingPeriod(?User $user): int
{
if (null === $user) {
@@ -158,6 +212,24 @@ final class AccompanyingPeriodACLAwareRepository implements AccompanyingPeriodAC
return $qb->getQuery()->getResult();
}
public function findByUserAndPostalCodesOpenedAccompanyingPeriod(?User $user, array $postalCodes, array $orderBy = [], int $limit = 0, int $offset = 50): array
{
if (null === $user) {
return [];
}
$qb = $this->buildQueryOpenedAccompanyingCourseByUser($user);
$qb->setFirstResult($offset)
->setMaxResults($limit);
foreach ($orderBy as $field => $direction) {
$qb->addOrderBy('ap.' . $field, $direction);
}
return $qb->getQuery()->getResult();
}
/**
* @return array|AccompanyingPeriod[]
*/

View File

@@ -11,6 +11,7 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Repository;
use Chill\MainBundle\Entity\PostalCode;
use Chill\MainBundle\Entity\Scope;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Entity\UserJob;
@@ -25,6 +26,11 @@ interface AccompanyingPeriodACLAwareRepositoryInterface
*/
public function countByUnDispatched(array $jobs, array $services, array $administrativeLocations): int;
/**
* @param array|PostalCode[] $postalCodes
*/
public function countByUserAndPostalCodesOpenedAccompanyingPeriod(?User $user, array $postalCodes): int;
public function countByUserOpenedAccompanyingPeriod(?User $user): int;
public function findByPerson(
@@ -43,5 +49,10 @@ interface AccompanyingPeriodACLAwareRepositoryInterface
*/
public function findByUnDispatched(array $jobs, array $services, array $administrativeLocations, ?int $limit = null, ?int $offset = null): array;
/**
* @param array|PostalCode[] $postalCodes
*/
public function findByUserAndPostalCodesOpenedAccompanyingPeriod(?User $user, array $postalCodes, array $orderBy = [], int $limit = 0, int $offset = 50): array;
public function findByUserOpenedAccompanyingPeriod(?User $user, array $orderBy = [], int $limit = 0, int $offset = 50): array;
}

View File

@@ -13,6 +13,7 @@ namespace Chill\PersonBundle\Repository\SocialWork;
use Chill\PersonBundle\Entity\SocialWork\Goal;
use Chill\PersonBundle\Entity\SocialWork\SocialAction;
use DateTime;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\QueryBuilder;
@@ -73,6 +74,14 @@ final class GoalRepository implements ObjectRepository
$qb = $this->buildQueryBySocialActionWithDescendants($action);
$qb->select('g');
$qb->andWhere(
$qb->expr()->orX(
$qb->expr()->isNull('g.desactivationDate'),
$qb->expr()->gt('g.desactivationDate', ':now')
)
)
->setParameter('now', new DateTime('now'));
foreach ($orderBy as $sort => $order) {
$qb->addOrderBy('g.' . $sort, $order);
}

View File

@@ -76,7 +76,7 @@
<div class="flex-table">
{% for period in periods %}
{% include '@ChillPerson/AccompanyingPeriod/_list_item.html.twig' with {'period': period,
'recordAction': m.period_actions(period), 'itemMeta': m.period_meta(period) } %}
'recordAction': m.period_actions(period), 'itemMeta': m.period_meta(period), 'show_address': true } %}
{% endfor %}
</div>
{% endif %}

View File

@@ -113,6 +113,16 @@
</div>
</div>
{% endif %}
{% if show_address|default(false) and period.location is not null %}
<div class="wl-row">
<div class="wl-col title"><h3>{{ 'Accompanying course location'|trans }}</h3></div>
<div class="wl-col list">
<p class="wl-item">
{{ period.location|chill_entity_render_string }}
</p>
</div>
</div>
{% endif %}
</div>
</div>
{% endif %}

View File

@@ -5,11 +5,13 @@
{% block js %}
{{ encore_entry_script_tags('mod_set_referrer') }}
{{ encore_entry_script_tags('mod_pickentity_type') }}
{{ encore_entry_script_tags('mod_pick_postal_code') }}
{% endblock %}
{% block css %}
{{ encore_entry_link_tags('mod_set_referrer') }}
{{ encore_entry_link_tags('mod_pickentity_type') }}
{{ encore_entry_link_tags('mod_pick_postal_code') }}
{% endblock %}
{% macro period_meta(period) %}
@@ -48,6 +50,8 @@
{{ form_start(form) }}
{{ form_label(form.user ) }}
{{ form_widget(form.user, {'attr': {'class': 'select2'}}) }}
{{ form_label(form.postal_code) }}
{{ form_widget(form.postal_code) }}
<ul class="record_actions">
<li>
<button type="submit" class="btn btn-misc">
@@ -87,7 +91,7 @@
<div class="flex-table">
{% for period in periods %}
{% include '@ChillPerson/AccompanyingPeriod/_list_item.html.twig' with {'period': period,
'recordAction': m.period_actions(period), 'itemMeta': m.period_meta(period) } %}
'recordAction': m.period_actions(period), 'itemMeta': m.period_meta(period), 'show_address': true } %}
{% else %}
{% if userFrom is same as(null) %}
<p class="chill-no-data-statement">{{ 'period_by_user_list.Pick a user'|trans }}</p>

View File

@@ -11,7 +11,6 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Service\DocGenerator;
use Chill\DocGeneratorBundle\Context\DocGeneratorContextWithAdminFormInterface;
use Chill\DocGeneratorBundle\Context\Exception\UnexpectedTypeException;
use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate;
use Chill\DocGeneratorBundle\Service\Context\BaseContextData;
@@ -19,46 +18,73 @@ use Chill\DocStoreBundle\Entity\DocumentCategory;
use Chill\DocStoreBundle\Entity\PersonDocument;
use Chill\DocStoreBundle\Entity\StoredObject;
use Chill\DocStoreBundle\Repository\DocumentCategoryRepository;
use Chill\DocStoreBundle\Security\Authorization\PersonDocumentVoter;
use Chill\MainBundle\Entity\Scope;
use Chill\MainBundle\Form\Type\ScopePickerType;
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface;
use Chill\MainBundle\Security\Resolver\CenterResolverManagerInterface;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use Chill\PersonBundle\Entity\Person;
use DateTime;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use LogicException;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use function array_key_exists;
use function count;
class PersonContext implements DocGeneratorContextWithAdminFormInterface
final class PersonContext implements PersonContextInterface
{
private AuthorizationHelperInterface $authorizationHelper;
private BaseContextData $baseContextData;
private CenterResolverManagerInterface $centerResolverManager;
private DocumentCategoryRepository $documentCategoryRepository;
private EntityManagerInterface $em;
private NormalizerInterface $normalizer;
private Security $security;
private bool $showScopes;
private TranslatableStringHelperInterface $translatableStringHelper;
private TranslatorInterface $translator;
public function __construct(
AuthorizationHelperInterface $authorizationHelper,
BaseContextData $baseContextData,
CenterResolverManagerInterface $centerResolverManager,
DocumentCategoryRepository $documentCategoryRepository,
NormalizerInterface $normalizer,
TranslatableStringHelperInterface $translatableStringHelper,
EntityManagerInterface $em,
NormalizerInterface $normalizer,
ParameterBagInterface $parameterBag,
Security $security,
TranslatorInterface $translator,
BaseContextData $baseContextData
TranslatableStringHelperInterface $translatableStringHelper
) {
$this->documentCategoryRepository = $documentCategoryRepository;
$this->normalizer = $normalizer;
$this->translatableStringHelper = $translatableStringHelper;
$this->em = $em;
$this->authorizationHelper = $authorizationHelper;
$this->centerResolverManager = $centerResolverManager;
$this->baseContextData = $baseContextData;
$this->documentCategoryRepository = $documentCategoryRepository;
$this->em = $em;
$this->normalizer = $normalizer;
$this->security = $security;
$this->showScopes = $parameterBag->get('chill_main')['acl']['form_show_scopes'];
$this->translator = $translator;
$this->translatableStringHelper = $translatableStringHelper;
}
public function adminFormReverseTransform(array $data): array
@@ -102,9 +128,30 @@ class PersonContext implements DocGeneratorContextWithAdminFormInterface
'choice_label' => function ($entity = null) {
return $entity ? $this->translatableStringHelper->localize($entity->getName()) : '';
},
'required' => true,
]);
}
/**
* @param Person $entity
*/
public function buildPublicForm(FormBuilderInterface $builder, DocGeneratorTemplate $template, $entity): void
{
$builder->add('title', TextType::class, [
'required' => true,
'label' => 'docgen.Document title',
'data' => $this->translatableStringHelper->localize($template->getName()),
]);
if ($this->isScopeNecessary($entity)) {
$builder->add('scope', ScopePickerType::class, [
'center' => $this->centerResolverManager->resolveCenters($entity),
'role' => PersonDocumentVoter::CREATE,
'label' => 'Scope',
]);
}
}
public function getData(DocGeneratorTemplate $template, $entity, array $contextGenerationData = []): array
{
if (!$entity instanceof Person) {
@@ -156,6 +203,14 @@ class PersonContext implements DocGeneratorContextWithAdminFormInterface
return true;
}
/**
* @param Person $entity
*/
public function hasPublicForm(DocGeneratorTemplate $template, $entity): bool
{
return true;
}
/**
* @param Person $entity
*/
@@ -163,7 +218,9 @@ class PersonContext implements DocGeneratorContextWithAdminFormInterface
{
$doc = new PersonDocument();
$doc->setTemplate($template)
->setTitle($this->translatableStringHelper->localize($template->getName()))
->setTitle(
$contextGenerationData['title'] ?? $this->translatableStringHelper->localize($template->getName())
)
->setDate(new DateTime())
->setDescription($this->translatableStringHelper->localize($template->getName()))
->setPerson($entity)
@@ -178,6 +235,36 @@ class PersonContext implements DocGeneratorContextWithAdminFormInterface
);
}
if ($this->isScopeNecessary($entity)) {
$doc->setScope($contextGenerationData['scope']);
} elseif ($this->showScopes) {
// in this case, it should have only one scope possible, we get it through AuthorizationHelper::getReachableScopes
$scopes = $this->authorizationHelper->getReachableScopes(
$this->security->getUser(),
PersonDocumentVoter::CREATE,
$this->centerResolverManager->resolveCenters($entity)
);
if (1 !== count($scopes)) {
throw new LogicException('at this step, it should have only one scope');
}
$doc->setScope($scopes[0]);
}
$this->em->persist($doc);
}
private function isScopeNecessary(Person $person): bool
{
if ($this->showScopes && 1 < $this->authorizationHelper->getReachableScopes(
$this->security->getUser(),
PersonDocumentVoter::CREATE,
$this->centerResolverManager->resolveCenters($person)
)) {
return true;
}
return false;
}
}

View File

@@ -0,0 +1,55 @@
<?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\PersonBundle\Service\DocGenerator;
use Chill\DocGeneratorBundle\Context\DocGeneratorContextWithAdminFormInterface;
use Chill\DocGeneratorBundle\Context\DocGeneratorContextWithPublicFormInterface;
use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate;
use Chill\DocStoreBundle\Entity\StoredObject;
use Chill\PersonBundle\Entity\Person;
use Symfony\Component\Form\FormBuilderInterface;
interface PersonContextInterface extends DocGeneratorContextWithAdminFormInterface, DocGeneratorContextWithPublicFormInterface
{
public function adminFormReverseTransform(array $data): array;
public function adminFormTransform(array $data): array;
public function buildAdminForm(FormBuilderInterface $builder): void;
/**
* @param Person $entity
*/
public function buildPublicForm(FormBuilderInterface $builder, DocGeneratorTemplate $template, $entity): void;
public function getData(DocGeneratorTemplate $template, $entity, array $contextGenerationData = []): array;
public function getDescription(): string;
public function getEntityClass(): string;
public function getFormData(DocGeneratorTemplate $template, $entity): array;
public function getName(): string;
public function hasAdminForm(): bool;
/**
* @param Person $entity
*/
public function hasPublicForm(DocGeneratorTemplate $template, $entity): bool;
/**
* @param Person $entity
*/
public function storeGenerated(DocGeneratorTemplate $template, StoredObject $storedObject, object $entity, array $contextGenerationData): void;
}

View File

@@ -0,0 +1,130 @@
<?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\PersonBundle\Service\DocGenerator;
use Chill\DocGeneratorBundle\Context\DocGeneratorContextWithAdminFormInterface;
use Chill\DocGeneratorBundle\Context\DocGeneratorContextWithPublicFormInterface;
use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate;
use Chill\DocStoreBundle\Entity\StoredObject;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use Chill\ThirdPartyBundle\Form\Type\PickThirdpartyDynamicType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
/**
* Context to generate a document with a destinee (i.e. generate a letter).
*/
class PersonContextWithThirdParty implements DocGeneratorContextWithAdminFormInterface, DocGeneratorContextWithPublicFormInterface
{
private NormalizerInterface $normalizer;
private PersonContextInterface $personContext;
public function __construct(
PersonContextInterface $personContext,
NormalizerInterface $normalizer
) {
$this->personContext = $personContext;
$this->normalizer = $normalizer;
}
public function adminFormReverseTransform(array $data): array
{
return array_merge(
$this->personContext->adminFormReverseTransform($data),
['label' => $data['label']]
);
}
public function adminFormTransform(array $data): array
{
return array_merge(
$this->personContext->adminFormTransform($data),
['label' => $data['label'] ?? '']
);
}
public function buildAdminForm(FormBuilderInterface $builder): void
{
$this->personContext->buildAdminForm($builder);
$builder->add('label', TextType::class, [
'label' => 'docgen.Label for third party',
'required' => true,
]);
}
public function buildPublicForm(FormBuilderInterface $builder, DocGeneratorTemplate $template, $entity): void
{
$this->personContext->buildPublicForm($builder, $template, $entity);
$builder->add('thirdParty', PickThirdpartyDynamicType::class, [
'multiple' => false,
'label' => $template->getOptions()['label'] ?? 'ThirdParty',
'validation_groups' => ['__none__'],
]);
}
public function getData(DocGeneratorTemplate $template, $entity, array $contextGenerationData = []): array
{
$data = $this->personContext->getData($template, $entity, $contextGenerationData);
$data['thirdParty'] = $this->normalizer->normalize(
$contextGenerationData['thirdParty'],
'docgen',
['docgen:expects' => ThirdParty::class, 'groups' => ['docgen:read']]
);
return $data;
}
public function getDescription(): string
{
return 'docgen.A context for person with a third party (for sending mail)';
}
public function getEntityClass(): string
{
return $this->personContext->getEntityClass();
}
public function getFormData(DocGeneratorTemplate $template, $entity): array
{
return $this->personContext->getFormData($template, $entity);
}
public static function getKey(): string
{
return self::class;
}
public function getName(): string
{
return 'docgen.Person with third party';
}
public function hasAdminForm(): bool
{
return true;
}
public function hasPublicForm(DocGeneratorTemplate $template, $entity): bool
{
return true;
}
public function storeGenerated(DocGeneratorTemplate $template, StoredObject $storedObject, object $entity, array $contextGenerationData): void
{
$this->personContext->storeGenerated($template, $storedObject, $entity, $contextGenerationData);
}
}

View File

@@ -193,7 +193,7 @@ final class SocialWorkMetadata implements SocialWorkMetadataInterface
/** @var Evaluation $eval */
$eval = $this->getOrCreateEntity($this->evaluationRepository, 'title', ['fr' => $evaluationTitle]);
$eval->setTitle(['fr' => $evaluationTitle]);
$eval->addSocialAction($socialAction);
$socialAction->addEvaluation($eval);
$this->entityManager->persist($eval);

View File

@@ -0,0 +1,46 @@
<?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\PersonBundle\Tests\Serializer\Normalizer;
use Chill\PersonBundle\Entity\AccompanyingPeriod\Origin;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
/**
* @internal
* @coversNothing
*/
final class AccompanyingPeriodOriginNormalizerTest extends KernelTestCase
{
private NormalizerInterface $normalizer;
protected function setUp(): void
{
self::bootKernel();
$this->normalizer = self::$container->get(NormalizerInterface::class);
}
public function testNormalization()
{
$o = new Origin();
$normalized = $this->normalizer->normalize(
$o,
'json',
['groups' => ['read']]
);
$this->assertIsArray($normalized);
$this->assertArrayHasKey('type', $normalized);
$this->assertEquals('origin', $normalized['type']);
}
}

View File

@@ -0,0 +1,67 @@
<?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 Serializer\Normalizer;
use Chill\PersonBundle\Entity\AccompanyingPeriod\Resource;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
/**
* @internal
* @coversNothing
*/
final class AccompanyingPeriodResourceNormalizerTest extends KernelTestCase
{
private NormalizerInterface $normalizer;
protected function setUp(): void
{
self::bootKernel();
$this->normalizer = self::$container->get(NormalizerInterface::class);
}
public function testNormalizeNullHasSameValueAsNotNull()
{
$nullResource = $this->normalizer->normalize(null, 'docgen', ['groups' => 'docgen:read', 'docgen:expects' => Resource::class]);
$notNull = $this->normalizer->normalize(new Resource(), 'docgen', ['groups' => 'docgen:read', 'docgen:expects' => Resource::class]);
$this->assertEqualsCanonicalizing(array_keys($notNull), array_keys($nullResource));
}
public function testNormalizeResource()
{
$resource = new Resource();
$resource
->setComment('blabla')
->setResource(new ThirdParty());
$expected = [
'type' => 'accompanying_period_resource',
'isNull' => false,
'comment' => 'blabla',
];
$actual = $this->normalizer->normalize($resource, 'docgen', ['groups' => 'docgen:read', 'docgen:expects' => Resource::class]);
// we do not test for sub array (person, thirdparty). We then check first for base value...
foreach ($expected as $key => $value) {
$this->assertArrayHasKey($key, $actual);
$this->assertEquals($value, $actual[$key]);
}
// ... and then for the existence of some values
$this->assertArrayHasKey('person', $actual);
$this->assertArrayHasKey('thirdParty', $actual);
}
}

View File

@@ -60,7 +60,7 @@ final class AccompanyingPeriodWorkDocGenNormalizerTest extends KernelTestCase
}
}
public function testNormlalize()
public function testNormalize()
{
$work = new AccompanyingPeriodWork();
$work

View File

@@ -0,0 +1,46 @@
<?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\PersonBundle\Tests\Serializer\Normalizer;
use Chill\PersonBundle\Entity\SocialWork\SocialAction;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
/**
* @internal
* @coversNothing
*/
final class SocialActionNormalizerTest extends KernelTestCase
{
private NormalizerInterface $normalizer;
protected function setUp(): void
{
self::bootKernel();
$this->normalizer = self::$container->get(NormalizerInterface::class);
}
public function testNormalization()
{
$sa = new SocialAction();
$normalized = $this->normalizer->normalize(
$sa,
'json',
['groups' => ['read']]
);
$this->assertIsArray($normalized);
$this->assertArrayHasKey('type', $normalized);
$this->assertEquals('social_work_social_action', $normalized['type']);
}
}

View File

@@ -0,0 +1,46 @@
<?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\PersonBundle\Tests\Serializer\Normalizer;
use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
/**
* @internal
* @coversNothing
*/
final class SocialIssueNormalizerTest extends KernelTestCase
{
private NormalizerInterface $normalizer;
protected function setUp(): void
{
self::bootKernel();
$this->normalizer = self::$container->get(NormalizerInterface::class);
}
public function testNormalization()
{
$si = new SocialIssue();
$normalized = $this->normalizer->normalize(
$si,
'json',
['groups' => ['read']]
);
$this->assertIsArray($normalized);
$this->assertArrayHasKey('type', $normalized);
$this->assertEquals('social_issue', $normalized['type']);
}
}

View File

@@ -0,0 +1,286 @@
<?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 Service\DocGenerator;
use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate;
use Chill\DocGeneratorBundle\Service\Context\BaseContextData;
use Chill\DocStoreBundle\Entity\DocumentCategory;
use Chill\DocStoreBundle\Entity\PersonDocument;
use Chill\DocStoreBundle\Entity\StoredObject;
use Chill\DocStoreBundle\Repository\DocumentCategoryRepository;
use Chill\DocStoreBundle\Security\Authorization\PersonDocumentVoter;
use Chill\MainBundle\Entity\Center;
use Chill\MainBundle\Entity\Scope;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Form\Type\ScopePickerType;
use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface;
use Chill\MainBundle\Security\Resolver\CenterResolverManagerInterface;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Service\DocGenerator\PersonContext;
use Doctrine\ORM\EntityManagerInterface;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\Exception\Prediction\FailedPredictionException;
use Prophecy\PhpUnit\ProphecyTrait;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use function count;
/**
* @internal
* @coversNothing
*/
final class PersonContextTest extends TestCase
{
use ProphecyTrait;
/**
* Test that the build person context works in the case when 'form_show_scope' is false.
*/
public function testScopeDoNotShowScopeInForms()
{
$person = new Person();
$docGen = (new DocGeneratorTemplate())
->setName(['fr' => 'template']);
$parameter = new ParameterBag(['chill_main' => ['acl' => ['form_show_scopes' => false]]]);
$em = $this->prophesize(EntityManagerInterface::class);
$em->persist(Argument::type(PersonDocument::class))
->should(static function ($calls, $object, $method) {
if (1 !== count($calls)) {
throw new FailedPredictionException(sprintf('the persist should be called exactly once, %d receivved', count($calls)));
}
/** @var PersonDocument $personDocument */
$personDocument = $calls[0]->getArguments()[0];
if (null !== $personDocument->getScope()) {
throw new FailedPredictionException('the person document should not have any scope');
}
});
$personContext = $this->buildPersonContext(
null,
null,
null,
null,
$em->reveal(),
null,
$parameter
);
$personContext->buildPublicForm($this->buildFormBuilder(false), $docGen, $person);
$personContext->storeGenerated(
$docGen,
new StoredObject(),
$person,
[]
);
}
public function testScopeScopeMustBeShownInFormsAndUserAccessMultipleScope()
{
$person = new Person();
$docGen = (new DocGeneratorTemplate())
->setName(['fr' => 'template']);
$scope = new Scope();
$em = $this->prophesize(EntityManagerInterface::class);
$em->persist(Argument::type(PersonDocument::class))
->should(static function ($calls, $object, $method) use ($scope) {
if (1 !== count($calls)) {
throw new FailedPredictionException(sprintf('the persist should be called exactly once, %d receivved', count($calls)));
}
/** @var PersonDocument $personDocument */
$personDocument = $calls[0]->getArguments()[0];
if ($personDocument->getScope() !== $scope) {
throw new FailedPredictionException('the person document should show the exactly prepared scope');
}
});
$authorizationHelper = $this->prophesize(AuthorizationHelperInterface::class);
$authorizationHelper->getReachableScopes(Argument::type(UserInterface::class), PersonDocumentVoter::CREATE, Argument::type('array'))
->willReturn([$scope, new Scope()]);
$personContext = $this->buildPersonContext(
$authorizationHelper->reveal(),
null,
null,
null,
$em->reveal(),
);
$personContext->buildPublicForm($this->buildFormBuilder(true), $docGen, $person);
$personContext->storeGenerated(
$docGen,
new StoredObject(),
$person,
['scope' => $scope]
);
}
public function testScopeScopeMustBeShownInFormsAndUserAccessOneScope()
{
$person = new Person();
$docGen = (new DocGeneratorTemplate())
->setName(['fr' => 'template']);
$scope = new Scope();
$em = $this->prophesize(EntityManagerInterface::class);
$em->persist(Argument::type(PersonDocument::class))
->should(static function ($calls, $object, $method) use ($scope) {
if (1 !== count($calls)) {
throw new FailedPredictionException(sprintf('the persist should be called exactly once, %d receivved', count($calls)));
}
/** @var PersonDocument $personDocument */
$personDocument = $calls[0]->getArguments()[0];
if ($personDocument->getScope() !== $scope) {
throw new FailedPredictionException('the person document should show the exactly prepared scope');
}
});
$authorizationHelper = $this->prophesize(AuthorizationHelperInterface::class);
$authorizationHelper->getReachableScopes(Argument::type(UserInterface::class), PersonDocumentVoter::CREATE, Argument::type('array'))
->willReturn([$scope]);
$personContext = $this->buildPersonContext(
$authorizationHelper->reveal(),
null,
null,
null,
$em->reveal(),
);
$personContext->buildPublicForm($this->buildFormBuilder(true), $docGen, $person);
$personContext->storeGenerated(
$docGen,
new StoredObject(),
$person,
['scope' => $scope]
);
}
private function buildFormBuilder(bool $withScope): FormBuilderInterface
{
$builder = $this->prophesize(FormBuilderInterface::class);
$builder->add('title', TextType::class, Argument::type('array'))
->shouldBeCalled(1);
if ($withScope) {
$builder->add('scope', ScopePickerType::class, Argument::type('array'))
->shouldBeCalled();
} else {
$builder->add('scope', ScopePickerType::class, Argument::type('array'))
->shouldNotBeCalled();
}
return $builder->reveal();
}
private function buildPersonContext(
?AuthorizationHelperInterface $authorizationHelper = null,
?BaseContextData $baseContextData = null,
?CenterResolverManagerInterface $centerResolverManager = null,
?DocumentCategoryRepository $documentCategoryRepository = null,
?EntityManagerInterface $em = null,
?NormalizerInterface $normalizer = null,
?ParameterBagInterface $parameterBag = null,
?Security $security = null,
?TranslatorInterface $translator = null,
?TranslatableStringHelperInterface $translatableStringHelper = null
): PersonContext {
if (null === $authorizationHelper) {
$authorizationHelper = $this->prophesize(AuthorizationHelperInterface::class)->reveal();
}
if (null === $baseContextData) {
$baseContextData = $this->prophesize(BaseContextData::class)->reveal();
}
if (null === $centerResolverManager) {
$centerResolverManager = $this->prophesize(CenterResolverManagerInterface::class);
$centerResolverManager->resolveCenters(Argument::any(), Argument::any())
->willReturn([new Center()]);
$centerResolverManager = $centerResolverManager->reveal();
}
if (null === $documentCategoryRepository) {
$documentCategoryRepository = $this->prophesize(DocumentCategoryRepository::class);
$documentCategoryRepository->find(Argument::type('integer'))->willReturn(
new DocumentCategory(PersonDocument::class, 1)
);
$documentCategoryRepository = $documentCategoryRepository->reveal();
}
if (null === $em) {
$em = $this->prophesize(EntityManagerInterface::class)->reveal();
}
if (null === $normalizer) {
$normalizer = $this->prophesize(NormalizerInterface::class);
$normalizer->normalize(Argument::type(Person::class), 'docgen', Argument::any())
->willReturn(['type' => 'person']);
$normalizer = $normalizer->reveal();
}
if (null === $parameterBag) {
$parameterBag = new ParameterBag(['chill_main' => ['acl' => ['form_show_scopes' => true]]]);
}
if (null === $security) {
$security = $this->prophesize(Security::class);
$security->getUser()->willReturn(new User());
$security = $security->reveal();
}
if (null === $translator) {
$translator = $this->prophesize(TranslatorInterface::class)->reveal();
}
if (null === $translatableStringHelper) {
$translatableStringHelper = $this->prophesize(TranslatableStringHelperInterface::class);
// return only the 'fr' key
$translatableStringHelper->localize(Argument::type('array'))->will(static function ($args) {
return $args[0]['fr'];
});
$translatableStringHelper = $translatableStringHelper->reveal();
}
return new PersonContext(
$authorizationHelper,
$baseContextData,
$centerResolverManager,
$documentCategoryRepository,
$em,
$normalizer,
$parameterBag,
$security,
$translator,
$translatableStringHelper
);
}
}

View File

@@ -0,0 +1,93 @@
<?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 Service\DocGenerator;
use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate;
use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Service\DocGenerator\PersonContextInterface;
use Chill\PersonBundle\Service\DocGenerator\PersonContextWithThirdParty;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
/**
* @internal
* @coversNothing
*/
final class PersonContextWithThirdPartyTest extends KernelTestCase
{
use ProphecyTrait;
public function testAdminFormReverseTransform()
{
$personContext = $this->buildPersonContextWithThirdParty();
$actual = $personContext->adminFormReverseTransform(['label' => 'bloup']);
$this->assertArrayHasKey('category', $actual);
$this->assertArrayHasKey('label', $actual);
$this->assertEquals('bloup', $actual['label']);
}
public function testAdminFormTransform()
{
$personContext = $this->buildPersonContextWithThirdParty();
$actual = $personContext->adminFormTransform(['label' => 'bloup']);
$this->assertArrayHasKey('from_person', $actual);
$this->assertArrayHasKey('label', $actual);
$this->assertEquals('bloup', $actual['label']);
}
public function testGetData()
{
$personContext = $this->buildPersonContextWithThirdParty();
$actual = $personContext->getData(
(new DocGeneratorTemplate())->setOptions(['label' => 'bloup']),
new Person(),
['thirdParty' => $tp = new ThirdParty()]
);
$this->assertArrayHasKey('person', $actual);
$this->assertArrayHasKey('thirdParty', $actual);
$this->assertEquals(spl_object_hash($tp), $actual['thirdParty']['hash']);
}
private function buildPersonContextWithThirdParty(): PersonContextWithThirdParty
{
$normalizer = $this->prophesize(NormalizerInterface::class);
$normalizer->normalize(Argument::type(ThirdParty::class), 'docgen', Argument::type('array'))
->will(static function ($args): array {
return ['class' => '3party', 'hash' => spl_object_hash($args[0])];
});
$personContext = $this->prophesize(PersonContextInterface::class);
$personContext->adminFormReverseTransform(Argument::type('array'))->willReturn(
['category' => ['idInsideBundle' => 1, 'bundleId' => 'abc']]
);
$personContext->adminFormTransform(Argument::type('array'))->willReturn(
['from_person' => 'kept']
);
$personContext->getData(Argument::type(DocGeneratorTemplate::class), Argument::type(Person::class), Argument::type('array'))
->willReturn(['person' => 'data']);
return new PersonContextWithThirdParty(
$personContext->reveal(),
$normalizer->reveal()
);
}
}

View File

@@ -887,6 +887,10 @@ docgen:
A context for accompanying period work evaluation: Contexte pour les évaluations dans les actions d'accompagnement
Person basic: Personne (basique)
A basic context for person: Contexte pour les personnes
Person with third party: Personne avec choix d'un tiers
A context for person with a third party (for sending mail): Un contexte d'une personne avec un tiers (pour envoyer un courrier à ce tiers, par exemple)
Label for third party: Label à afficher aux utilisateurs
Document title: Titre du document généré
period_notification:
period_designated_subject: Vous êtes référent d'un parcours d'accompagnement
@@ -937,6 +941,8 @@ reassign:
All periods on this list will be reassigned to this user, excepted the one you manually reassigned before: Tous les parcours visibles sur cette page seront assignés à cet utilisateur, sauf ceux que vous aurez assigné à un utilisateur manuellement.
Reassign: Assigner le référent
List periods to be able to reassign them: Choisissez un utilisateur et cliquez sur "Filtrer" pour visualiser ses parcours. Vous pourrez ensuite les réassigner.
Filter by postal code: Filtrer par code postal
Filter course which are located inside a postal code: Afficher uniquement les parcours localisés auprès de ce code postal (une commune peut comporter plusieurs codes postaux).
notification:
Notify referrer: Notifier le référent