mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Merge branch 'issue347_document_gen_activity' into 'master'
activity: doc gen See merge request Chill-Projet/chill-bundles!295
This commit is contained in:
commit
f866eae581
@ -13,6 +13,7 @@ namespace Chill\ActivityBundle\Entity;
|
|||||||
|
|
||||||
use Chill\ActivityBundle\Validator\Constraints as ActivityValidator;
|
use Chill\ActivityBundle\Validator\Constraints as ActivityValidator;
|
||||||
use Chill\DocStoreBundle\Entity\Document;
|
use Chill\DocStoreBundle\Entity\Document;
|
||||||
|
use Chill\DocStoreBundle\Entity\StoredObject;
|
||||||
use Chill\MainBundle\Entity\Center;
|
use Chill\MainBundle\Entity\Center;
|
||||||
use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable;
|
use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable;
|
||||||
use Chill\MainBundle\Entity\HasCenterInterface;
|
use Chill\MainBundle\Entity\HasCenterInterface;
|
||||||
@ -61,13 +62,13 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\ManyToOne(targetEntity="Chill\PersonBundle\Entity\AccompanyingPeriod")
|
* @ORM\ManyToOne(targetEntity="Chill\PersonBundle\Entity\AccompanyingPeriod")
|
||||||
* @Groups({"read"})
|
* @Groups({"read", "docgen:read"})
|
||||||
*/
|
*/
|
||||||
private ?AccompanyingPeriod $accompanyingPeriod = null;
|
private ?AccompanyingPeriod $accompanyingPeriod = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\ManyToOne(targetEntity="Chill\ActivityBundle\Entity\ActivityType")
|
* @ORM\ManyToOne(targetEntity="Chill\ActivityBundle\Entity\ActivityType")
|
||||||
* @Groups({"read"})
|
* @Groups({"read", "docgen:read"})
|
||||||
* @SerializedName("activityType")
|
* @SerializedName("activityType")
|
||||||
* @ORM\JoinColumn(name="type_id")
|
* @ORM\JoinColumn(name="type_id")
|
||||||
*/
|
*/
|
||||||
@ -107,13 +108,13 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac
|
|||||||
* @ORM\Id
|
* @ORM\Id
|
||||||
* @ORM\Column(name="id", type="integer")
|
* @ORM\Column(name="id", type="integer")
|
||||||
* @ORM\GeneratedValue(strategy="AUTO")
|
* @ORM\GeneratedValue(strategy="AUTO")
|
||||||
* @Groups({"read"})
|
* @Groups({"read", "docgen:read"})
|
||||||
*/
|
*/
|
||||||
private ?int $id = null;
|
private ?int $id = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\Location")
|
* @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\Location")
|
||||||
* @groups({"read"})
|
* @groups({"read", "docgen:read"})
|
||||||
*/
|
*/
|
||||||
private ?Location $location = null;
|
private ?Location $location = null;
|
||||||
|
|
||||||
@ -124,7 +125,7 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\ManyToMany(targetEntity="Chill\PersonBundle\Entity\Person")
|
* @ORM\ManyToMany(targetEntity="Chill\PersonBundle\Entity\Person")
|
||||||
* @Groups({"read"})
|
* @Groups({"read", "docgen:read"})
|
||||||
*/
|
*/
|
||||||
private ?Collection $persons = null;
|
private ?Collection $persons = null;
|
||||||
|
|
||||||
@ -146,20 +147,20 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac
|
|||||||
/**
|
/**
|
||||||
* @ORM\ManyToMany(targetEntity="Chill\PersonBundle\Entity\SocialWork\SocialAction")
|
* @ORM\ManyToMany(targetEntity="Chill\PersonBundle\Entity\SocialWork\SocialAction")
|
||||||
* @ORM\JoinTable(name="chill_activity_activity_chill_person_socialaction")
|
* @ORM\JoinTable(name="chill_activity_activity_chill_person_socialaction")
|
||||||
* @Groups({"read"})
|
* @Groups({"read", "docgen:read"})
|
||||||
*/
|
*/
|
||||||
private Collection $socialActions;
|
private Collection $socialActions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\ManyToMany(targetEntity="Chill\PersonBundle\Entity\SocialWork\SocialIssue")
|
* @ORM\ManyToMany(targetEntity="Chill\PersonBundle\Entity\SocialWork\SocialIssue")
|
||||||
* @ORM\JoinTable(name="chill_activity_activity_chill_person_socialissue")
|
* @ORM\JoinTable(name="chill_activity_activity_chill_person_socialissue")
|
||||||
* @Groups({"read"})
|
* @Groups({"read", "docgen:read"})
|
||||||
*/
|
*/
|
||||||
private Collection $socialIssues;
|
private Collection $socialIssues;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\ManyToMany(targetEntity="Chill\ThirdPartyBundle\Entity\ThirdParty")
|
* @ORM\ManyToMany(targetEntity="Chill\ThirdPartyBundle\Entity\ThirdParty")
|
||||||
* @Groups({"read"})
|
* @Groups({"read", "docgen:read"})
|
||||||
*/
|
*/
|
||||||
private ?Collection $thirdParties = null;
|
private ?Collection $thirdParties = null;
|
||||||
|
|
||||||
@ -191,7 +192,7 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac
|
|||||||
$this->socialActions = new ArrayCollection();
|
$this->socialActions = new ArrayCollection();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addDocument(Document $document): self
|
public function addDocument(StoredObject $document): self
|
||||||
{
|
{
|
||||||
$this->documents[] = $document;
|
$this->documents[] = $document;
|
||||||
|
|
||||||
@ -425,7 +426,7 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac
|
|||||||
return $this->getEmergency();
|
return $this->getEmergency();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function removeDocument(Document $document): void
|
public function removeDocument(StoredObject $document): void
|
||||||
{
|
{
|
||||||
$this->documents->removeElement($document);
|
$this->documents->removeElement($document);
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
action: 'show', displayBadge: true,
|
action: 'show', displayBadge: true,
|
||||||
targetEntity: { name: type, id: entity.id },
|
targetEntity: { name: type, id: entity.id },
|
||||||
buttonText: entity|chill_entity_render_string,
|
buttonText: entity|chill_entity_render_string,
|
||||||
isDead: entity.deathdate is not null,
|
isDead: entity.deathdate is defined and entity.deathdate is not null,
|
||||||
parent: parent
|
parent: parent
|
||||||
} %}
|
} %}
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
@ -83,15 +83,15 @@
|
|||||||
{{ form_row(edit_form.comment) }}
|
{{ form_row(edit_form.comment) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{%- if edit_form.documents is defined -%}
|
|
||||||
{{ form_row(edit_form.documents) }}
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{%- if edit_form.attendee is defined -%}
|
{%- if edit_form.attendee is defined -%}
|
||||||
{{ form_row(edit_form.attendee) }}
|
{{ form_row(edit_form.attendee) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{# TODO .. status #}
|
{%- if edit_form.documents is defined -%}
|
||||||
|
{{ form_row(edit_form.documents) }}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<div data-docgen-template-picker="data-docgen-template-picker" data-entity-class="Chill\ActivityBundle\Entity\Activity" data-entity-id="{{ entity.id }}"></div>
|
||||||
|
|
||||||
{% set person_id = null %}
|
{% set person_id = null %}
|
||||||
{% if entity.person %}
|
{% if entity.person %}
|
||||||
|
@ -24,10 +24,12 @@
|
|||||||
window.activity = {{ activity_json|json_encode|raw }};
|
window.activity = {{ activity_json|json_encode|raw }};
|
||||||
</script>
|
</script>
|
||||||
{{ encore_entry_script_tags('vue_activity') }}
|
{{ encore_entry_script_tags('vue_activity') }}
|
||||||
|
{{ encore_entry_script_tags('mod_docgen_picktemplate') }}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block css %}
|
{% block css %}
|
||||||
{{ parent() }}
|
{{ parent() }}
|
||||||
{{ encore_entry_link_tags('mod_async_upload') }}
|
{{ encore_entry_link_tags('mod_async_upload') }}
|
||||||
{{ encore_entry_link_tags('vue_activity') }}
|
{{ encore_entry_link_tags('vue_activity') }}
|
||||||
|
{{ encore_entry_link_tags('mod_docgen_picktemplate') }}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -39,9 +39,11 @@
|
|||||||
window.activity = {{ activity_json|json_encode|raw }};
|
window.activity = {{ activity_json|json_encode|raw }};
|
||||||
</script>
|
</script>
|
||||||
{{ encore_entry_script_tags('vue_activity') }}
|
{{ encore_entry_script_tags('vue_activity') }}
|
||||||
|
{{ encore_entry_script_tags('mod_docgen_picktemplate') }}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block css %}
|
{% block css %}
|
||||||
{{ encore_entry_link_tags('mod_async_upload') }}
|
{{ encore_entry_link_tags('mod_async_upload') }}
|
||||||
{{ encore_entry_link_tags('vue_activity') }}
|
{{ encore_entry_link_tags('vue_activity') }}
|
||||||
|
{{ encore_entry_link_tags('mod_docgen_picktemplate') }}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -0,0 +1,223 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Chill\ActivityBundle\Service\DocGenerator;
|
||||||
|
|
||||||
|
use Chill\ActivityBundle\Entity\Activity;
|
||||||
|
use Chill\DocGeneratorBundle\Context\DocGeneratorContextWithAdminFormInterface;
|
||||||
|
use Chill\DocGeneratorBundle\Context\DocGeneratorContextWithPublicFormInterface;
|
||||||
|
use Chill\DocGeneratorBundle\Context\Exception\UnexpectedTypeException;
|
||||||
|
use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate;
|
||||||
|
use Chill\DocGeneratorBundle\Service\Context\BaseContextData;
|
||||||
|
use Chill\DocStoreBundle\Entity\Document;
|
||||||
|
use Chill\DocStoreBundle\Entity\StoredObject;
|
||||||
|
use Chill\DocStoreBundle\Repository\DocumentCategoryRepository;
|
||||||
|
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
|
||||||
|
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||||
|
use Chill\PersonBundle\Entity\Person;
|
||||||
|
use Chill\PersonBundle\Templating\Entity\PersonRender;
|
||||||
|
use DateTime;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||||
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
|
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
||||||
|
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||||
|
|
||||||
|
use function array_key_exists;
|
||||||
|
|
||||||
|
class ActivityContext implements
|
||||||
|
DocGeneratorContextWithAdminFormInterface,
|
||||||
|
DocGeneratorContextWithPublicFormInterface
|
||||||
|
{
|
||||||
|
private BaseContextData $baseContextData;
|
||||||
|
|
||||||
|
private DocumentCategoryRepository $documentCategoryRepository;
|
||||||
|
|
||||||
|
private EntityManagerInterface $em;
|
||||||
|
|
||||||
|
private NormalizerInterface $normalizer;
|
||||||
|
|
||||||
|
private PersonRender $personRender;
|
||||||
|
|
||||||
|
private TranslatableStringHelperInterface $translatableStringHelper;
|
||||||
|
|
||||||
|
private TranslatorInterface $translator;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
DocumentCategoryRepository $documentCategoryRepository,
|
||||||
|
NormalizerInterface $normalizer,
|
||||||
|
TranslatableStringHelperInterface $translatableStringHelper,
|
||||||
|
EntityManagerInterface $em,
|
||||||
|
PersonRender $personRender,
|
||||||
|
TranslatorInterface $translator,
|
||||||
|
BaseContextData $baseContextData
|
||||||
|
) {
|
||||||
|
$this->documentCategoryRepository = $documentCategoryRepository;
|
||||||
|
$this->normalizer = $normalizer;
|
||||||
|
$this->translatableStringHelper = $translatableStringHelper;
|
||||||
|
$this->em = $em;
|
||||||
|
$this->personRender = $personRender;
|
||||||
|
$this->translator = $translator;
|
||||||
|
$this->baseContextData = $baseContextData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function adminFormReverseTransform(array $data): array
|
||||||
|
{
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function adminFormTransform(array $data): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'mainPerson' => $data['mainPerson'] ?? false,
|
||||||
|
'mainPersonLabel' => $data['mainPersonLabel'] ?? $this->translator->trans('docgen.Main person'),
|
||||||
|
'person1' => $data['person1'] ?? false,
|
||||||
|
'person1Label' => $data['person1Label'] ?? $this->translator->trans('docgen.person 1'),
|
||||||
|
'person2' => $data['person2'] ?? false,
|
||||||
|
'person2Label' => $data['person2Label'] ?? $this->translator->trans('docgen.person 2'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function buildAdminForm(FormBuilderInterface $builder): void
|
||||||
|
{
|
||||||
|
$builder
|
||||||
|
->add('mainPerson', CheckboxType::class, [
|
||||||
|
'required' => false,
|
||||||
|
'label' => 'docgen.Ask for main person',
|
||||||
|
])
|
||||||
|
->add('mainPersonLabel', TextType::class, [
|
||||||
|
'label' => 'main person label',
|
||||||
|
'required' => true,
|
||||||
|
])
|
||||||
|
->add('person1', CheckboxType::class, [
|
||||||
|
'required' => false,
|
||||||
|
'label' => 'docgen.Ask for person 1',
|
||||||
|
])
|
||||||
|
->add('person1Label', TextType::class, [
|
||||||
|
'label' => 'person 1 label',
|
||||||
|
'required' => true,
|
||||||
|
])
|
||||||
|
->add('person2', CheckboxType::class, [
|
||||||
|
'required' => false,
|
||||||
|
'label' => 'docgen.Ask for person 2',
|
||||||
|
])
|
||||||
|
->add('person2Label', TextType::class, [
|
||||||
|
'label' => 'person 2 label',
|
||||||
|
'required' => true,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Activity $entity
|
||||||
|
*/
|
||||||
|
public function buildPublicForm(FormBuilderInterface $builder, DocGeneratorTemplate $template, $entity): void
|
||||||
|
{
|
||||||
|
$options = $template->getOptions();
|
||||||
|
$persons = $entity->getPersons();
|
||||||
|
|
||||||
|
foreach (['mainPerson', 'person1', 'person2'] as $key) {
|
||||||
|
if ($options[$key] ?? false) {
|
||||||
|
$builder->add($key, EntityType::class, [
|
||||||
|
'class' => Person::class,
|
||||||
|
'choices' => $persons,
|
||||||
|
'choice_label' => function (Person $p) {
|
||||||
|
return $this->personRender->renderString($p, []);
|
||||||
|
},
|
||||||
|
'multiple' => false,
|
||||||
|
'expanded' => true,
|
||||||
|
'label' => $options[$key . 'Label'],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getData(DocGeneratorTemplate $template, $entity, array $contextGenerationData = []): array
|
||||||
|
{
|
||||||
|
if (!$entity instanceof Activity) {
|
||||||
|
throw new UnexpectedTypeException($entity, Activity::class);
|
||||||
|
}
|
||||||
|
$options = $template->getOptions();
|
||||||
|
|
||||||
|
$data = [];
|
||||||
|
$data = array_merge($data, $this->baseContextData->getData());
|
||||||
|
$data['activity'] = $this->normalizer->normalize($entity, 'docgen', ['docgen:expects' => Activity::class, 'groups' => 'docgen:read']);
|
||||||
|
|
||||||
|
$data['course'] = $this->normalizer->normalize($entity->getAccompanyingPeriod(), 'docgen', ['docgen:expects' => AccompanyingPeriod::class, 'groups' => 'docgen:read']);
|
||||||
|
$data['person'] = $this->normalizer->normalize($entity->getPerson(), 'docgen', ['docgen:expects' => Person::class, 'groups' => 'docgen:read']);
|
||||||
|
|
||||||
|
foreach (['mainPerson', 'person1', 'person2'] as $k) {
|
||||||
|
if ($options[$k]) {
|
||||||
|
$data[$k] = $this->normalizer->normalize($contextGenerationData[$k], 'docgen', [
|
||||||
|
'docgen:expects' => Person::class,
|
||||||
|
'groups' => 'docgen:read',
|
||||||
|
'docgen:person:with-household' => true,
|
||||||
|
'docgen:person:with-relations' => true,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDescription(): string
|
||||||
|
{
|
||||||
|
return 'docgen.A basic context for activity';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getEntityClass(): string
|
||||||
|
{
|
||||||
|
return Activity::class;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFormData(DocGeneratorTemplate $template, $entity): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'activity' => $entity,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getKey(): string
|
||||||
|
{
|
||||||
|
return self::class;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getName(): string
|
||||||
|
{
|
||||||
|
return 'docgen.Activity basic';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function hasAdminForm(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function hasPublicForm(DocGeneratorTemplate $template, $entity): bool
|
||||||
|
{
|
||||||
|
$options = $template->getOptions();
|
||||||
|
|
||||||
|
return $options['mainPerson'] || $options['person1'] || $options['person2'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Activity $entity
|
||||||
|
*/
|
||||||
|
public function storeGenerated(DocGeneratorTemplate $template, StoredObject $storedObject, object $entity, array $contextGenerationData): void
|
||||||
|
{
|
||||||
|
$doc = new StoredObject();
|
||||||
|
// TODO push document to remote
|
||||||
|
|
||||||
|
$this->em->persist($doc);
|
||||||
|
|
||||||
|
$entity->addDocument($doc);
|
||||||
|
}
|
||||||
|
}
|
@ -32,3 +32,8 @@ services:
|
|||||||
autowire: true
|
autowire: true
|
||||||
autoconfigure: true
|
autoconfigure: true
|
||||||
resource: '../Validator/Constraints/'
|
resource: '../Validator/Constraints/'
|
||||||
|
|
||||||
|
Chill\ActivityBundle\Service\DocGenerator\:
|
||||||
|
autowire: true
|
||||||
|
autoconfigure: true
|
||||||
|
resource: '../Service/DocGenerator/'
|
||||||
|
@ -228,3 +228,7 @@ See activity in accompanying course context: Voir l'activité dans le contexte d
|
|||||||
You get notified of an activity which does not exists any more: Cette notification ne correspond pas à une activité valide.
|
You get notified of an activity which does not exists any more: Cette notification ne correspond pas à une activité valide.
|
||||||
you are not allowed to see it details: La notification fait référence à une activité à laquelle vous n'avez pas accès.
|
you are not allowed to see it details: La notification fait référence à une activité à laquelle vous n'avez pas accès.
|
||||||
This is the minimal activity data: Activité n°
|
This is the minimal activity data: Activité n°
|
||||||
|
|
||||||
|
docgen:
|
||||||
|
Activity basic: Echange
|
||||||
|
A basic context for activity: Contexte pour les échanges
|
||||||
|
Loading…
x
Reference in New Issue
Block a user