From dc0fae7549849c2d5317fbdec6d7b95d5cda509c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 26 Jan 2022 17:53:09 +0100 Subject: [PATCH 1/5] fixes person resources --- .../EntityToJsonTransformer.php | 2 - .../public/module/pick-entity/index.js | 33 +++--- .../Controller/PersonResourceController.php | 4 +- .../Entity/Person/PersonResource.php | 9 +- .../views/PersonResource/create.html.twig | 2 +- .../views/PersonResource/form.html.twig | 11 +- .../views/PersonResource/list.html.twig | 102 ++++++++---------- .../Normalizer/PersonDocGenNormalizer.php | 4 +- .../translations/validators.fr.yml | 3 + 9 files changed, 81 insertions(+), 89 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Form/Type/DataTransformer/EntityToJsonTransformer.php b/src/Bundle/ChillMainBundle/Form/Type/DataTransformer/EntityToJsonTransformer.php index c6c205a47..95c447119 100644 --- a/src/Bundle/ChillMainBundle/Form/Type/DataTransformer/EntityToJsonTransformer.php +++ b/src/Bundle/ChillMainBundle/Form/Type/DataTransformer/EntityToJsonTransformer.php @@ -45,8 +45,6 @@ class EntityToJsonTransformer implements DataTransformerInterface { $denormalized = json_decode($value, true); - dump($value); - if ($this->multiple) { if (null === $denormalized) { return []; diff --git a/src/Bundle/ChillMainBundle/Resources/public/module/pick-entity/index.js b/src/Bundle/ChillMainBundle/Resources/public/module/pick-entity/index.js index c3786f137..1fd6b34f7 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/module/pick-entity/index.js +++ b/src/Bundle/ChillMainBundle/Resources/public/module/pick-entity/index.js @@ -7,7 +7,6 @@ const i18n = _createI18n(appMessages); let appsOnPage = new Map(); - function loadDynamicPicker(element) { let apps = element.querySelectorAll('[data-module="pick-dynamic"]'); @@ -75,23 +74,23 @@ function loadDynamicPicker(element) { } -// document.addEventListener('show-hide-show', function(e) { -// console.log('creation event caught') -// loadDynamicPicker(e.detail.container) -// }) +document.addEventListener('show-hide-show', function(e) { + console.log('creation event caught') + loadDynamicPicker(e.detail.container) +}) -// document.addEventListener('show-hide-hide', function(e) { -// console.log('hiding event caught') -// e.detail.container.querySelectorAll('[data-module="pick-dynamic"]').forEach((el) => { -// let uniqId = el.dataset.uniqid; -// console.log(uniqId); -// if (appsOnPage.has(uniqId)) { -// appsOnPage.get(uniqId).unmount(); -// console.log('App has been unmounted') -// appsOnPage.delete(uniqId); -// } -// }) -// }) +document.addEventListener('show-hide-hide', function(e) { + console.log('hiding event caught') + e.detail.container.querySelectorAll('[data-module="pick-dynamic"]').forEach((el) => { + let uniqId = el.dataset.uniqid; + console.log(uniqId); + if (appsOnPage.has(uniqId)) { + appsOnPage.get(uniqId).unmount(); + console.log('App has been unmounted') + appsOnPage.delete(uniqId); + } + }) +}) document.addEventListener('DOMContentLoaded', function(e) { console.log('loaded event', e) diff --git a/src/Bundle/ChillPersonBundle/Controller/PersonResourceController.php b/src/Bundle/ChillPersonBundle/Controller/PersonResourceController.php index 6b9b5dc6a..210b507e5 100644 --- a/src/Bundle/ChillPersonBundle/Controller/PersonResourceController.php +++ b/src/Bundle/ChillPersonBundle/Controller/PersonResourceController.php @@ -114,8 +114,6 @@ final class PersonResourceController extends AbstractController ]); } - dump($resource); - return $this->render( 'ChillPersonBundle:PersonResource:edit.html.twig', [ @@ -139,7 +137,7 @@ final class PersonResourceController extends AbstractController $form->handleRequest($request); - if ($request->getMethod() === Request::METHOD_POST && $form->isValid()) { + if ($form->isSubmitted() && $form->isValid()) { $this->denyAccessUnlessGranted(PersonVoter::CREATE, $personOwner); $personResource = new PersonResource(); diff --git a/src/Bundle/ChillPersonBundle/Entity/Person/PersonResource.php b/src/Bundle/ChillPersonBundle/Entity/Person/PersonResource.php index 4e1718a64..2e8441511 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Person/PersonResource.php +++ b/src/Bundle/ChillPersonBundle/Entity/Person/PersonResource.php @@ -55,7 +55,7 @@ class PersonResource implements TrackCreationInterface, TrackUpdateInterface * @ORM\Column(type="text", nullable=true) * @Groups({"read"}) */ - private $freeText; + private ?string $freeText = null; /** * @ORM\Id @@ -204,6 +204,10 @@ class PersonResource implements TrackCreationInterface, TrackUpdateInterface $this->setThirdParty(null); } + if ('' === $freeText) { + $this->freeText = null; + } + return $this; } @@ -266,9 +270,8 @@ class PersonResource implements TrackCreationInterface, TrackUpdateInterface */ public function validate(ExecutionContextInterface $context, $payload) { - if (null === $this->person && null === $this->thirdParty && null === $this->freeText) { + if (null === $this->person && null === $this->thirdParty && (null === $this->freeText || '' === $this->freeText)) { $context->buildViolation('You must associate at least one entity') - ->atPath('person') ->addViolation(); } } diff --git a/src/Bundle/ChillPersonBundle/Resources/views/PersonResource/create.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/PersonResource/create.html.twig index 46ba4ebef..8dde19750 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/PersonResource/create.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/PersonResource/create.html.twig @@ -1,5 +1,5 @@
-
+

{{ 'Add a person resource'|trans }}

{% include "@ChillPerson/PersonResource/form.html.twig" %}
diff --git a/src/Bundle/ChillPersonBundle/Resources/views/PersonResource/form.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/PersonResource/form.html.twig index 1ce3ea2ba..6fa294336 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/PersonResource/form.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/PersonResource/form.html.twig @@ -1,7 +1,6 @@ {{ form_start(form, {'attr' : {'id' : 'create-form'}}) }} - +{{ form_errors(form) }} {{ form_row(form.kind) }} -
@@ -10,7 +9,7 @@
{% if resource is defined and resource.person is not null %} - + {% else %} @@ -19,7 +18,7 @@
{% if resource is defined and resource.thirdparty is not null %} - + {% else %} @@ -28,7 +27,7 @@
{% if resource is defined and resource.freeText is not null %} - + {% else %} @@ -75,4 +74,4 @@ {% endif %} -{{ form_end(form) }} \ No newline at end of file +{{ form_end(form) }} diff --git a/src/Bundle/ChillPersonBundle/Resources/views/PersonResource/list.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/PersonResource/list.html.twig index d8a67912f..a273277f9 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/PersonResource/list.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/PersonResource/list.html.twig @@ -19,74 +19,66 @@

{{ 'List of resources'|trans }}

{% if personResources|length > 0 %} - {% for resource in personResources %} -
+
+ {% for resource in personResources %}
-
-
-
- {% if resource.person is not null %} -
-
- {{ resource.person }} - {{ 'person'|trans|capitalize }} -
-
- {% elseif resource.thirdparty is not null %} -
-
- {{ resource.thirdparty }} - - {{ 'thirdparty'|trans|capitalize }} - - -
-
- {% else %} -
-
- {{ resource.freetext }} -
-
- {% endif %} -
- {% if resource.kind %} - {{ resource.kind.title.fr|capitalize }} - {% endif %} -
-
+
+ {% if resource.person is not null %} +
+ {{ resource.person }} + {{ 'person'|trans|capitalize }}
+ {% elseif resource.thirdparty is not null %} +
+ {{ resource.thirdparty }} + + {{ 'thirdparty'|trans|capitalize }} + + +
+ {% else %} +
+ {{ resource.freetext }} +
+ {% endif %} +
+
+ {% if resource.kind %} + {{ resource.kind.title.fr|capitalize }} + {% endif %}
- {% if resource.comment.comment is not null %} + {% if resource.comment.comment is not empty %}
{{ resource.comment|chill_entity_render_box }}
{% endif %} -
-
-
    -
  • - -
  • -
  • - -
  • -
+ {% if is_granted('CHILL_PERSON_UPDATE', resource.person) %} +
+
+
    +
  • + +
  • +
  • + +
  • +
+
-
+ {% endif %}
-
- {% endfor %} + {% endfor %} +
{% else %}

{{ 'There are no available resources'|trans }}

diff --git a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonDocGenNormalizer.php b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonDocGenNormalizer.php index 2a99dfa8b..71b6ed92e 100644 --- a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonDocGenNormalizer.php +++ b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonDocGenNormalizer.php @@ -76,8 +76,8 @@ class PersonDocGenNormalizer implements 'type' => 'person', 'isNull' => false, 'civility' => $this->normalizer->normalize($person->getCivility(), $format, array_merge($context, ['docgen:expects' => Civility::class])), - 'firstname' => $person->getFirstName(), - 'lastname' => $person->getLastName(), + 'firstName' => $person->getFirstName(), + 'lastName' => $person->getLastName(), 'altNames' => implode( ', ', array_map( diff --git a/src/Bundle/ChillPersonBundle/translations/validators.fr.yml b/src/Bundle/ChillPersonBundle/translations/validators.fr.yml index 96cfd565f..a73880195 100644 --- a/src/Bundle/ChillPersonBundle/translations/validators.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/validators.fr.yml @@ -50,3 +50,6 @@ household_membership: A course must contains at least one social issue: 'Un parcours doit être associé à au moins une problématique sociale' A course must be associated to at least one scope: 'Un parcours doit être associé à au moins un service' The social %name% issue cannot be deleted because it is associated with an activity or an action: 'La problématique sociale "%name%" ne peut pas être supprimée car elle est associée à une activité ou une action' + +# resource +You must associate at least one entity: Associez un usager, un tiers ou indiquez une description libre From c70a4dc664c2f0ec311940a0cba0113a8df0c88d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 26 Jan 2022 21:46:07 +0100 Subject: [PATCH 2/5] fix loading of evaluations --- .../Resources/public/vuejs/_components/PickTemplate.vue | 9 +++++++-- .../AccompanyingPeriodWorkEvaluationApiController.php | 2 +- .../public/vuejs/AccompanyingCourseWorkEdit/store.js | 8 +++++--- .../AccompanyingPeriodWorkEvaluationContext.php | 2 +- .../ChillPersonBundle/translations/messages.fr.yml | 3 +++ 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/Bundle/ChillDocGeneratorBundle/Resources/public/vuejs/_components/PickTemplate.vue b/src/Bundle/ChillDocGeneratorBundle/Resources/public/vuejs/_components/PickTemplate.vue index f1fb6c84b..04d563782 100644 --- a/src/Bundle/ChillDocGeneratorBundle/Resources/public/vuejs/_components/PickTemplate.vue +++ b/src/Bundle/ChillDocGeneratorBundle/Resources/public/vuejs/_components/PickTemplate.vue @@ -17,7 +17,7 @@ @@ -48,6 +48,7 @@ export default { required: true, }, templates: { + type: Array, required: true, }, // beforeMove execute "something" before @@ -73,7 +74,11 @@ export default { return true; }, getDescription() { - return this.templates.find(t => t.id === this.template).description || ''; + let desc = this.templates.find(t => t.id === this.template); + if (null === desc) { + return ''; + } + return desc.description || ''; }, }, methods: { diff --git a/src/Bundle/ChillPersonBundle/Controller/AccompanyingPeriodWorkEvaluationApiController.php b/src/Bundle/ChillPersonBundle/Controller/AccompanyingPeriodWorkEvaluationApiController.php index de9433558..cc918c1db 100644 --- a/src/Bundle/ChillPersonBundle/Controller/AccompanyingPeriodWorkEvaluationApiController.php +++ b/src/Bundle/ChillPersonBundle/Controller/AccompanyingPeriodWorkEvaluationApiController.php @@ -69,7 +69,7 @@ class AccompanyingPeriodWorkEvaluationApiController $paginator->setItemsPerPage(count($evaluations)); return new JsonResponse($this->serializer->serialize( - new Collection($evaluations, $paginator), + new Collection(array_values($evaluations), $paginator), 'json', [ AbstractNormalizer::GROUPS => ['read'], diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/store.js b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/store.js index 21ec4b168..a46a0e221 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/store.js +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/store.js @@ -58,7 +58,11 @@ const store = createStore({ return state.thirdParties.length > 0; }, getTemplatesAvailablesForEvaluation: (state) => (evaluation) => { - return state.templatesAvailablesForEvaluation.get(evaluation.id) || []; + if (state.templatesAvailablesForEvaluation.has(evaluation.id)) { + return state.templatesAvailablesForEvaluation.get(evaluation.id); + } + + return []; }, buildPayload(state) { return { @@ -171,7 +175,6 @@ const store = createStore({ }; g.id = tmpIndex() -1 state.goalsPicked.push(g); - //console.log('goals picked ids', state.goalsPicked.map(g => g.id)) }, removeGoal(state, goal) { state.goalsPicked = state.goalsPicked.filter(g => g.id !== goal.id); @@ -369,7 +372,6 @@ const store = createStore({ return makeFetch('PUT', url, payload) .then(data => { - console.log('data received', data); if (typeof(callback) !== 'undefined') { return callback(data); } else { diff --git a/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkEvaluationContext.php b/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkEvaluationContext.php index b68921abf..918b68dc1 100644 --- a/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkEvaluationContext.php +++ b/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkEvaluationContext.php @@ -98,7 +98,7 @@ class AccompanyingPeriodWorkEvaluationContext implements return $this->translatableStringHelper->localize($e->getTitle()); }, 'multiple' => true, - 'expanded' => true, + 'attr' => ['class' => 'select2'], ]); } diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index db00540da..2d6ff4c1e 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -530,3 +530,6 @@ household_composition: Currently no composition: Aucune composition famiale renseignée. Add a composition: Ajouter une composition familiale Update composition: Modifier la composition familiale + +# docgen +Linked evaluations: Évaluations associées From 7af7135971d2436545cc6cdf51bbe79a464c7c79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 26 Jan 2022 21:51:13 +0100 Subject: [PATCH 3/5] use trait to implement TrackCreationInterface and TrackUpdateInterface --- .../Entity/Person/PersonResource.php | 76 +------------------ 1 file changed, 4 insertions(+), 72 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Entity/Person/PersonResource.php b/src/Bundle/ChillPersonBundle/Entity/Person/PersonResource.php index 2e8441511..bc792ef95 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Person/PersonResource.php +++ b/src/Bundle/ChillPersonBundle/Entity/Person/PersonResource.php @@ -12,7 +12,9 @@ declare(strict_types=1); namespace Chill\PersonBundle\Entity\Person; use Chill\MainBundle\Doctrine\Model\TrackCreationInterface; +use Chill\MainBundle\Doctrine\Model\TrackCreationTrait; use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface; +use Chill\MainBundle\Doctrine\Model\TrackUpdateTrait; use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable; use Chill\MainBundle\Entity\User; use Chill\PersonBundle\Entity\Person; @@ -34,23 +36,14 @@ use Symfony\Component\Validator\Context\ExecutionContextInterface; */ class PersonResource implements TrackCreationInterface, TrackUpdateInterface { + use TrackCreationTrait; + use TrackUpdateTrait; /** * @ORM\Embedded(class="Chill\MainBundle\Entity\Embeddable\CommentEmbeddable", columnPrefix="comment_") * @Groups({"read"}) */ private CommentEmbeddable $comment; - /** - * @ORM\Column(type="datetime") - */ - private $createdAt; - - /** - * @ORM\ManyToOne(targetEntity=User::class) - * @ORM\JoinColumn(nullable=false) - */ - private User $createdBy; - /** * @ORM\Column(type="text", nullable=true) * @Groups({"read"}) @@ -92,16 +85,6 @@ class PersonResource implements TrackCreationInterface, TrackUpdateInterface */ private ?ThirdParty $thirdParty = null; - /** - * @ORM\Column(type="datetime", nullable=true) - */ - private $updatedAt; - - /** - * @ORM\ManyToOne(targetEntity=User::class) - */ - private User $updatedBy; - public function __construct() { $this->comment = new CommentEmbeddable(); @@ -112,16 +95,6 @@ class PersonResource implements TrackCreationInterface, TrackUpdateInterface return $this->comment; } - public function getCreatedAt(): ?DateTimeInterface - { - return $this->createdAt; - } - - public function getCreatedBy(): ?User - { - return $this->createdBy; - } - public function getFreeText(): ?string { return $this->freeText; @@ -155,16 +128,6 @@ class PersonResource implements TrackCreationInterface, TrackUpdateInterface return $this->thirdParty; } - public function getUpdatedAt(): ?DateTimeInterface - { - return $this->updatedAt; - } - - public function getUpdatedBy(): ?User - { - return $this->updatedBy; - } - public function setComment(?CommentEmbeddable $comment): self { if (null === $comment) { @@ -178,23 +141,6 @@ class PersonResource implements TrackCreationInterface, TrackUpdateInterface return $this; } - public function setCreatedAt(DateTimeInterface $createdAt): self - { - $this->createdAt = $createdAt; - - return $this; - } - - public function setCreatedBy(?User $createdBy): self - { - $this->createdBy = $createdBy; - - return $this; - } - - /** - * SETTERS. - */ public function setFreeText(?string $freeText): self { $this->freeText = $freeText; @@ -249,20 +195,6 @@ class PersonResource implements TrackCreationInterface, TrackUpdateInterface return $this; } - public function setUpdatedAt(DateTimeInterface $updatedAt): self - { - $this->updatedAt = $updatedAt; - - return $this; - } - - public function setUpdatedBy(?User $updatedBy): self - { - $this->updatedBy = $updatedBy; - - return $this; - } - /** * @Assert\Callback * From 0a92ad905b363847e0d5e8a5da10646293a98dc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 26 Jan 2022 23:49:24 +0100 Subject: [PATCH 4/5] variables for docgen --- .../ChillActivityBundle/Entity/Activity.php | 36 +++++++- .../Entity/ActivityPresence.php | 4 + .../Entity/ActivityType.php | 5 +- .../ChillMainBundle/Entity/Location.php | 2 +- .../CommentEmbeddableDocGenNormalizer.php | 88 +++++++++++++++++++ .../Entity/Person/PersonResource.php | 4 +- .../AccompanyingPeriodDocGenNormalizer.php | 3 + .../Normalizer/SocialActionNormalizer.php | 3 + ...AccompanyingPeriodDocGenNormalizerTest.php | 2 + 9 files changed, 140 insertions(+), 7 deletions(-) create mode 100644 src/Bundle/ChillMainBundle/Serializer/Normalizer/CommentEmbeddableDocGenNormalizer.php diff --git a/src/Bundle/ChillActivityBundle/Entity/Activity.php b/src/Bundle/ChillActivityBundle/Entity/Activity.php index 75c2aeaf6..2bb40d432 100644 --- a/src/Bundle/ChillActivityBundle/Entity/Activity.php +++ b/src/Bundle/ChillActivityBundle/Entity/Activity.php @@ -61,7 +61,7 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac /** * @ORM\ManyToOne(targetEntity="Chill\PersonBundle\Entity\AccompanyingPeriod") - * @Groups({"read", "docgen:read"}) + * @Groups({"read"}) */ private ?AccompanyingPeriod $accompanyingPeriod = null; @@ -75,16 +75,19 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac /** * @ORM\ManyToOne(targetEntity="Chill\ActivityBundle\Entity\ActivityPresence") + * @Groups({"docgen:read"}) */ private ?ActivityPresence $attendee = null; /** * @ORM\Embedded(class="Chill\MainBundle\Entity\Embeddable\CommentEmbeddable", columnPrefix="comment_") + * @Groups({"docgen:read"}) */ private CommentEmbeddable $comment; /** * @ORM\Column(type="datetime") + * @Groups({"docgen:read"}) */ private DateTime $date; @@ -100,6 +103,7 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac /** * @ORM\Column(type="boolean", options={"default": false}) + * @Groups({"docgen:read"}) */ private bool $emergency = false; @@ -130,16 +134,19 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac /** * @ORM\ManyToMany(targetEntity="Chill\ActivityBundle\Entity\ActivityReason") + * @Groups({"docgen:read"}) */ private Collection $reasons; /** * @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\Scope") + * @Groups({"docgen:read"}) */ private ?Scope $scope = null; /** * @ORM\Column(type="string", options={"default": ""}) + * @Groups({"docgen:read"}) */ private string $sentReceived = ''; @@ -170,12 +177,13 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac /** * @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\User") + * @Groups({"docgen:read"}) */ private User $user; /** * @ORM\ManyToMany(targetEntity="Chill\MainBundle\Entity\User") - * @Groups({"read"}) + * @Groups({"read", "docgen:read"}) */ private ?Collection $users = null; @@ -302,6 +310,18 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac return $this->documents; } + /** + * @Groups({"docgen:read"}) + */ + public function getDurationMinute(): int + { + if (null === $this->durationTime) { + return 0; + } + + return (int) round(($this->durationTime->getTimestamp() + $this->durationTime->getOffset()) / 60.0, 0); + } + public function getDurationTime(): ?DateTime { return $this->durationTime; @@ -402,6 +422,18 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac return $this->travelTime; } + /** + * @Groups({"docgen:read"}) + */ + public function getTravelTimeMinute(): int + { + if (null === $this->travelTime) { + return 0; + } + + return (int) round(($this->travelTime->getTimestamp() + $this->travelTime->getOffset()) / 60.0, 0); + } + /** * @deprecated */ diff --git a/src/Bundle/ChillActivityBundle/Entity/ActivityPresence.php b/src/Bundle/ChillActivityBundle/Entity/ActivityPresence.php index 725b1eb8e..89f616dc2 100644 --- a/src/Bundle/ChillActivityBundle/Entity/ActivityPresence.php +++ b/src/Bundle/ChillActivityBundle/Entity/ActivityPresence.php @@ -12,6 +12,7 @@ declare(strict_types=1); namespace Chill\ActivityBundle\Entity; use Doctrine\ORM\Mapping as ORM; +use Symfony\Component\Serializer\Annotation as Serializer; /** * Class ActivityPresence. @@ -31,11 +32,14 @@ class ActivityPresence * @ORM\Id * @ORM\Column(name="id", type="integer") * @ORM\GeneratedValue(strategy="AUTO") + * @Serializer\Groups({"docgen:read"}) */ private ?int $id; /** * @ORM\Column(type="json") + * @Serializer\Groups({"docgen:read"}) + * @Serializer\Context({"is-translatable": true}, groups={"docgen:read"}) */ private array $name = []; diff --git a/src/Bundle/ChillActivityBundle/Entity/ActivityType.php b/src/Bundle/ChillActivityBundle/Entity/ActivityType.php index 5ad692bf4..c7448e07d 100644 --- a/src/Bundle/ChillActivityBundle/Entity/ActivityType.php +++ b/src/Bundle/ChillActivityBundle/Entity/ActivityType.php @@ -13,6 +13,7 @@ namespace Chill\ActivityBundle\Entity; use Doctrine\ORM\Mapping as ORM; use InvalidArgumentException; +use Symfony\Component\Serializer\Annotation as Serializer; use Symfony\Component\Serializer\Annotation\Groups; use Symfony\Component\Validator\Constraints as Assert; @@ -118,6 +119,7 @@ class ActivityType * @ORM\Id * @ORM\Column(name="id", type="integer") * @ORM\GeneratedValue(strategy="AUTO") + * @Groups({"docgen:read"}) */ private ?int $id; @@ -133,7 +135,8 @@ class ActivityType /** * @ORM\Column(type="json") - * @Groups({"read"}) + * @Groups({"read", "docgen:read"}) + * @Serializer\Context({"is-translatable": true}, groups={"docgen:read"}) */ private array $name = []; diff --git a/src/Bundle/ChillMainBundle/Entity/Location.php b/src/Bundle/ChillMainBundle/Entity/Location.php index 8496374d8..bff3ff37b 100644 --- a/src/Bundle/ChillMainBundle/Entity/Location.php +++ b/src/Bundle/ChillMainBundle/Entity/Location.php @@ -64,7 +64,7 @@ class Location implements TrackCreationInterface, TrackUpdateInterface /** * @ORM\Column(type="string", length=255, nullable=true) - * @Serializer\Groups({"read", "write"}) + * @Serializer\Groups({"read", "write", "docgen:read"}) */ private ?string $email = null; diff --git a/src/Bundle/ChillMainBundle/Serializer/Normalizer/CommentEmbeddableDocGenNormalizer.php b/src/Bundle/ChillMainBundle/Serializer/Normalizer/CommentEmbeddableDocGenNormalizer.php new file mode 100644 index 000000000..e5a37c430 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Serializer/Normalizer/CommentEmbeddableDocGenNormalizer.php @@ -0,0 +1,88 @@ +userRepository = $userRepository; + } + + /** + * @param CommentEmbeddable $object + * + * @throws ExceptionInterface + */ + public function normalize($object, ?string $format = null, array $context = []): array + { + if (null === $object) { + return [ + 'comment' => '', + 'isNull' => true, + 'date' => $this->normalizer->normalize(null, $format, array_merge($context, [ + 'docgen:expects' => DateTime::class, + ])), + 'user' => $this->normalizer->normalize(null, $format, array_merge($context, [ + 'docgen:expects' => User::class, + ])), + ]; + } + + $user = $this->userRepository->find($object->getUserId()); + + return [ + 'comment' => (string) $object->getComment(), + 'isNull' => false, + 'date' => $this->normalizer->normalize($object->getDate(), $format, array_merge($context, [ + 'docgen:expects' => DateTime::class, + ])), + 'user' => $this->normalizer->normalize($user, $format, array_merge($context, [ + 'docgen:expects' => User::class, + ])), + ]; + } + + public function supportsNormalization($data, ?string $format = null, array $context = []): bool + { + if ('docgen' !== $format) { + return false; + } + + if ($data instanceof CommentEmbeddable) { + return true; + } + + if ( + null === $data + && array_key_exists('docgen:expects', $context) + && CommentEmbeddable::class === $context['docgen:expects']) { + return true; + } + + return false; + } +} diff --git a/src/Bundle/ChillPersonBundle/Entity/Person/PersonResource.php b/src/Bundle/ChillPersonBundle/Entity/Person/PersonResource.php index bc792ef95..cdd928598 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Person/PersonResource.php +++ b/src/Bundle/ChillPersonBundle/Entity/Person/PersonResource.php @@ -16,11 +16,8 @@ use Chill\MainBundle\Doctrine\Model\TrackCreationTrait; use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface; use Chill\MainBundle\Doctrine\Model\TrackUpdateTrait; use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable; -use Chill\MainBundle\Entity\User; use Chill\PersonBundle\Entity\Person; use Chill\ThirdPartyBundle\Entity\ThirdParty; -use DateTime; -use DateTimeInterface; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Serializer\Annotation\DiscriminatorMap; use Symfony\Component\Serializer\Annotation\Groups; @@ -38,6 +35,7 @@ class PersonResource implements TrackCreationInterface, TrackUpdateInterface { use TrackCreationTrait; use TrackUpdateTrait; + /** * @ORM\Embedded(class="Chill\MainBundle\Entity\Embeddable\CommentEmbeddable", columnPrefix="comment_") * @Groups({"read"}) diff --git a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodDocGenNormalizer.php b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodDocGenNormalizer.php index ceaba6ed8..fab2a022d 100644 --- a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodDocGenNormalizer.php +++ b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodDocGenNormalizer.php @@ -114,6 +114,7 @@ class AccompanyingPeriodDocGenNormalizer implements ContextAwareNormalizerInterf $userContext = array_merge($context, ['docgen:expects' => User::class, 'groups' => 'docgen:read']); $participationContext = array_merge($context, ['docgen:expects' => AccompanyingPeriodParticipation::class, 'groups' => 'docgen:read']); $administrativeLocationContext = array_merge($context, ['docgen:expects' => Location::class, 'groups' => 'docgen:read']); + $workContext = array_merge($context, ['docgen:expects' => AccompanyingPeriod\AccompanyingPeriodWork::class, 'groups' => 'docgen:read']); return [ 'id' => $period->getId(), @@ -160,6 +161,7 @@ class AccompanyingPeriodDocGenNormalizer implements ContextAwareNormalizerInterf 'locationPerson' => $this->normalizer->normalize($period->getPersonLocation(), $format, array_merge($context, ['docgen:expects' => Person::class])), 'location' => $this->normalizer->normalize($period->getLocation(), $format, $addressContext), 'administrativeLocation' => $this->normalizer->normalize($period->getAdministrativeLocation(), $format, $administrativeLocationContext), + 'works' => $this->normalizer->normalize($period->getWorks(), $format, $workContext), ]; } @@ -178,6 +180,7 @@ class AccompanyingPeriodDocGenNormalizer implements ContextAwareNormalizerInterf 'hasLocation' => false, 'hasLocationPerson' => false, 'hasAdministrativeLocation' => false, + 'works' => [], ] ); } diff --git a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/SocialActionNormalizer.php b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/SocialActionNormalizer.php index e971c793a..e210e1c4f 100644 --- a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/SocialActionNormalizer.php +++ b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/SocialActionNormalizer.php @@ -49,8 +49,11 @@ class SocialActionNormalizer implements NormalizerAwareInterface, NormalizerInte return [ 'id' => $socialAction->getId(), + 'type' => 'social_work_social_action', 'text' => $this->render->renderString($socialAction, []), 'title' => $socialAction->getTitle(), + 'parent' => $this->normalizer->normalize($socialAction->getParent(), $format, $context), + 'issue' => $this->normalizer->normalize($socialAction->getIssue(), $format, $context), ]; default: diff --git a/src/Bundle/ChillPersonBundle/Tests/Serializer/Normalizer/AccompanyingPeriodDocGenNormalizerTest.php b/src/Bundle/ChillPersonBundle/Tests/Serializer/Normalizer/AccompanyingPeriodDocGenNormalizerTest.php index c99e2ddc4..58ca55262 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Serializer/Normalizer/AccompanyingPeriodDocGenNormalizerTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Serializer/Normalizer/AccompanyingPeriodDocGenNormalizerTest.php @@ -100,6 +100,7 @@ final class AccompanyingPeriodDocGenNormalizerTest extends KernelTestCase 'hasLocationPerson' => false, 'location' => '@ignored', 'locationPerson' => '@ignored', + 'works' => [], ]; $this->assertIsArray($data); @@ -160,6 +161,7 @@ final class AccompanyingPeriodDocGenNormalizerTest extends KernelTestCase 'hasLocationPerson' => false, 'location' => '@ignored', 'locationPerson' => '@ignored', + 'works' => [], ]; $this->assertIsArray($data); From 4d76de5f9f22ae58b8ff50eb0d0f29b9f71388db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 26 Jan 2022 23:52:27 +0100 Subject: [PATCH 5/5] fix normalization for person in docgen --- .../Serializer/Normalizer/PersonDocGenNormalizer.php | 2 +- .../Serializer/Normalizer/PersonDocGenNormalizerTest.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonDocGenNormalizer.php b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonDocGenNormalizer.php index 71b6ed92e..4dd32aa54 100644 --- a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonDocGenNormalizer.php +++ b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonDocGenNormalizer.php @@ -151,7 +151,7 @@ class PersonDocGenNormalizer implements $normalizer = new NormalizeNullValueHelper($this->normalizer, 'type', 'person'); $attributes = [ - 'firstname', 'lastname', 'age', 'altNames', 'text', + 'firstName', 'lastName', 'age', 'altNames', 'text', 'civility' => Civility::class, 'birthdate' => DateTimeInterface::class, 'deathdate' => DateTimeInterface::class, diff --git a/src/Bundle/ChillPersonBundle/Tests/Serializer/Normalizer/PersonDocGenNormalizerTest.php b/src/Bundle/ChillPersonBundle/Tests/Serializer/Normalizer/PersonDocGenNormalizerTest.php index 3283972e6..817125422 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Serializer/Normalizer/PersonDocGenNormalizerTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Serializer/Normalizer/PersonDocGenNormalizerTest.php @@ -38,8 +38,8 @@ final class PersonDocGenNormalizerTest extends KernelTestCase use ProphecyTrait; private const BLANK = [ - 'firstname' => '', - 'lastname' => '', + 'firstName' => '', + 'lastName' => '', 'altNames' => '', 'text' => '', 'isNull' => true, @@ -80,7 +80,7 @@ final class PersonDocGenNormalizerTest extends KernelTestCase $expected = array_merge( self::BLANK, - ['firstname' => 'Renaud', 'lastname' => 'Mégane', + ['firstName' => 'Renaud', 'lastName' => 'Mégane', 'text' => 'Renaud Mégane', ] );