mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 21:34:25 +00:00
variables for docgen
This commit is contained in:
parent
7af7135971
commit
0a92ad905b
@ -61,7 +61,7 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\ManyToOne(targetEntity="Chill\PersonBundle\Entity\AccompanyingPeriod")
|
* @ORM\ManyToOne(targetEntity="Chill\PersonBundle\Entity\AccompanyingPeriod")
|
||||||
* @Groups({"read", "docgen:read"})
|
* @Groups({"read"})
|
||||||
*/
|
*/
|
||||||
private ?AccompanyingPeriod $accompanyingPeriod = null;
|
private ?AccompanyingPeriod $accompanyingPeriod = null;
|
||||||
|
|
||||||
@ -75,16 +75,19 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\ManyToOne(targetEntity="Chill\ActivityBundle\Entity\ActivityPresence")
|
* @ORM\ManyToOne(targetEntity="Chill\ActivityBundle\Entity\ActivityPresence")
|
||||||
|
* @Groups({"docgen:read"})
|
||||||
*/
|
*/
|
||||||
private ?ActivityPresence $attendee = null;
|
private ?ActivityPresence $attendee = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Embedded(class="Chill\MainBundle\Entity\Embeddable\CommentEmbeddable", columnPrefix="comment_")
|
* @ORM\Embedded(class="Chill\MainBundle\Entity\Embeddable\CommentEmbeddable", columnPrefix="comment_")
|
||||||
|
* @Groups({"docgen:read"})
|
||||||
*/
|
*/
|
||||||
private CommentEmbeddable $comment;
|
private CommentEmbeddable $comment;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="datetime")
|
* @ORM\Column(type="datetime")
|
||||||
|
* @Groups({"docgen:read"})
|
||||||
*/
|
*/
|
||||||
private DateTime $date;
|
private DateTime $date;
|
||||||
|
|
||||||
@ -100,6 +103,7 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="boolean", options={"default": false})
|
* @ORM\Column(type="boolean", options={"default": false})
|
||||||
|
* @Groups({"docgen:read"})
|
||||||
*/
|
*/
|
||||||
private bool $emergency = false;
|
private bool $emergency = false;
|
||||||
|
|
||||||
@ -130,16 +134,19 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\ManyToMany(targetEntity="Chill\ActivityBundle\Entity\ActivityReason")
|
* @ORM\ManyToMany(targetEntity="Chill\ActivityBundle\Entity\ActivityReason")
|
||||||
|
* @Groups({"docgen:read"})
|
||||||
*/
|
*/
|
||||||
private Collection $reasons;
|
private Collection $reasons;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\Scope")
|
* @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\Scope")
|
||||||
|
* @Groups({"docgen:read"})
|
||||||
*/
|
*/
|
||||||
private ?Scope $scope = null;
|
private ?Scope $scope = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="string", options={"default": ""})
|
* @ORM\Column(type="string", options={"default": ""})
|
||||||
|
* @Groups({"docgen:read"})
|
||||||
*/
|
*/
|
||||||
private string $sentReceived = '';
|
private string $sentReceived = '';
|
||||||
|
|
||||||
@ -170,12 +177,13 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\User")
|
* @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\User")
|
||||||
|
* @Groups({"docgen:read"})
|
||||||
*/
|
*/
|
||||||
private User $user;
|
private User $user;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\ManyToMany(targetEntity="Chill\MainBundle\Entity\User")
|
* @ORM\ManyToMany(targetEntity="Chill\MainBundle\Entity\User")
|
||||||
* @Groups({"read"})
|
* @Groups({"read", "docgen:read"})
|
||||||
*/
|
*/
|
||||||
private ?Collection $users = null;
|
private ?Collection $users = null;
|
||||||
|
|
||||||
@ -302,6 +310,18 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac
|
|||||||
return $this->documents;
|
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
|
public function getDurationTime(): ?DateTime
|
||||||
{
|
{
|
||||||
return $this->durationTime;
|
return $this->durationTime;
|
||||||
@ -402,6 +422,18 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac
|
|||||||
return $this->travelTime;
|
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
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
|
@ -12,6 +12,7 @@ declare(strict_types=1);
|
|||||||
namespace Chill\ActivityBundle\Entity;
|
namespace Chill\ActivityBundle\Entity;
|
||||||
|
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
use Symfony\Component\Serializer\Annotation as Serializer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class ActivityPresence.
|
* Class ActivityPresence.
|
||||||
@ -31,11 +32,14 @@ class ActivityPresence
|
|||||||
* @ORM\Id
|
* @ORM\Id
|
||||||
* @ORM\Column(name="id", type="integer")
|
* @ORM\Column(name="id", type="integer")
|
||||||
* @ORM\GeneratedValue(strategy="AUTO")
|
* @ORM\GeneratedValue(strategy="AUTO")
|
||||||
|
* @Serializer\Groups({"docgen:read"})
|
||||||
*/
|
*/
|
||||||
private ?int $id;
|
private ?int $id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="json")
|
* @ORM\Column(type="json")
|
||||||
|
* @Serializer\Groups({"docgen:read"})
|
||||||
|
* @Serializer\Context({"is-translatable": true}, groups={"docgen:read"})
|
||||||
*/
|
*/
|
||||||
private array $name = [];
|
private array $name = [];
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ namespace Chill\ActivityBundle\Entity;
|
|||||||
|
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
|
use Symfony\Component\Serializer\Annotation as Serializer;
|
||||||
use Symfony\Component\Serializer\Annotation\Groups;
|
use Symfony\Component\Serializer\Annotation\Groups;
|
||||||
use Symfony\Component\Validator\Constraints as Assert;
|
use Symfony\Component\Validator\Constraints as Assert;
|
||||||
|
|
||||||
@ -118,6 +119,7 @@ class ActivityType
|
|||||||
* @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({"docgen:read"})
|
||||||
*/
|
*/
|
||||||
private ?int $id;
|
private ?int $id;
|
||||||
|
|
||||||
@ -133,7 +135,8 @@ class ActivityType
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="json")
|
* @ORM\Column(type="json")
|
||||||
* @Groups({"read"})
|
* @Groups({"read", "docgen:read"})
|
||||||
|
* @Serializer\Context({"is-translatable": true}, groups={"docgen:read"})
|
||||||
*/
|
*/
|
||||||
private array $name = [];
|
private array $name = [];
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ class Location implements TrackCreationInterface, TrackUpdateInterface
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="string", length=255, nullable=true)
|
* @ORM\Column(type="string", length=255, nullable=true)
|
||||||
* @Serializer\Groups({"read", "write"})
|
* @Serializer\Groups({"read", "write", "docgen:read"})
|
||||||
*/
|
*/
|
||||||
private ?string $email = null;
|
private ?string $email = null;
|
||||||
|
|
||||||
|
@ -0,0 +1,88 @@
|
|||||||
|
<?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\MainBundle\Serializer\Normalizer;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable;
|
||||||
|
use Chill\MainBundle\Entity\User;
|
||||||
|
use Chill\MainBundle\Repository\UserRepository;
|
||||||
|
use DateTime;
|
||||||
|
use Symfony\Component\Serializer\Exception\ExceptionInterface;
|
||||||
|
use Symfony\Component\Serializer\Normalizer\ContextAwareNormalizerInterface;
|
||||||
|
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
|
||||||
|
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
|
||||||
|
use function array_key_exists;
|
||||||
|
|
||||||
|
class CommentEmbeddableDocGenNormalizer implements ContextAwareNormalizerInterface, NormalizerAwareInterface
|
||||||
|
{
|
||||||
|
use NormalizerAwareTrait;
|
||||||
|
|
||||||
|
private UserRepository $userRepository;
|
||||||
|
|
||||||
|
public function __construct(UserRepository $userRepository)
|
||||||
|
{
|
||||||
|
$this->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;
|
||||||
|
}
|
||||||
|
}
|
@ -16,11 +16,8 @@ use Chill\MainBundle\Doctrine\Model\TrackCreationTrait;
|
|||||||
use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface;
|
use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface;
|
||||||
use Chill\MainBundle\Doctrine\Model\TrackUpdateTrait;
|
use Chill\MainBundle\Doctrine\Model\TrackUpdateTrait;
|
||||||
use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable;
|
use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable;
|
||||||
use Chill\MainBundle\Entity\User;
|
|
||||||
use Chill\PersonBundle\Entity\Person;
|
use Chill\PersonBundle\Entity\Person;
|
||||||
use Chill\ThirdPartyBundle\Entity\ThirdParty;
|
use Chill\ThirdPartyBundle\Entity\ThirdParty;
|
||||||
use DateTime;
|
|
||||||
use DateTimeInterface;
|
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
|
use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
|
||||||
use Symfony\Component\Serializer\Annotation\Groups;
|
use Symfony\Component\Serializer\Annotation\Groups;
|
||||||
@ -38,6 +35,7 @@ class PersonResource implements TrackCreationInterface, TrackUpdateInterface
|
|||||||
{
|
{
|
||||||
use TrackCreationTrait;
|
use TrackCreationTrait;
|
||||||
use TrackUpdateTrait;
|
use TrackUpdateTrait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Embedded(class="Chill\MainBundle\Entity\Embeddable\CommentEmbeddable", columnPrefix="comment_")
|
* @ORM\Embedded(class="Chill\MainBundle\Entity\Embeddable\CommentEmbeddable", columnPrefix="comment_")
|
||||||
* @Groups({"read"})
|
* @Groups({"read"})
|
||||||
|
@ -114,6 +114,7 @@ class AccompanyingPeriodDocGenNormalizer implements ContextAwareNormalizerInterf
|
|||||||
$userContext = array_merge($context, ['docgen:expects' => User::class, 'groups' => 'docgen:read']);
|
$userContext = array_merge($context, ['docgen:expects' => User::class, 'groups' => 'docgen:read']);
|
||||||
$participationContext = array_merge($context, ['docgen:expects' => AccompanyingPeriodParticipation::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']);
|
$administrativeLocationContext = array_merge($context, ['docgen:expects' => Location::class, 'groups' => 'docgen:read']);
|
||||||
|
$workContext = array_merge($context, ['docgen:expects' => AccompanyingPeriod\AccompanyingPeriodWork::class, 'groups' => 'docgen:read']);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'id' => $period->getId(),
|
'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])),
|
'locationPerson' => $this->normalizer->normalize($period->getPersonLocation(), $format, array_merge($context, ['docgen:expects' => Person::class])),
|
||||||
'location' => $this->normalizer->normalize($period->getLocation(), $format, $addressContext),
|
'location' => $this->normalizer->normalize($period->getLocation(), $format, $addressContext),
|
||||||
'administrativeLocation' => $this->normalizer->normalize($period->getAdministrativeLocation(), $format, $administrativeLocationContext),
|
'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,
|
'hasLocation' => false,
|
||||||
'hasLocationPerson' => false,
|
'hasLocationPerson' => false,
|
||||||
'hasAdministrativeLocation' => false,
|
'hasAdministrativeLocation' => false,
|
||||||
|
'works' => [],
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -49,8 +49,11 @@ class SocialActionNormalizer implements NormalizerAwareInterface, NormalizerInte
|
|||||||
|
|
||||||
return [
|
return [
|
||||||
'id' => $socialAction->getId(),
|
'id' => $socialAction->getId(),
|
||||||
|
'type' => 'social_work_social_action',
|
||||||
'text' => $this->render->renderString($socialAction, []),
|
'text' => $this->render->renderString($socialAction, []),
|
||||||
'title' => $socialAction->getTitle(),
|
'title' => $socialAction->getTitle(),
|
||||||
|
'parent' => $this->normalizer->normalize($socialAction->getParent(), $format, $context),
|
||||||
|
'issue' => $this->normalizer->normalize($socialAction->getIssue(), $format, $context),
|
||||||
];
|
];
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -100,6 +100,7 @@ final class AccompanyingPeriodDocGenNormalizerTest extends KernelTestCase
|
|||||||
'hasLocationPerson' => false,
|
'hasLocationPerson' => false,
|
||||||
'location' => '@ignored',
|
'location' => '@ignored',
|
||||||
'locationPerson' => '@ignored',
|
'locationPerson' => '@ignored',
|
||||||
|
'works' => [],
|
||||||
];
|
];
|
||||||
|
|
||||||
$this->assertIsArray($data);
|
$this->assertIsArray($data);
|
||||||
@ -160,6 +161,7 @@ final class AccompanyingPeriodDocGenNormalizerTest extends KernelTestCase
|
|||||||
'hasLocationPerson' => false,
|
'hasLocationPerson' => false,
|
||||||
'location' => '@ignored',
|
'location' => '@ignored',
|
||||||
'locationPerson' => '@ignored',
|
'locationPerson' => '@ignored',
|
||||||
|
'works' => [],
|
||||||
];
|
];
|
||||||
|
|
||||||
$this->assertIsArray($data);
|
$this->assertIsArray($data);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user