diff --git a/src/Bundle/ChillActivityBundle/translations/messages.fr.yml b/src/Bundle/ChillActivityBundle/translations/messages.fr.yml
index 81a34d47d..051497b69 100644
--- a/src/Bundle/ChillActivityBundle/translations/messages.fr.yml
+++ b/src/Bundle/ChillActivityBundle/translations/messages.fr.yml
@@ -76,7 +76,7 @@ activity:
Insert a document: Insérer un document
Remove a document: Supprimer le document
comment: Commentaire
-No documents: Pas de documents
+No documents: Aucun document
#timeline
'%user% has done an %activity_type%': '%user% a effectué une activité de type "%activity_type%"'
diff --git a/src/Bundle/ChillDocStoreBundle/Controller/DocumentAccompanyingCourseController.php b/src/Bundle/ChillDocStoreBundle/Controller/DocumentAccompanyingCourseController.php
index 199f88c60..ae8db17f6 100644
--- a/src/Bundle/ChillDocStoreBundle/Controller/DocumentAccompanyingCourseController.php
+++ b/src/Bundle/ChillDocStoreBundle/Controller/DocumentAccompanyingCourseController.php
@@ -21,6 +21,8 @@ use Chill\PersonBundle\Entity\AccompanyingPeriod;
use DateTime;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
+use Symfony\Component\Form\Extension\Core\Type\FormType;
+use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
@@ -59,21 +61,37 @@ class DocumentAccompanyingCourseController extends AbstractController
}
/**
- * @Route("/{id}", name="accompanying_course_document_delete", methods="DELETE")
+ * @Route("/{id}/delete", name="chill_docstore_accompanying_course_document_delete")
*/
public function delete(Request $request, AccompanyingPeriod $course, AccompanyingCourseDocument $document): Response
{
$this->denyAccessUnlessGranted(AccompanyingCourseDocumentVoter::DELETE, $document);
- if ($this->isCsrfTokenValid('delete' . $document->getId(), $request->request->get('_token'))) {
- $em = $this->getDoctrine()->getManager();
- $em->remove($document);
- $em->flush();
+ $form = $this->createForm(FormType::class);
+ $form->add('submit', SubmitType::class, ['label' => 'Delete']);
+
+ $form->handleRequest($request);
+
+ if ($form->isSubmitted() && $form->isValid()) {
+ $this->getDoctrine()->getManager()->remove($document);
+ $this->getDoctrine()->getManager()->flush();
+
+ $this->addFlash('success', $this->translator->trans('The document is successfully removed'));
+
+ if ($request->query->has('returnPath')) {
+ return $this->redirect($request->query->get('returnPath'));
+ }
+
+ return $this->redirectToRoute('accompanying_course_document_index', ['course' => $course->getId()]);
}
- return $this->redirectToRoute(
- 'accompanying_course_document_index',
- ['accompanyingCourse' => $course->getId()]
+ return $this->render(
+ 'ChillDocStoreBundle:AccompanyingCourseDocument:delete.html.twig',
+ [
+ 'document' => $document,
+ 'delete_form' => $form->createView(),
+ 'accompanyingCourse' => $course,
+ ]
);
}
diff --git a/src/Bundle/ChillDocStoreBundle/Controller/DocumentPersonController.php b/src/Bundle/ChillDocStoreBundle/Controller/DocumentPersonController.php
index fcb3a4958..42e49ad3c 100644
--- a/src/Bundle/ChillDocStoreBundle/Controller/DocumentPersonController.php
+++ b/src/Bundle/ChillDocStoreBundle/Controller/DocumentPersonController.php
@@ -14,6 +14,7 @@ namespace Chill\DocStoreBundle\Controller;
use Chill\DocStoreBundle\Entity\PersonDocument;
use Chill\DocStoreBundle\Form\PersonDocumentType;
use Chill\DocStoreBundle\Repository\PersonDocumentACLAwareRepositoryInterface;
+use Chill\DocStoreBundle\Security\Authorization\PersonDocumentVoter;
use Chill\MainBundle\Pagination\PaginatorFactory;
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
use Chill\PersonBundle\Entity\Person;
@@ -22,6 +23,8 @@ use Chill\PersonBundle\Security\Authorization\PersonVoter;
use DateTime;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
+use Symfony\Component\Form\Extension\Core\Type\FormType;
+use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
@@ -64,22 +67,37 @@ class DocumentPersonController extends AbstractController
}
/**
- * @Route("/{id}", name="person_document_delete", methods="DELETE")
+ * @Route("/{id}/delete", name="chill_docstore_person_document_delete")
*/
public function delete(Request $request, Person $person, PersonDocument $document): Response
{
- $this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person);
- $this->denyAccessUnlessGranted('CHILL_PERSON_DOCUMENT_DELETE', $document);
+ $this->denyAccessUnlessGranted(PersonDocumentVoter::DELETE, $document);
- if ($this->isCsrfTokenValid('delete' . $document->getId(), $request->request->get('_token'))) {
- $em = $this->getDoctrine()->getManager();
- $em->remove($document);
- $em->flush();
+ $form = $this->createForm(FormType::class);
+ $form->add('submit', SubmitType::class, ['label' => 'Delete']);
+
+ $form->handleRequest($request);
+
+ if ($form->isSubmitted() && $form->isValid()) {
+ $this->getDoctrine()->getManager()->remove($document);
+ $this->getDoctrine()->getManager()->flush();
+
+ $this->addFlash('success', $this->translator->trans('The document is successfully removed'));
+
+ if ($request->query->has('returnPath')) {
+ return $this->redirect($request->query->get('returnPath'));
+ }
+
+ return $this->redirectToRoute('person_document_index', ['person' => $person->getId()]);
}
- return $this->redirectToRoute(
- 'person_document_index',
- ['person' => $person->getId()]
+ return $this->render(
+ 'ChillDocStoreBundle:PersonDocument:delete.html.twig',
+ [
+ 'document' => $document,
+ 'delete_form' => $form->createView(),
+ 'person' => $person,
+ ]
);
}
@@ -98,7 +116,6 @@ class DocumentPersonController extends AbstractController
PersonDocumentType::class,
$document,
[
- 'center' => $document->getCenter(),
'role' => 'CHILL_PERSON_DOCUMENT_UPDATE',
]
);
@@ -199,7 +216,6 @@ class DocumentPersonController extends AbstractController
$document->setDate(new DateTime('Now'));
$form = $this->createForm(PersonDocumentType::class, $document, [
- 'center' => $document->getCenter(),
'role' => 'CHILL_PERSON_DOCUMENT_CREATE',
]);
$form->handleRequest($request);
diff --git a/src/Bundle/ChillDocStoreBundle/Form/PersonDocumentType.php b/src/Bundle/ChillDocStoreBundle/Form/PersonDocumentType.php
index bcbd4d707..41dc73154 100644
--- a/src/Bundle/ChillDocStoreBundle/Form/PersonDocumentType.php
+++ b/src/Bundle/ChillDocStoreBundle/Form/PersonDocumentType.php
@@ -13,15 +13,13 @@ namespace Chill\DocStoreBundle\Form;
use Chill\DocStoreBundle\Entity\Document;
use Chill\DocStoreBundle\Entity\PersonDocument;
-use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Form\Type\ChillDateType;
use Chill\MainBundle\Form\Type\ChillTextareaType;
use Chill\MainBundle\Form\Type\ScopePickerType;
-use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
+use Chill\MainBundle\Security\Resolver\CenterResolverDispatcher;
use Chill\MainBundle\Security\Resolver\ScopeResolverDispatcher;
-use Chill\MainBundle\Templating\TranslatableStringHelper;
+use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use Doctrine\ORM\EntityRepository;
-use Doctrine\Persistence\ObjectManager;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Form\AbstractType;
@@ -31,34 +29,16 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
class PersonDocumentType extends AbstractType
{
- /**
- * @var AuthorizationHelper
- */
- protected $authorizationHelper;
-
- /**
- * @var ObjectManager
- */
- protected $om;
-
- /**
- * @var TranslatableStringHelper
- */
- protected $translatableStringHelper;
-
- /**
- * the user running this form.
- *
- * @var User
- */
- protected $user;
+ private CenterResolverDispatcher $centerResolverDispatcher;
private ParameterBagInterface $parameterBag;
private ScopeResolverDispatcher $scopeResolverDispatcher;
+ private TranslatableStringHelperInterface $translatableStringHelper;
+
public function __construct(
- TranslatableStringHelper $translatableStringHelper,
+ TranslatableStringHelperInterface $translatableStringHelper,
ScopeResolverDispatcher $scopeResolverDispatcher,
ParameterBagInterface $parameterBag
) {
@@ -96,7 +76,7 @@ class PersonDocumentType extends AbstractType
if ($isScopeConcerned && $this->parameterBag->get('chill_main')['acl']['form_show_scopes']) {
$builder->add('scope', ScopePickerType::class, [
- 'center' => $options['center'],
+ 'center' => $this->centerResolverDispatcher->resolveCenter($document),
'role' => $options['role'],
]);
}
@@ -108,8 +88,7 @@ class PersonDocumentType extends AbstractType
'data_class' => Document::class,
]);
- $resolver->setRequired(['role', 'center'])
- ->setAllowedTypes('role', ['string'])
- ->setAllowedTypes('center', [\Chill\MainBundle\Entity\Center::class]);
+ $resolver->setRequired(['role'])
+ ->setAllowedTypes('role', ['string']);
}
}
diff --git a/src/Bundle/ChillDocStoreBundle/Resources/views/AccompanyingCourseDocument/_delete_form.html.twig b/src/Bundle/ChillDocStoreBundle/Resources/views/AccompanyingCourseDocument/_delete_form.html.twig
deleted file mode 100644
index 90ee734e0..000000000
--- a/src/Bundle/ChillDocStoreBundle/Resources/views/AccompanyingCourseDocument/_delete_form.html.twig
+++ /dev/null
@@ -1,5 +0,0 @@
-
diff --git a/src/Bundle/ChillDocStoreBundle/Resources/views/AccompanyingCourseDocument/delete.html.twig b/src/Bundle/ChillDocStoreBundle/Resources/views/AccompanyingCourseDocument/delete.html.twig
new file mode 100644
index 000000000..a6679829b
--- /dev/null
+++ b/src/Bundle/ChillDocStoreBundle/Resources/views/AccompanyingCourseDocument/delete.html.twig
@@ -0,0 +1,43 @@
+{% extends "@ChillPerson/AccompanyingCourse/layout.html.twig" %}
+
+{% set activeRouteKey = '' %}
+
+{% block title %}{{ 'Delete document ?' }}{% endblock %}
+
+{% block docdescription %}
+
+ {{ 'Title'|trans }}
+ {{ document.title }}
+
+ {% if document.scope is not null %}
+ {{ 'Scope' | trans }}
+ {{ document.scope.name | localize_translatable_string }}
+ {% endif %}
+
+ {{ 'Category'|trans }}
+ {{ document.category.name|localize_translatable_string }}
+
+ {{ 'Description' | trans }}
+
+ {% if document.description is empty %}
+ {{ 'Any description'|trans }}
+ {% else %}
+
+ {{ document.description|chill_markdown_to_html }}
+
+ {% endif %}
+
+
+{% endblock %}
+
+{% block content %}
+{{ include('@ChillMain/Util/confirmation_template.html.twig',
+ {
+ 'title' : 'Delete document ?'|trans,
+ 'display_content' : block('docdescription'),
+ 'confirm_question' : 'Are you sure you want to remove this document ?'|trans,
+ 'cancel_route' : 'accompanying_course_document_index',
+ 'cancel_parameters' : {'course' : accompanyingCourse.id, 'id': document.id},
+ 'form' : delete_form
+ } ) }}
+{% endblock %}
diff --git a/src/Bundle/ChillDocStoreBundle/Resources/views/AccompanyingCourseDocument/edit.html.twig b/src/Bundle/ChillDocStoreBundle/Resources/views/AccompanyingCourseDocument/edit.html.twig
index d7a5325cf..0ca5661fc 100644
--- a/src/Bundle/ChillDocStoreBundle/Resources/views/AccompanyingCourseDocument/edit.html.twig
+++ b/src/Bundle/ChillDocStoreBundle/Resources/views/AccompanyingCourseDocument/edit.html.twig
@@ -25,8 +25,13 @@
{{ 'Back to the list' | trans }}
-
- {{ 'Edit'|trans }}
+ {% if is_granted('CHILL_ACCOMPANYING_COURSE_DOCUMENT_DELETE', document) %}
+
+
+
+ {% endif %}
+
+ {{ 'Edit'|trans }}
diff --git a/src/Bundle/ChillDocStoreBundle/Resources/views/AccompanyingCourseDocument/show.html.twig b/src/Bundle/ChillDocStoreBundle/Resources/views/AccompanyingCourseDocument/show.html.twig
index 1e4fdb8e6..45ed3988b 100644
--- a/src/Bundle/ChillDocStoreBundle/Resources/views/AccompanyingCourseDocument/show.html.twig
+++ b/src/Bundle/ChillDocStoreBundle/Resources/views/AccompanyingCourseDocument/show.html.twig
@@ -49,12 +49,9 @@
{{ 'Back to the list' | trans }}
-
- {{ m.download_button(document.object, document.title) }}
-
- {% if chill_document_is_editable(document.object) %}
-
- {{ document.object|chill_document_edit_button }}
+ {% if is_granted('CHILL_ACCOMPANYING_COURSE_DOCUMENT_DELETE', document) %}
+
+
{% endif %}
{% if is_granted('CHILL_ACCOMPANYING_COURSE_DOCUMENT_UPDATE', document) %}
@@ -63,6 +60,14 @@
class="btn btn-edit" title="{{ 'Edit attributes' | trans }}">
{% endif %}
+
+ {{ m.download_button(document.object, document.title) }}
+
+ {% if chill_document_is_editable(document.object) %}
+
+ {{ document.object|chill_document_edit_button }}
+
+ {% endif %}
{% set workflows_frame = chill_entity_workflow_list('Chill\\DocStoreBundle\\Entity\\AccompanyingCourseDocument', document.id) %}
{% if workflows_frame is not empty %}
diff --git a/src/Bundle/ChillDocStoreBundle/Resources/views/List/list_item.html.twig b/src/Bundle/ChillDocStoreBundle/Resources/views/List/list_item.html.twig
index 5ce03091b..8fbc3fa5c 100644
--- a/src/Bundle/ChillDocStoreBundle/Resources/views/List/list_item.html.twig
+++ b/src/Bundle/ChillDocStoreBundle/Resources/views/List/list_item.html.twig
@@ -44,6 +44,16 @@
{% if document.course is defined %}
+ {% if is_granted('CHILL_ACCOMPANYING_COURSE_DOCUMENT_DELETE', document) %}
+
+
+
+ {% endif %}
+ {% if is_granted('CHILL_ACCOMPANYING_COURSE_DOCUMENT_UPDATE', document) %}
+
+
+
+ {% endif %}
{% if is_granted('CHILL_ACCOMPANYING_COURSE_DOCUMENT_SEE_DETAILS', document) %}
{{ m.download_button(document.object, document.title) }}
@@ -52,15 +62,20 @@
{% endif %}
- {% if is_granted('CHILL_ACCOMPANYING_COURSE_DOCUMENT_UPDATE', document) %}
-
-
-
- {% endif %}
{{ chill_entity_workflow_list('Chill\\DocStoreBundle\\Entity\\AccompanyingCourseDocument', document.id) }}
{% else %}
+ {% if is_granted('CHILL_PERSON_DOCUMENT_DELETE', document) %}
+
+
+
+ {% endif %}
+ {% if is_granted('CHILL_PERSON_DOCUMENT_UPDATE', document) %}
+
+
+
+ {% endif %}
{% if is_granted('CHILL_PERSON_DOCUMENT_SEE_DETAILS', document) %}
{{ m.download_button(document.object, document.title) }}
@@ -69,13 +84,8 @@
{% endif %}
- {% if is_granted('CHILL_PERSON_DOCUMENT_UPDATE', document) %}
-
-
-
- {% endif %}
{% endif %}
-
+
diff --git a/src/Bundle/ChillDocStoreBundle/Resources/views/PersonDocument/delete.html.twig b/src/Bundle/ChillDocStoreBundle/Resources/views/PersonDocument/delete.html.twig
new file mode 100644
index 000000000..e3f6687fd
--- /dev/null
+++ b/src/Bundle/ChillDocStoreBundle/Resources/views/PersonDocument/delete.html.twig
@@ -0,0 +1,43 @@
+{% extends "@ChillPerson/Person/layout.html.twig" %}
+
+{% set activeRouteKey = '' %}
+
+{% block title %}{{ 'Delete document ?' }}{% endblock %}
+
+{% block docdescription %}
+
+ {{ 'Title'|trans }}
+ {{ document.title }}
+
+ {% if document.scope is not null %}
+ {{ 'Scope' | trans }}
+ {{ document.scope.name | localize_translatable_string }}
+ {% endif %}
+
+ {{ 'Category'|trans }}
+ {{ document.category.name|localize_translatable_string }}
+
+ {{ 'Description' | trans }}
+
+ {% if document.description is empty %}
+ {{ 'Any description'|trans }}
+ {% else %}
+
+ {{ document.description|chill_markdown_to_html }}
+
+ {% endif %}
+
+
+{% endblock %}
+
+{% block personcontent %}
+{{ include('@ChillMain/Util/confirmation_template.html.twig',
+ {
+ 'title' : 'Delete document ?'|trans,
+ 'display_content' : block('docdescription'),
+ 'confirm_question' : 'Are you sure you want to remove this document ?'|trans,
+ 'cancel_route' : 'person_document_index',
+ 'cancel_parameters' : {'person' : person.id, 'id': document.id},
+ 'form' : delete_form
+ } ) }}
+{% endblock %}
diff --git a/src/Bundle/ChillDocStoreBundle/Resources/views/PersonDocument/edit.html.twig b/src/Bundle/ChillDocStoreBundle/Resources/views/PersonDocument/edit.html.twig
index 7533f1120..4a9eab8e3 100644
--- a/src/Bundle/ChillDocStoreBundle/Resources/views/PersonDocument/edit.html.twig
+++ b/src/Bundle/ChillDocStoreBundle/Resources/views/PersonDocument/edit.html.twig
@@ -36,20 +36,20 @@
{{ form_row(form.description) }}
{{ form_row(form.object, { 'label': 'Document', 'existing': document.object }) }}
-
+
{{ form_end(form) }}
diff --git a/src/Bundle/ChillDocStoreBundle/Resources/views/PersonDocument/new.html.twig b/src/Bundle/ChillDocStoreBundle/Resources/views/PersonDocument/new.html.twig
index ad4fcfc81..357120a4e 100644
--- a/src/Bundle/ChillDocStoreBundle/Resources/views/PersonDocument/new.html.twig
+++ b/src/Bundle/ChillDocStoreBundle/Resources/views/PersonDocument/new.html.twig
@@ -40,9 +40,9 @@
{{ form_row(form.description) }}
{{ form_row(form.object, { 'label': 'Document', 'existing': document.object }) }}
-
-
- {{ m.download_button(document.object, document.title) }}
-
-
- {% if chill_document_is_editable(document.object) %}
-
- {{ document.object|chill_document_edit_button }}
+ {% if is_granted('CHILL_PERSON_DOCUMENT_DELETE', document) %}
+
+
{% endif %}
@@ -82,5 +78,15 @@
{% endif %}
- {# {{ include('ChillDocStoreBundle:PersonDocument:_delete_form.html.twig') }} #}
+
+ {{ m.download_button(document.object, document.title) }}
+
+
+ {% if chill_document_is_editable(document.object) %}
+
+ {{ document.object|chill_document_edit_button }}
+
+ {% endif %}
+
+ {# {{ include('ChillDocStoreBundle:PersonDocument:_delete_form.html.twig') }} #}
{% endblock %}
diff --git a/src/Bundle/ChillDocStoreBundle/translations/messages.fr.yml b/src/Bundle/ChillDocStoreBundle/translations/messages.fr.yml
index f438731d4..009f4d987 100644
--- a/src/Bundle/ChillDocStoreBundle/translations/messages.fr.yml
+++ b/src/Bundle/ChillDocStoreBundle/translations/messages.fr.yml
@@ -19,6 +19,12 @@ The document is successfully registered: Le document est enregistré
The document is successfully updated: Le document est mis à jour
Any description: Aucune description
+# delete
+Delete document ?: Supprimer le document ?
+Are you sure you want to remove this document ?: Êtes-vous sûr·e de vouloir supprimer ce document ?
+The document is successfully removed: Le document a été supprimé
+
+
# dropzone upload
File too big: Fichier trop volumineux
Drop your file or click here: Cliquez ici ou faites glissez votre nouveau fichier dans cette zone
diff --git a/src/Bundle/ChillMainBundle/Validation/Validator/ValidPhonenumber.php b/src/Bundle/ChillMainBundle/Validation/Validator/ValidPhonenumber.php
index 9620f7cb9..267b2a70b 100644
--- a/src/Bundle/ChillMainBundle/Validation/Validator/ValidPhonenumber.php
+++ b/src/Bundle/ChillMainBundle/Validation/Validator/ValidPhonenumber.php
@@ -43,7 +43,7 @@ final class ValidPhonenumber extends ConstraintValidator
return;
}
- if ('' === $value) {
+ if (null === $value) {
return;
}
diff --git a/src/Bundle/ChillPersonBundle/Entity/Person/ResidentialAddress.php b/src/Bundle/ChillPersonBundle/Entity/Person/ResidentialAddress.php
index cb82f766a..bfa3760fa 100644
--- a/src/Bundle/ChillPersonBundle/Entity/Person/ResidentialAddress.php
+++ b/src/Bundle/ChillPersonBundle/Entity/Person/ResidentialAddress.php
@@ -18,8 +18,8 @@ use Chill\PersonBundle\Repository\ResidentialAddressRepository;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use DateTimeImmutable;
use Doctrine\ORM\Mapping as ORM;
-use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Annotation\Context;
+use Symfony\Component\Serializer\Annotation\Groups;
/**
* @ORM\Entity(repositoryClass=ResidentialAddressRepository::class)
@@ -49,7 +49,7 @@ class ResidentialAddress
* @ORM\ManyToOne(targetEntity=Person::class)
* @ORM\JoinColumn(nullable=true)
* @Groups({"read"})
- * @Context(normalizationContext={"groups"={"minimal"}})
+ * @Context(normalizationContext={"groups": {"minimal"}})
*/
private ?Person $hostPerson = null;
diff --git a/src/Bundle/ChillPersonBundle/Repository/ResidentialAddressRepository.php b/src/Bundle/ChillPersonBundle/Repository/ResidentialAddressRepository.php
index b5d64a31a..4e6131de0 100644
--- a/src/Bundle/ChillPersonBundle/Repository/ResidentialAddressRepository.php
+++ b/src/Bundle/ChillPersonBundle/Repository/ResidentialAddressRepository.php
@@ -32,26 +32,11 @@ class ResidentialAddressRepository extends ServiceEntityRepository
parent::__construct($registry, ResidentialAddress::class);
}
- /**
- * @param Person $person
- * @param DateTimeImmutable|null $at
- * @return array|ResidentialAddress[]|null
- */
- public function findCurrentResidentialAddressByPerson(Person $person, ?DateTimeImmutable $at = null): array
- {
- return $this->buildQueryFindCurrentResidentialAddresses($person, $at)
- ->select('ra')
- ->getQuery()
- ->getResult();
- }
-
public function buildQueryFindCurrentResidentialAddresses(Person $person, ?DateTimeImmutable $at = null): QueryBuilder
{
$date = null === $at ? new DateTimeImmutable('today') : $at;
$qb = $this->createQueryBuilder('ra');
-
-
$dateFilter = $qb->expr()->andX(
$qb->expr()->lte('ra.startDate', ':dateIn'),
$qb->expr()->orX(
@@ -69,6 +54,17 @@ class ResidentialAddressRepository extends ServiceEntityRepository
return $qb;
}
+ /**
+ * @return array|ResidentialAddress[]|null
+ */
+ public function findCurrentResidentialAddressByPerson(Person $person, ?DateTimeImmutable $at = null): array
+ {
+ return $this->buildQueryFindCurrentResidentialAddresses($person, $at)
+ ->select('ra')
+ ->getQuery()
+ ->getResult();
+ }
+
// /**
// * @return ResidentialAddress[] Returns an array of ResidentialAddress objects
// */
diff --git a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonJsonNormalizer.php b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonJsonNormalizer.php
index b42e30ff6..1901fd50c 100644
--- a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonJsonNormalizer.php
+++ b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonJsonNormalizer.php
@@ -31,6 +31,8 @@ use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
use Symfony\Component\Serializer\Normalizer\ObjectToPopulateTrait;
use function array_key_exists;
+use function count;
+use function in_array;
/**
* Serialize a Person entity.
@@ -207,8 +209,8 @@ class PersonJsonNormalizer implements DenormalizerAwareInterface, NormalizerAwar
'gender' => $person->getGender(),
];
- if (in_array("minimal", $groups) && 1 === count($groups)) {
- return $data;
+ if (in_array('minimal', $groups, true) && 1 === count($groups)) {
+ return $data;
}
return array_merge($data, [