mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-28 09:34:59 +00:00
Compare commits
199 Commits
fix-test-a
...
deploy/qui
Author | SHA1 | Date | |
---|---|---|---|
014170989e | |||
9d9be7f831 | |||
2a974e1269 | |||
beca41774e | |||
c26d342d30 | |||
2cf28b6c2d | |||
ed5351da14 | |||
8dca8d9b37 | |||
1cddad5c66 | |||
c98eda93cf | |||
dd991e3572 | |||
0640631821 | |||
e845d9ba90 | |||
|
6f8231f6f6 | ||
|
048161e300 | ||
b705c5910f | |||
6f1209eaf5 | |||
020759180b | |||
3748b4fbf4 | |||
|
4f49292178 | ||
357bf192b8 | |||
6eaffcae49 | |||
|
f92d710a26 | ||
|
bc6ba88acd | ||
efefb64119 | |||
6fa882f60f | |||
484058dcfc | |||
61c2934d64 | |||
28b4d9562c | |||
e06aded1ec | |||
3a81124e04 | |||
|
b72d45d9db | ||
2a1f5cbad1 | |||
e8566fd006 | |||
cd6b5c9a39 | |||
9aa3974071 | |||
a8bf478ee8 | |||
a35f3363b2 | |||
0b117e5158 | |||
7cae9e1769 | |||
25f2d17097 | |||
4fd43310c0 | |||
c85ca894b8 | |||
fe22e6c7dc | |||
b7513068da | |||
2dd71ea197 | |||
cb67605bd2 | |||
d26e08324c | |||
e55a2691b7 | |||
|
aa5c7f333e | ||
0afe277b04 | |||
757c064b7b | |||
f5d38f606c | |||
5abe482b12 | |||
5ded4822a2 | |||
981b9299ad | |||
|
36eb247995 | ||
2cda6ceebf | |||
1ceabec400 | |||
|
91c5cd74f7 | ||
|
b7f2e189dc | ||
|
ab8deb036b | ||
|
ac47a75a75 | ||
|
4e6454d7de | ||
92a95d4186 | |||
|
c23ada3533 | ||
b72b1bd4c7 | |||
ca9ae3874c | |||
7fb4616aa6 | |||
ac4cf43753 | |||
5a4a0a3617 | |||
2cc1274ee0 | |||
154fa4719d | |||
193e7b4c7e | |||
80c2bd285f | |||
133c0ac1ac | |||
6122a5d62f | |||
c8d5c2c67b | |||
0754d20622 | |||
99d6e030ca | |||
5d38d193e2 | |||
86f7b116a9 | |||
bcab5a1211 | |||
65a6607112 | |||
1cd376bf86 | |||
84f6f9b44d | |||
b53f6af8d8 | |||
34d6452286 | |||
c04ccef4cd | |||
|
d8afbc4a40 | ||
95edbc673c | |||
07ffdfab86 | |||
50be29308d | |||
d1e0d997ac | |||
|
504b2efacf | ||
4c3c67344a | |||
40fcb09082 | |||
aa4a9e874a | |||
3abfdbf6fd | |||
07cc394abd | |||
99337c4aa6 | |||
04ccca092b | |||
|
b3792f6714 | ||
e1f01a47f8 | |||
dc79e1a02d | |||
7a6117a264 | |||
|
1a204312f3 | ||
1b1a25edc4 | |||
5ab7f7a37b | |||
b174397823 | |||
9d35e4efbb | |||
0e9933ca41 | |||
|
3d14f00cac | ||
0add757230 | |||
2bf65dfadb | |||
a7ecd08d78 | |||
|
bccaf5ad6e | ||
585a19e803 | |||
b801b75eb9 | |||
f1120af59e | |||
9d58356b90 | |||
a7131653c9 | |||
9f3cd943cb | |||
|
970635dfad | ||
|
c8297b2230 | ||
994cce41e5 | |||
86e41fb877 | |||
f8b97b96f4 | |||
27907e7558 | |||
fd7c7388d9 | |||
ef55d2cf7f | |||
|
8406c30c8e | ||
|
901ae47ce6 | ||
|
951160982d | ||
|
e2633a2a79 | ||
|
5b72eeb147 | ||
|
06daf35e96 | ||
38bff2e42f | |||
e68a5405a1 | |||
8bd20c9c78 | |||
54997e5893 | |||
|
35d35c9f40 | ||
78ca61c82e | |||
b68de1f2e9 | |||
68ecff253a | |||
e95d8fbc7a | |||
efdfd10e49 | |||
|
000ae6c2cb | ||
|
7c26f0a56c | ||
f827e50431 | |||
41617295c1 | |||
b2c1d75fc5 | |||
17c3ecbabe | |||
51399b21b9 | |||
c40019da8f | |||
1df759e970 | |||
807d3674fc | |||
af740fd87d | |||
45dc8ed661 | |||
ecc8b929ca | |||
|
c378f59f5a | ||
4fd6d38187 | |||
|
f3a7556bca | ||
|
14db7265fe | ||
|
f22461af1b | ||
|
1b709d39a4 | ||
|
5daf5cbe84 | ||
|
331cdf13ca | ||
cbadcb4980 | |||
|
1551ea796d | ||
|
4c025184b4 | ||
|
6f2c219e3b | ||
|
550aaacaab | ||
|
dd78e9759c | ||
|
1b36d9b1ab | ||
|
e14a125bf3 | ||
|
9375c2cf86 | ||
|
db77224b9f | ||
0e1bbbfee9 | |||
|
6a42edd460 | ||
|
76d945f2a7 | ||
|
7d13bc7cfe | ||
|
66b54bad31 | ||
|
9d32ccbcad | ||
|
63c3b5a970 | ||
|
03a7ec389b | ||
|
f39fe05dd5 | ||
|
6c126b0581 | ||
|
5ee824d1c2 | ||
|
6d20476b81 | ||
|
2b5ed5e5a3 | ||
|
6f68349f57 | ||
|
d513be2fce | ||
|
aff140230c | ||
|
7e1b7b7e9f | ||
|
878ee5d9c7 | ||
|
7b67ef5db2 | ||
|
d806a074a7 | ||
|
14a9d9c739 |
@@ -106,15 +106,16 @@ class Activity implements HasCenterInterface, HasScopeInterface
|
|||||||
/**
|
/**
|
||||||
* @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"})
|
||||||
*/
|
*/
|
||||||
private $socialIssues;
|
private Collection $socialIssues;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @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"})
|
||||||
*/
|
*/
|
||||||
private $socialActions;
|
private Collection $socialActions;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\ManyToOne(targetEntity="Chill\ActivityBundle\Entity\ActivityType")
|
* @ORM\ManyToOne(targetEntity="Chill\ActivityBundle\Entity\ActivityType")
|
||||||
@@ -281,7 +282,7 @@ class Activity implements HasCenterInterface, HasScopeInterface
|
|||||||
return $this->socialIssues;
|
return $this->socialIssues;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addSocialIssue(SocialIssue $socialIssue): self
|
public function addSocialIssue(?SocialIssue $socialIssue): self
|
||||||
{
|
{
|
||||||
if (!$this->socialIssues->contains($socialIssue)) {
|
if (!$this->socialIssues->contains($socialIssue)) {
|
||||||
$this->socialIssues[] = $socialIssue;
|
$this->socialIssues[] = $socialIssue;
|
||||||
@@ -297,15 +298,12 @@ class Activity implements HasCenterInterface, HasScopeInterface
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Collection|SocialAction[]
|
|
||||||
*/
|
|
||||||
public function getSocialActions(): Collection
|
public function getSocialActions(): Collection
|
||||||
{
|
{
|
||||||
return $this->socialActions;
|
return $this->socialActions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addSocialAction(SocialAction $socialAction): self
|
public function addSocialAction(?SocialAction $socialAction): self
|
||||||
{
|
{
|
||||||
if (!$this->socialActions->contains($socialAction)) {
|
if (!$this->socialActions->contains($socialAction)) {
|
||||||
$this->socialActions[] = $socialAction;
|
$this->socialActions[] = $socialAction;
|
||||||
|
@@ -35,6 +35,7 @@ use Symfony\Component\Form\Extension\Core\Type\HiddenType;
|
|||||||
use Symfony\Component\Form\CallbackTransformer;
|
use Symfony\Component\Form\CallbackTransformer;
|
||||||
use Chill\PersonBundle\Form\DataTransformer\PersonToIdTransformer;
|
use Chill\PersonBundle\Form\DataTransformer\PersonToIdTransformer;
|
||||||
use Chill\PersonBundle\Templating\Entity\SocialIssueRender;
|
use Chill\PersonBundle\Templating\Entity\SocialIssueRender;
|
||||||
|
use Chill\PersonBundle\Templating\Entity\SocialActionRender;
|
||||||
|
|
||||||
class ActivityType extends AbstractType
|
class ActivityType extends AbstractType
|
||||||
{
|
{
|
||||||
@@ -46,6 +47,10 @@ class ActivityType extends AbstractType
|
|||||||
|
|
||||||
protected TranslatableStringHelper $translatableStringHelper;
|
protected TranslatableStringHelper $translatableStringHelper;
|
||||||
|
|
||||||
|
protected SocialIssueRender $socialIssueRender;
|
||||||
|
|
||||||
|
protected SocialActionRender $socialActionRender;
|
||||||
|
|
||||||
protected array $timeChoices;
|
protected array $timeChoices;
|
||||||
|
|
||||||
public function __construct (
|
public function __construct (
|
||||||
@@ -54,7 +59,8 @@ class ActivityType extends AbstractType
|
|||||||
ObjectManager $om,
|
ObjectManager $om,
|
||||||
TranslatableStringHelper $translatableStringHelper,
|
TranslatableStringHelper $translatableStringHelper,
|
||||||
array $timeChoices,
|
array $timeChoices,
|
||||||
SocialIssueRender $socialIssueRender
|
SocialIssueRender $socialIssueRender,
|
||||||
|
SocialActionRender $socialActionRender
|
||||||
) {
|
) {
|
||||||
if (!$tokenStorage->getToken()->getUser() instanceof User) {
|
if (!$tokenStorage->getToken()->getUser() instanceof User) {
|
||||||
throw new \RuntimeException("you should have a valid user");
|
throw new \RuntimeException("you should have a valid user");
|
||||||
@@ -66,6 +72,7 @@ class ActivityType extends AbstractType
|
|||||||
$this->translatableStringHelper = $translatableStringHelper;
|
$this->translatableStringHelper = $translatableStringHelper;
|
||||||
$this->timeChoices = $timeChoices;
|
$this->timeChoices = $timeChoices;
|
||||||
$this->socialIssueRender = $socialIssueRender;
|
$this->socialIssueRender = $socialIssueRender;
|
||||||
|
$this->socialActionRender = $socialActionRender;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||||
@@ -105,31 +112,51 @@ class ActivityType extends AbstractType
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($activityType->isVisible('socialIssues') && $accompanyingPeriod) {
|
if ($activityType->isVisible('socialIssues') && $accompanyingPeriod) {
|
||||||
$builder->add('socialIssues', EntityType::class, [
|
$builder->add('socialIssues', HiddenType::class);
|
||||||
'label' => $activityType->getLabel('socialIssues'),
|
$builder->get('socialIssues')
|
||||||
'required' => $activityType->isRequired('socialIssues'),
|
->addModelTransformer(new CallbackTransformer(
|
||||||
'class' => SocialIssue::class,
|
function (iterable $socialIssuesAsIterable): string {
|
||||||
'choice_label' => function (SocialIssue $socialIssue) {
|
$socialIssueIds = [];
|
||||||
return $this->socialIssueRender->renderString($socialIssue, []);
|
foreach ($socialIssuesAsIterable as $value) {
|
||||||
|
$socialIssueIds[] = $value->getId();
|
||||||
|
}
|
||||||
|
return implode(',', $socialIssueIds);
|
||||||
},
|
},
|
||||||
'multiple' => true,
|
function (?string $socialIssuesAsString): array {
|
||||||
'choices' => $accompanyingPeriod->getRecursiveSocialIssues(),
|
if (null === $socialIssuesAsString) {
|
||||||
'expanded' => true,
|
return [];
|
||||||
]);
|
}
|
||||||
|
return array_map(
|
||||||
|
fn(string $id): ?SocialIssue => $this->om->getRepository(SocialIssue::class)->findOneBy(['id' => (int) $id]),
|
||||||
|
explode(',', $socialIssuesAsString)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
))
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($activityType->isVisible('socialActions') && $accompanyingPeriod) {
|
if ($activityType->isVisible('socialActions') && $accompanyingPeriod) {
|
||||||
$builder->add('socialActions', EntityType::class, [
|
$builder->add('socialActions', HiddenType::class);
|
||||||
'label' => $activityType->getLabel('socialActions'),
|
$builder->get('socialActions')
|
||||||
'required' => $activityType->isRequired('socialActions'),
|
->addModelTransformer(new CallbackTransformer(
|
||||||
'class' => SocialAction::class,
|
function (iterable $socialActionsAsIterable): string {
|
||||||
'choice_label' => function (SocialAction $socialAction) {
|
$socialActionIds = [];
|
||||||
return $this->translatableStringHelper->localize($socialAction->getTitle());
|
foreach ($socialActionsAsIterable as $value) {
|
||||||
|
$socialActionIds[] = $value->getId();
|
||||||
|
}
|
||||||
|
return implode(',', $socialActionIds);
|
||||||
},
|
},
|
||||||
'multiple' => true,
|
function (?string $socialActionsAsString): array {
|
||||||
'choices' => $accompanyingPeriod->getRecursiveSocialActions(),
|
if (null === $socialActionsAsString) {
|
||||||
'expanded' => true,
|
return [];
|
||||||
]);
|
}
|
||||||
|
return array_map(
|
||||||
|
fn(string $id): ?SocialAction => $this->om->getRepository(SocialAction::class)->findOneBy(['id' => (int) $id]),
|
||||||
|
explode(',', $socialActionsAsString)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
))
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($activityType->isVisible('date')) {
|
if ($activityType->isVisible('date')) {
|
||||||
@@ -203,9 +230,7 @@ class ActivityType extends AbstractType
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($activityType->isVisible('persons')) {
|
if ($activityType->isVisible('persons')) {
|
||||||
$builder->add('persons', HiddenType::class, [
|
$builder->add('persons', HiddenType::class);
|
||||||
//'data_class' => Person::class,
|
|
||||||
]);
|
|
||||||
$builder->get('persons')
|
$builder->get('persons')
|
||||||
->addModelTransformer(new CallbackTransformer(
|
->addModelTransformer(new CallbackTransformer(
|
||||||
function (iterable $personsAsIterable): string {
|
function (iterable $personsAsIterable): string {
|
||||||
@@ -226,9 +251,7 @@ class ActivityType extends AbstractType
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($activityType->isVisible('thirdParties')) {
|
if ($activityType->isVisible('thirdParties')) {
|
||||||
$builder->add('thirdParties', HiddenType::class, [
|
$builder->add('thirdParties', HiddenType::class);
|
||||||
//'data_class' => ThirdParty::class,
|
|
||||||
]);
|
|
||||||
$builder->get('thirdParties')
|
$builder->get('thirdParties')
|
||||||
->addModelTransformer(new CallbackTransformer(
|
->addModelTransformer(new CallbackTransformer(
|
||||||
function (iterable $thirdpartyAsIterable): string {
|
function (iterable $thirdpartyAsIterable): string {
|
||||||
@@ -260,9 +283,7 @@ class ActivityType extends AbstractType
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($activityType->isVisible('users')) {
|
if ($activityType->isVisible('users')) {
|
||||||
$builder->add('users', HiddenType::class, [
|
$builder->add('users', HiddenType::class);
|
||||||
//'data_class' => User::class,
|
|
||||||
]);
|
|
||||||
$builder->get('users')
|
$builder->get('users')
|
||||||
->addModelTransformer(new CallbackTransformer(
|
->addModelTransformer(new CallbackTransformer(
|
||||||
function (iterable $usersAsIterable): string {
|
function (iterable $usersAsIterable): string {
|
||||||
|
@@ -4,6 +4,7 @@ namespace Chill\ActivityBundle\Menu;
|
|||||||
|
|
||||||
use Chill\MainBundle\Routing\LocalMenuBuilderInterface;
|
use Chill\MainBundle\Routing\LocalMenuBuilderInterface;
|
||||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
||||||
|
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||||
use Knp\Menu\MenuItem;
|
use Knp\Menu\MenuItem;
|
||||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
||||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||||
@@ -34,21 +35,13 @@ class AccompanyingCourseMenuBuilder implements LocalMenuBuilderInterface
|
|||||||
{
|
{
|
||||||
$period = $parameters['accompanyingCourse'];
|
$period = $parameters['accompanyingCourse'];
|
||||||
|
|
||||||
|
if (AccompanyingPeriod::STEP_DRAFT !== $period->getStep()) {
|
||||||
$menu->addChild($this->translator->trans('Activity list'), [
|
$menu->addChild($this->translator->trans('Activity list'), [
|
||||||
'route' => 'chill_activity_activity_list',
|
'route' => 'chill_activity_activity_list',
|
||||||
'routeParameters' => [
|
'routeParameters' => [
|
||||||
'accompanying_period_id' => $period->getId(),
|
'accompanying_period_id' => $period->getId(),
|
||||||
]])
|
]])
|
||||||
->setExtras(['order' => 40]);
|
->setExtras(['order' => 40]);
|
||||||
|
}
|
||||||
$menu->addChild($this->translator->trans('Add a new activity'), [
|
|
||||||
'route' => 'chill_activity_activity_select_type',
|
|
||||||
'routeParameters' => [
|
|
||||||
'accompanying_period_id' => $period->getId(),
|
|
||||||
]])
|
|
||||||
->setExtras(['order' => 41]);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -56,6 +56,7 @@ class PersonMenuBuilder implements LocalMenuBuilderInterface
|
|||||||
/* @var $person \Chill\PersonBundle\Entity\Person */
|
/* @var $person \Chill\PersonBundle\Entity\Person */
|
||||||
$person = $parameters['person'];
|
$person = $parameters['person'];
|
||||||
|
|
||||||
|
if (false) {
|
||||||
if ($this->authorizationChecker->isGranted(ActivityVoter::SEE, $person)) {
|
if ($this->authorizationChecker->isGranted(ActivityVoter::SEE, $person)) {
|
||||||
$menu->addChild(
|
$menu->addChild(
|
||||||
$this->translator->trans('Activity list'), [
|
$this->translator->trans('Activity list'), [
|
||||||
@@ -75,6 +76,7 @@ class PersonMenuBuilder implements LocalMenuBuilderInterface
|
|||||||
;
|
;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static function getMenuIds(): array
|
public static function getMenuIds(): array
|
||||||
{
|
{
|
||||||
|
@@ -112,3 +112,19 @@ div.flex-table.list-records {
|
|||||||
margin-top: 1em;
|
margin-top: 1em;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
div.activity-row {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 12px;
|
||||||
|
div.bloc {
|
||||||
|
width: 200px;
|
||||||
|
align-self: flex-end;
|
||||||
|
height: 140px;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -1,170 +1,17 @@
|
|||||||
<template>
|
<template>
|
||||||
<teleport to="#add-persons">
|
<concerned-groups></concerned-groups>
|
||||||
|
<social-issues-acc></social-issues-acc>
|
||||||
<div class="flex-bloc concerned-groups" :class="getContext">
|
|
||||||
<persons-bloc
|
|
||||||
v-for="bloc in contextPersonsBlocs"
|
|
||||||
v-bind:key="bloc.key"
|
|
||||||
v-bind:bloc="bloc"
|
|
||||||
v-bind:setPersonsInBloc="setPersonsInBloc">
|
|
||||||
</persons-bloc>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<add-persons
|
|
||||||
buttonTitle="activity.add_persons"
|
|
||||||
modalTitle="activity.add_persons"
|
|
||||||
v-bind:key="addPersons.key"
|
|
||||||
v-bind:options="addPersons.options"
|
|
||||||
@addNewPersons="addNewPersons"
|
|
||||||
ref="addPersons">
|
|
||||||
</add-persons>
|
|
||||||
|
|
||||||
</teleport>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { mapState } from 'vuex';
|
import ConcernedGroups from './components/ConcernedGroups.vue';
|
||||||
import AddPersons from 'ChillPersonAssets/vuejs/_components/AddPersons.vue';
|
import SocialIssuesAcc from './components/SocialIssuesAcc.vue';
|
||||||
import PersonsBloc from './components/PersonsBloc.vue';
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "App",
|
name: "App",
|
||||||
components: {
|
components: {
|
||||||
AddPersons,
|
ConcernedGroups,
|
||||||
PersonsBloc
|
SocialIssuesAcc
|
||||||
},
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
personsBlocs: [
|
|
||||||
{ key: 'persons',
|
|
||||||
title: 'activity.bloc_persons',
|
|
||||||
persons: [],
|
|
||||||
included: false
|
|
||||||
},
|
|
||||||
{ key: 'personsAssociated',
|
|
||||||
title: 'activity.bloc_persons_associated',
|
|
||||||
persons: [],
|
|
||||||
included: false
|
|
||||||
},
|
|
||||||
{ key: 'personsNotAssociated',
|
|
||||||
title: 'activity.bloc_persons_not_associated',
|
|
||||||
persons: [],
|
|
||||||
included: false
|
|
||||||
},
|
|
||||||
{ key: 'thirdparty',
|
|
||||||
title: 'activity.bloc_thirdparty',
|
|
||||||
persons: [],
|
|
||||||
included: true
|
|
||||||
},
|
|
||||||
{ key: 'users',
|
|
||||||
title: 'activity.bloc_users',
|
|
||||||
persons: [],
|
|
||||||
included: true
|
|
||||||
},
|
|
||||||
],
|
|
||||||
addPersons: {
|
|
||||||
key: 'activity',
|
|
||||||
options: {
|
|
||||||
type: ['person', 'thirdparty'], // TODO add 'user'
|
|
||||||
priority: null,
|
|
||||||
uniq: false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
...mapState({
|
|
||||||
persons: state => state.activity.persons,
|
|
||||||
thirdParties: state => state.activity.thirdParties,
|
|
||||||
users: state => state.activity.users,
|
|
||||||
accompanyingCourse: state => state.activity.accompanyingPeriod
|
|
||||||
}),
|
|
||||||
getContext() {
|
|
||||||
return (this.accompanyingCourse) ? "accompanyingCourse" : "person";
|
|
||||||
},
|
|
||||||
contextPersonsBlocs() {
|
|
||||||
return this.personsBlocs.filter(bloc => bloc.included !== false);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
mounted() {
|
|
||||||
this.setPersonsInBloc();
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
setPersonsInBloc() {
|
|
||||||
let groups;
|
|
||||||
if (this.accompanyingCourse) {
|
|
||||||
groups = this.splitPersonsInGroups();
|
|
||||||
}
|
|
||||||
this.personsBlocs.forEach(bloc => {
|
|
||||||
if (this.accompanyingCourse) {
|
|
||||||
switch (bloc.key) {
|
|
||||||
case 'personsAssociated':
|
|
||||||
bloc.persons = groups.personsAssociated;
|
|
||||||
bloc.included = true;
|
|
||||||
break;
|
|
||||||
case 'personsNotAssociated':
|
|
||||||
bloc.persons = groups.personsNotAssociated;
|
|
||||||
bloc.included = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
switch (bloc.key) {
|
|
||||||
case 'persons':
|
|
||||||
bloc.persons = this.persons;
|
|
||||||
bloc.included = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
switch (bloc.key) {
|
|
||||||
case 'thirdparty':
|
|
||||||
bloc.persons = this.thirdParties;
|
|
||||||
break;
|
|
||||||
case 'users':
|
|
||||||
bloc.persons = this.users;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}, groups);
|
|
||||||
},
|
|
||||||
splitPersonsInGroups() {
|
|
||||||
let personsAssociated = [];
|
|
||||||
let personsNotAssociated = this.persons;
|
|
||||||
let participations = this.getCourseParticipations();
|
|
||||||
this.persons.forEach(person => {
|
|
||||||
participations.forEach(participation => {
|
|
||||||
if (person.id === participation.id) {
|
|
||||||
console.log(person.id);
|
|
||||||
personsAssociated.push(person);
|
|
||||||
personsNotAssociated = personsNotAssociated.filter(p => p !== person);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
return {
|
|
||||||
'personsAssociated': personsAssociated,
|
|
||||||
'personsNotAssociated': personsNotAssociated
|
|
||||||
};
|
|
||||||
},
|
|
||||||
getCourseParticipations() {
|
|
||||||
let participations = [];
|
|
||||||
this.accompanyingCourse.participations.forEach(participation => {
|
|
||||||
if (!participation.endDate) {
|
|
||||||
participations.push(participation.person);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return participations;
|
|
||||||
},
|
|
||||||
addNewPersons({ selected, modal }) {
|
|
||||||
console.log('@@@ CLICK button addNewPersons', selected);
|
|
||||||
selected.forEach(function(item) {
|
|
||||||
this.$store.dispatch('addPersonsInvolved', item);
|
|
||||||
}, this
|
|
||||||
);
|
|
||||||
this.$refs.addPersons.resetSearch(); // to cast child method
|
|
||||||
modal.showModal = false;
|
|
||||||
this.setPersonsInBloc();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss">
|
|
||||||
</style>
|
|
||||||
|
@@ -0,0 +1,18 @@
|
|||||||
|
import { getSocialIssues } from 'ChillPersonAssets/vuejs/AccompanyingCourse/api.js';
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Load socialActions by socialIssue (id)
|
||||||
|
*/
|
||||||
|
const getSocialActionByIssue = (id) => {
|
||||||
|
const url = `/api/1.0/person/social/social-action/by-social-issue/${id}.json`;
|
||||||
|
return fetch(url)
|
||||||
|
.then(response => {
|
||||||
|
if (response.ok) { return response.json(); }
|
||||||
|
throw Error('Error with request resource response');
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export {
|
||||||
|
getSocialIssues,
|
||||||
|
getSocialActionByIssue
|
||||||
|
};
|
@@ -0,0 +1,170 @@
|
|||||||
|
<template>
|
||||||
|
<teleport to="#add-persons">
|
||||||
|
|
||||||
|
<div class="flex-bloc concerned-groups" :class="getContext">
|
||||||
|
<persons-bloc
|
||||||
|
v-for="bloc in contextPersonsBlocs"
|
||||||
|
v-bind:key="bloc.key"
|
||||||
|
v-bind:bloc="bloc"
|
||||||
|
v-bind:setPersonsInBloc="setPersonsInBloc">
|
||||||
|
</persons-bloc>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<add-persons
|
||||||
|
buttonTitle="activity.add_persons"
|
||||||
|
modalTitle="activity.add_persons"
|
||||||
|
v-bind:key="addPersons.key"
|
||||||
|
v-bind:options="addPersons.options"
|
||||||
|
@addNewPersons="addNewPersons"
|
||||||
|
ref="addPersons">
|
||||||
|
</add-persons>
|
||||||
|
|
||||||
|
</teleport>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import { mapState } from 'vuex';
|
||||||
|
import AddPersons from 'ChillPersonAssets/vuejs/_components/AddPersons.vue';
|
||||||
|
import PersonsBloc from './ConcernedGroups/PersonsBloc.vue';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: "ConcernedGroups",
|
||||||
|
components: {
|
||||||
|
AddPersons,
|
||||||
|
PersonsBloc
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
personsBlocs: [
|
||||||
|
{ key: 'persons',
|
||||||
|
title: 'activity.bloc_persons',
|
||||||
|
persons: [],
|
||||||
|
included: false
|
||||||
|
},
|
||||||
|
{ key: 'personsAssociated',
|
||||||
|
title: 'activity.bloc_persons_associated',
|
||||||
|
persons: [],
|
||||||
|
included: false
|
||||||
|
},
|
||||||
|
{ key: 'personsNotAssociated',
|
||||||
|
title: 'activity.bloc_persons_not_associated',
|
||||||
|
persons: [],
|
||||||
|
included: false
|
||||||
|
},
|
||||||
|
{ key: 'thirdparty',
|
||||||
|
title: 'activity.bloc_thirdparty',
|
||||||
|
persons: [],
|
||||||
|
included: true
|
||||||
|
},
|
||||||
|
{ key: 'users',
|
||||||
|
title: 'activity.bloc_users',
|
||||||
|
persons: [],
|
||||||
|
included: true
|
||||||
|
},
|
||||||
|
],
|
||||||
|
addPersons: {
|
||||||
|
key: 'activity',
|
||||||
|
options: {
|
||||||
|
type: ['person', 'thirdparty'], // TODO add 'user'
|
||||||
|
priority: null,
|
||||||
|
uniq: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
...mapState({
|
||||||
|
persons: state => state.activity.persons,
|
||||||
|
thirdParties: state => state.activity.thirdParties,
|
||||||
|
users: state => state.activity.users,
|
||||||
|
accompanyingCourse: state => state.activity.accompanyingPeriod
|
||||||
|
}),
|
||||||
|
getContext() {
|
||||||
|
return (this.accompanyingCourse) ? "accompanyingCourse" : "person";
|
||||||
|
},
|
||||||
|
contextPersonsBlocs() {
|
||||||
|
return this.personsBlocs.filter(bloc => bloc.included !== false);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
mounted() {
|
||||||
|
this.setPersonsInBloc();
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
setPersonsInBloc() {
|
||||||
|
let groups;
|
||||||
|
if (this.accompanyingCourse) {
|
||||||
|
groups = this.splitPersonsInGroups();
|
||||||
|
}
|
||||||
|
this.personsBlocs.forEach(bloc => {
|
||||||
|
if (this.accompanyingCourse) {
|
||||||
|
switch (bloc.key) {
|
||||||
|
case 'personsAssociated':
|
||||||
|
bloc.persons = groups.personsAssociated;
|
||||||
|
bloc.included = true;
|
||||||
|
break;
|
||||||
|
case 'personsNotAssociated':
|
||||||
|
bloc.persons = groups.personsNotAssociated;
|
||||||
|
bloc.included = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
switch (bloc.key) {
|
||||||
|
case 'persons':
|
||||||
|
bloc.persons = this.persons;
|
||||||
|
bloc.included = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
switch (bloc.key) {
|
||||||
|
case 'thirdparty':
|
||||||
|
bloc.persons = this.thirdParties;
|
||||||
|
break;
|
||||||
|
case 'users':
|
||||||
|
bloc.persons = this.users;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}, groups);
|
||||||
|
},
|
||||||
|
splitPersonsInGroups() {
|
||||||
|
let personsAssociated = [];
|
||||||
|
let personsNotAssociated = this.persons;
|
||||||
|
let participations = this.getCourseParticipations();
|
||||||
|
this.persons.forEach(person => {
|
||||||
|
participations.forEach(participation => {
|
||||||
|
if (person.id === participation.id) {
|
||||||
|
//console.log(person.id);
|
||||||
|
personsAssociated.push(person);
|
||||||
|
personsNotAssociated = personsNotAssociated.filter(p => p !== person);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return {
|
||||||
|
'personsAssociated': personsAssociated,
|
||||||
|
'personsNotAssociated': personsNotAssociated
|
||||||
|
};
|
||||||
|
},
|
||||||
|
getCourseParticipations() {
|
||||||
|
let participations = [];
|
||||||
|
this.accompanyingCourse.participations.forEach(participation => {
|
||||||
|
if (!participation.endDate) {
|
||||||
|
participations.push(participation.person);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return participations;
|
||||||
|
},
|
||||||
|
addNewPersons({ selected, modal }) {
|
||||||
|
console.log('@@@ CLICK button addNewPersons', selected);
|
||||||
|
selected.forEach(function(item) {
|
||||||
|
this.$store.dispatch('addPersonsInvolved', item);
|
||||||
|
}, this
|
||||||
|
);
|
||||||
|
this.$refs.addPersons.resetSearch(); // to cast child method
|
||||||
|
modal.showModal = false;
|
||||||
|
this.setPersonsInBloc();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
</style>
|
@@ -0,0 +1,214 @@
|
|||||||
|
<template>
|
||||||
|
<teleport to="#social-issues-acc">
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
<div class="grid-4 clear">
|
||||||
|
<label>{{ $t('activity.social_issues') }}</label>
|
||||||
|
</div>
|
||||||
|
<div class="grid-8">
|
||||||
|
|
||||||
|
<check-social-issue
|
||||||
|
v-for="issue in socialIssuesList"
|
||||||
|
v-bind:key="issue.id"
|
||||||
|
v-bind:issue="issue"
|
||||||
|
v-bind:selection="socialIssuesSelected"
|
||||||
|
@updateSelected="updateIssuesSelected">
|
||||||
|
</check-social-issue>
|
||||||
|
|
||||||
|
<div class="my-3">
|
||||||
|
<VueMultiselect
|
||||||
|
name="otherIssues"
|
||||||
|
label="text"
|
||||||
|
track-by="id"
|
||||||
|
open-direction="bottom"
|
||||||
|
v-bind:close-on-select="true"
|
||||||
|
v-bind:preserve-search="false"
|
||||||
|
v-bind:reset-after="true"
|
||||||
|
v-bind:hide-selected="true"
|
||||||
|
v-bind:taggable="false"
|
||||||
|
v-bind:multiple="false"
|
||||||
|
v-bind:searchable="true"
|
||||||
|
v-bind:allow-empty="true"
|
||||||
|
v-bind:show-labels="false"
|
||||||
|
v-bind:loading="issueIsLoading"
|
||||||
|
v-bind:placeholder="$t('activity.choose_other_social_issue')"
|
||||||
|
v-bind:options="socialIssuesOther"
|
||||||
|
v-model="value"
|
||||||
|
@select="addIssueInList">
|
||||||
|
</VueMultiselect>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
<div class="grid-4 clear">
|
||||||
|
<label>{{ $t('activity.social_actions') }}</label>
|
||||||
|
</div>
|
||||||
|
<div class="grid-8">
|
||||||
|
|
||||||
|
<div v-if="actionIsLoading === true">
|
||||||
|
<i class="chill-green fa fa-circle-o-notch fa-spin fa-lg"></i>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<check-social-action
|
||||||
|
v-if="socialIssuesSelected.length || socialActionsSelected.length"
|
||||||
|
v-for="action in socialActionsList"
|
||||||
|
v-bind:key="action.id"
|
||||||
|
v-bind:action="action"
|
||||||
|
v-bind:selection="socialActionsSelected"
|
||||||
|
@updateSelected="updateActionsSelected">
|
||||||
|
</check-social-action>
|
||||||
|
|
||||||
|
<span v-else class="inline-choice chill-no-data-statement mt-3">
|
||||||
|
{{ $t('activity.select_first_a_social_issue') }}
|
||||||
|
</span>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</teleport>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import { readonly } from 'vue';
|
||||||
|
import VueMultiselect from 'vue-multiselect';
|
||||||
|
import CheckSocialIssue from './SocialIssuesAcc/CheckSocialIssue.vue';
|
||||||
|
import CheckSocialAction from './SocialIssuesAcc/CheckSocialAction.vue';
|
||||||
|
import { getSocialIssues, getSocialActionByIssue } from '../api.js';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: "SocialIssuesAcc",
|
||||||
|
components: {
|
||||||
|
CheckSocialIssue,
|
||||||
|
CheckSocialAction,
|
||||||
|
VueMultiselect
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
issueIsLoading: false,
|
||||||
|
actionIsLoading: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
socialIssuesList() {
|
||||||
|
return this.$store.state.activity.accompanyingPeriod.socialIssues;
|
||||||
|
},
|
||||||
|
socialIssuesSelected() {
|
||||||
|
return this.$store.state.activity.socialIssues;
|
||||||
|
},
|
||||||
|
socialIssuesOther() {
|
||||||
|
return this.$store.state.socialIssuesOther;
|
||||||
|
},
|
||||||
|
socialActionsList() {
|
||||||
|
return this.$store.state.socialActionsList;
|
||||||
|
},
|
||||||
|
socialActionsSelected() {
|
||||||
|
return this.$store.state.activity.socialActions;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
mounted() {
|
||||||
|
/* Load others issues in multiselect
|
||||||
|
*/
|
||||||
|
this.issueIsLoading = true;
|
||||||
|
getSocialIssues().then(response => new Promise((resolve, reject) => {
|
||||||
|
this.$store.commit('updateIssuesOther', response.results);
|
||||||
|
|
||||||
|
/* Add in list the issues already associated (if not yet listed)
|
||||||
|
*/
|
||||||
|
this.socialIssuesSelected.forEach(issue => {
|
||||||
|
if (this.socialIssuesList.filter(i => i.id === issue.id).length !== 1) {
|
||||||
|
this.$store.commit('addIssueInList', issue);
|
||||||
|
}
|
||||||
|
}, this);
|
||||||
|
|
||||||
|
/* Remove from multiselect the issues that are not yet in checkbox list
|
||||||
|
*/
|
||||||
|
this.socialIssuesList.forEach(issue => {
|
||||||
|
this.$store.commit('removeIssueInOther', issue);
|
||||||
|
}, this);
|
||||||
|
|
||||||
|
/* Filter issues
|
||||||
|
*/
|
||||||
|
this.$store.commit('filterList', 'issues');
|
||||||
|
|
||||||
|
/* Add in list the actions already associated (if not yet listed)
|
||||||
|
*/
|
||||||
|
this.socialActionsSelected.forEach(action => {
|
||||||
|
this.$store.commit('addActionInList', action);
|
||||||
|
}, this);
|
||||||
|
|
||||||
|
/* Filter issues
|
||||||
|
*/
|
||||||
|
this.$store.commit('filterList', 'actions');
|
||||||
|
|
||||||
|
this.issueIsLoading = false;
|
||||||
|
resolve();
|
||||||
|
}));
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
|
||||||
|
/* When choosing an issue in multiselect, add it in checkboxes (as selected),
|
||||||
|
remove it from multiselect, and add socialActions concerned
|
||||||
|
*/
|
||||||
|
addIssueInList(value) {
|
||||||
|
//console.log('addIssueInList', value);
|
||||||
|
this.$store.commit('addIssueInList', value);
|
||||||
|
this.$store.commit('removeIssueInOther', value);
|
||||||
|
this.$store.dispatch('addIssueSelected', value);
|
||||||
|
this.updateActionsList();
|
||||||
|
},
|
||||||
|
/* Update value for selected issues checkboxes
|
||||||
|
*/
|
||||||
|
updateIssuesSelected(issues) {
|
||||||
|
//console.log('updateIssuesSelected', issues);
|
||||||
|
this.$store.dispatch('updateIssuesSelected', issues);
|
||||||
|
this.updateActionsList();
|
||||||
|
},
|
||||||
|
/* Update value for selected actions checkboxes
|
||||||
|
*/
|
||||||
|
updateActionsSelected(actions) {
|
||||||
|
//console.log('updateActionsSelected', actions);
|
||||||
|
this.$store.dispatch('updateActionsSelected', actions);
|
||||||
|
},
|
||||||
|
/* Add socialActions concerned: after reset, loop on each issue selected
|
||||||
|
to get social actions concerned
|
||||||
|
*/
|
||||||
|
updateActionsList() {
|
||||||
|
//console.log('updateActionsList');
|
||||||
|
this.resetActionsList();
|
||||||
|
this.socialIssuesSelected.forEach(item => {
|
||||||
|
|
||||||
|
this.actionIsLoading = true;
|
||||||
|
getSocialActionByIssue(item.id)
|
||||||
|
.then(actions => new Promise((resolve, reject) => {
|
||||||
|
|
||||||
|
actions.results.forEach(action => {
|
||||||
|
this.$store.commit('addActionInList', action);
|
||||||
|
}, this);
|
||||||
|
|
||||||
|
this.$store.commit('filterList', 'actions');
|
||||||
|
|
||||||
|
this.actionIsLoading = false;
|
||||||
|
resolve();
|
||||||
|
}));
|
||||||
|
}, this);
|
||||||
|
},
|
||||||
|
/* Reset socialActions List: flush list and restore selected actions
|
||||||
|
*/
|
||||||
|
resetActionsList() {
|
||||||
|
this.$store.commit('resetActionsList');
|
||||||
|
this.socialActionsSelected.forEach(item => {
|
||||||
|
this.$store.commit('addActionInList', item);
|
||||||
|
}, this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style src="vue-multiselect/dist/vue-multiselect.css"></style>
|
||||||
|
<style lang="scss">
|
||||||
|
span.multiselect__single {
|
||||||
|
display: none !important;
|
||||||
|
}
|
||||||
|
</style>
|
@@ -0,0 +1,34 @@
|
|||||||
|
<template>
|
||||||
|
<span class="inline-choice">
|
||||||
|
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
v-model="selected"
|
||||||
|
name="action"
|
||||||
|
v-bind:id="action.id"
|
||||||
|
v-bind:value="action"
|
||||||
|
/>
|
||||||
|
<label class="inline" v-bind:for="action.id">
|
||||||
|
{{ action.text }}
|
||||||
|
</label>
|
||||||
|
|
||||||
|
</span><br>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
name: "CheckSocialAction",
|
||||||
|
props: [ 'action', 'selection' ],
|
||||||
|
emits: [ 'updateSelected' ],
|
||||||
|
computed: {
|
||||||
|
selected: {
|
||||||
|
set(value) {
|
||||||
|
this.$emit('updateSelected', value);
|
||||||
|
},
|
||||||
|
get() {
|
||||||
|
return this.selection;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
@@ -0,0 +1,34 @@
|
|||||||
|
<template>
|
||||||
|
<span class="inline-choice">
|
||||||
|
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
v-model="selected"
|
||||||
|
name="issue"
|
||||||
|
v-bind:id="issue.id"
|
||||||
|
v-bind:value="issue"
|
||||||
|
/>
|
||||||
|
<label class="inline" v-bind:for="issue.id">
|
||||||
|
{{ issue.text }}
|
||||||
|
</label>
|
||||||
|
|
||||||
|
</span><br>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
name: "CheckSocialIssue",
|
||||||
|
props: [ 'issue', 'selection' ],
|
||||||
|
emits: [ 'updateSelected' ],
|
||||||
|
computed: {
|
||||||
|
selected: {
|
||||||
|
set(value) {
|
||||||
|
this.$emit('updateSelected', value);
|
||||||
|
},
|
||||||
|
get() {
|
||||||
|
return this.selection;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
@@ -3,6 +3,13 @@ import { personMessages } from 'ChillPersonAssets/vuejs/_js/i18n'
|
|||||||
const appMessages = {
|
const appMessages = {
|
||||||
fr: {
|
fr: {
|
||||||
activity: {
|
activity: {
|
||||||
|
//
|
||||||
|
social_issues: "Problématiques sociales",
|
||||||
|
choose_other_social_issue: "Ajouter une autre problématique sociale...",
|
||||||
|
social_actions: "Actions d'accompagnement",
|
||||||
|
select_first_a_social_issue: "Sélectionnez d'abord une problématique sociale",
|
||||||
|
|
||||||
|
//
|
||||||
add_persons: "Ajouter des personnes concernées",
|
add_persons: "Ajouter des personnes concernées",
|
||||||
bloc_persons: "Usagers",
|
bloc_persons: "Usagers",
|
||||||
bloc_persons_associated: "Usagers du parcours",
|
bloc_persons_associated: "Usagers du parcours",
|
||||||
|
@@ -21,11 +21,62 @@ const removeIdFromValue = (string, id) => {
|
|||||||
const store = createStore({
|
const store = createStore({
|
||||||
strict: debug,
|
strict: debug,
|
||||||
state: {
|
state: {
|
||||||
activity: window.activity
|
activity: window.activity,
|
||||||
},
|
socialIssuesOther: [],
|
||||||
getters: {
|
socialActionsList: [],
|
||||||
},
|
},
|
||||||
mutations: {
|
mutations: {
|
||||||
|
|
||||||
|
// SocialIssueAcc
|
||||||
|
addIssueInList(state, issue) {
|
||||||
|
//console.log('add issue list', issue.id);
|
||||||
|
state.activity.accompanyingPeriod.socialIssues.push(issue);
|
||||||
|
},
|
||||||
|
addIssueSelected(state, issue) {
|
||||||
|
//console.log('add issue selected', issue.id);
|
||||||
|
state.activity.socialIssues.push(issue);
|
||||||
|
},
|
||||||
|
updateIssuesSelected(state, issues) {
|
||||||
|
//console.log('update issues selected', issues);
|
||||||
|
state.activity.socialIssues = issues;
|
||||||
|
},
|
||||||
|
updateIssuesOther(state, payload) {
|
||||||
|
//console.log('update issues other');
|
||||||
|
state.socialIssuesOther = payload;
|
||||||
|
},
|
||||||
|
removeIssueInOther(state, issue) {
|
||||||
|
//console.log('remove issue other', issue.id);
|
||||||
|
state.socialIssuesOther = state.socialIssuesOther.filter(i => i.id !== issue.id);
|
||||||
|
},
|
||||||
|
resetActionsList(state) {
|
||||||
|
//console.log('reset list actions');
|
||||||
|
state.socialActionsList = [];
|
||||||
|
},
|
||||||
|
addActionInList(state, action) {
|
||||||
|
//console.log('add action list', action.id);
|
||||||
|
state.socialActionsList.push(action);
|
||||||
|
},
|
||||||
|
updateActionsSelected(state, actions) {
|
||||||
|
//console.log('update actions selected', actions);
|
||||||
|
state.activity.socialActions = actions;
|
||||||
|
},
|
||||||
|
filterList(state, list) {
|
||||||
|
const filterList = (list) => {
|
||||||
|
// remove duplicates entries
|
||||||
|
list = list.filter((value, index) => list.findIndex(array => array.id === value.id) === index);
|
||||||
|
// alpha sort
|
||||||
|
list.sort((a,b) => (a.text > b.text) ? 1 : ((b.text > a.text) ? -1 : 0));
|
||||||
|
return list;
|
||||||
|
};
|
||||||
|
if (list === 'issues') {
|
||||||
|
state.activity.accompanyingPeriod.socialIssues = filterList(state.activity.accompanyingPeriod.socialIssues);
|
||||||
|
}
|
||||||
|
if (list === 'actions') {
|
||||||
|
state.socialActionsList = filterList(state.socialActionsList);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// ConcernedGroups
|
||||||
addPersonsInvolved(state, payload) {
|
addPersonsInvolved(state, payload) {
|
||||||
//console.log('### mutation addPersonsInvolved', payload.result.type);
|
//console.log('### mutation addPersonsInvolved', payload.result.type);
|
||||||
switch (payload.result.type) {
|
switch (payload.result.type) {
|
||||||
@@ -56,8 +107,29 @@ const store = createStore({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
|
addIssueSelected({ commit }, issue) {
|
||||||
|
let aSocialIssues = document.getElementById("chill_activitybundle_activity_socialIssues");
|
||||||
|
aSocialIssues.value = addIdToValue(aSocialIssues.value, issue.id);
|
||||||
|
commit('addIssueSelected', issue);
|
||||||
|
},
|
||||||
|
updateIssuesSelected({ commit }, payload) {
|
||||||
|
let aSocialIssues = document.getElementById("chill_activitybundle_activity_socialIssues");
|
||||||
|
aSocialIssues.value = '';
|
||||||
|
payload.forEach(item => {
|
||||||
|
aSocialIssues.value = addIdToValue(aSocialIssues.value, item.id);
|
||||||
|
});
|
||||||
|
commit('updateIssuesSelected', payload);
|
||||||
|
},
|
||||||
|
updateActionsSelected({ commit }, payload) {
|
||||||
|
let aSocialActions = document.getElementById("chill_activitybundle_activity_socialActions");
|
||||||
|
aSocialActions.value = '';
|
||||||
|
payload.forEach(item => {
|
||||||
|
aSocialActions.value = addIdToValue(aSocialActions.value, item.id);
|
||||||
|
});
|
||||||
|
commit('updateActionsSelected', payload);
|
||||||
|
},
|
||||||
addPersonsInvolved({ commit }, payload) {
|
addPersonsInvolved({ commit }, payload) {
|
||||||
console.log('### action addPersonsInvolved', payload.result.type);
|
//console.log('### action addPersonsInvolved', payload.result.type);
|
||||||
switch (payload.result.type) {
|
switch (payload.result.type) {
|
||||||
case 'person':
|
case 'person':
|
||||||
let aPersons = document.getElementById("chill_activitybundle_activity_persons");
|
let aPersons = document.getElementById("chill_activitybundle_activity_persons");
|
||||||
@@ -75,7 +147,7 @@ const store = createStore({
|
|||||||
commit('addPersonsInvolved', payload);
|
commit('addPersonsInvolved', payload);
|
||||||
},
|
},
|
||||||
removePersonInvolved({ commit }, payload) {
|
removePersonInvolved({ commit }, payload) {
|
||||||
console.log('### action removePersonInvolved', payload);
|
//console.log('### action removePersonInvolved', payload);
|
||||||
switch (payload.type) {
|
switch (payload.type) {
|
||||||
case 'person':
|
case 'person':
|
||||||
let aPersons = document.getElementById("chill_activitybundle_activity_persons");
|
let aPersons = document.getElementById("chill_activitybundle_activity_persons");
|
||||||
|
@@ -1,4 +1,8 @@
|
|||||||
<h1>{{ "Update activity"|trans }}</h1>
|
<h1>{{ "Update activity"|trans ~ ' :' }}
|
||||||
|
<span style="font-size: 70%; text-transform: lowercase; margin-left: 1em;">
|
||||||
|
{{ entity.type.name|localize_translatable_string }}
|
||||||
|
</span>
|
||||||
|
</h1>
|
||||||
|
|
||||||
{{ form_start(edit_form) }}
|
{{ form_start(edit_form) }}
|
||||||
{{ form_errors(edit_form) }}
|
{{ form_errors(edit_form) }}
|
||||||
@@ -19,13 +23,15 @@
|
|||||||
{{ form_row(edit_form.scope) }}
|
{{ form_row(edit_form.scope) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{%- if edit_form.socialIssues is defined -%}
|
||||||
|
{{ form_row(edit_form.socialIssues) }}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{%- if edit_form.socialActions is defined -%}
|
{%- if edit_form.socialActions is defined -%}
|
||||||
{{ form_row(edit_form.socialActions) }}
|
{{ form_row(edit_form.socialActions) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{%- if edit_form.socialIssues is defined -%}
|
<div id="social-issues-acc"></div>
|
||||||
{{ form_row(edit_form.socialIssues) }}
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{%- if edit_form.reasons is defined -%}
|
{%- if edit_form.reasons is defined -%}
|
||||||
{{ form_row(edit_form.reasons) }}
|
{{ form_row(edit_form.reasons) }}
|
||||||
|
@@ -12,8 +12,10 @@
|
|||||||
{% block js %}
|
{% block js %}
|
||||||
{{ encore_entry_link_tags('async_upload') }}
|
{{ encore_entry_link_tags('async_upload') }}
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
window.addEventListener('DOMContentLoaded', function (e) {
|
||||||
chill.displayAlertWhenLeavingModifiedForm('form[name="{{ edit_form.vars.form.vars.name }}"]',
|
chill.displayAlertWhenLeavingModifiedForm('form[name="{{ edit_form.vars.form.vars.name }}"]',
|
||||||
'{{ "You are going to leave a page with unsubmitted data. Are you sure you want to leave ?"|trans }}');
|
'{{ "You are going to leave a page with unsubmitted data. Are you sure you want to leave ?"|trans }}');
|
||||||
|
});
|
||||||
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') }}
|
||||||
|
@@ -21,15 +21,17 @@
|
|||||||
{% block title 'Update activity'|trans %}
|
{% block title 'Update activity'|trans %}
|
||||||
|
|
||||||
{% block personcontent %}
|
{% block personcontent %}
|
||||||
{% include 'ChillActivityBundle:Activity:edit.html.twig' %}
|
|
||||||
<div id="activity"></div> {# <=== vue component #}
|
<div id="activity"></div> {# <=== vue component #}
|
||||||
|
{% include 'ChillActivityBundle:Activity:edit.html.twig' %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block js %}
|
{% block js %}
|
||||||
{{ encore_entry_link_tags('async_upload') }}
|
{{ encore_entry_link_tags('async_upload') }}
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
window.addEventListener('DOMContentLoaded', function (e) {
|
||||||
chill.displayAlertWhenLeavingModifiedForm('form[name="{{ edit_form.vars.form.vars.name }}"]',
|
chill.displayAlertWhenLeavingModifiedForm('form[name="{{ edit_form.vars.form.vars.name }}"]',
|
||||||
'{{ "You are going to leave a page with unsubmitted data. Are you sure you want to leave ?"|trans }}');
|
'{{ "You are going to leave a page with unsubmitted data. Are you sure you want to leave ?"|trans }}');
|
||||||
|
});
|
||||||
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') }}
|
||||||
|
@@ -1,4 +1,8 @@
|
|||||||
<h1>{{ "Activity creation"|trans }}</h1>
|
<h1>{{ "Activity creation"|trans ~ ' :' }}
|
||||||
|
<span style="font-size: 70%; text-transform: lowercase; margin-left: 1em;">
|
||||||
|
{{ entity.type.name|localize_translatable_string }}
|
||||||
|
</span>
|
||||||
|
</h1>
|
||||||
|
|
||||||
{{ form_start(form) }}
|
{{ form_start(form) }}
|
||||||
{{ form_errors(form) }}
|
{{ form_errors(form) }}
|
||||||
@@ -20,14 +24,15 @@
|
|||||||
{{ form_row(form.scope) }}
|
{{ form_row(form.scope) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{%- if form.socialActions is defined -%}
|
|
||||||
{{ form_row(form.socialActions) }}
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{%- if form.socialIssues is defined -%}
|
{%- if form.socialIssues is defined -%}
|
||||||
{{ form_row(form.socialIssues) }}
|
{{ form_row(form.socialIssues) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{%- if form.socialActions is defined -%}
|
||||||
|
{{ form_row(form.socialActions) }}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<div id="social-issues-acc"></div>
|
||||||
|
|
||||||
{%- if form.reasons is defined -%}
|
{%- if form.reasons is defined -%}
|
||||||
{{ form_row(form.reasons) }}
|
{{ form_row(form.reasons) }}
|
||||||
|
@@ -12,8 +12,10 @@
|
|||||||
{% block js %}
|
{% block js %}
|
||||||
{{ encore_entry_script_tags('async_upload') }}
|
{{ encore_entry_script_tags('async_upload') }}
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
window.addEventListener('DOMContentLoaded', function (e) {
|
||||||
chill.displayAlertWhenLeavingUnsubmittedForm('form[name="{{ form.vars.form.vars.name }}"]',
|
chill.displayAlertWhenLeavingUnsubmittedForm('form[name="{{ form.vars.form.vars.name }}"]',
|
||||||
'{{ "You are going to leave a page with unsubmitted data. Are you sure you want to leave ?"|trans }}');
|
'{{ "You are going to leave a page with unsubmitted data. Are you sure you want to leave ?"|trans }}');
|
||||||
|
});
|
||||||
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') }}
|
||||||
|
@@ -5,15 +5,17 @@
|
|||||||
{% block title 'Activity creation' |trans %}
|
{% block title 'Activity creation' |trans %}
|
||||||
|
|
||||||
{% block personcontent %}
|
{% block personcontent %}
|
||||||
{% include 'ChillActivityBundle:Activity:new.html.twig' with {'context': 'person'} %}
|
|
||||||
<div id="activity"></div> {# <=== vue component #}
|
<div id="activity"></div> {# <=== vue component #}
|
||||||
|
{% include 'ChillActivityBundle:Activity:new.html.twig' with {'context': 'person'} %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block js %}
|
{% block js %}
|
||||||
{{ encore_entry_link_tags('async_upload') }}
|
{{ encore_entry_link_tags('async_upload') }}
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
window.addEventListener('DOMContentLoaded', function (e) {
|
||||||
chill.displayAlertWhenLeavingUnsubmittedForm('form[name="{{ form.vars.form.vars.name }}"]',
|
chill.displayAlertWhenLeavingUnsubmittedForm('form[name="{{ form.vars.form.vars.name }}"]',
|
||||||
'{{ "You are going to leave a page with unsubmitted data. Are you sure you want to leave ?"|trans }}');
|
'{{ "You are going to leave a page with unsubmitted data. Are you sure you want to leave ?"|trans }}');
|
||||||
|
});
|
||||||
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') }}
|
||||||
|
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
{% for row in data %}
|
{% for row in data %}
|
||||||
<h3>{{ row.activityTypeCategory.name|localize_translatable_string }}</h3>
|
<h3>{{ row.activityTypeCategory.name|localize_translatable_string }}</h3>
|
||||||
<div style="display:flex;justify-content:center;gap:12px;flex-wrap:wrap;">
|
<div class="activity-row">
|
||||||
{% for activityType in row.activityTypes %}
|
{% for activityType in row.activityTypes %}
|
||||||
|
|
||||||
{% set person_id = null %}
|
{% set person_id = null %}
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
<a href="{{ path('chill_activity_activity_new', {'person_id': person_id, 'activityType_id': activityType.id, 'accompanying_period_id': accompanying_course_id }) }}">
|
<a href="{{ path('chill_activity_activity_new', {'person_id': person_id, 'activityType_id': activityType.id, 'accompanying_period_id': accompanying_course_id }) }}">
|
||||||
|
|
||||||
<div style="width:200px;height:200px;border:1px dotted red;display:flex;justify-content:center;align-items:center;align-content:center;">
|
<div class="bloc btn btn-primary btn-lg btn-block">
|
||||||
{{ activityType.name|localize_translatable_string }}
|
{{ activityType.name|localize_translatable_string }}
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
|
@@ -32,6 +32,7 @@ services:
|
|||||||
- "@chill.main.helper.translatable_string"
|
- "@chill.main.helper.translatable_string"
|
||||||
- "%chill_activity.form.time_duration%"
|
- "%chill_activity.form.time_duration%"
|
||||||
- '@Chill\PersonBundle\Templating\Entity\SocialIssueRender'
|
- '@Chill\PersonBundle\Templating\Entity\SocialIssueRender'
|
||||||
|
- '@Chill\PersonBundle\Templating\Entity\SocialActionRender'
|
||||||
tags:
|
tags:
|
||||||
- { name: form.type, alias: chill_activitybundle_activity }
|
- { name: form.type, alias: chill_activitybundle_activity }
|
||||||
|
|
||||||
|
@@ -38,7 +38,7 @@ Required: Obligatoire
|
|||||||
Persons: Personnes
|
Persons: Personnes
|
||||||
Users: Utilisateurs
|
Users: Utilisateurs
|
||||||
Emergency: Urgent
|
Emergency: Urgent
|
||||||
Sent received: Envoyer / Recevoir
|
Sent received: Entrant / Sortant
|
||||||
Sent: Envoyer
|
Sent: Envoyer
|
||||||
Received: Recevoir
|
Received: Recevoir
|
||||||
by: 'Par '
|
by: 'Par '
|
||||||
|
@@ -22,6 +22,7 @@ use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
|||||||
use Symfony\Component\DependencyInjection\Reference;
|
use Symfony\Component\DependencyInjection\Reference;
|
||||||
use Chill\MainBundle\Routing\MenuComposer;
|
use Chill\MainBundle\Routing\MenuComposer;
|
||||||
use Symfony\Component\DependencyInjection\Definition;
|
use Symfony\Component\DependencyInjection\Definition;
|
||||||
|
use Symfony\Component\DependencyInjection\Alias;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -49,29 +50,32 @@ class CRUDControllerCompilerPass implements CompilerPassInterface
|
|||||||
private function configureCrudController(ContainerBuilder $container, array $crudEntry, string $apiOrCrud): void
|
private function configureCrudController(ContainerBuilder $container, array $crudEntry, string $apiOrCrud): void
|
||||||
{
|
{
|
||||||
$controllerClass = $crudEntry['controller'];
|
$controllerClass = $crudEntry['controller'];
|
||||||
|
|
||||||
$controllerServiceName = 'cs'.$apiOrCrud.'_'.$crudEntry['name'].'_controller';
|
$controllerServiceName = 'cs'.$apiOrCrud.'_'.$crudEntry['name'].'_controller';
|
||||||
|
|
||||||
if ($container->hasDefinition($controllerClass)) {
|
// create config parameter in container
|
||||||
$controller = $container->getDefinition($controllerClass);
|
|
||||||
$container->removeDefinition($controllerClass);
|
|
||||||
$alreadyDefined = true;
|
|
||||||
} else {
|
|
||||||
$controller = new Definition($controllerClass);
|
|
||||||
$alreadyDefined = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$controller->addTag('controller.service_arguments');
|
|
||||||
if (FALSE === $alreadyDefined) {
|
|
||||||
$controller->setAutoconfigured(true);
|
|
||||||
$controller->setPublic(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
$param = 'chill_main_'.$apiOrCrud.'_config_'.$crudEntry['name'];
|
$param = 'chill_main_'.$apiOrCrud.'_config_'.$crudEntry['name'];
|
||||||
$container->setParameter($param, $crudEntry);
|
$container->setParameter($param, $crudEntry);
|
||||||
|
|
||||||
|
if ($container->hasDefinition($controllerClass)) {
|
||||||
|
// create an alias to not to re-create the service
|
||||||
|
$alias = new Alias($controllerClass, true);
|
||||||
|
$container->setAlias($controllerServiceName, $alias);
|
||||||
|
|
||||||
|
// add the "addMethodCall"
|
||||||
|
$container->getDefinition($controllerClass)
|
||||||
|
->addMethodCall('setCrudConfig', ['%'.$param.'%']);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$controller = new Definition($controllerClass);
|
||||||
|
|
||||||
|
$controller->addTag('controller.service_arguments');
|
||||||
|
$controller->setAutoconfigured(true);
|
||||||
|
$controller->setPublic(true);
|
||||||
|
|
||||||
$controller->addMethodCall('setCrudConfig', ['%'.$param.'%']);
|
$controller->addMethodCall('setCrudConfig', ['%'.$param.'%']);
|
||||||
|
|
||||||
$container->setDefinition($controllerServiceName, $controller);
|
$container->setDefinition($controllerServiceName, $controller);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -8,6 +8,11 @@ use Symfony\Component\HttpFoundation\Response;
|
|||||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||||
use Chill\MainBundle\Pagination\PaginatorFactory;
|
use Chill\MainBundle\Pagination\PaginatorFactory;
|
||||||
use Chill\MainBundle\Pagination\PaginatorInterface;
|
use Chill\MainBundle\Pagination\PaginatorInterface;
|
||||||
|
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
||||||
|
use Chill\MainBundle\CRUD\Resolver\Resolver;
|
||||||
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||||
|
use Symfony\Component\Serializer\SerializerInterface;
|
||||||
|
use Symfony\Component\Translation\TranslatorInterface;
|
||||||
|
|
||||||
class AbstractCRUDController extends AbstractController
|
class AbstractCRUDController extends AbstractController
|
||||||
{
|
{
|
||||||
@@ -248,4 +253,24 @@ class AbstractCRUDController extends AbstractController
|
|||||||
{
|
{
|
||||||
return $this->get('validator');
|
return $this->get('validator');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function getSubscribedServices(): array
|
||||||
|
{
|
||||||
|
return \array_merge(
|
||||||
|
parent::getSubscribedServices(),
|
||||||
|
[
|
||||||
|
'chill_main.paginator_factory' => PaginatorFactory::class,
|
||||||
|
|
||||||
|
'translator' => TranslatorInterface::class,
|
||||||
|
AuthorizationHelper::class => AuthorizationHelper::class,
|
||||||
|
EventDispatcherInterface::class => EventDispatcherInterface::class,
|
||||||
|
Resolver::class => Resolver::class,
|
||||||
|
SerializerInterface::class => SerializerInterface::class,
|
||||||
|
'validator' => ValidatorInterface::class,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -359,9 +359,10 @@ class ApiController extends AbstractCRUDController
|
|||||||
* 6. validate the base entity (not the deserialized one). Groups are fetched from getValidationGroups, validation is perform by `validate`
|
* 6. validate the base entity (not the deserialized one). Groups are fetched from getValidationGroups, validation is perform by `validate`
|
||||||
* 7. run onAfterValidation
|
* 7. run onAfterValidation
|
||||||
* 8. if errors, return a 422 response with errors
|
* 8. if errors, return a 422 response with errors
|
||||||
* 9. flush the data
|
* 9. if $forcePersist === true, persist the entity
|
||||||
* 10. run onAfterFlush
|
* 10. flush the data
|
||||||
* 11. return a 202 response for DELETE with empty body, or HTTP 200 for post with serialized posted entity
|
* 11. run onAfterFlush
|
||||||
|
* 12. return a 202 response for DELETE with empty body, or HTTP 200 for post with serialized posted entity
|
||||||
*
|
*
|
||||||
* @param string action
|
* @param string action
|
||||||
* @param mixed id
|
* @param mixed id
|
||||||
@@ -370,11 +371,12 @@ class ApiController extends AbstractCRUDController
|
|||||||
* @param string $property the name of the property. This will be used to make a `add+$property` and `remove+$property` method
|
* @param string $property the name of the property. This will be used to make a `add+$property` and `remove+$property` method
|
||||||
* @param string $postedDataType the type of the posted data (the content)
|
* @param string $postedDataType the type of the posted data (the content)
|
||||||
* @param string $postedDataContext a context to deserialize posted data (the content)
|
* @param string $postedDataContext a context to deserialize posted data (the content)
|
||||||
|
* @param bool $forcePersist force to persist the created element (only for POST request)
|
||||||
* @throw BadRequestException if unable to deserialize the posted data
|
* @throw BadRequestException if unable to deserialize the posted data
|
||||||
* @throw BadRequestException if the method is not POST or DELETE
|
* @throw BadRequestException if the method is not POST or DELETE
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
protected function addRemoveSomething(string $action, $id, Request $request, string $_format, string $property, string $postedDataType, $postedDataContext = []): Response
|
protected function addRemoveSomething(string $action, $id, Request $request, string $_format, string $property, string $postedDataType, array $postedDataContext = [], bool $forcePersist = false): Response
|
||||||
{
|
{
|
||||||
$entity = $this->getEntity($action, $id, $request);
|
$entity = $this->getEntity($action, $id, $request);
|
||||||
|
|
||||||
@@ -429,6 +431,10 @@ class ApiController extends AbstractCRUDController
|
|||||||
return $this->json($errors, 422);
|
return $this->json($errors, 422);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($forcePersist && $request->getMethod() === Request::METHOD_POST) {
|
||||||
|
$this->getDoctrine()->getManager()->persist($postedData);
|
||||||
|
}
|
||||||
|
|
||||||
$this->getDoctrine()->getManager()->flush();
|
$this->getDoctrine()->getManager()->flush();
|
||||||
|
|
||||||
|
|
||||||
|
@@ -142,11 +142,11 @@ class CRUDRoutesLoader extends Loader
|
|||||||
protected function loadApi(array $crudConfig): RouteCollection
|
protected function loadApi(array $crudConfig): RouteCollection
|
||||||
{
|
{
|
||||||
$collection = new RouteCollection();
|
$collection = new RouteCollection();
|
||||||
$controller ='csapi_'.$crudConfig['name'].'_controller';
|
$controller = 'csapi_'.$crudConfig['name'].'_controller';
|
||||||
|
|
||||||
foreach ($crudConfig['actions'] as $name => $action) {
|
foreach ($crudConfig['actions'] as $name => $action) {
|
||||||
// filter only on single actions
|
// filter only on single actions
|
||||||
$singleCollection = $action['single-collection'] ?? $name === '_entity' ? 'single' : NULL;
|
$singleCollection = $action['single_collection'] ?? $name === '_entity' ? 'single' : NULL;
|
||||||
if ('collection' === $singleCollection) {
|
if ('collection' === $singleCollection) {
|
||||||
// continue;
|
// continue;
|
||||||
}
|
}
|
||||||
@@ -171,7 +171,7 @@ class CRUDRoutesLoader extends Loader
|
|||||||
// path are rewritten
|
// path are rewritten
|
||||||
// if name === 'default', we rewrite it to nothing :-)
|
// if name === 'default', we rewrite it to nothing :-)
|
||||||
$localName = \in_array($name, [ '_entity', '_index' ]) ? '' : '/'.$name;
|
$localName = \in_array($name, [ '_entity', '_index' ]) ? '' : '/'.$name;
|
||||||
if ('collection' === $action['single-collection'] || '_index' === $name) {
|
if ('collection' === $action['single_collection'] || '_index' === $name) {
|
||||||
$localPath = $action['path'] ?? $localName.'.{_format}';
|
$localPath = $action['path'] ?? $localName.'.{_format}';
|
||||||
} else {
|
} else {
|
||||||
$localPath = $action['path'] ?? '/{id}'.$localName.'.{_format}';
|
$localPath = $action['path'] ?? '/{id}'.$localName.'.{_format}';
|
||||||
|
@@ -36,6 +36,7 @@ use Chill\MainBundle\Search\SearchProvider;
|
|||||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||||
use Chill\MainBundle\Pagination\PaginatorFactory;
|
use Chill\MainBundle\Pagination\PaginatorFactory;
|
||||||
use Chill\MainBundle\Search\SearchApi;
|
use Chill\MainBundle\Search\SearchApi;
|
||||||
|
use Symfony\Component\HttpFoundation\Exception\BadRequestException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class SearchController
|
* Class SearchController
|
||||||
@@ -151,11 +152,14 @@ class SearchController extends AbstractController
|
|||||||
{
|
{
|
||||||
//TODO this is an incomplete implementation
|
//TODO this is an incomplete implementation
|
||||||
$query = $request->query->get('q', '');
|
$query = $request->query->get('q', '');
|
||||||
|
$types = $request->query->get('type', []);
|
||||||
|
|
||||||
$results = $this->searchApi->getResults($query, 0, 150);
|
if (count($types) === 0) {
|
||||||
$paginator = $this->paginatorFactory->create(count($results));
|
throw new BadRequestException("The request must contains at "
|
||||||
|
." one type");
|
||||||
|
}
|
||||||
|
|
||||||
$collection = new Collection($results, $paginator);
|
$collection = $this->searchApi->getResults($query, $types, []);
|
||||||
|
|
||||||
return $this->json($collection);
|
return $this->json($collection);
|
||||||
}
|
}
|
||||||
|
@@ -196,6 +196,8 @@ class ChillMainExtension extends Extension implements PrependExtensionInterface,
|
|||||||
'doctrine',
|
'doctrine',
|
||||||
[
|
[
|
||||||
'dbal' => [
|
'dbal' => [
|
||||||
|
// ignore views:
|
||||||
|
'schema_filter' => '~^(?!view_)~',
|
||||||
// This is mandatory since we are using postgis as database.
|
// This is mandatory since we are using postgis as database.
|
||||||
'mapping_types' => [
|
'mapping_types' => [
|
||||||
'geometry' => 'string',
|
'geometry' => 'string',
|
||||||
@@ -277,7 +279,8 @@ class ChillMainExtension extends Extension implements PrependExtensionInterface,
|
|||||||
'methods' => [
|
'methods' => [
|
||||||
Request::METHOD_GET => true,
|
Request::METHOD_GET => true,
|
||||||
Request::METHOD_POST => true,
|
Request::METHOD_POST => true,
|
||||||
Request::METHOD_HEAD => true
|
Request::METHOD_HEAD => true,
|
||||||
|
Request::METHOD_PATCH => true
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
]
|
]
|
||||||
@@ -319,7 +322,8 @@ class ChillMainExtension extends Extension implements PrependExtensionInterface,
|
|||||||
'_entity' => [
|
'_entity' => [
|
||||||
'methods' => [
|
'methods' => [
|
||||||
Request::METHOD_GET => true,
|
Request::METHOD_GET => true,
|
||||||
Request::METHOD_HEAD => true
|
Request::METHOD_HEAD => true,
|
||||||
|
Request::METHOD_POST => true,
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
]
|
]
|
||||||
|
@@ -205,7 +205,7 @@ class Configuration implements ConfigurationInterface
|
|||||||
->ignoreExtraKeys(false)
|
->ignoreExtraKeys(false)
|
||||||
->info('the requirements for the route. Will be set to `[ \'id\' => \'\d+\' ]` if left empty.')
|
->info('the requirements for the route. Will be set to `[ \'id\' => \'\d+\' ]` if left empty.')
|
||||||
->end()
|
->end()
|
||||||
->enumNode('single-collection')
|
->enumNode('single_collection')
|
||||||
->values(['single', 'collection'])
|
->values(['single', 'collection'])
|
||||||
->defaultValue('single')
|
->defaultValue('single')
|
||||||
->info('indicates if the returned object is a single element or a collection. '.
|
->info('indicates if the returned object is a single element or a collection. '.
|
||||||
|
@@ -116,7 +116,7 @@ class Address
|
|||||||
* @ORM\Column(type="date")
|
* @ORM\Column(type="date")
|
||||||
* @groups({"write"})
|
* @groups({"write"})
|
||||||
*/
|
*/
|
||||||
private $validFrom;
|
private \DateTime $validFrom;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates when the address ends. Used to build an history
|
* Indicates when the address ends. Used to build an history
|
||||||
@@ -127,11 +127,12 @@ class Address
|
|||||||
* @ORM\Column(type="date", nullable=true)
|
* @ORM\Column(type="date", nullable=true)
|
||||||
* @groups({"write"})
|
* @groups({"write"})
|
||||||
*/
|
*/
|
||||||
private $validTo;
|
private ?\DateTime $validTo = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* True if the address is a "no address", aka homeless person, ...
|
* True if the address is a "no address", aka homeless person, ...
|
||||||
* @groups({"write"})
|
* @groups({"write"})
|
||||||
|
* @ORM\Column(type="boolean")
|
||||||
*
|
*
|
||||||
* @var bool
|
* @var bool
|
||||||
*/
|
*/
|
||||||
@@ -298,7 +299,7 @@ class Address
|
|||||||
* @param bool $isNoAddress
|
* @param bool $isNoAddress
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function setIsNoAddress(bool $isNoAddress)
|
public function setIsNoAddress(bool $isNoAddress): self
|
||||||
{
|
{
|
||||||
$this->isNoAddress = $isNoAddress;
|
$this->isNoAddress = $isNoAddress;
|
||||||
return $this;
|
return $this;
|
||||||
|
@@ -26,7 +26,7 @@ class PostalCode
|
|||||||
* @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({"write", "read"})
|
||||||
*/
|
*/
|
||||||
private $id;
|
private $id;
|
||||||
|
|
||||||
@@ -34,7 +34,7 @@ class PostalCode
|
|||||||
* @var string
|
* @var string
|
||||||
*
|
*
|
||||||
* @ORM\Column(type="string", length=255, name="label")
|
* @ORM\Column(type="string", length=255, name="label")
|
||||||
* @groups({"read"})
|
* @groups({"write", "read"})
|
||||||
*/
|
*/
|
||||||
private $name;
|
private $name;
|
||||||
|
|
||||||
@@ -42,7 +42,7 @@ class PostalCode
|
|||||||
* @var string
|
* @var string
|
||||||
*
|
*
|
||||||
* @ORM\Column(type="string", length=100)
|
* @ORM\Column(type="string", length=100)
|
||||||
* @groups({"read"})
|
* @groups({"write", "read"})
|
||||||
*/
|
*/
|
||||||
private $code;
|
private $code;
|
||||||
|
|
||||||
@@ -50,10 +50,17 @@ class PostalCode
|
|||||||
* @var Country
|
* @var Country
|
||||||
*
|
*
|
||||||
* @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\Country")
|
* @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\Country")
|
||||||
* @groups({"read"})
|
* @groups({"write", "read"})
|
||||||
*/
|
*/
|
||||||
private $country;
|
private $country;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var integer
|
||||||
|
*
|
||||||
|
* @ORM\Column(name="origin", type="integer", nullable=true)
|
||||||
|
* @groups({"write", "read"})
|
||||||
|
*/
|
||||||
|
private $origin = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get id
|
* Get id
|
||||||
@@ -65,6 +72,32 @@ class PostalCode
|
|||||||
return $this->id;
|
return $this->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set origin
|
||||||
|
*
|
||||||
|
* @param int $origin
|
||||||
|
*
|
||||||
|
* @return PostalCode
|
||||||
|
*/
|
||||||
|
public function setOrigin($origin)
|
||||||
|
{
|
||||||
|
$this->origin = $origin;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get origin
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getOrigin()
|
||||||
|
{
|
||||||
|
return $this->origin;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set name
|
* Set name
|
||||||
*
|
*
|
||||||
|
@@ -51,7 +51,7 @@ class CommentType extends AbstractType
|
|||||||
|
|
||||||
$builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) {
|
$builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) {
|
||||||
$data = $event->getForm()->getData();
|
$data = $event->getForm()->getData();
|
||||||
$comment = $event->getData();
|
$comment = $event->getData() ?? ['comment' => ''];
|
||||||
|
|
||||||
if ($data->getComment() !== $comment['comment']) {
|
if ($data->getComment() !== $comment['comment']) {
|
||||||
$data->setDate(new \DateTime());
|
$data->setDate(new \DateTime());
|
||||||
|
@@ -44,6 +44,11 @@ final class ScopeRepository implements ObjectRepository
|
|||||||
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
|
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function createQueryBuilder($alias, $indexBy = null)
|
||||||
|
{
|
||||||
|
return $this->repository->createQueryBuilder($alias, $indexBy);
|
||||||
|
}
|
||||||
|
|
||||||
public function getClassName() {
|
public function getClassName() {
|
||||||
return Scope::class;
|
return Scope::class;
|
||||||
}
|
}
|
||||||
|
@@ -11,13 +11,16 @@
|
|||||||
*
|
*
|
||||||
* Do not take time into account
|
* Do not take time into account
|
||||||
*
|
*
|
||||||
* **Experimental**
|
|
||||||
*/
|
*/
|
||||||
const dateToISO = (date) => {
|
const dateToISO = (date) => {
|
||||||
|
if (null === date) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
this.$store.state.startDate.getFullYear(),
|
date.getFullYear(),
|
||||||
(this.$store.state.startDate.getMonth() + 1).toString().padStart(2, '0'),
|
(date.getMonth() + 1).toString().padStart(2, '0'),
|
||||||
this.$store.state.startDate.getDate().toString().padStart(2, '0')
|
date.getDate().toString().padStart(2, '0')
|
||||||
].join('-');
|
].join('-');
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -36,15 +39,17 @@ const ISOToDate = (str) => {
|
|||||||
/**
|
/**
|
||||||
* Return a date object from iso string formatted as YYYY-mm-dd:HH:MM:ss+01:00
|
* Return a date object from iso string formatted as YYYY-mm-dd:HH:MM:ss+01:00
|
||||||
*
|
*
|
||||||
* **Experimental**
|
|
||||||
*/
|
*/
|
||||||
const ISOToDatetime = (str) => {
|
const ISOToDatetime = (str) => {
|
||||||
console.log(str);
|
if (null === str) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
let
|
let
|
||||||
[cal, times] = str.split('T'),
|
[cal, times] = str.split('T'),
|
||||||
[year, month, date] = cal.split('-'),
|
[year, month, date] = cal.split('-'),
|
||||||
[time, timezone] = cal.split(times.charAt(9)),
|
[time, timezone] = times.split(times.charAt(8)),
|
||||||
[hours, minutes, seconds] = cal.split(':')
|
[hours, minutes, seconds] = time.split(':')
|
||||||
;
|
;
|
||||||
|
|
||||||
return new Date(year, month-1, date, hours, minutes, seconds);
|
return new Date(year, month-1, date, hours, minutes, seconds);
|
||||||
|
@@ -30,7 +30,7 @@
|
|||||||
&.bt-cancel::before,
|
&.bt-cancel::before,
|
||||||
&.bt-view::before,
|
&.bt-view::before,
|
||||||
&.bt-show::before {
|
&.bt-show::before {
|
||||||
font: normal normal normal 14px/1 FontAwesome;
|
font: normal normal normal 14px/1 ForkAwesome;
|
||||||
margin-right: 0.5em;
|
margin-right: 0.5em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -0,0 +1,10 @@
|
|||||||
|
/*
|
||||||
|
* when an alert is the first child of the page, with a banner, we do not want the alert to be merged with the banner
|
||||||
|
*/
|
||||||
|
div.container.content {
|
||||||
|
& > div {
|
||||||
|
div.alert:nth-child(2) {
|
||||||
|
margin-top: 1rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,29 @@
|
|||||||
|
|
||||||
|
div.alert.alert-with-actions {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
|
||||||
|
ul.record_actions {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
padding: 0;
|
||||||
|
margin: 0;
|
||||||
|
|
||||||
|
li:nth-child(1n+2) {
|
||||||
|
margin-top: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
li {
|
||||||
|
margin-right: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: 1050px) {
|
||||||
|
flex-direction: column;
|
||||||
|
|
||||||
|
ul.record_actions {
|
||||||
|
margin-top: 1rem;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -7,6 +7,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
@import 'alert-first-child';
|
||||||
|
@import 'alert-with-actions';
|
||||||
|
|
||||||
|
|
||||||
/* [hack] /!\ Contourne le positionnement problématique du div#content_conainter suivant,
|
/* [hack] /!\ Contourne le positionnement problématique du div#content_conainter suivant,
|
||||||
* car sa position: relative le place au-dessus du bandeau et les liens sont incliquables */
|
* car sa position: relative le place au-dessus du bandeau et les liens sont incliquables */
|
||||||
div.subheader {
|
div.subheader {
|
||||||
@@ -41,33 +45,6 @@ table {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* ACCOMPANYING_COURSE
|
|
||||||
* Header custom for Accompanying Course
|
|
||||||
*/
|
|
||||||
|
|
||||||
div#header-accompanying_course-name {
|
|
||||||
background: none repeat scroll 0 0 #718596;
|
|
||||||
color: #FFF;
|
|
||||||
h1 {
|
|
||||||
margin: 0.4em 0;
|
|
||||||
}
|
|
||||||
span {
|
|
||||||
a {
|
|
||||||
color: white;
|
|
||||||
}
|
|
||||||
a:hover {
|
|
||||||
text-decoration: underline;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
div#header-accompanying_course-details {
|
|
||||||
background: none repeat scroll 0 0 #718596ab;
|
|
||||||
color: #FFF;
|
|
||||||
padding-top: 1em;
|
|
||||||
padding-bottom: 1em;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* FLEX RESPONSIVE TABLE/BLOCK PRESENTATION
|
* FLEX RESPONSIVE TABLE/BLOCK PRESENTATION
|
||||||
*/
|
*/
|
||||||
@@ -105,23 +82,13 @@ div.flex-bloc {
|
|||||||
align-content: stretch;
|
align-content: stretch;
|
||||||
|
|
||||||
div.item-bloc {
|
div.item-bloc {
|
||||||
flex-grow: 0; flex-shrink: 1; flex-basis: 50%;
|
flex-grow: 0; flex-shrink: 1; flex-basis: 33%;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 1em;
|
padding: 1em;
|
||||||
border-top: 0;
|
|
||||||
&:nth-child(1), &:nth-child(2) {
|
|
||||||
border-top: 1px solid #000;
|
|
||||||
}
|
|
||||||
border-left: 0;
|
|
||||||
&:nth-child(odd) {
|
|
||||||
border-left: 1px solid #000;
|
|
||||||
}
|
|
||||||
|
|
||||||
//background-color: #e6e6e6;
|
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
|
||||||
& > div.item-row {
|
div.item-row {
|
||||||
flex-grow: 1; flex-shrink: 1; flex-basis: auto;
|
flex-grow: 1; flex-shrink: 1; flex-basis: auto;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
@@ -154,12 +121,6 @@ div.flex-bloc {
|
|||||||
@media only screen and (max-width: 900px) {
|
@media only screen and (max-width: 900px) {
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
margin: auto 0;
|
margin: auto 0;
|
||||||
div.item-bloc {
|
|
||||||
border-left: 1px solid #000;
|
|
||||||
&:nth-child(2) {
|
|
||||||
border-top: 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -228,8 +189,6 @@ div.flex-table {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Address form
|
* Address form
|
||||||
*/
|
*/
|
||||||
@@ -248,6 +207,9 @@ div.address_form {
|
|||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
flex-grow: 1;
|
flex-grow: 1;
|
||||||
|
div.custom-address, div.custom-postcode {
|
||||||
|
padding: 12px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
div.address_form__select__map {
|
div.address_form__select__map {
|
||||||
@@ -255,13 +217,18 @@ div.address_form {
|
|||||||
div#address_map {
|
div#address_map {
|
||||||
height:400px;
|
height:400px;
|
||||||
width:400px;
|
width:400px;
|
||||||
|
input {
|
||||||
|
border: 1px solid #999;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
div.address_form__more {
|
div.address_form__more {
|
||||||
|
& > div {
|
||||||
|
display: flex;
|
||||||
|
& > label {
|
||||||
|
width: 30%;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@@ -1,33 +1,85 @@
|
|||||||
<template>
|
<template>
|
||||||
|
|
||||||
<div v-if="address.address">
|
<div class='person__address__create'>
|
||||||
{{ address.address.street }}, {{ address.address.streetNumber }}
|
<div>
|
||||||
</div>
|
<h2 v-if="!edit">{{ $t('create_a_new_address') }}</h2>
|
||||||
<div v-if="address.city">
|
<h2 v-else>{{ $t('edit_a_new_address') }}</h2>
|
||||||
{{ address.city.code }} {{ address.city.name }}
|
|
||||||
</div>
|
|
||||||
<div v-if="address.country">
|
|
||||||
{{ address.country.name }}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<add-address
|
<add-address
|
||||||
@addNewAddress="addNewAddress">
|
@addNewAddress="addNewAddress">
|
||||||
</add-address>
|
</add-address>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<show-address
|
||||||
|
v-if="address"
|
||||||
|
v-bind:address="address">
|
||||||
|
</show-address>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div v-if="!edit" class='person__address__valid'>
|
||||||
|
<h2>{{ $t('date') }}</h2>
|
||||||
|
<input
|
||||||
|
type="date"
|
||||||
|
name="validFrom"
|
||||||
|
:placeholder="$t('validFrom')"
|
||||||
|
v-model="validFrom"/>
|
||||||
|
<div v-if="errors.length > 0">
|
||||||
|
{{ errors }}
|
||||||
|
</div>
|
||||||
|
<div v-if="loading">
|
||||||
|
{{ $t('loading') }}
|
||||||
|
</div>
|
||||||
|
<div v-if="success">
|
||||||
|
{{ $t('person_address_creation_success') }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<ul class="record_actions sticky-form-buttons">
|
||||||
|
<li class="cancel">
|
||||||
|
<a :href=backUrl class="sc-button bt-cancel">{{ $t('back_to_the_list') }}</a>
|
||||||
|
</li>
|
||||||
|
<li v-if="!edit">
|
||||||
|
<button type="submit" class="sc-button bt-update centered" @click="addToPerson">
|
||||||
|
{{ $t('add_an_address_to_person') }}
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { mapState } from 'vuex';
|
|
||||||
|
|
||||||
import AddAddress from '../_components/AddAddress.vue';
|
import AddAddress from '../_components/AddAddress.vue';
|
||||||
|
import ShowAddress from '../_components/ShowAddress.vue';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'App',
|
name: 'App',
|
||||||
components: {
|
components: {
|
||||||
AddAddress
|
AddAddress,
|
||||||
|
ShowAddress
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
edit: window.mode === 'edit',
|
||||||
|
personId: window.personId,
|
||||||
|
addressId: window.addressId,
|
||||||
|
backUrl: `/fr/person/${window.personId}/address/list`, //TODO better way to pass this
|
||||||
|
validFrom: new Date().toISOString().split('T')[0]
|
||||||
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
address() {
|
address() {
|
||||||
return this.$store.state.address;
|
return this.$store.state.address;
|
||||||
|
},
|
||||||
|
errors() {
|
||||||
|
return this.$store.state.errorMsg;
|
||||||
|
},
|
||||||
|
loading() {
|
||||||
|
return this.$store.state.loading;
|
||||||
|
},
|
||||||
|
success() {
|
||||||
|
return this.$store.state.success;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
@@ -36,9 +88,9 @@ export default {
|
|||||||
|
|
||||||
let newAddress = {
|
let newAddress = {
|
||||||
'isNoAddress': address.isNoAddress,
|
'isNoAddress': address.isNoAddress,
|
||||||
'street': address.selected.address.street,
|
'street': address.isNoAddress ? '' : address.street,
|
||||||
'streetNumber': address.selected.address.streetNumber,
|
'streetNumber': address.isNoAddress ? '' : address.streetNumber,
|
||||||
'postcode': {'id': address.selected.city.id },
|
'postcode': {'id': address.selected.city.id},
|
||||||
'floor': address.floor,
|
'floor': address.floor,
|
||||||
'corridor': address.corridor,
|
'corridor': address.corridor,
|
||||||
'steps': address.steps,
|
'steps': address.steps,
|
||||||
@@ -49,12 +101,47 @@ export default {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (address.selected.address.point !== undefined){
|
if (address.selected.address.point !== undefined){
|
||||||
newAddress = Object.assign(newAddress, {'point': address.selected.address.point.coordinates});
|
newAddress = Object.assign(newAddress, {
|
||||||
|
'point': address.selected.address.point.coordinates
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (address.writeNewPostalCode){
|
||||||
|
let newPostalCode = address.newPostalCode;
|
||||||
|
newPostalCode = Object.assign(newPostalCode, {
|
||||||
|
'country': {'id': address.selected.country.id },
|
||||||
|
});
|
||||||
|
newAddress = Object.assign(newAddress, {
|
||||||
|
'newPostalCode': newPostalCode
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.edit){
|
||||||
|
this.$store.dispatch('updateAddress', {
|
||||||
|
addressId: this.addressId,
|
||||||
|
newAddress: newAddress
|
||||||
|
});
|
||||||
|
} else {
|
||||||
this.$store.dispatch('addAddress', newAddress);
|
this.$store.dispatch('addAddress', newAddress);
|
||||||
|
}
|
||||||
|
|
||||||
modal.showModal = false;
|
modal.showModal = false;
|
||||||
|
},
|
||||||
|
addToPerson() {
|
||||||
|
this.$store.dispatch('addDateToAddressAndAddressToPerson', {
|
||||||
|
personId: this.personId,
|
||||||
|
addressId: this.$store.state.address.address_id,
|
||||||
|
body: { validFrom: {datetime: `${this.validFrom}T00:00:00+0100`}}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
getEditAddress() {
|
||||||
|
this.$store.dispatch('getEditAddress', this.addressId);
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
mounted() {
|
||||||
|
if (this.edit) {
|
||||||
|
this.getEditAddress();
|
||||||
}
|
}
|
||||||
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
@@ -1,20 +1,34 @@
|
|||||||
const addressMessages = {
|
const addressMessages = {
|
||||||
fr: {
|
fr: {
|
||||||
add_an_address_title: 'Ajouter une adresse',
|
add_an_address_title: 'Créer une adresse',
|
||||||
|
edit_an_address_title: 'Modifier une adresse',
|
||||||
|
create_a_new_address: 'Créer une nouvelle adresse',
|
||||||
|
edit_a_new_address: 'Modifier l\'adresse',
|
||||||
select_an_address_title: 'Sélectionner une adresse',
|
select_an_address_title: 'Sélectionner une adresse',
|
||||||
fill_an_address: 'Compléter l\'adresse',
|
fill_an_address: 'Compléter l\'adresse',
|
||||||
select_country: 'Choisir le pays',
|
select_country: 'Choisir le pays',
|
||||||
select_city: 'Choisir une localité',
|
select_city: 'Choisir une localité',
|
||||||
select_address: 'Choisir une adresse',
|
select_address: 'Choisir une adresse',
|
||||||
create_address: 'Appuyer sur "Entrée" pour créer une nouvelle adresse',
|
create_address: 'Adresse inconnue. Cliquez ici pour créer une nouvelle adresse',
|
||||||
isNoAddress: 'Pas d\'adresse complète',
|
isNoAddress: 'Pas d\'adresse complète',
|
||||||
|
street: 'Nom de rue',
|
||||||
|
streetNumber: 'Numéro',
|
||||||
floor: 'Étage',
|
floor: 'Étage',
|
||||||
corridor: 'Couloir',
|
corridor: 'Couloir',
|
||||||
steps: 'Escalier',
|
steps: 'Escalier',
|
||||||
flat: 'Appartement',
|
flat: 'Appartement',
|
||||||
buildingName: 'Nom du batiment',
|
buildingName: 'Nom du batiment',
|
||||||
extra: 'Complément d\'adresse',
|
extra: 'Complément d\'adresse',
|
||||||
distribution: 'Service particulier de distribution'
|
distribution: 'Service particulier de distribution',
|
||||||
|
create_postal_code: 'Localité inconnue. Cliquez ici pour créer une nouvelle localité',
|
||||||
|
postalCode_name: 'Nom de la localité',
|
||||||
|
postalCode_code: 'Code postal de la localité',
|
||||||
|
date: 'Date de la nouvelle adresse',
|
||||||
|
add_an_address_to_person: 'Ajouter l\'adresse à la personne',
|
||||||
|
validFrom: 'Date de la nouvelle adresse',
|
||||||
|
back_to_the_list: 'Retour à la liste',
|
||||||
|
person_address_creation_success: 'La nouvelle adresse de la personne est enregistrée',
|
||||||
|
loading: 'chargement en cours...'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
import 'es6-promise/auto';
|
import 'es6-promise/auto';
|
||||||
import { createStore } from 'vuex';
|
import { createStore } from 'vuex';
|
||||||
|
|
||||||
import { postAddress } from '../../_api/AddAddress'
|
import { patchAddress, postAddress, postPostalCode, postAddressToPerson, getAddress } from '../../_api/AddAddress'
|
||||||
|
|
||||||
const debug = process.env.NODE_ENV !== 'production';
|
const debug = process.env.NODE_ENV !== 'production';
|
||||||
|
|
||||||
@@ -9,7 +9,11 @@ const store = createStore({
|
|||||||
strict: debug,
|
strict: debug,
|
||||||
state: {
|
state: {
|
||||||
address: {},
|
address: {},
|
||||||
errorMsg: []
|
editAddress: {}, //TODO or should be address?
|
||||||
|
person: {},
|
||||||
|
errorMsg: [],
|
||||||
|
loading: false,
|
||||||
|
success: false
|
||||||
},
|
},
|
||||||
getters: {
|
getters: {
|
||||||
},
|
},
|
||||||
@@ -20,25 +24,133 @@ const store = createStore({
|
|||||||
addAddress(state, address) {
|
addAddress(state, address) {
|
||||||
console.log('@M addAddress address', address);
|
console.log('@M addAddress address', address);
|
||||||
state.address = address;
|
state.address = address;
|
||||||
|
},
|
||||||
|
updateAddress(state, address) {
|
||||||
|
console.log('@M updateAddress address', address);
|
||||||
|
state.address = address;
|
||||||
|
},
|
||||||
|
addAddressToPerson(state, person) {
|
||||||
|
console.log('@M addAddressToPerson person', person);
|
||||||
|
state.person = person;
|
||||||
|
},
|
||||||
|
addDateToAddress(state, validFrom) {
|
||||||
|
console.log('@M addDateToAddress address.validFrom', validFrom);
|
||||||
|
state.validFrom = validFrom;
|
||||||
|
},
|
||||||
|
getEditAddress(state, address) {
|
||||||
|
console.log('@M getEditAddress address', address);
|
||||||
|
state.editAddress = address;
|
||||||
|
},
|
||||||
|
setLoading(state, b) {
|
||||||
|
state.loading = b;
|
||||||
|
},
|
||||||
|
setSuccess(state, b) {
|
||||||
|
state.success = b;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
addAddress({ commit }, payload) {
|
addAddress({ commit }, payload) {
|
||||||
console.log('@A addAddress payload', payload);
|
console.log('@A addAddress payload', payload);
|
||||||
//commit('addAddress', payload); // à remplacer par la suite
|
commit('setLoading', true);
|
||||||
|
if('newPostalCode' in payload){
|
||||||
//fetch POST qui envoie l'adresse, et récupère la confirmation que c'est ok.
|
let postalCodeBody = payload.newPostalCode;
|
||||||
//La confirmation est l'adresse elle-même.
|
postalCodeBody = Object.assign(postalCodeBody, {'origin': 3});
|
||||||
|
postPostalCode(postalCodeBody)
|
||||||
|
.then(postalCode => {
|
||||||
|
let body = payload;
|
||||||
|
body.postcode = {'id': postalCode.id},
|
||||||
|
postAddress(body)
|
||||||
|
.then(address => new Promise((resolve, reject) => {
|
||||||
|
commit('addAddress', address);
|
||||||
|
resolve();
|
||||||
|
commit('setLoading', false);
|
||||||
|
}))
|
||||||
|
.catch((error) => {
|
||||||
|
commit('catchError', error);
|
||||||
|
commit('setLoading', false);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
|
||||||
|
} else {
|
||||||
postAddress(payload)
|
postAddress(payload)
|
||||||
.then(address => new Promise((resolve, reject) => {
|
.then(address => new Promise((resolve, reject) => {
|
||||||
commit('addAddress', address);
|
commit('addAddress', address);
|
||||||
resolve();
|
resolve();
|
||||||
|
commit('setLoading', false);
|
||||||
|
}))
|
||||||
|
.catch((error) => {
|
||||||
|
commit('catchError', error);
|
||||||
|
commit('setLoading', false);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
addDateToAddressAndAddressToPerson({ commit }, payload) {
|
||||||
|
console.log('@A addDateToAddressAndAddressToPerson payload', payload);
|
||||||
|
commit('setLoading', true);
|
||||||
|
patchAddress(payload.addressId, payload.body)
|
||||||
|
.then(address => new Promise((resolve, reject) => {
|
||||||
|
commit('addDateToAddress', address.validFrom);
|
||||||
|
resolve();
|
||||||
|
}).then(
|
||||||
|
postAddressToPerson(payload.personId, payload.addressId)
|
||||||
|
.then(person => new Promise((resolve, reject) => {
|
||||||
|
commit('addAddressToPerson', person);
|
||||||
|
resolve();
|
||||||
|
commit('setLoading', false);
|
||||||
|
commit('setSuccess', true);
|
||||||
|
}))
|
||||||
|
.catch((error) => {
|
||||||
|
commit('catchError', error);
|
||||||
|
commit('setLoading', false);
|
||||||
|
})
|
||||||
|
))
|
||||||
|
.catch((error) => {
|
||||||
|
commit('catchError', error);
|
||||||
|
commit('setLoading', false);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
updateAddress({ commit }, payload) {
|
||||||
|
console.log('@A updateAddress payload', payload);
|
||||||
|
|
||||||
|
if('newPostalCode' in payload.newAddress){ // TODO change the condition because it writes new postal code in edit mode now: !writeNewPostalCode
|
||||||
|
let postalCodeBody = payload.newAddress.newPostalCode;
|
||||||
|
postalCodeBody = Object.assign(postalCodeBody, {'origin': 3});
|
||||||
|
postPostalCode(postalCodeBody)
|
||||||
|
.then(postalCode => {
|
||||||
|
let body = payload.newAddress;
|
||||||
|
body.postcode = {'id': postalCode.id },
|
||||||
|
patchAddress(payload.addressId, body)
|
||||||
|
.then(address => new Promise((resolve, reject) => {
|
||||||
|
commit('updateAddress', address);
|
||||||
|
resolve();
|
||||||
|
}))
|
||||||
|
.catch((error) => {
|
||||||
|
commit('catchError', error);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
|
||||||
|
} else {
|
||||||
|
patchAddress(payload.addressId, payload.newAddress)
|
||||||
|
.then(address => new Promise((resolve, reject) => {
|
||||||
|
commit('updateAddress', address);
|
||||||
|
resolve();
|
||||||
}))
|
}))
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
commit('catchError', error);
|
commit('catchError', error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
getEditAddress({ commit }, payload) {
|
||||||
|
console.log('@A getEditAddress payload', payload);
|
||||||
|
|
||||||
|
getAddress(payload).then(address => new Promise((resolve, reject) => {
|
||||||
|
commit('getEditAddress', address);
|
||||||
|
resolve();
|
||||||
|
}))
|
||||||
|
.catch((error) => {
|
||||||
|
commit('catchError', error);
|
||||||
|
});
|
||||||
|
},
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -36,7 +36,6 @@ const fetchCities = (country) => {
|
|||||||
*/
|
*/
|
||||||
const fetchReferenceAddresses = (postalCode) => {
|
const fetchReferenceAddresses = (postalCode) => {
|
||||||
console.log('<<< fetching references addresses for', postalCode);
|
console.log('<<< fetching references addresses for', postalCode);
|
||||||
//TODO deal with huge number of addresses... we should do suggestion...
|
|
||||||
const url = `/api/1.0/main/address-reference.json?item_per_page=1000&postal_code=${postalCode.id}`;
|
const url = `/api/1.0/main/address-reference.json?item_per_page=1000&postal_code=${postalCode.id}`;
|
||||||
return fetch(url)
|
return fetch(url)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
@@ -45,13 +44,28 @@ const fetchReferenceAddresses = (postalCode) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Endpoint chill_api_single_address_reference__index
|
||||||
|
* method GET, get AddressReference Object
|
||||||
|
* @returns {Promise} a promise containing all AddressReference objects filtered with postal code
|
||||||
|
*/
|
||||||
|
const fetchAddresses = () => {
|
||||||
|
console.log('<<< fetching addresses');
|
||||||
|
//TODO deal with huge number of addresses... we should do suggestion...
|
||||||
|
const url = `/api/1.0/main/address.json?item_per_page=1000`;
|
||||||
|
return fetch(url)
|
||||||
|
.then(response => {
|
||||||
|
if (response.ok) { return response.json(); }
|
||||||
|
throw Error('Error with request resource response');
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Endpoint chill_api_single_address__entity__create
|
* Endpoint chill_api_single_address__entity__create
|
||||||
* method POST, post Address Object
|
* method POST, post Address Object
|
||||||
* @returns {Promise}
|
* @returns {Promise}
|
||||||
*/
|
*/
|
||||||
const postAddress = (address) => {
|
const postAddress = (address) => {
|
||||||
console.log(address);
|
|
||||||
const url = `/api/1.0/main/address.json?`;
|
const url = `/api/1.0/main/address.json?`;
|
||||||
const body = address;
|
const body = address;
|
||||||
|
|
||||||
@@ -67,9 +81,99 @@ const postAddress = (address) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Endpoint chill_api_single_address__entity__create
|
||||||
|
* method PATCH, patch Address Instance
|
||||||
|
*
|
||||||
|
* @id integer - id of address
|
||||||
|
* @body Object - dictionary with changes to post
|
||||||
|
*/
|
||||||
|
const patchAddress = (id, body) => {
|
||||||
|
const url = `/api/1.0/main/address/${id}.json`;
|
||||||
|
return fetch(url, {
|
||||||
|
method: 'PATCH',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json;charset=utf-8'
|
||||||
|
},
|
||||||
|
body: JSON.stringify(body)
|
||||||
|
})
|
||||||
|
.then(response => {
|
||||||
|
if (response.ok) { return response.json(); }
|
||||||
|
throw Error('Error with request resource response');
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Endpoint chill_api_single_postal_code__entity_create
|
||||||
|
* method POST, post Postal Code Object
|
||||||
|
* @returns {Promise}
|
||||||
|
*/
|
||||||
|
const postPostalCode = (postalCode) => {
|
||||||
|
const url = `/api/1.0/main/postal-code.json?`;
|
||||||
|
const body = postalCode;
|
||||||
|
|
||||||
|
return fetch(url, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json;charset=utf-8'
|
||||||
|
},
|
||||||
|
body: JSON.stringify(body)
|
||||||
|
}).then(response => {
|
||||||
|
if (response.ok) { return response.json(); }
|
||||||
|
throw Error('Error with request resource response');
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Endpoint chill_api_single_person_address
|
||||||
|
* method POST, post Person instance
|
||||||
|
*
|
||||||
|
* @id integer - id of Person
|
||||||
|
* @body Object - dictionary with changes to post
|
||||||
|
*/
|
||||||
|
const postAddressToPerson = (personId, addressId) => {
|
||||||
|
console.log(personId);
|
||||||
|
console.log(addressId);
|
||||||
|
const body = {
|
||||||
|
'id': addressId
|
||||||
|
};
|
||||||
|
const url = `/api/1.0/person/person/${personId}/address.json`
|
||||||
|
return fetch(url, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {'Content-Type': 'application/json;charset=utf-8'},
|
||||||
|
body: JSON.stringify(body)
|
||||||
|
})
|
||||||
|
.then(response => {
|
||||||
|
if (response.ok) { return response.json(); }
|
||||||
|
throw Error('Error with request resource response');
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Endpoint chill_api_single_address__index
|
||||||
|
* method GET, get Address Object
|
||||||
|
* @params {id} the address id
|
||||||
|
* @returns {Promise} a promise containing a Address object
|
||||||
|
*/
|
||||||
|
const getAddress = (id) => {
|
||||||
|
console.log('<<< get address');
|
||||||
|
const url = `/api/1.0/main/address/${id}.json`;
|
||||||
|
return fetch(url)
|
||||||
|
.then(response => {
|
||||||
|
if (response.ok) { return response.json(); }
|
||||||
|
throw Error('Error with request resource response');
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
export {
|
export {
|
||||||
fetchCountries,
|
fetchCountries,
|
||||||
fetchCities,
|
fetchCities,
|
||||||
fetchReferenceAddresses,
|
fetchReferenceAddresses,
|
||||||
postAddress
|
fetchAddresses,
|
||||||
|
postAddress,
|
||||||
|
patchAddress,
|
||||||
|
postPostalCode,
|
||||||
|
postAddressToPerson,
|
||||||
|
getAddress
|
||||||
};
|
};
|
||||||
|
@@ -1,7 +1,10 @@
|
|||||||
<template>
|
<template>
|
||||||
<button class="sc-button bt-create centered mt-4" @click="openModal">
|
<button v-if="!edit" class="sc-button bt-create mt-4" @click="openModal">
|
||||||
{{ $t('add_an_address_title') }}
|
{{ $t('add_an_address_title') }}
|
||||||
</button>
|
</button>
|
||||||
|
<button v-else class="sc-button bt-create mt-4" @click="openModal">
|
||||||
|
{{ $t('edit_an_address_title') }}
|
||||||
|
</button>
|
||||||
|
|
||||||
<teleport to="body">
|
<teleport to="body">
|
||||||
<modal v-if="modal.showModal"
|
<modal v-if="modal.showModal"
|
||||||
@@ -9,12 +12,17 @@
|
|||||||
@close="modal.showModal = false">
|
@close="modal.showModal = false">
|
||||||
|
|
||||||
<template v-slot:header>
|
<template v-slot:header>
|
||||||
<h3 class="modal-title">{{ $t('add_an_address_title') }}</h3>
|
<h3 v-if="!edit" class="modal-title">{{ $t('add_an_address_title') }}</h3>
|
||||||
|
<h3 v-if="edit" class="modal-title">{{ $t('edit_an_address_title') }}</h3>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template v-slot:body>
|
<template v-slot:body>
|
||||||
<div class="address_form">
|
<div class="address_form">
|
||||||
|
|
||||||
|
<div v-if="loading">
|
||||||
|
{{ $t('loading') }}
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="address_form__header">
|
<div class="address_form__header">
|
||||||
<h4>{{ $t('select_an_address_title') }}</h4>
|
<h4>{{ $t('select_an_address_title') }}</h4>
|
||||||
</div>
|
</div>
|
||||||
@@ -42,6 +50,7 @@
|
|||||||
</city-selection>
|
</city-selection>
|
||||||
|
|
||||||
<address-selection
|
<address-selection
|
||||||
|
v-if="!isNoAddress"
|
||||||
v-bind:address="address"
|
v-bind:address="address"
|
||||||
v-bind:updateMapCenter="updateMapCenter">
|
v-bind:updateMapCenter="updateMapCenter">
|
||||||
</address-selection>
|
</address-selection>
|
||||||
@@ -100,11 +109,15 @@ export default {
|
|||||||
emits: ['addNewAddress'],
|
emits: ['addNewAddress'],
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
edit: window.mode === 'edit',
|
||||||
modal: {
|
modal: {
|
||||||
showModal: false,
|
showModal: false,
|
||||||
modalDialogClass: "modal-dialog-scrollable modal-xl"
|
modalDialogClass: "modal-dialog-scrollable modal-xl"
|
||||||
},
|
},
|
||||||
|
loading: false,
|
||||||
address: {
|
address: {
|
||||||
|
writeNewAddress: false,
|
||||||
|
writeNewPostalCode: false,
|
||||||
loaded: {
|
loaded: {
|
||||||
countries: [],
|
countries: [],
|
||||||
cities: [],
|
cities: [],
|
||||||
@@ -115,11 +128,17 @@ export default {
|
|||||||
city: {},
|
city: {},
|
||||||
address: {},
|
address: {},
|
||||||
},
|
},
|
||||||
|
newPostalCode: {
|
||||||
|
code: null,
|
||||||
|
name: null
|
||||||
|
},
|
||||||
addressMap: {
|
addressMap: {
|
||||||
center : [48.8589, 2.3469], // Note: LeafletJs demands [lat, lon] cfr https://macwright.com/lonlat/
|
center : [48.8589, 2.3469], // Note: LeafletJs demands [lat, lon] cfr https://macwright.com/lonlat/
|
||||||
zoom: 12
|
zoom: 12
|
||||||
},
|
},
|
||||||
isNoAddress: false,
|
isNoAddress: false,
|
||||||
|
street: null,
|
||||||
|
streetNumber: null,
|
||||||
floor: null,
|
floor: null,
|
||||||
corridor: null,
|
corridor: null,
|
||||||
steps: null,
|
steps: null,
|
||||||
@@ -129,7 +148,7 @@ export default {
|
|||||||
extra: null,
|
extra: null,
|
||||||
distribution: null,
|
distribution: null,
|
||||||
},
|
},
|
||||||
errorMsg: {}
|
errorMsg: {},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@@ -156,33 +175,42 @@ export default {
|
|||||||
},
|
},
|
||||||
getCountries() {
|
getCountries() {
|
||||||
console.log('getCountries');
|
console.log('getCountries');
|
||||||
|
this.loading = true;
|
||||||
fetchCountries().then(countries => new Promise((resolve, reject) => {
|
fetchCountries().then(countries => new Promise((resolve, reject) => {
|
||||||
this.address.loaded.countries = countries.results;
|
this.address.loaded.countries = countries.results;
|
||||||
resolve()
|
resolve()
|
||||||
|
this.loading = false;
|
||||||
}))
|
}))
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
this.errorMsg.push(error.message);
|
this.errorMsg.push(error.message);
|
||||||
|
this.loading = false;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
getCities(country) {
|
getCities(country) {
|
||||||
console.log('getCities for', country.name);
|
console.log('getCities for', country.name);
|
||||||
|
this.loading = true;
|
||||||
fetchCities(country).then(cities => new Promise((resolve, reject) => {
|
fetchCities(country).then(cities => new Promise((resolve, reject) => {
|
||||||
this.address.loaded.cities = cities.results;
|
this.address.loaded.cities = cities.results.filter(c => c.origin !== 3); // filter out user-defined cities
|
||||||
resolve()
|
resolve();
|
||||||
|
this.loading = false;
|
||||||
}))
|
}))
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
this.errorMsg.push(error.message);
|
this.errorMsg.push(error.message);
|
||||||
|
this.loading = false;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
getReferenceAddresses(city) {
|
getReferenceAddresses(city) {
|
||||||
|
this.loading = true;
|
||||||
console.log('getReferenceAddresses for', city.name);
|
console.log('getReferenceAddresses for', city.name);
|
||||||
fetchReferenceAddresses(city).then(addresses => new Promise((resolve, reject) => {
|
fetchReferenceAddresses(city).then(addresses => new Promise((resolve, reject) => {
|
||||||
console.log('addresses', addresses);
|
console.log('addresses', addresses);
|
||||||
this.address.loaded.addresses = addresses.results;
|
this.address.loaded.addresses = addresses.results;
|
||||||
resolve();
|
resolve();
|
||||||
|
this.loading = false;
|
||||||
}))
|
}))
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
this.errorMsg.push(error.message);
|
this.errorMsg.push(error.message);
|
||||||
|
this.loading = false;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
updateMapCenter(point) {
|
updateMapCenter(point) {
|
||||||
@@ -198,6 +226,23 @@ export default {
|
|||||||
this.address.loaded.cities = [];
|
this.address.loaded.cities = [];
|
||||||
this.address.selected.city = {};
|
this.address.selected.city = {};
|
||||||
this.address.selected.country = {};
|
this.address.selected.country = {};
|
||||||
|
this.address.isNoAddress = this.edit ? this.$store.state.editAddress.isNoAddress: false;;
|
||||||
|
this.address.street = this.edit ? this.$store.state.editAddress.street: null;
|
||||||
|
this.address.streetNumber = this.edit ? this.$store.state.editAddress.streetNumber: null;
|
||||||
|
this.address.floor = this.edit ? this.$store.state.editAddress.floor: null;
|
||||||
|
this.address.corridor = this.edit ? this.$store.state.editAddress.corridor: null;
|
||||||
|
this.address.steps = this.edit ? this.$store.state.editAddress.steps: null;
|
||||||
|
this.address.flat = this.edit ? this.$store.state.editAddress.flat: null;
|
||||||
|
this.address.buildingName = this.edit ? this.$store.state.editAddress.buildingName: null;
|
||||||
|
this.address.distribution = this.edit ? this.$store.state.editAddress.distribution: null;
|
||||||
|
this.address.extra = this.edit ? this.$store.state.editAddress.extra: null;
|
||||||
|
this.address.writeNewAddress = this.edit;
|
||||||
|
this.address.writeNewPostalCode = this.edit;
|
||||||
|
this.address.newPostalCode = this.edit ?
|
||||||
|
{
|
||||||
|
code: this.$store.state.editAddress.postcode !== undefined ? this.$store.state.editAddress.postcode.code : null,
|
||||||
|
name: this.$store.state.editAddress.postcode !== undefined ? this.$store.state.editAddress.postcode.name : null
|
||||||
|
} : {};
|
||||||
console.log('cities and addresses', this.address.loaded.cities, this.address.loaded.addresses);
|
console.log('cities and addresses', this.address.loaded.cities, this.address.loaded.addresses);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -23,7 +23,7 @@ export default {
|
|||||||
},
|
},
|
||||||
methods:{
|
methods:{
|
||||||
init() {
|
init() {
|
||||||
map = L.map('address_map').setView([48.8589, 2.3469], 12);
|
map = L.map('address_map').setView([46.67059, -1.42683], 12);
|
||||||
|
|
||||||
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
||||||
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
|
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
|
||||||
@@ -40,7 +40,7 @@ export default {
|
|||||||
update() {
|
update() {
|
||||||
console.log('update map with : ', this.address.addressMap.center)
|
console.log('update map with : ', this.address.addressMap.center)
|
||||||
marker.setLatLng(this.address.addressMap.center);
|
marker.setLatLng(this.address.addressMap.center);
|
||||||
map.setView(this.address.addressMap.center, 12);
|
map.setView(this.address.addressMap.center, 15);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted(){
|
mounted(){
|
||||||
|
@@ -1,39 +1,65 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
|
||||||
<h4>{{ $t('fill_an_address') }}</h4>
|
<h4>{{ $t('fill_an_address') }}</h4>
|
||||||
|
<div>
|
||||||
|
<label for="floor">{{ $t('floor') }}</label>
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
name="floor"
|
name="floor"
|
||||||
|
maxlength=16
|
||||||
:placeholder="$t('floor')"
|
:placeholder="$t('floor')"
|
||||||
v-model="floor"/>
|
v-model="floor"/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label for="corridor">{{ $t('corridor') }}</label>
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
name="corridor"
|
name="corridor"
|
||||||
|
maxlength=16
|
||||||
:placeholder="$t('corridor')"
|
:placeholder="$t('corridor')"
|
||||||
v-model="corridor"/>
|
v-model="corridor"/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label for="steps">{{ $t('steps') }}</label>
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
name="steps"
|
name="steps"
|
||||||
|
maxlength=16
|
||||||
:placeholder="$t('steps')"
|
:placeholder="$t('steps')"
|
||||||
v-model="steps"/>
|
v-model="steps"/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label for="flat">{{ $t('flat') }}</label>
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
name="flat"
|
name="flat"
|
||||||
|
maxlength=16
|
||||||
:placeholder="$t('flat')"
|
:placeholder="$t('flat')"
|
||||||
v-model="flat"/>
|
v-model="flat"/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label for="buildingName">{{ $t('buildingName') }}</label>
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
name="buildingName"
|
name="buildingName"
|
||||||
|
maxlength=255
|
||||||
:placeholder="$t('buildingName')"
|
:placeholder="$t('buildingName')"
|
||||||
v-model="buildingName"/>
|
v-model="buildingName"/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label for="extra">{{ $t('extra') }}</label>
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
name="extra"
|
name="extra"
|
||||||
|
maxlength=255
|
||||||
:placeholder="$t('extra')"
|
:placeholder="$t('extra')"
|
||||||
v-model="extra"/>
|
v-model="extra"/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label for="distribution">{{ $t('distribution') }}</label>
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
name="distribution"
|
name="distribution"
|
||||||
|
maxlength=255
|
||||||
:placeholder="$t('distribution')"
|
:placeholder="$t('distribution')"
|
||||||
v-model="distribution"/>
|
v-model="distribution"/>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -15,6 +15,18 @@
|
|||||||
:options="addresses">
|
:options="addresses">
|
||||||
</VueMultiselect>
|
</VueMultiselect>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="custom-address" v-if="writeNewAddress || writeNewPostalCode">
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
name="street"
|
||||||
|
:placeholder="$t('street')"
|
||||||
|
v-model="street"/>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
name="streetNumber"
|
||||||
|
:placeholder="$t('streetNumber')"
|
||||||
|
v-model="streetNumber"/>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
@@ -30,24 +42,44 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
writeNewAddress() {
|
||||||
|
return this.address.writeNewAddress;
|
||||||
|
},
|
||||||
|
writeNewPostalCode() {
|
||||||
|
return this.address.writeNewPostalCode;
|
||||||
|
},
|
||||||
addresses() {
|
addresses() {
|
||||||
return this.address.loaded.addresses;
|
return this.address.loaded.addresses;
|
||||||
|
},
|
||||||
|
street: {
|
||||||
|
set(value) {
|
||||||
|
this.address.street = value;
|
||||||
|
},
|
||||||
|
get() {
|
||||||
|
return this.address.street;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
streetNumber: {
|
||||||
|
set(value) {
|
||||||
|
this.address.streetNumber = value;
|
||||||
|
},
|
||||||
|
get() {
|
||||||
|
return this.address.streetNumber;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
transName(value) {
|
transName(value) {
|
||||||
return value.streetNumber === undefined ? value.street : `${value.street}, ${value.streetNumber}`
|
return value.streetNumber === undefined ? value.street : `${value.street}, ${value.streetNumber}`
|
||||||
},
|
},
|
||||||
selectAddress(value) {
|
selectAddress(value) {
|
||||||
this.address.selected.address = value;
|
this.address.selected.address = value;
|
||||||
|
this.address.street = value.street;
|
||||||
|
this.address.streetNumber = value.streetNumber;
|
||||||
this.updateMapCenter(value.point);
|
this.updateMapCenter(value.point);
|
||||||
},
|
},
|
||||||
addAddress (newAddress) {
|
addAddress() {
|
||||||
const address = {
|
this.address.writeNewAddress = true;
|
||||||
street: newAddress
|
|
||||||
};
|
|
||||||
this.value = address;
|
|
||||||
this.address.selected.address = address;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@@ -8,9 +8,25 @@
|
|||||||
label="value"
|
label="value"
|
||||||
:custom-label="transName"
|
:custom-label="transName"
|
||||||
:placeholder="$t('select_city')"
|
:placeholder="$t('select_city')"
|
||||||
|
:taggable="true"
|
||||||
|
:multiple="false"
|
||||||
|
@tag="addPostalCode"
|
||||||
|
:tagPlaceholder="$t('create_postal_code')"
|
||||||
:options="cities">
|
:options="cities">
|
||||||
</VueMultiselect>
|
</VueMultiselect>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="custom-postcode" v-if="writeNewPostalCode">
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
name="name"
|
||||||
|
:placeholder="$t('postalCode_name')"
|
||||||
|
v-model="name"/>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
name="code"
|
||||||
|
:placeholder="$t('postalCode_code')"
|
||||||
|
v-model="code"/>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
@@ -25,18 +41,42 @@ export default {
|
|||||||
value: null
|
value: null
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
computed: {
|
||||||
|
writeNewPostalCode() {
|
||||||
|
return this.address.writeNewPostalCode;
|
||||||
|
},
|
||||||
|
cities() {
|
||||||
|
return this.address.loaded.cities;
|
||||||
|
},
|
||||||
|
name: {
|
||||||
|
set(value) {
|
||||||
|
this.address.newPostalCode.name = value;
|
||||||
|
},
|
||||||
|
get() {
|
||||||
|
return this.address.newPostalCode.name;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
code: {
|
||||||
|
set(value) {
|
||||||
|
this.address.newPostalCode.code= value;
|
||||||
|
},
|
||||||
|
get() {
|
||||||
|
return this.address.newPostalCode.code;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
transName(value) {
|
transName(value) {
|
||||||
return `${value.code}-${value.name}`
|
return `${value.code}-${value.name}`
|
||||||
},
|
},
|
||||||
selectCity(value) {
|
selectCity(value) {
|
||||||
this.address.selected.city = value;
|
this.address.selected.city = value;
|
||||||
|
this.address.newPostalCode.name = value.name;
|
||||||
|
this.address.newPostalCode.code = value.code;
|
||||||
this.getReferenceAddresses(value);
|
this.getReferenceAddresses(value);
|
||||||
},
|
},
|
||||||
},
|
addPostalCode() {
|
||||||
computed: {
|
this.address.writeNewPostalCode = true;
|
||||||
cities() {
|
|
||||||
return this.address.loaded.cities;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@@ -22,13 +22,18 @@ export default {
|
|||||||
props: ['address', 'getCities'],
|
props: ['address', 'getCities'],
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
value: this.address.loaded.countries.filter(c => c.countryCode === 'FR')[0]
|
edit: window.mode === 'edit',
|
||||||
|
defaultCountry: this.edit ? this.$store.state.editAddress.country.code : 'FR',
|
||||||
|
value: this.address.loaded.countries.filter(c => c.countryCode === this.defaultCountry)[0]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
init() {
|
init() {
|
||||||
|
this.value = this.edit ?
|
||||||
|
this.address.loaded.countries.filter(c => c.countryCode === this.$store.state.editAddress.country.code)[0]:
|
||||||
|
this.address.loaded.countries.filter(c => c.countryCode === 'FR')[0]
|
||||||
if (this.value !== undefined) {
|
if (this.value !== undefined) {
|
||||||
this.getCities(this.value);
|
this.selectCountry(this.value);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
transName ({ name }) {
|
transName ({ name }) {
|
||||||
|
@@ -0,0 +1,46 @@
|
|||||||
|
<template>
|
||||||
|
<div class="chill_address_address chill_address_address--multiline">
|
||||||
|
<div v-if="address.text">
|
||||||
|
{{ address.text }}
|
||||||
|
</div>
|
||||||
|
<div v-if="address.postcode">
|
||||||
|
{{ address.postcode.name }}
|
||||||
|
</div>
|
||||||
|
<div v-if="address.country">
|
||||||
|
{{ address.country.name.fr }}
|
||||||
|
</div>
|
||||||
|
<div v-if="address.floor">
|
||||||
|
<span>{{ $t('floor') }}</span>: {{ address.floor }}
|
||||||
|
</div>
|
||||||
|
<div v-if="address.corridor">
|
||||||
|
<span>{{ $t('corridor') }}</span>: {{ address.corridor }}
|
||||||
|
</div>
|
||||||
|
<div v-if="address.steps">
|
||||||
|
<span>{{ $t('steps') }}</span>: {{ address.steps }}
|
||||||
|
</div>
|
||||||
|
<div v-if="address.flat">
|
||||||
|
<span>{{ $t('flat') }}</span>: {{ address.flat }}
|
||||||
|
</div>
|
||||||
|
<div v-if="address.buildingName">
|
||||||
|
<span>{{ $t('buildingName') }}</span>: {{ address.buildingName }}
|
||||||
|
</div>
|
||||||
|
<div v-if="address.extra">
|
||||||
|
<span>{{ $t('extra') }}</span>: {{ address.extra }}
|
||||||
|
</div>
|
||||||
|
<div v-if="address.distribution">
|
||||||
|
<span>{{ $t('distribution') }}</span>: {{ address.distribution }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'ShowAddress',
|
||||||
|
props: ['address'],
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
|
</script>
|
@@ -58,9 +58,9 @@ const messages = {
|
|||||||
},
|
},
|
||||||
create: {
|
create: {
|
||||||
button: "Créer \"{q}\"",
|
button: "Créer \"{q}\"",
|
||||||
title: "Créer à la volée…",
|
title: "Création d'un nouvel usager ou d'un tiers professionnel",
|
||||||
person: "un nouvel usager",
|
person: "un nouvel usager",
|
||||||
thirdparty: "un nouveau tiers"
|
thirdparty: "un nouveau tiers professionnel"
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@@ -164,10 +164,12 @@
|
|||||||
{{ encore_entry_script_tags('ckeditor5') }}
|
{{ encore_entry_script_tags('ckeditor5') }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
window.addEventListener('DOMContentLoaded', function(e) {
|
||||||
chill.checkOtherValueOnChange();
|
chill.checkOtherValueOnChange();
|
||||||
$('.select2').select2({allowClear: true});
|
$('.select2').select2({allowClear: true});
|
||||||
chill.categoryLinkParentChildSelect();
|
chill.categoryLinkParentChildSelect();
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
{% block js%}<!-- nothing added to js -->{% endblock %}
|
{% block js%}<!-- nothing added to js -->{% endblock %}
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@@ -2,88 +2,169 @@
|
|||||||
|
|
||||||
namespace Chill\MainBundle\Search;
|
namespace Chill\MainBundle\Search;
|
||||||
|
|
||||||
use Chill\PersonBundle\Entity\Person;
|
use Chill\MainBundle\Serializer\Model\Collection;
|
||||||
use Chill\ThirdPartyBundle\Entity\ThirdParty;
|
use Chill\MainBundle\Pagination\PaginatorFactory;
|
||||||
|
use Chill\PersonBundle\Search\SearchPersonApiProvider;
|
||||||
|
use Chill\ThirdPartyBundle\Search\ThirdPartyApiSearch;
|
||||||
|
use Doctrine\DBAL\Types\Types;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
use Doctrine\ORM\Query\ResultSetMappingBuilder;
|
||||||
use Chill\MainBundle\Search\SearchProvider;
|
use Chill\MainBundle\Search\SearchProvider;
|
||||||
use Symfony\Component\VarDumper\Resources\functions\dump;
|
use Symfony\Component\VarDumper\Resources\functions\dump;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ***Warning*** This is an incomplete implementation ***Warning***
|
|
||||||
*/
|
*/
|
||||||
class SearchApi
|
class SearchApi
|
||||||
{
|
{
|
||||||
private EntityManagerInterface $em;
|
private EntityManagerInterface $em;
|
||||||
private SearchProvider $search;
|
private PaginatorFactory $paginator;
|
||||||
|
|
||||||
public function __construct(EntityManagerInterface $em, SearchProvider $search)
|
private array $providers = [];
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
EntityManagerInterface $em,
|
||||||
|
SearchPersonApiProvider $searchPerson,
|
||||||
|
ThirdPartyApiSearch $thirdPartyApiSearch,
|
||||||
|
PaginatorFactory $paginator
|
||||||
|
)
|
||||||
{
|
{
|
||||||
$this->em = $em;
|
$this->em = $em;
|
||||||
$this->search = $search;
|
$this->providers[] = $searchPerson;
|
||||||
|
$this->providers[] = $thirdPartyApiSearch;
|
||||||
|
$this->paginator = $paginator;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Model/Result[]
|
* @return Model/Result[]
|
||||||
*/
|
*/
|
||||||
public function getResults(string $query, int $offset, int $maxResult): array
|
public function getResults(string $pattern, array $types, array $parameters): Collection
|
||||||
{
|
{
|
||||||
// **warning again**: this is an incomplete implementation
|
$queries = $this->findQueries($pattern, $types, $parameters);
|
||||||
$results = [];
|
|
||||||
|
|
||||||
foreach ($this->getPersons($query) as $p) {
|
$total = $this->countItems($queries, $types, $parameters);
|
||||||
$results[] = new Model\Result((float)\rand(0, 100) / 100, $p);
|
$paginator = $this->paginator->create($total);
|
||||||
}
|
|
||||||
foreach ($this->getThirdParties($query) as $t) {
|
$rawResults = $this->fetchRawResult($queries, $types, $parameters, $paginator);
|
||||||
$results[] = new Model\Result((float)\rand(0, 100) / 100, $t);
|
|
||||||
|
$this->prepareProviders($rawResults);
|
||||||
|
$results = $this->buildResults($rawResults);
|
||||||
|
|
||||||
|
$collection = new Collection($results, $paginator);
|
||||||
|
|
||||||
|
return $collection;
|
||||||
}
|
}
|
||||||
|
|
||||||
\usort($results, function(Model\Result $a, Model\Result $b) {
|
private function findQueries($pattern, array $types, array $parameters): array
|
||||||
return ($a->getRelevance() <=> $b->getRelevance()) * -1;
|
|
||||||
});
|
|
||||||
|
|
||||||
return $results;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function countResults(string $query): int
|
|
||||||
{
|
{
|
||||||
return 0;
|
return \array_map(
|
||||||
|
fn($p) => $p->provideQuery($pattern, $parameters),
|
||||||
|
$this->findProviders($pattern, $types, $parameters),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getThirdParties(string $query)
|
private function findProviders(string $pattern, array $types, array $parameters): array
|
||||||
{
|
{
|
||||||
$thirdPartiesIds = $this->em->createQuery('SELECT t.id FROM '.ThirdParty::class.' t')
|
return \array_filter(
|
||||||
->getScalarResult();
|
$this->providers,
|
||||||
$nbResults = rand(0, 15);
|
fn($p) => $p->supportsTypes($pattern, $types, $parameters)
|
||||||
|
);
|
||||||
if ($nbResults === 1) {
|
|
||||||
$nbResults++;
|
|
||||||
} elseif ($nbResults === 0) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
$ids = \array_map(function ($e) use ($thirdPartiesIds) { return $thirdPartiesIds[$e]['id'];},
|
|
||||||
\array_rand($thirdPartiesIds, $nbResults));
|
|
||||||
|
|
||||||
$a = $this->em->getRepository(ThirdParty::class)
|
|
||||||
->findById($ids);
|
|
||||||
return $a;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getPersons(string $query)
|
private function countItems($providers, $types, $parameters): int
|
||||||
{
|
{
|
||||||
$params = [
|
list($countQuery, $parameters) = $this->buildCountQuery($providers, $types, $parameters);
|
||||||
SearchInterface::SEARCH_PREVIEW_OPTION => false
|
$rsmCount = new ResultSetMappingBuilder($this->em);
|
||||||
|
$rsmCount->addScalarResult('count', 'count');
|
||||||
|
$countNq = $this->em->createNativeQuery($countQuery, $rsmCount);
|
||||||
|
$countNq->setParameters($parameters);
|
||||||
|
|
||||||
|
return $countNq->getSingleScalarResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function buildCountQuery(array $queries, $types, $parameters)
|
||||||
|
{
|
||||||
|
$query = "SELECT COUNT(sq.key) AS count FROM ({union_unordered}) AS sq";
|
||||||
|
$unions = [];
|
||||||
|
$parameters = [];
|
||||||
|
|
||||||
|
foreach ($queries as $q) {
|
||||||
|
$unions[] = $q->buildQuery();
|
||||||
|
$parameters = \array_merge($parameters, $q->buildParameters());
|
||||||
|
}
|
||||||
|
|
||||||
|
$unionUnordered = \implode(" UNION ", $unions);
|
||||||
|
|
||||||
|
return [
|
||||||
|
\strtr($query, [ '{union_unordered}' => $unionUnordered ]),
|
||||||
|
$parameters
|
||||||
];
|
];
|
||||||
$search = $this->search->getResultByName($query, 'person_regular', 0, 50, $params, 'json');
|
|
||||||
$ids = \array_map(function($r) { return $r['id']; }, $search['results']);
|
|
||||||
|
|
||||||
|
|
||||||
if (count($ids) === 0) {
|
|
||||||
return [];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->em->getRepository(Person::class)
|
private function buildUnionQuery(array $queries, $types, $parameters)
|
||||||
->findById($ids)
|
{
|
||||||
|
$query = "{unions} ORDER BY pertinence DESC";
|
||||||
|
$unions = [];
|
||||||
|
$parameters = [];
|
||||||
|
|
||||||
|
foreach ($queries as $q) {
|
||||||
|
$unions[] = $q->buildQuery();
|
||||||
|
$parameters = \array_merge($parameters, $q->buildParameters());
|
||||||
|
}
|
||||||
|
|
||||||
|
$union = \implode(" UNION ", $unions);
|
||||||
|
|
||||||
|
return [
|
||||||
|
\strtr($query, [ '{unions}' => $union]),
|
||||||
|
$parameters
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
private function fetchRawResult($queries, $types, $parameters, $paginator): array
|
||||||
|
{
|
||||||
|
list($union, $parameters) = $this->buildUnionQuery($queries, $types, $parameters, $paginator);
|
||||||
|
$rsm = new ResultSetMappingBuilder($this->em);
|
||||||
|
$rsm->addScalarResult('key', 'key', Types::STRING)
|
||||||
|
->addScalarResult('metadata', 'metadata', Types::JSON)
|
||||||
|
->addScalarResult('pertinence', 'pertinence', Types::FLOAT)
|
||||||
;
|
;
|
||||||
|
|
||||||
|
$nq = $this->em->createNativeQuery($union, $rsm);
|
||||||
|
$nq->setParameters($parameters);
|
||||||
|
|
||||||
|
return $nq->getResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function prepareProviders($rawResults)
|
||||||
|
{
|
||||||
|
$metadatas = [];
|
||||||
|
foreach ($rawResults as $r) {
|
||||||
|
foreach ($this->providers as $k => $p) {
|
||||||
|
if ($p->supportsResult($r['key'], $r['metadata'])) {
|
||||||
|
$metadatas[$k][] = $r['metadata'];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($metadatas as $k => $m) {
|
||||||
|
$this->providers[$k]->prepare($m);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function buildResults($rawResults)
|
||||||
|
{
|
||||||
|
foreach ($rawResults as $r) {
|
||||||
|
foreach ($this->providers as $k => $p) {
|
||||||
|
if ($p->supportsResult($r['key'], $r['metadata'])) {
|
||||||
|
$items[] = (new SearchApiResult($r['pertinence']))
|
||||||
|
->setResult(
|
||||||
|
$p->getResult($r['key'], $r['metadata'], $r['pertinence'])
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $items ?? [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
18
src/Bundle/ChillMainBundle/Search/SearchApiInterface.php
Normal file
18
src/Bundle/ChillMainBundle/Search/SearchApiInterface.php
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Chill\MainBundle\Search;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Search\SearchApiQuery;
|
||||||
|
|
||||||
|
interface SearchApiInterface
|
||||||
|
{
|
||||||
|
public function provideQuery(string $pattern, array $parameters): SearchApiQuery;
|
||||||
|
|
||||||
|
public function supportsTypes(string $pattern, array $types, array $parameters): bool;
|
||||||
|
|
||||||
|
public function prepare(array $metadatas): void;
|
||||||
|
|
||||||
|
public function supportsResult(string $key, array $metadatas): bool;
|
||||||
|
|
||||||
|
public function getResult(string $key, array $metadata, float $pertinence);
|
||||||
|
}
|
85
src/Bundle/ChillMainBundle/Search/SearchApiQuery.php
Normal file
85
src/Bundle/ChillMainBundle/Search/SearchApiQuery.php
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Chill\MainBundle\Search;
|
||||||
|
|
||||||
|
class SearchApiQuery
|
||||||
|
{
|
||||||
|
private ?string $selectKey;
|
||||||
|
private array $selectKeyParams = [];
|
||||||
|
private ?string $jsonbMetadata;
|
||||||
|
private array $jsonbMetadataParams = [];
|
||||||
|
private ?string $pertinence;
|
||||||
|
private array $pertinenceParams = [];
|
||||||
|
private ?string $fromClause;
|
||||||
|
private array $fromClauseParams = [];
|
||||||
|
private ?string $whereClause;
|
||||||
|
private array $whereClauseParams = [];
|
||||||
|
|
||||||
|
public function setSelectKey(string $selectKey, array $params = []): self
|
||||||
|
{
|
||||||
|
$this->selectKey = $selectKey;
|
||||||
|
$this->selectKeyParams = $params;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setSelectJsonbMetadata(string $jsonbMetadata, array $params = []): self
|
||||||
|
{
|
||||||
|
$this->jsonbMetadata = $jsonbMetadata;
|
||||||
|
$this->jsonbMetadataParams = $params;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setSelectPertinence(string $pertinence, array $params = []): self
|
||||||
|
{
|
||||||
|
$this->pertinence = $pertinence;
|
||||||
|
$this->pertinenceParams = $params;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setFromClause(string $fromClause, array $params = []): self
|
||||||
|
{
|
||||||
|
$this->fromClause = $fromClause;
|
||||||
|
$this->fromClauseParams = $params;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setWhereClause(string $whereClause, array $params = []): self
|
||||||
|
{
|
||||||
|
$this->whereClause = $whereClause;
|
||||||
|
$this->whereClauseParams = $params;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function buildQuery(): string
|
||||||
|
{
|
||||||
|
return \strtr("SELECT
|
||||||
|
'{key}' AS key,
|
||||||
|
{metadata} AS metadata,
|
||||||
|
{pertinence} AS pertinence
|
||||||
|
FROM {from}
|
||||||
|
WHERE {where}
|
||||||
|
", [
|
||||||
|
'{key}' => $this->selectKey,
|
||||||
|
'{metadata}' => $this->jsonbMetadata,
|
||||||
|
'{pertinence}' => $this->pertinence,
|
||||||
|
'{from}' => $this->fromClause,
|
||||||
|
'{where}' => $this->whereClause
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function buildParameters(): array
|
||||||
|
{
|
||||||
|
return \array_merge(
|
||||||
|
$this->selectKeyParams,
|
||||||
|
$this->jsonbMetadataParams,
|
||||||
|
$this->pertinenceParams,
|
||||||
|
$this->fromClauseParams,
|
||||||
|
$this->whereClauseParams
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
40
src/Bundle/ChillMainBundle/Search/SearchApiResult.php
Normal file
40
src/Bundle/ChillMainBundle/Search/SearchApiResult.php
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Chill\MainBundle\Search;
|
||||||
|
|
||||||
|
use Symfony\Component\Serializer\Annotation as Serializer;
|
||||||
|
|
||||||
|
class SearchApiResult
|
||||||
|
{
|
||||||
|
private float $pertinence;
|
||||||
|
|
||||||
|
private $result;
|
||||||
|
|
||||||
|
public function __construct(float $relevance)
|
||||||
|
{
|
||||||
|
$this->relevance = $relevance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setResult($result): self
|
||||||
|
{
|
||||||
|
$this->result = $result;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Serializer\Groups({"read"})
|
||||||
|
*/
|
||||||
|
public function getResult()
|
||||||
|
{
|
||||||
|
return $this->result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Serializer\Groups({"read"})
|
||||||
|
*/
|
||||||
|
public function getRelevance(): float
|
||||||
|
{
|
||||||
|
return $this->relevance;
|
||||||
|
}
|
||||||
|
}
|
@@ -14,8 +14,20 @@ class AddressNormalizer implements NormalizerAwareInterface, NormalizerInterface
|
|||||||
public function normalize($address, string $format = null, array $context = [])
|
public function normalize($address, string $format = null, array $context = [])
|
||||||
{
|
{
|
||||||
$data['address_id'] = $address->getId();
|
$data['address_id'] = $address->getId();
|
||||||
$data['text'] = $address->getStreet().', '.$address->getBuildingName();
|
$data['text'] = $address->isNoAddress() ? '' : $address->getStreet().', '.$address->getStreetNumber();
|
||||||
|
$data['street'] = $address->getStreet();
|
||||||
|
$data['streetNumber'] = $address->getStreetNumber();
|
||||||
$data['postcode']['name'] = $address->getPostCode()->getName();
|
$data['postcode']['name'] = $address->getPostCode()->getName();
|
||||||
|
$data['postcode']['code'] = $address->getPostCode()->getCode();
|
||||||
|
$data['country']['name'] = $address->getPostCode()->getCountry()->getName();
|
||||||
|
$data['country']['code'] = $address->getPostCode()->getCountry()->getCountryCode();
|
||||||
|
$data['floor'] = $address->getFloor();
|
||||||
|
$data['corridor'] = $address->getCorridor();
|
||||||
|
$data['steps'] = $address->getSteps();
|
||||||
|
$data['flat'] = $address->getBuildingName();
|
||||||
|
$data['buildingName'] = $address->getFlat();
|
||||||
|
$data['distribution'] = $address->getDistribution();
|
||||||
|
$data['extra'] = $address->getExtra();
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
@@ -19,7 +19,6 @@ class CollectionNormalizer implements NormalizerInterface, NormalizerAwareInterf
|
|||||||
public function normalize($collection, string $format = null, array $context = [])
|
public function normalize($collection, string $format = null, array $context = [])
|
||||||
{
|
{
|
||||||
/** @var $collection Collection */
|
/** @var $collection Collection */
|
||||||
/** @var $collection Chill\MainBundle\Pagination\PaginatorInterface */
|
|
||||||
$paginator = $collection->getPaginator();
|
$paginator = $collection->getPaginator();
|
||||||
|
|
||||||
$data['count'] = $paginator->getTotalItems();
|
$data['count'] = $paginator->getTotalItems();
|
||||||
|
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Bundle\ChillMainBundle\Tests\Controller;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Test\PrepareClientTrait;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
|
||||||
|
class SearchApiControllerTest extends WebTestCase
|
||||||
|
{
|
||||||
|
use PrepareClientTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider generateSearchData
|
||||||
|
*/
|
||||||
|
public function testSearch(string $pattern, array $types)
|
||||||
|
{
|
||||||
|
$client = $this->getClientAuthenticated();
|
||||||
|
|
||||||
|
$client->request(
|
||||||
|
Request::METHOD_GET,
|
||||||
|
'/api/1.0/search.json',
|
||||||
|
[ 'q' => $pattern, 'type' => $types ]
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertResponseIsSuccessful();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function generateSearchData()
|
||||||
|
{
|
||||||
|
yield ['per', ['person', 'thirdparty'] ];
|
||||||
|
yield ['per', ['thirdparty'] ];
|
||||||
|
yield ['per', ['person'] ];
|
||||||
|
yield ['fjklmeqjfkdqjklrmefdqjklm', ['person', 'thirdparty'] ];
|
||||||
|
}
|
||||||
|
}
|
216
src/Bundle/ChillMainBundle/Tests/Util/DateRangeCoveringTest.php
Normal file
216
src/Bundle/ChillMainBundle/Tests/Util/DateRangeCoveringTest.php
Normal file
@@ -0,0 +1,216 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Chill\MainBundle\Tests\Util;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Util\DateRangeCovering;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
class DateRangeCoveringTest extends TestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
public function testCoveringWithMinCover1()
|
||||||
|
{
|
||||||
|
$cover = new DateRangeCovering(1, new \DateTimeZone('Europe/Brussels'));
|
||||||
|
$cover
|
||||||
|
->add(new \DateTime('2010-01-01'), new \DateTime('2010-12-01'), 1)
|
||||||
|
->add(new \DateTime('2010-06-01'), new \DateTime('2011-06-01'), 2)
|
||||||
|
->add(new \DateTime('2019-06-01'), new \DateTime('2019-06-01'), 3)
|
||||||
|
->compute()
|
||||||
|
;
|
||||||
|
|
||||||
|
$this->assertTrue($cover->hasIntersections());
|
||||||
|
$this->assertIsArray($cover->getIntersections());
|
||||||
|
$this->assertCount(1, $cover->getIntersections());
|
||||||
|
$this->assertEquals(
|
||||||
|
new \DateTime('2010-06-01'),
|
||||||
|
$cover->getIntersections()[0][0],
|
||||||
|
"assert date start are the intersection"
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
new \DateTime('2010-12-01'),
|
||||||
|
$cover->getIntersections()[0][1],
|
||||||
|
"assert date end are the intersection"
|
||||||
|
);
|
||||||
|
$this->assertIsArray($cover->getIntersections()[0][2]);
|
||||||
|
$this->assertContains(1, $cover->getIntersections()[0][2]);
|
||||||
|
$this->assertContains(2, $cover->getIntersections()[0][2]);
|
||||||
|
$this->assertNotContains(3, $cover->getIntersections()[0][2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCoveringWithMinCover1WithTwoIntersections()
|
||||||
|
{
|
||||||
|
$cover = new DateRangeCovering(1, new \DateTimeZone('Europe/Brussels'));
|
||||||
|
$cover
|
||||||
|
->add(new \DateTime('2010-01-01'), new \DateTime('2010-12-01'), 1)
|
||||||
|
->add(new \DateTime('2010-06-01'), new \DateTime('2011-06-01'), 2)
|
||||||
|
->add(new \DateTime('2019-01-01'), new \DateTime('2019-12-01'), 3)
|
||||||
|
->add(new \DateTime('2019-06-01'), new \DateTime('2020-06-01'), 4)
|
||||||
|
->compute()
|
||||||
|
;
|
||||||
|
|
||||||
|
$this->assertTrue($cover->hasIntersections());
|
||||||
|
$this->assertIsArray($cover->getIntersections());
|
||||||
|
$this->assertCount(2, $cover->getIntersections());
|
||||||
|
|
||||||
|
$intersections = $cover->getIntersections();
|
||||||
|
|
||||||
|
// sort the intersections to compare them in expected order
|
||||||
|
\usort($intersections, function($a, $b) {
|
||||||
|
if ($a[0] === $b[0]) {
|
||||||
|
return $a[1] <=> $b[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $a[0] <=> $b[0];
|
||||||
|
});
|
||||||
|
|
||||||
|
// first intersection
|
||||||
|
$this->assertEquals(
|
||||||
|
new \DateTime('2010-06-01'),
|
||||||
|
$intersections[0][0],
|
||||||
|
"assert date start are the intersection"
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
new \DateTime('2010-12-01'),
|
||||||
|
$intersections[0][1],
|
||||||
|
"assert date end are the intersection"
|
||||||
|
);
|
||||||
|
$this->assertIsArray($intersections[0][2]);
|
||||||
|
$this->assertContains(1, $intersections[0][2]);
|
||||||
|
$this->assertContains(2, $intersections[0][2]);
|
||||||
|
$this->assertNotContains(3, $intersections[0][2]);
|
||||||
|
$this->assertNotContains(4, $intersections[0][2]);
|
||||||
|
|
||||||
|
// second intersection
|
||||||
|
$this->assertEquals(
|
||||||
|
new \DateTime('2019-06-01'),
|
||||||
|
$intersections[1][0],
|
||||||
|
"assert date start are the intersection"
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
new \DateTime('2019-12-01'),
|
||||||
|
$intersections[1][1],
|
||||||
|
"assert date end are the intersection"
|
||||||
|
);
|
||||||
|
$this->assertIsArray($intersections[1][2]);
|
||||||
|
$this->assertContains(3, $intersections[1][2]);
|
||||||
|
$this->assertContains(4, $intersections[1][2]);
|
||||||
|
$this->assertNotContains(1, $intersections[1][2]);
|
||||||
|
$this->assertNotContains(2, $intersections[1][2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCoveringWithMinCover2()
|
||||||
|
{
|
||||||
|
$cover = new DateRangeCovering(2, new \DateTimeZone('Europe/Brussels'));
|
||||||
|
$cover
|
||||||
|
->add(new \DateTime('2010-01-01'), new \DateTime('2010-10-01'), 1)
|
||||||
|
->add(new \DateTime('2010-06-01'), new \DateTime('2010-09-01'), 2)
|
||||||
|
->add(new \DateTime('2010-04-01'), new \DateTime('2010-12-01'), 3)
|
||||||
|
->add(new \DateTime('2019-01-01'), new \DateTime('2019-10-01'), 4)
|
||||||
|
->add(new \DateTime('2019-06-01'), new \DateTime('2019-09-01'), 5)
|
||||||
|
->compute()
|
||||||
|
;
|
||||||
|
$this->assertTrue($cover->hasIntersections());
|
||||||
|
$this->assertIsArray($cover->getIntersections());
|
||||||
|
$this->assertCount(1, $cover->getIntersections());
|
||||||
|
|
||||||
|
$this->assertEquals(
|
||||||
|
new \DateTime('2010-06-01'),
|
||||||
|
$cover->getIntersections()[0][0],
|
||||||
|
"assert date start are the intersection"
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
new \DateTime('2010-09-01'),
|
||||||
|
$cover->getIntersections()[0][1],
|
||||||
|
"assert date end are the intersection"
|
||||||
|
);
|
||||||
|
$this->assertIsArray($cover->getIntersections()[0][2]);
|
||||||
|
$this->assertContains(1, $cover->getIntersections()[0][2]);
|
||||||
|
$this->assertContains(2, $cover->getIntersections()[0][2]);
|
||||||
|
$this->assertContains(3, $cover->getIntersections()[0][2]);
|
||||||
|
$this->assertNotContains(4, $cover->getIntersections()[0][2]);
|
||||||
|
$this->assertNotContains(5, $cover->getIntersections()[0][2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCoveringWithMinCover2AndThreePeriodsCovering()
|
||||||
|
{
|
||||||
|
$cover = new DateRangeCovering(2, new \DateTimeZone('Europe/Brussels'));
|
||||||
|
$cover
|
||||||
|
->add(new \DateTime('2010-01-01'), new \DateTime('2010-10-01'), 1)
|
||||||
|
->add(new \DateTime('2010-06-01'), new \DateTime('2010-09-01'), 2)
|
||||||
|
->add(new \DateTime('2010-04-01'), new \DateTime('2010-12-01'), 3)
|
||||||
|
->add(new \DateTime('2009-01-01'), new \DateTime('2010-09-15'), 4)
|
||||||
|
->add(new \DateTime('2019-01-01'), new \DateTime('2019-10-01'), 5)
|
||||||
|
->add(new \DateTime('2019-06-01'), new \DateTime('2019-09-01'), 6)
|
||||||
|
->compute()
|
||||||
|
;
|
||||||
|
|
||||||
|
$this->assertTrue($cover->hasIntersections());
|
||||||
|
$this->assertIsArray($cover->getIntersections());
|
||||||
|
$this->assertCount(1, $cover->getIntersections());
|
||||||
|
|
||||||
|
$this->assertEquals(
|
||||||
|
new \DateTime('2010-04-01'),
|
||||||
|
$cover->getIntersections()[0][0],
|
||||||
|
"assert date start are the intersection"
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
new \DateTime('2010-09-15'),
|
||||||
|
$cover->getIntersections()[0][1],
|
||||||
|
"assert date end are the intersection"
|
||||||
|
);
|
||||||
|
$this->assertIsArray($cover->getIntersections()[0][2]);
|
||||||
|
$this->assertContains(1, $cover->getIntersections()[0][2]);
|
||||||
|
$this->assertContains(2, $cover->getIntersections()[0][2]);
|
||||||
|
$this->assertContains(3, $cover->getIntersections()[0][2]);
|
||||||
|
$this->assertContains(4, $cover->getIntersections()[0][2]);
|
||||||
|
$this->assertNotContains(5, $cover->getIntersections()[0][2]);
|
||||||
|
$this->assertNotContains(6, $cover->getIntersections()[0][2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCoveringWithMinCover2AndThreePeriodsCoveringWithNullMetadata()
|
||||||
|
{
|
||||||
|
$cover = new DateRangeCovering(2, new \DateTimeZone('Europe/Brussels'));
|
||||||
|
$cover
|
||||||
|
->add(new \DateTime('2010-01-01'), new \DateTime('2010-10-01'), null)
|
||||||
|
->add(new \DateTime('2010-06-01'), new \DateTime('2010-09-01'), null)
|
||||||
|
->add(new \DateTime('2010-04-01'), new \DateTime('2010-12-01'), null)
|
||||||
|
->add(new \DateTime('2009-01-01'), new \DateTime('2010-09-15'), null)
|
||||||
|
->add(new \DateTime('2019-01-01'), new \DateTime('2019-10-01'), null)
|
||||||
|
->add(new \DateTime('2019-06-01'), new \DateTime('2019-09-01'), null)
|
||||||
|
->compute()
|
||||||
|
;
|
||||||
|
|
||||||
|
$this->assertTrue($cover->hasIntersections());
|
||||||
|
$this->assertIsArray($cover->getIntersections());
|
||||||
|
$this->assertCount(1, $cover->getIntersections());
|
||||||
|
|
||||||
|
$this->assertEquals(
|
||||||
|
new \DateTime('2010-04-01'),
|
||||||
|
$cover->getIntersections()[0][0],
|
||||||
|
"assert date start are the intersection"
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
new \DateTime('2010-09-15'),
|
||||||
|
$cover->getIntersections()[0][1],
|
||||||
|
"assert date end are the intersection"
|
||||||
|
);
|
||||||
|
$this->assertIsArray($cover->getIntersections()[0][2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testCoveringWithMinCover3Absent()
|
||||||
|
{
|
||||||
|
$cover = new DateRangeCovering(3, new \DateTimeZone('Europe/Brussels'));
|
||||||
|
$cover
|
||||||
|
->add(new \DateTime('2010-01-01'), new \DateTime('2010-10-01'), 1)
|
||||||
|
->add(new \DateTime('2010-06-01'), new \DateTime('2010-09-01'), 2)
|
||||||
|
->add(new \DateTime('2010-04-01'), new \DateTime('2010-12-01'), 3)
|
||||||
|
->add(new \DateTime('2019-01-01'), new \DateTime('2019-10-01'), 4)
|
||||||
|
->add(new \DateTime('2019-06-01'), new \DateTime('2019-09-01'), 5)
|
||||||
|
->compute()
|
||||||
|
;
|
||||||
|
$this->assertFalse($cover->hasIntersections());
|
||||||
|
$this->assertIsArray($cover->getIntersections());
|
||||||
|
$this->assertCount(0, $cover->getIntersections());
|
||||||
|
}
|
||||||
|
}
|
224
src/Bundle/ChillMainBundle/Util/DateRangeCovering.php
Normal file
224
src/Bundle/ChillMainBundle/Util/DateRangeCovering.php
Normal file
@@ -0,0 +1,224 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Chill\MainBundle\Util;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utilities to compare date periods
|
||||||
|
*
|
||||||
|
* This class allow to compare periods when there are period covering. The
|
||||||
|
* argument `minCovers` allow to find also when there are more than 2 period
|
||||||
|
* which intersects.
|
||||||
|
*
|
||||||
|
* Example: a team may have maximum 2 leaders on a same period: you will
|
||||||
|
* find here all periods where there are more than 2 leaders.
|
||||||
|
*
|
||||||
|
* Usage:
|
||||||
|
*
|
||||||
|
* ```php
|
||||||
|
* $cover = new DateRangeCovering(2); // 2 means we will have periods
|
||||||
|
* // when there are 2+ periods intersecting
|
||||||
|
* $cover
|
||||||
|
* ->add(new \DateTime('2010-01-01'), new \DateTime('2010-10-01'), null)
|
||||||
|
* ->add(new \DateTime('2010-06-01'), new \DateTime('2010-09-01'), null)
|
||||||
|
* ->add(new \DateTime('2010-04-01'), new \DateTime('2010-12-01'), null)
|
||||||
|
* ->add(new \DateTime('2009-01-01'), new \DateTime('2010-09-15'), null)
|
||||||
|
* ->add(new \DateTime('2019-01-01'), new \DateTime('2019-10-01'), null)
|
||||||
|
* ->add(new \DateTime('2019-06-01'), new \DateTime('2019-09-01'), null)
|
||||||
|
* ->compute()
|
||||||
|
* ;
|
||||||
|
* $cover->getIntersections();
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
class DateRangeCovering
|
||||||
|
{
|
||||||
|
private bool $computed = false;
|
||||||
|
|
||||||
|
private array $intersections = [];
|
||||||
|
|
||||||
|
private array $intervals = [];
|
||||||
|
|
||||||
|
private int $minCover;
|
||||||
|
|
||||||
|
private int $uniqueKeyCounter = 0;
|
||||||
|
|
||||||
|
private array $metadatas = [];
|
||||||
|
|
||||||
|
private array $sequence = [];
|
||||||
|
|
||||||
|
private \DateTimeZone $tz;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $minCover the minimum of covering required
|
||||||
|
*/
|
||||||
|
public function __construct(int $minCover, \DateTimeZone $tz)
|
||||||
|
{
|
||||||
|
if ($minCover < 0) {
|
||||||
|
throw new \LogicException("argument minCover cannot be lower than 0");
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->minCover = $minCover;
|
||||||
|
$this->tz = $tz;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function add(\DateTimeInterface $start, \DateTimeInterface $end = null, $metadata = null): self
|
||||||
|
{
|
||||||
|
if ($this->computed) {
|
||||||
|
throw new \LogicException("You cannot add intervals to a computed instance");
|
||||||
|
}
|
||||||
|
|
||||||
|
$k = $this->uniqueKeyCounter++;
|
||||||
|
$this->intervals[$k] = [$start, $end];
|
||||||
|
$this->metadatas[$k] = $metadata;
|
||||||
|
|
||||||
|
$this->addToSequence($start->getTimestamp(), $k, null);
|
||||||
|
$this->addToSequence(
|
||||||
|
NULL === $end ? PHP_INT_MAX : $end->getTimestamp(), null, $k
|
||||||
|
);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function addToSequence($timestamp, int $start = null, int $end = null)
|
||||||
|
{
|
||||||
|
if (!\array_key_exists($timestamp, $this->sequence)) {
|
||||||
|
$this->sequence[$timestamp] = [ 's' => [], 'e' => [] ];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (NULL !== $start) {
|
||||||
|
$this->sequence[$timestamp]['s'][] = $start;
|
||||||
|
}
|
||||||
|
if (NULL !== $end) {
|
||||||
|
$this->sequence[$timestamp]['e'][] = $end;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function compute(): self
|
||||||
|
{
|
||||||
|
\ksort($this->sequence);
|
||||||
|
|
||||||
|
$currentPeriod = [];
|
||||||
|
$currents = [];
|
||||||
|
$isOpen = false;
|
||||||
|
$overs = [];
|
||||||
|
|
||||||
|
foreach ($this->sequence as $ts => $moves) {
|
||||||
|
$currents = \array_merge($currents, $moves['s']);
|
||||||
|
$currents = \array_diff($currents, $moves['e']);
|
||||||
|
|
||||||
|
if (count($currents) > $this->minCover && !$isOpen) {
|
||||||
|
$currentPeriod[0] = $ts;
|
||||||
|
$currentPeriod[2] = $currents;
|
||||||
|
$isOpen = true;
|
||||||
|
} elseif ($isOpen && count($currents) <= $this->minCover) {
|
||||||
|
$currentPeriod[1] = $ts;
|
||||||
|
$overs[] = $currentPeriod;
|
||||||
|
$currentPeriod = [];
|
||||||
|
$isOpen = false;
|
||||||
|
} elseif ($isOpen) {
|
||||||
|
$currentPeriod[2] = \array_merge($currentPeriod[2], $currents);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// process metadata
|
||||||
|
foreach ($overs as list($start, $end, $metadata)) {
|
||||||
|
$this->intersections[] = [
|
||||||
|
(new \DateTimeImmutable('@'.$start))
|
||||||
|
->setTimezone($this->tz),
|
||||||
|
$end === PHP_INT_MAX ? null : (new \DateTimeImmutable('@'.$end))
|
||||||
|
->setTimezone($this->tz),
|
||||||
|
\array_values(
|
||||||
|
\array_intersect_key(
|
||||||
|
$this->metadatas,
|
||||||
|
\array_flip(\array_unique($metadata))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->computed = true;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function process(array $intersections): array
|
||||||
|
{
|
||||||
|
$result = [];
|
||||||
|
$starts = [];
|
||||||
|
$ends = [];
|
||||||
|
$metadatas = [];
|
||||||
|
|
||||||
|
while (null !== ($current = \array_pop($intersections))) {
|
||||||
|
list($cStart, $cEnd, $cMetadata) = $current;
|
||||||
|
$n = count($cMetadata);
|
||||||
|
|
||||||
|
foreach ($intersections as list($iStart, $iEnd, $iMetadata)) {
|
||||||
|
$start = max($cStart, $iStart);
|
||||||
|
$end = min($cEnd, $iEnd);
|
||||||
|
|
||||||
|
if ($start <= $end) {
|
||||||
|
if (FALSE !== ($key = \array_search($start, $starts))) {
|
||||||
|
if ($ends[$key] === $end) {
|
||||||
|
$metadatas[$key] = \array_unique(\array_merge($metadatas[$key], $iMetadata));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$starts[] = $start;
|
||||||
|
$ends[] = $end;
|
||||||
|
$metadatas[] = \array_unique(\array_merge($iMetadata, $cMetadata));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// recompose results
|
||||||
|
foreach ($starts as $k => $start) {
|
||||||
|
$result[] = [$start, $ends[$k], \array_unique($metadatas[$k])];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function addToIntersections(array $intersections, array $intersection)
|
||||||
|
{
|
||||||
|
$foundExisting = false;
|
||||||
|
list($nStart, $nEnd, $nMetadata) = $intersection;
|
||||||
|
|
||||||
|
\array_walk($intersections,
|
||||||
|
function(&$i, $key) use ($nStart, $nEnd, $nMetadata, $foundExisting) {
|
||||||
|
if ($foundExisting) {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
if ($i[0] === $nStart && $i[1] === $nEnd) {
|
||||||
|
$foundExisting = true;
|
||||||
|
$i[2] = \array_merge($i[2], $nMetadata);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!$foundExisting) {
|
||||||
|
$intersections[] = $intersection;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $intersections;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function hasIntersections(): bool
|
||||||
|
{
|
||||||
|
if (!$this->computed) {
|
||||||
|
throw new \LogicException(sprintf("You cannot call the method %s before ".
|
||||||
|
"'process'", __METHOD));
|
||||||
|
}
|
||||||
|
|
||||||
|
return count($this->intersections) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getIntersections(): array
|
||||||
|
{
|
||||||
|
if (!$this->computed) {
|
||||||
|
throw new \LogicException(sprintf("You cannot call the method %s before ".
|
||||||
|
"'process'", __METHOD));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->intersections;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -17,6 +17,93 @@ components:
|
|||||||
type: integer
|
type: integer
|
||||||
name:
|
name:
|
||||||
type: string
|
type: string
|
||||||
|
Address:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
address_id:
|
||||||
|
type: integer
|
||||||
|
text:
|
||||||
|
type: string
|
||||||
|
postcode:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
name:
|
||||||
|
type: string
|
||||||
|
|
||||||
|
Country:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
id:
|
||||||
|
type: integer
|
||||||
|
name:
|
||||||
|
type: object
|
||||||
|
countryCode:
|
||||||
|
type: string
|
||||||
|
|
||||||
|
PostalCode:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
id:
|
||||||
|
type: integer
|
||||||
|
name:
|
||||||
|
type: string
|
||||||
|
code:
|
||||||
|
type: string
|
||||||
|
country:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
id:
|
||||||
|
type: integer
|
||||||
|
name:
|
||||||
|
type: object
|
||||||
|
countryCode:
|
||||||
|
type: string
|
||||||
|
|
||||||
|
AddressReference:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
id:
|
||||||
|
type: integer
|
||||||
|
refId:
|
||||||
|
type: string
|
||||||
|
street:
|
||||||
|
type: string
|
||||||
|
streetNumber:
|
||||||
|
type: string
|
||||||
|
postcode:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
id:
|
||||||
|
type: integer
|
||||||
|
name:
|
||||||
|
type: string
|
||||||
|
code:
|
||||||
|
type: string
|
||||||
|
country:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
id:
|
||||||
|
type: integer
|
||||||
|
name:
|
||||||
|
type: object
|
||||||
|
countryCode:
|
||||||
|
type: string
|
||||||
|
municipalityCode:
|
||||||
|
type: string
|
||||||
|
source:
|
||||||
|
type: string
|
||||||
|
point:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
type:
|
||||||
|
type: string
|
||||||
|
coordinates:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
type: number
|
||||||
|
minItems: 2
|
||||||
|
maxItems: 2
|
||||||
|
|
||||||
|
|
||||||
paths:
|
paths:
|
||||||
/1.0/search.json:
|
/1.0/search.json:
|
||||||
@@ -55,4 +142,286 @@ paths:
|
|||||||
responses:
|
responses:
|
||||||
200:
|
200:
|
||||||
description: "OK"
|
description: "OK"
|
||||||
|
/1.0/main/address.json:
|
||||||
|
get:
|
||||||
|
tags:
|
||||||
|
- address
|
||||||
|
summary: Return a list of all Chill addresses
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
description: "ok"
|
||||||
|
post:
|
||||||
|
tags:
|
||||||
|
- address
|
||||||
|
summary: create a new address
|
||||||
|
requestBody:
|
||||||
|
required: true
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
buildingName:
|
||||||
|
type: string
|
||||||
|
corridor:
|
||||||
|
type: string
|
||||||
|
distribution:
|
||||||
|
type: string
|
||||||
|
extra:
|
||||||
|
type: string
|
||||||
|
flat:
|
||||||
|
type: string
|
||||||
|
floor:
|
||||||
|
type: string
|
||||||
|
isNoAddress:
|
||||||
|
type: boolean
|
||||||
|
point:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
type: number
|
||||||
|
minItems: 2
|
||||||
|
maxItems: 2
|
||||||
|
postcode:
|
||||||
|
$ref: '#/components/schemas/PostalCode'
|
||||||
|
steps:
|
||||||
|
type: string
|
||||||
|
street:
|
||||||
|
type: string
|
||||||
|
streetNumber:
|
||||||
|
type: string
|
||||||
|
responses:
|
||||||
|
401:
|
||||||
|
description: "Unauthorized"
|
||||||
|
404:
|
||||||
|
description: "Not found"
|
||||||
|
200:
|
||||||
|
description: "OK"
|
||||||
|
422:
|
||||||
|
description: "Unprocessable entity (validation errors)"
|
||||||
|
400:
|
||||||
|
description: "transition cannot be applyed"
|
||||||
|
patch:
|
||||||
|
tags:
|
||||||
|
- address
|
||||||
|
summary: patch an address
|
||||||
|
requestBody:
|
||||||
|
required: true
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
buildingName:
|
||||||
|
type: string
|
||||||
|
corridor:
|
||||||
|
type: string
|
||||||
|
distribution:
|
||||||
|
type: string
|
||||||
|
extra:
|
||||||
|
type: string
|
||||||
|
flat:
|
||||||
|
type: string
|
||||||
|
floor:
|
||||||
|
type: string
|
||||||
|
isNoAddress:
|
||||||
|
type: boolean
|
||||||
|
point:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
type: number
|
||||||
|
minItems: 2
|
||||||
|
maxItems: 2
|
||||||
|
postcode:
|
||||||
|
$ref: '#/components/schemas/PostalCode'
|
||||||
|
steps:
|
||||||
|
type: string
|
||||||
|
street:
|
||||||
|
type: string
|
||||||
|
streetNumber:
|
||||||
|
type: string
|
||||||
|
validFrom:
|
||||||
|
type: string
|
||||||
|
validTo:
|
||||||
|
type: string
|
||||||
|
responses:
|
||||||
|
401:
|
||||||
|
description: "Unauthorized"
|
||||||
|
404:
|
||||||
|
description: "Not found"
|
||||||
|
200:
|
||||||
|
description: "OK"
|
||||||
|
422:
|
||||||
|
description: "Unprocessable entity (validation errors)"
|
||||||
|
400:
|
||||||
|
description: "transition cannot be applyed"
|
||||||
|
|
||||||
|
/1.0/main/address/{id}.json:
|
||||||
|
get:
|
||||||
|
tags:
|
||||||
|
- address
|
||||||
|
summary: Return an address by id
|
||||||
|
parameters:
|
||||||
|
- name: id
|
||||||
|
in: path
|
||||||
|
required: true
|
||||||
|
description: The address id
|
||||||
|
schema:
|
||||||
|
type: integer
|
||||||
|
format: integer
|
||||||
|
minimum: 1
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
description: "ok"
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/Address'
|
||||||
|
404:
|
||||||
|
description: "not found"
|
||||||
|
401:
|
||||||
|
description: "Unauthorized"
|
||||||
|
|
||||||
|
/1.0/main/address-reference.json:
|
||||||
|
get:
|
||||||
|
tags:
|
||||||
|
- address
|
||||||
|
summary: Return a list of all reference addresses
|
||||||
|
parameters:
|
||||||
|
- in: query
|
||||||
|
name: postal_code
|
||||||
|
required: false
|
||||||
|
schema:
|
||||||
|
type: integer
|
||||||
|
description: The id of a postal code to filter the reference addresses
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
description: "ok"
|
||||||
|
/1.0/main/address-reference/{id}.json:
|
||||||
|
get:
|
||||||
|
tags:
|
||||||
|
- address
|
||||||
|
summary: Return a reference address by id
|
||||||
|
parameters:
|
||||||
|
- name: id
|
||||||
|
in: path
|
||||||
|
required: true
|
||||||
|
description: The reference address id
|
||||||
|
schema:
|
||||||
|
type: integer
|
||||||
|
format: integer
|
||||||
|
minimum: 1
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
description: "ok"
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/AddressReference'
|
||||||
|
404:
|
||||||
|
description: "not found"
|
||||||
|
401:
|
||||||
|
description: "Unauthorized"
|
||||||
|
|
||||||
|
/1.0/main/postal-code.json:
|
||||||
|
get:
|
||||||
|
tags:
|
||||||
|
- address
|
||||||
|
summary: Return a list of all postal-code
|
||||||
|
parameters:
|
||||||
|
- in: query
|
||||||
|
name: country
|
||||||
|
required: false
|
||||||
|
schema:
|
||||||
|
type: integer
|
||||||
|
description: The id of a country to filter the postal code
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
description: "ok"
|
||||||
|
post:
|
||||||
|
tags:
|
||||||
|
- address
|
||||||
|
summary: create a new PostalCode
|
||||||
|
requestBody:
|
||||||
|
required: true
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
name:
|
||||||
|
type: string
|
||||||
|
code:
|
||||||
|
type: string
|
||||||
|
country:
|
||||||
|
$ref: '#/components/schemas/Country'
|
||||||
|
responses:
|
||||||
|
401:
|
||||||
|
description: "Unauthorized"
|
||||||
|
404:
|
||||||
|
description: "Not found"
|
||||||
|
200:
|
||||||
|
description: "OK"
|
||||||
|
422:
|
||||||
|
description: "Unprocessable entity (validation errors)"
|
||||||
|
400:
|
||||||
|
description: "transition cannot be applyed"
|
||||||
|
|
||||||
|
/1.0/main/postal-code/{id}.json:
|
||||||
|
get:
|
||||||
|
tags:
|
||||||
|
- address
|
||||||
|
summary: Return a postal code by id
|
||||||
|
parameters:
|
||||||
|
- name: id
|
||||||
|
in: path
|
||||||
|
required: true
|
||||||
|
description: The postal code id
|
||||||
|
schema:
|
||||||
|
type: integer
|
||||||
|
format: integer
|
||||||
|
minimum: 1
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
description: "ok"
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/PostalCode'
|
||||||
|
404:
|
||||||
|
description: "not found"
|
||||||
|
401:
|
||||||
|
description: "Unauthorized"
|
||||||
|
|
||||||
|
/1.0/main/country.json:
|
||||||
|
get:
|
||||||
|
tags:
|
||||||
|
- address
|
||||||
|
summary: Return a list of all countries
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
description: "ok"
|
||||||
|
/1.0/main/country/{id}.json:
|
||||||
|
get:
|
||||||
|
tags:
|
||||||
|
- address
|
||||||
|
summary: Return a country by id
|
||||||
|
parameters:
|
||||||
|
- name: id
|
||||||
|
in: path
|
||||||
|
required: true
|
||||||
|
description: The country id
|
||||||
|
schema:
|
||||||
|
type: integer
|
||||||
|
format: integer
|
||||||
|
minimum: 1
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
description: "ok"
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/Country'
|
||||||
|
404:
|
||||||
|
description: "not found"
|
||||||
|
401:
|
||||||
|
description: "Unauthorized"
|
||||||
|
@@ -56,7 +56,6 @@ module.exports = function(encore, entries)
|
|||||||
// Chill2 new assets
|
// Chill2 new assets
|
||||||
encore.addEntry('forkawesome', __dirname + '/Resources/public/modules/forkawesome/index.js');
|
encore.addEntry('forkawesome', __dirname + '/Resources/public/modules/forkawesome/index.js');
|
||||||
encore.addEntry('bootstrap', __dirname + '/Resources/public/modules/bootstrap/index.js');
|
encore.addEntry('bootstrap', __dirname + '/Resources/public/modules/bootstrap/index.js');
|
||||||
//encore.addEntry('vuejs', __dirname + '/Resources/public/modules/vue/index.js');
|
|
||||||
|
|
||||||
// CKEditor5
|
// CKEditor5
|
||||||
buildCKEditor(encore);
|
buildCKEditor(encore);
|
||||||
|
@@ -58,13 +58,14 @@ services:
|
|||||||
arguments:
|
arguments:
|
||||||
- "@chill.main.helper.translatable_string"
|
- "@chill.main.helper.translatable_string"
|
||||||
- '@Symfony\Component\Routing\Generator\UrlGeneratorInterface'
|
- '@Symfony\Component\Routing\Generator\UrlGeneratorInterface'
|
||||||
- '@chill.main.form.choice_loader.postal_code'
|
- '@Chill\MainBundle\Form\ChoiceLoader\PostalCodeChoiceLoader'
|
||||||
- '@Symfony\Component\Translation\TranslatorInterface'
|
- '@Symfony\Component\Translation\TranslatorInterface'
|
||||||
tags:
|
tags:
|
||||||
- { name: form.type }
|
- { name: form.type }
|
||||||
|
|
||||||
chill.main.form.choice_loader.postal_code:
|
Chill\MainBundle\Form\ChoiceLoader\PostalCodeChoiceLoader:
|
||||||
class: Chill\MainBundle\Form\ChoiceLoader\PostalCodeChoiceLoader
|
autowire: true
|
||||||
|
autoconfigure: true
|
||||||
|
|
||||||
chill.main.form.type.export:
|
chill.main.form.type.export:
|
||||||
class: Chill\MainBundle\Form\Type\Export\ExportType
|
class: Chill\MainBundle\Form\Type\Export\ExportType
|
||||||
|
@@ -5,6 +5,5 @@ services:
|
|||||||
Chill\MainBundle\Search\SearchProvider: '@chill_main.search_provider'
|
Chill\MainBundle\Search\SearchProvider: '@chill_main.search_provider'
|
||||||
|
|
||||||
Chill\MainBundle\Search\SearchApi:
|
Chill\MainBundle\Search\SearchApi:
|
||||||
arguments:
|
autowire: true
|
||||||
$em: '@Doctrine\ORM\EntityManagerInterface'
|
autoconfigure: true
|
||||||
$search: '@Chill\MainBundle\Search\SearchProvider'
|
|
||||||
|
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Chill\Migrations\Main;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
use Doctrine\Migrations\AbstractMigration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auto-generated Migration: Please modify to your needs!
|
||||||
|
*/
|
||||||
|
final class Version20210616134328 extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function getDescription(): string
|
||||||
|
{
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function up(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->addSql('ALTER TABLE chill_main_postal_code ADD origin INT DEFAULT NULL');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->addSql('ALTER TABLE chill_main_postal_code DROP origin');
|
||||||
|
}
|
||||||
|
}
|
@@ -6,6 +6,7 @@ use Chill\MainBundle\CRUD\Controller\ApiController;
|
|||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||||
|
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWork;
|
||||||
use Symfony\Component\HttpFoundation\Exception\BadRequestException;
|
use Symfony\Component\HttpFoundation\Exception\BadRequestException;
|
||||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||||
@@ -116,6 +117,20 @@ $workflow = $this->registry->get($accompanyingPeriod);
|
|||||||
return $this->addRemoveSomething('socialissue', $id, $request, $_format, 'socialIssue', SocialIssue::class, [ 'groups' => [ 'read' ] ]);
|
return $this->addRemoveSomething('socialissue', $id, $request, $_format, 'socialIssue', SocialIssue::class, [ 'groups' => [ 'read' ] ]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function workApi($id, Request $request, string $_format): Response
|
||||||
|
{
|
||||||
|
return $this->addRemoveSomething(
|
||||||
|
'work',
|
||||||
|
$id,
|
||||||
|
$request,
|
||||||
|
$_format,
|
||||||
|
'work',
|
||||||
|
AccompanyingPeriodWork::class,
|
||||||
|
[ 'groups' => [ 'accompanying_period_work:create' ] ],
|
||||||
|
true // force persist
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public function requestorApi($id, Request $request, string $_format): Response
|
public function requestorApi($id, Request $request, string $_format): Response
|
||||||
{
|
{
|
||||||
/** @var AccompanyingPeriod $accompanyingPeriod */
|
/** @var AccompanyingPeriod $accompanyingPeriod */
|
||||||
|
@@ -2,10 +2,12 @@
|
|||||||
|
|
||||||
namespace Chill\PersonBundle\Controller;
|
namespace Chill\PersonBundle\Controller;
|
||||||
|
|
||||||
|
use Chill\ActivityBundle\Entity\Activity;
|
||||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||||
use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation;
|
use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation;
|
||||||
use Chill\PersonBundle\Privacy\AccompanyingPeriodPrivacyEvent;
|
use Chill\PersonBundle\Privacy\AccompanyingPeriodPrivacyEvent;
|
||||||
use Chill\PersonBundle\Entity\Person;
|
use Chill\PersonBundle\Entity\Person;
|
||||||
|
use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkRepository;
|
||||||
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
|
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
|
||||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||||
@@ -34,14 +36,18 @@ class AccompanyingCourseController extends Controller
|
|||||||
|
|
||||||
protected ValidatorInterface $validator;
|
protected ValidatorInterface $validator;
|
||||||
|
|
||||||
|
private AccompanyingPeriodWorkRepository $workRepository;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
SerializerInterface $serializer,
|
SerializerInterface $serializer,
|
||||||
EventDispatcherInterface $dispatcher,
|
EventDispatcherInterface $dispatcher,
|
||||||
ValidatorInterface $validator
|
ValidatorInterface $validator,
|
||||||
|
AccompanyingPeriodWorkRepository $workRepository
|
||||||
) {
|
) {
|
||||||
$this->serializer = $serializer;
|
$this->serializer = $serializer;
|
||||||
$this->dispatcher = $dispatcher;
|
$this->dispatcher = $dispatcher;
|
||||||
$this->validator = $validator;
|
$this->validator = $validator;
|
||||||
|
$this->workRepository = $workRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -86,8 +92,32 @@ class AccompanyingCourseController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function indexAction(AccompanyingPeriod $accompanyingCourse): Response
|
public function indexAction(AccompanyingPeriod $accompanyingCourse): Response
|
||||||
{
|
{
|
||||||
|
// compute some warnings
|
||||||
|
// get persons without household
|
||||||
|
$withoutHousehold = [];
|
||||||
|
foreach ($accompanyingCourse->getParticipations() as
|
||||||
|
$p) {
|
||||||
|
if (FALSE === $p->getPerson()->isSharingHousehold()) {
|
||||||
|
$withoutHousehold[] = $p->getPerson();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$activities = $this->getDoctrine()->getManager()->getRepository(Activity::class)->findBy(
|
||||||
|
['accompanyingPeriod' => $accompanyingCourse],
|
||||||
|
['date' => 'DESC'],
|
||||||
|
);
|
||||||
|
|
||||||
|
$works = $this->workRepository->findByAccompanyingPeriod(
|
||||||
|
$accompanyingCourse,
|
||||||
|
['startDate' => 'DESC', 'endDate' => 'DESC'],
|
||||||
|
3
|
||||||
|
);
|
||||||
|
|
||||||
return $this->render('@ChillPerson/AccompanyingCourse/index.html.twig', [
|
return $this->render('@ChillPerson/AccompanyingCourse/index.html.twig', [
|
||||||
'accompanyingCourse' => $accompanyingCourse
|
'accompanyingCourse' => $accompanyingCourse,
|
||||||
|
'withoutHousehold' => $withoutHousehold,
|
||||||
|
'works' => $works,
|
||||||
|
'activities' => $activities
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Chill\PersonBundle\Controller;
|
||||||
|
|
||||||
|
use Chill\MainBundle\CRUD\Controller\ApiController;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
|
||||||
|
class AccompanyingCourseWorkApiController extends ApiController
|
||||||
|
{
|
||||||
|
protected function getContextForSerialization(string $action, Request $request, string $_format, $entity): array
|
||||||
|
{
|
||||||
|
switch($action) {
|
||||||
|
case '_entity':
|
||||||
|
switch ($request->getMethod()) {
|
||||||
|
case Request::METHOD_PUT:
|
||||||
|
return [ 'groups' => [ 'accompanying_period_work:edit' ] ];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return parent::getContextForSerialization($action, $request, $_format, $entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,109 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Chill\PersonBundle\Controller;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Pagination\PaginatorFactory;
|
||||||
|
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||||
|
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWork;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\Routing\Annotation\Route;
|
||||||
|
use Symfony\Component\Serializer\SerializerInterface;
|
||||||
|
use Symfony\Component\Translation\TranslatorInterface;
|
||||||
|
use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkRepository;
|
||||||
|
|
||||||
|
class AccompanyingCourseWorkController extends AbstractController
|
||||||
|
{
|
||||||
|
private TranslatorInterface $trans;
|
||||||
|
private SerializerInterface $serializer;
|
||||||
|
private AccompanyingPeriodWorkRepository $workRepository;
|
||||||
|
private PaginatorFactory $paginator;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
TranslatorInterface $trans,
|
||||||
|
SerializerInterface $serializer,
|
||||||
|
AccompanyingPeriodWorkRepository $workRepository,
|
||||||
|
PaginatorFactory $paginator
|
||||||
|
) {
|
||||||
|
$this->trans = $trans;
|
||||||
|
$this->serializer = $serializer;
|
||||||
|
$this->workRepository = $workRepository;
|
||||||
|
$this->paginator = $paginator;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Route(
|
||||||
|
* "{_locale}/person/accompanying-period/{id}/work/new",
|
||||||
|
* name="chill_person_accompanying_period_work_new",
|
||||||
|
* methods={"GET"}
|
||||||
|
* )
|
||||||
|
*/
|
||||||
|
public function createWork(AccompanyingPeriod $period): Response
|
||||||
|
{
|
||||||
|
// TODO ACL
|
||||||
|
|
||||||
|
if ($period->getSocialIssues()->count() === 0) {
|
||||||
|
$this->addFlash('error', $this->trans->trans(
|
||||||
|
"accompanying_work.You must add at least ".
|
||||||
|
"one social issue on accompanying period")
|
||||||
|
);
|
||||||
|
|
||||||
|
return $this->redirectToRoute('chill_person_accompanying_course_index', [
|
||||||
|
'accompanying_period_id' => $period->getId()
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$json = $this->serializer->normalize($period, 'json', [ "groups" => [ "read" ]]);
|
||||||
|
|
||||||
|
return $this->render('@ChillPerson/AccompanyingCourseWork/create.html.twig', [
|
||||||
|
'accompanyingCourse' => $period,
|
||||||
|
'json' => $json
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Route(
|
||||||
|
* "{_locale}/person/accompanying-period/work/{id}/edit",
|
||||||
|
* name="chill_person_accompanying_period_work_edit",
|
||||||
|
* methods={"GET"}
|
||||||
|
* )
|
||||||
|
*/
|
||||||
|
public function editWork(AccompanyingPeriodWork $work): Response
|
||||||
|
{
|
||||||
|
// TODO ACL
|
||||||
|
$json = $this->serializer->normalize($work, 'json', [ "groups" => [ "read" ] ]);
|
||||||
|
return $this->render('@ChillPerson/AccompanyingCourseWork/edit.html.twig', [
|
||||||
|
'accompanyingCourse' => $work->getAccompanyingPeriod(),
|
||||||
|
'work' => $work,
|
||||||
|
'json' => $json
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Route(
|
||||||
|
* "{_locale}/person/accompanying-period/{id}/work",
|
||||||
|
* name="chill_person_accompanying_period_work_list",
|
||||||
|
* methods={"GET"}
|
||||||
|
* )
|
||||||
|
*/
|
||||||
|
public function listWorkByAccompanyingPeriod(AccompanyingPeriod $period): Response
|
||||||
|
{
|
||||||
|
// TODO ACL
|
||||||
|
$totalItems = $this->workRepository->countByAccompanyingPeriod($period);
|
||||||
|
$paginator = $this->paginator->create($totalItems);
|
||||||
|
|
||||||
|
$works = $this->workRepository->findByAccompanyingPeriod(
|
||||||
|
$period,
|
||||||
|
['startDate' => 'DESC', 'endDate' => 'DESC'],
|
||||||
|
$paginator->getItemsPerPage(),
|
||||||
|
$paginator->getCurrentPageFirstItemNumber()
|
||||||
|
);
|
||||||
|
|
||||||
|
return $this->render('@ChillPerson/AccompanyingCourseWork/list_by_accompanying_period.html.twig', [
|
||||||
|
'accompanyingCourse' => $period,
|
||||||
|
'works' => $works,
|
||||||
|
'paginator' => $paginator
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
@@ -75,8 +75,10 @@ class AccompanyingPeriodController extends AbstractController
|
|||||||
]);
|
]);
|
||||||
$this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event);
|
$this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event);
|
||||||
|
|
||||||
|
$accompanyingPeriods = $person->getAccompanyingPeriodsOrdered();
|
||||||
|
|
||||||
return $this->render('ChillPersonBundle:AccompanyingPeriod:list.html.twig', [
|
return $this->render('ChillPersonBundle:AccompanyingPeriod:list.html.twig', [
|
||||||
'accompanying_periods' => $person->getAccompanyingPeriodsOrdered(),
|
'accompanying_periods' => $accompanyingPeriods,
|
||||||
'person' => $person
|
'person' => $person
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Chill\PersonBundle\Controller;
|
||||||
|
|
||||||
|
use Chill\MainBundle\CRUD\Controller\ApiController;
|
||||||
|
use Chill\MainBundle\Entity\Address;
|
||||||
|
use Chill\MainBundle\Serializer\Model\Collection;
|
||||||
|
use Chill\PersonBundle\Entity\Person;
|
||||||
|
use Chill\PersonBundle\Repository\Household\HouseholdRepository;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
||||||
|
|
||||||
|
class HouseholdApiController extends ApiController
|
||||||
|
{
|
||||||
|
private HouseholdRepository $householdRepository;
|
||||||
|
|
||||||
|
public function __construct(HouseholdRepository $householdRepository)
|
||||||
|
{
|
||||||
|
$this->householdRepository = $householdRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function householdAddressApi($id, Request $request, string $_format): Response
|
||||||
|
{
|
||||||
|
return $this->addRemoveSomething('address', $id, $request, $_format, 'address', Address::class, [ 'groups' => [ 'read' ] ]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find Household of people participating to the same AccompanyingPeriod
|
||||||
|
*
|
||||||
|
* @ParamConverter("person", options={"id" = "person_id"})
|
||||||
|
*/
|
||||||
|
public function suggestHouseholdByAccompanyingPeriodParticipationApi(Person $person, string $_format)
|
||||||
|
{
|
||||||
|
// TODO add acl
|
||||||
|
|
||||||
|
$count = $this->householdRepository->countByAccompanyingPeriodParticipation($person);
|
||||||
|
$paginator = $this->getPaginatorFactory()->create($count);
|
||||||
|
|
||||||
|
if ($count === 0) {
|
||||||
|
$households = [];
|
||||||
|
} else {
|
||||||
|
$households = $this->householdRepository->findByAccompanyingPeriodParticipation($person,
|
||||||
|
$paginator->getItemsPerPage(), $paginator->getCurrentPageFirstItemNumber());
|
||||||
|
}
|
||||||
|
|
||||||
|
$collection = new Collection($households, $paginator);
|
||||||
|
|
||||||
|
return $this->json($collection, Response::HTTP_OK, [],
|
||||||
|
[ "groups" => ["read"]]);
|
||||||
|
}
|
||||||
|
}
|
@@ -2,19 +2,35 @@
|
|||||||
|
|
||||||
namespace Chill\PersonBundle\Controller;
|
namespace Chill\PersonBundle\Controller;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Entity\Address;
|
||||||
|
use Chill\PersonBundle\Form\HouseholdType;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
use Symfony\Component\Form\FormInterface;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\Routing\Annotation\Route;
|
use Symfony\Component\Routing\Annotation\Route;
|
||||||
|
use Symfony\Component\Translation\TranslatorInterface;
|
||||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
||||||
use Chill\PersonBundle\Entity\Household\Household;
|
use Chill\PersonBundle\Entity\Household\Household;
|
||||||
use Chill\PersonBundle\Entity\Household\Position;
|
use Chill\PersonBundle\Entity\Household\Position;
|
||||||
|
use Chill\PersonBundle\Repository\Household\PositionRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Route("/{_locale}/person/household")
|
* @Route("/{_locale}/person/household")
|
||||||
*/
|
*/
|
||||||
class HouseholdController extends AbstractController
|
class HouseholdController extends AbstractController
|
||||||
{
|
{
|
||||||
|
private TranslatorInterface $translator;
|
||||||
|
|
||||||
|
private PositionRepository $positionRepository;
|
||||||
|
|
||||||
|
public function __construct(TranslatorInterface $translator, PositionRepository $positionRepository)
|
||||||
|
|
||||||
|
{
|
||||||
|
$this->translator = $translator;
|
||||||
|
$this->positionRepository = $positionRepository;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Route(
|
* @Route(
|
||||||
* "/{household_id}/summary",
|
* "/{household_id}/summary",
|
||||||
@@ -27,48 +43,26 @@ class HouseholdController extends AbstractController
|
|||||||
{
|
{
|
||||||
// TODO ACL
|
// TODO ACL
|
||||||
|
|
||||||
$positions = $this->getDoctrine()->getManager()
|
$positions = $this->positionRepository
|
||||||
->getRepository(Position::class)
|
->findByActiveOrdered()
|
||||||
->findAll()
|
|
||||||
;
|
;
|
||||||
|
|
||||||
// little performance improvement:
|
// little performance improvement:
|
||||||
// initialize members collection, which will avoid
|
// initialize members collection, which will avoid
|
||||||
// some queries
|
// some queries
|
||||||
$household->getMembers()->initialize();
|
$household->getMembers()->initialize();
|
||||||
|
|
||||||
|
if ($request->query->has('edit')) {
|
||||||
|
$form = $this->createMetadataForm($household);
|
||||||
|
} else {
|
||||||
|
$form = null;
|
||||||
|
}
|
||||||
|
|
||||||
return $this->render('@ChillPerson/Household/summary.html.twig',
|
return $this->render('@ChillPerson/Household/summary.html.twig',
|
||||||
[
|
[
|
||||||
'household' => $household,
|
'household' => $household,
|
||||||
'positions' => $positions
|
'positions' => $positions,
|
||||||
]
|
'form' => NULL !== $form ? $form->createView() : null,
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Route(
|
|
||||||
* "/{household_id}/members",
|
|
||||||
* name="chill_person_household_members",
|
|
||||||
* methods={"GET", "HEAD"}
|
|
||||||
* )
|
|
||||||
* @ParamConverter("household", options={"id" = "household_id"})
|
|
||||||
*/
|
|
||||||
public function members(Request $request, Household $household)
|
|
||||||
{
|
|
||||||
// TODO ACL
|
|
||||||
$positions = $this->getDoctrine()->getManager()
|
|
||||||
->getRepository(Position::class)
|
|
||||||
->findAll()
|
|
||||||
;
|
|
||||||
|
|
||||||
// little performance improvement:
|
|
||||||
// initialize members collection, which will avoid
|
|
||||||
// some queries
|
|
||||||
$household->getMembers()->initialize();
|
|
||||||
|
|
||||||
return $this->render('@ChillPerson/Household/members.html.twig',
|
|
||||||
[
|
|
||||||
'household' => $household,
|
|
||||||
'positions' => $positions
|
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -84,6 +78,16 @@ class HouseholdController extends AbstractController
|
|||||||
public function addresses(Request $request, Household $household)
|
public function addresses(Request $request, Household $household)
|
||||||
{
|
{
|
||||||
// TODO ACL
|
// TODO ACL
|
||||||
|
|
||||||
|
//TODO put these lines into a validator constraint on household->getAddress
|
||||||
|
$addresses = $household->getAddresses();
|
||||||
|
$cond = True;
|
||||||
|
for ($i=0; $i < count($addresses) - 1; $i++) {
|
||||||
|
if ($addresses[$i]->getValidFrom() != $addresses[$i + 1]->getValidTo()) {
|
||||||
|
$cond = False;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $this->render('@ChillPerson/Household/addresses.html.twig',
|
return $this->render('@ChillPerson/Household/addresses.html.twig',
|
||||||
[
|
[
|
||||||
'household' => $household
|
'household' => $household
|
||||||
@@ -91,6 +95,7 @@ class HouseholdController extends AbstractController
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Route(
|
* @Route(
|
||||||
* "/{household_id}/address/move",
|
* "/{household_id}/address/move",
|
||||||
@@ -102,10 +107,83 @@ class HouseholdController extends AbstractController
|
|||||||
public function addressMove(Request $request, Household $household)
|
public function addressMove(Request $request, Household $household)
|
||||||
{
|
{
|
||||||
// TODO ACL
|
// TODO ACL
|
||||||
|
|
||||||
return $this->render('@ChillPerson/Household/address_move.html.twig',
|
return $this->render('@ChillPerson/Household/address_move.html.twig',
|
||||||
[
|
[
|
||||||
'household' => $household
|
'household' => $household
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Route(
|
||||||
|
* "/{household_id}/address/edit",
|
||||||
|
* name="chill_person_household_address_edit",
|
||||||
|
* methods={"GET", "HEAD", "POST"}
|
||||||
|
* )
|
||||||
|
* @ParamConverter("household", options={"id" = "household_id"})
|
||||||
|
*/
|
||||||
|
public function addressEdit(Request $request, Household $household)
|
||||||
|
{
|
||||||
|
// TODO ACL
|
||||||
|
//$address = $this->findAddressById($household, $address_id); //TODO
|
||||||
|
|
||||||
|
|
||||||
|
return $this->render('@ChillPerson/Household/address_edit.html.twig',
|
||||||
|
[
|
||||||
|
'household' => $household,
|
||||||
|
//'address' => $address,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Route(
|
||||||
|
* "/{household_id}/members/metadata/edit",
|
||||||
|
* name="chill_person_household_members_metadata_edit",
|
||||||
|
* methods={"GET", "POST"}
|
||||||
|
* )
|
||||||
|
* @ParamConverter("household", options={"id" = "household_id"})
|
||||||
|
*/
|
||||||
|
public function editHouseholdMetadata(Request $request, Household $household)
|
||||||
|
{
|
||||||
|
// TODO ACL
|
||||||
|
$form = $this->createMetadataForm($household);
|
||||||
|
|
||||||
|
$form->handleRequest($request);
|
||||||
|
|
||||||
|
if ($form->isSubmitted() and $form->isValid()) {
|
||||||
|
$this->getDoctrine()->getManager()->flush();
|
||||||
|
|
||||||
|
$this->addFlash('success', $this->translator->trans('household.data_saved'));
|
||||||
|
|
||||||
|
return $this->redirectToRoute('chill_person_household_summary', [
|
||||||
|
'household_id' => $household->getId()
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->render('@ChillPerson/Household/edit_member_metadata.html.twig', [
|
||||||
|
'household' => $household,
|
||||||
|
'form' => $form->createView()
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createMetadataForm(Household $household): FormInterface
|
||||||
|
{
|
||||||
|
$form = $this->createForm(
|
||||||
|
HouseholdType::class,
|
||||||
|
$household,
|
||||||
|
[
|
||||||
|
'action' => $this->generateUrl(
|
||||||
|
'chill_person_household_members_metadata_edit',
|
||||||
|
[
|
||||||
|
'household_id' => $household->getId()
|
||||||
|
]
|
||||||
|
)
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
return $form;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -3,6 +3,7 @@
|
|||||||
namespace Chill\PersonBundle\Controller;
|
namespace Chill\PersonBundle\Controller;
|
||||||
|
|
||||||
use Chill\PersonBundle\Entity\Household\Position;
|
use Chill\PersonBundle\Entity\Household\Position;
|
||||||
|
use Chill\PersonBundle\Repository\AccompanyingPeriodRepository;
|
||||||
use Chill\PersonBundle\Security\Authorization\PersonVoter;
|
use Chill\PersonBundle\Security\Authorization\PersonVoter;
|
||||||
use Chill\PersonBundle\Entity\Person;
|
use Chill\PersonBundle\Entity\Person;
|
||||||
use Chill\PersonBundle\Entity\Household\Household;
|
use Chill\PersonBundle\Entity\Household\Household;
|
||||||
@@ -25,11 +26,17 @@ class HouseholdMemberController extends ApiController
|
|||||||
|
|
||||||
private TranslatorInterface $translator;
|
private TranslatorInterface $translator;
|
||||||
|
|
||||||
|
private AccompanyingPeriodRepository $periodRepository;
|
||||||
|
|
||||||
public function __construct(UrlGeneratorInterface $generator, TranslatorInterface $translator)
|
public function __construct(
|
||||||
|
UrlGeneratorInterface $generator,
|
||||||
|
TranslatorInterface $translator,
|
||||||
|
AccompanyingPeriodRepository $periodRepository
|
||||||
|
)
|
||||||
{
|
{
|
||||||
$this->generator = $generator;
|
$this->generator = $generator;
|
||||||
$this->translator = $translator;
|
$this->translator = $translator;
|
||||||
|
$this->periodRepository = $periodRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -50,8 +57,12 @@ class HouseholdMemberController extends ApiController
|
|||||||
|
|
||||||
// TODO ACL
|
// TODO ACL
|
||||||
//
|
//
|
||||||
// TODO validation
|
$errors = $editor->validate();
|
||||||
//
|
|
||||||
|
if (count($errors) > 0) {
|
||||||
|
return $this->json($errors, 422);
|
||||||
|
}
|
||||||
|
|
||||||
$em = $this->getDoctrine()->getManager();
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
|
||||||
// if new household, persist it
|
// if new household, persist it
|
||||||
@@ -140,8 +151,23 @@ class HouseholdMemberController extends ApiController
|
|||||||
'allowLeaveWithoutHousehold' => $allowLeaveWithoutHousehold ?? $request->query->has('allow_leave_without_household'),
|
'allowLeaveWithoutHousehold' => $allowLeaveWithoutHousehold ?? $request->query->has('allow_leave_without_household'),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// context
|
||||||
|
if ($request->query->has('accompanying_period_id')) {
|
||||||
|
$period = $this->periodRepository->find(
|
||||||
|
$request->query->getInt('accompanying_period_id')
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($period === null) {
|
||||||
|
throw $this->createNotFoundException('period not found');
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO add acl on accompanying Course
|
||||||
|
}
|
||||||
|
|
||||||
return $this->render('@ChillPerson/Household/members_editor.html.twig', [
|
return $this->render('@ChillPerson/Household/members_editor.html.twig', [
|
||||||
'data' => $data
|
'data' => $data,
|
||||||
|
'expandSuggestions' => (int) $request->query->getBoolean('expand_suggestions', false),
|
||||||
|
'accompanyingCourse' => $period ?? null,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,7 +181,9 @@ class HouseholdMemberController extends ApiController
|
|||||||
{
|
{
|
||||||
// TODO ACL
|
// TODO ACL
|
||||||
|
|
||||||
$form = $this->createForm(HouseholdMemberType::class, $member);
|
$form = $this->createForm(HouseholdMemberType::class, $member, [
|
||||||
|
'validation_groups' => [ 'household_memberships' ]
|
||||||
|
]);
|
||||||
$form->handleRequest($request);
|
$form->handleRequest($request);
|
||||||
|
|
||||||
if ($form->isSubmitted() && $form->isValid()) {
|
if ($form->isSubmitted() && $form->isValid()) {
|
||||||
@@ -167,7 +195,7 @@ class HouseholdMemberController extends ApiController
|
|||||||
|
|
||||||
return $this->redirect(
|
return $this->redirect(
|
||||||
$request->get('returnPath', null) ??
|
$request->get('returnPath', null) ??
|
||||||
$this->generator->generate('chill_person_household_members', [ 'household_id' =>
|
$this->generator->generate('chill_person_household_summary', [ 'household_id' =>
|
||||||
$member->getHousehold()->getId() ])
|
$member->getHousehold()->getId() ])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -297,18 +297,16 @@ class PersonAddressController extends AbstractController
|
|||||||
*/
|
*/
|
||||||
protected function findAddressById(Person $person, $address_id)
|
protected function findAddressById(Person $person, $address_id)
|
||||||
{
|
{
|
||||||
// filtering address
|
$address = $this->getDoctrine()->getManager()
|
||||||
$criteria = Criteria::create()
|
->getRepository(Address::class)
|
||||||
->where(Criteria::expr()->eq('id', $address_id))
|
->find($address_id)
|
||||||
->setMaxResults(1);
|
;
|
||||||
$addresses = $person->getAddresses()->matching($criteria);
|
|
||||||
|
|
||||||
if (count($addresses) === 0) {
|
if (!$person->getAddresses()->contains($address)) {
|
||||||
throw $this->createNotFoundException("Address with id $address_id "
|
throw $this->createAccessDeniedException("Not allowed to see this address");
|
||||||
. "matching person $person_id not found ");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $addresses->first();
|
return $address;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -22,7 +22,8 @@ use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
|||||||
use Symfony\Component\Security\Core\Role\Role;
|
use Symfony\Component\Security\Core\Role\Role;
|
||||||
use Chill\MainBundle\CRUD\Controller\ApiController;
|
use Chill\MainBundle\CRUD\Controller\ApiController;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Chill\MainBundle\Entity\Address;
|
||||||
|
|
||||||
class PersonApiController extends ApiController
|
class PersonApiController extends ApiController
|
||||||
{
|
{
|
||||||
@@ -47,4 +48,10 @@ class PersonApiController extends ApiController
|
|||||||
|
|
||||||
return $person;
|
return $person;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function personAddressApi($id, Request $request, string $_format): Response
|
||||||
|
{
|
||||||
|
return $this->addRemoveSomething('address', $id, $request, $_format, 'address', Address::class, [ 'groups' => [ 'read' ] ]);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -41,6 +41,8 @@ use Chill\PersonBundle\Config\ConfigPersonAltNamesHelper;
|
|||||||
use Chill\PersonBundle\Repository\PersonNotDuplicateRepository;
|
use Chill\PersonBundle\Repository\PersonNotDuplicateRepository;
|
||||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
use Symfony\Component\Routing\Annotation\Route;
|
||||||
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
||||||
|
|
||||||
final class PersonController extends AbstractController
|
final class PersonController extends AbstractController
|
||||||
{
|
{
|
||||||
@@ -416,4 +418,29 @@ final class PersonController extends AbstractController
|
|||||||
|
|
||||||
return $person;
|
return $person;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @Route(
|
||||||
|
* "/{_locale}/person/household/{person_id}/history",
|
||||||
|
* name="chill_person_household_person_history",
|
||||||
|
* methods={"GET", "POST"}
|
||||||
|
* )
|
||||||
|
* @ParamConverter("person", options={"id" = "person_id"})
|
||||||
|
*/
|
||||||
|
public function householdHistoryByPerson(Request $request, Person $person): Response
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person,
|
||||||
|
"You are not allowed to see this person.");
|
||||||
|
|
||||||
|
$event = new PrivacyEvent($person);
|
||||||
|
$this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event);
|
||||||
|
|
||||||
|
return $this->render(
|
||||||
|
'@ChillPerson/Person/household_history.html.twig',
|
||||||
|
[
|
||||||
|
'person' => $person
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Chill\PersonBundle\Controller;
|
||||||
|
|
||||||
|
use Chill\MainBundle\CRUD\Controller\ApiController;
|
||||||
|
use Chill\MainBundle\Pagination\PaginatorInterface;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
|
||||||
|
class SocialIssueApiController extends ApiController
|
||||||
|
{
|
||||||
|
protected function customizeQuery(string $action, Request $request, $query): void
|
||||||
|
{
|
||||||
|
$query->where(
|
||||||
|
$query->expr()->orX(
|
||||||
|
$query->expr()->gt('e.desactivationDate', ':now'),
|
||||||
|
$query->expr()->isNull('e.desactivationDate')
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$query->setParameter('now', new \DateTimeImmutable());
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Chill\PersonBundle\Controller;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Pagination\PaginatorFactory;
|
||||||
|
use Chill\MainBundle\Serializer\Model\Collection;
|
||||||
|
use Chill\PersonBundle\Entity\SocialWork\SocialAction;
|
||||||
|
use Chill\PersonBundle\Entity\SocialWork\Goal;
|
||||||
|
use Chill\PersonBundle\Repository\SocialWork\GoalRepository;
|
||||||
|
use Chill\MainBundle\CRUD\Controller\ApiController;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
|
||||||
|
class SocialWorkGoalApiController extends ApiController
|
||||||
|
{
|
||||||
|
private GoalRepository $goalRepository;
|
||||||
|
|
||||||
|
private PaginatorFactory $paginator;
|
||||||
|
|
||||||
|
|
||||||
|
public function __construct(GoalRepository $goalRepository, PaginatorFactory $paginator)
|
||||||
|
{
|
||||||
|
$this->goalRepository = $goalRepository;
|
||||||
|
$this->paginator = $paginator;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function listBySocialAction(Request $request, SocialAction $action): Response
|
||||||
|
{
|
||||||
|
$totalItems = $this->goalRepository->countBySocialActionWithDescendants($action);
|
||||||
|
$paginator = $this->getPaginatorFactory()->create($totalItems);
|
||||||
|
|
||||||
|
$entities = $this->goalRepository->findBySocialActionWithDescendants($action, ["id" => "ASC"],
|
||||||
|
$paginator->getItemsPerPage(), $paginator->getCurrentPageFirstItemNumber());
|
||||||
|
|
||||||
|
$model = new Collection($entities, $paginator);
|
||||||
|
|
||||||
|
return $this->json($model, Response::HTTP_OK, [], [ "groups" => [ "read" ]]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Chill\PersonBundle\Controller;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Serializer\Model\Collection;
|
||||||
|
use Chill\PersonBundle\Entity\SocialWork\SocialAction;
|
||||||
|
use Chill\PersonBundle\Entity\SocialWork\Goal;
|
||||||
|
use Chill\PersonBundle\Repository\SocialWork\ResultRepository;
|
||||||
|
use Chill\MainBundle\CRUD\Controller\ApiController;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
|
||||||
|
class SocialWorkResultApiController extends ApiController
|
||||||
|
{
|
||||||
|
private ResultRepository $resultRepository;
|
||||||
|
|
||||||
|
public function __construct(ResultRepository $resultRepository)
|
||||||
|
{
|
||||||
|
$this->resultRepository = $resultRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function listBySocialAction(Request $request, SocialAction $action): Response
|
||||||
|
{
|
||||||
|
$totalItems = $this->resultRepository->countBySocialActionWithDescendants($action);
|
||||||
|
$paginator = $this->getPaginatorFactory()->create($totalItems);
|
||||||
|
|
||||||
|
$entities = $this->resultRepository->findBySocialActionWithDescendants($action, ["id" => "ASC"],
|
||||||
|
$paginator->getItemsPerPage(), $paginator->getCurrentPageFirstItemNumber());
|
||||||
|
|
||||||
|
$model = new Collection($entities, $paginator);
|
||||||
|
|
||||||
|
return $this->json($model, Response::HTTP_OK, [], [ "groups" => [ "read" ]]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function listByGoal(Request $request, Goal $goal): Response
|
||||||
|
{
|
||||||
|
$totalItems = $this->resultRepository->countByGoal($goal);
|
||||||
|
$paginator = $this->getPaginatorFactory()->create($totalItems);
|
||||||
|
|
||||||
|
$entities = $this->resultRepository->findByGoal($goal, ["id" => "ASC"],
|
||||||
|
$paginator->getItemsPerPage(), $paginator->getCurrentPageFirstItemNumber());
|
||||||
|
|
||||||
|
$model = new Collection($entities, $paginator);
|
||||||
|
|
||||||
|
return $this->json($model, Response::HTTP_OK, [], [ "groups" => [ "read" ]]);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Chill\PersonBundle\Controller;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Serializer\Model\Collection;
|
||||||
|
use Chill\MainBundle\Pagination\PaginatorFactory;
|
||||||
|
use Chill\PersonBundle\Repository\SocialWork\SocialIssueRepository;
|
||||||
|
use Chill\MainBundle\CRUD\Controller\ApiController;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
|
|
||||||
|
class SocialWorkSocialActionApiController extends ApiController
|
||||||
|
{
|
||||||
|
private SocialIssueRepository $socialIssueRepository;
|
||||||
|
|
||||||
|
private PaginatorFactory $paginator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param SocialIssueRepository $socialIssueRepository
|
||||||
|
*/
|
||||||
|
public function __construct(SocialIssueRepository $socialIssueRepository, PaginatorFactory $paginator)
|
||||||
|
{
|
||||||
|
$this->socialIssueRepository = $socialIssueRepository;
|
||||||
|
$this->paginator = $paginator;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function listBySocialIssueApi($id, Request $request)
|
||||||
|
{
|
||||||
|
$socialIssue = $this->socialIssueRepository
|
||||||
|
->find($id);
|
||||||
|
|
||||||
|
if (NULL === $socialIssue) {
|
||||||
|
throw $this->createNotFoundException("socialIssue not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
$socialActions = $socialIssue->getRecursiveSocialActions();
|
||||||
|
$pagination = $this->paginator->create(count($socialActions));
|
||||||
|
// max one page
|
||||||
|
$pagination->setItemsPerPage(count($socialActions));
|
||||||
|
|
||||||
|
$collection = new Collection($socialActions, $pagination);
|
||||||
|
|
||||||
|
|
||||||
|
return $this->json($collection, JsonResponse::HTTP_OK, [], [ "groups" => [ "read" ]]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -4,11 +4,15 @@ namespace Chill\PersonBundle\DataFixtures\ORM;
|
|||||||
|
|
||||||
use Chill\PersonBundle\Entity\Person;
|
use Chill\PersonBundle\Entity\Person;
|
||||||
use Chill\PersonBundle\Entity\Household\Household;
|
use Chill\PersonBundle\Entity\Household\Household;
|
||||||
|
use Chill\MainBundle\Entity\PostalCode;
|
||||||
|
use Chill\MainBundle\Entity\Address;
|
||||||
use Chill\PersonBundle\Household\MembersEditorFactory;
|
use Chill\PersonBundle\Household\MembersEditorFactory;
|
||||||
use Doctrine\Bundle\FixturesBundle\Fixture;
|
use Doctrine\Bundle\FixturesBundle\Fixture;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Doctrine\Persistence\ObjectManager;
|
use Doctrine\Persistence\ObjectManager;
|
||||||
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
|
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
|
||||||
|
use Nelmio\Alice\Loader\NativeLoader;
|
||||||
|
use Chill\MainBundle\DataFixtures\ORM\LoadPostalCodes;
|
||||||
|
|
||||||
class LoadHousehold extends Fixture implements DependentFixtureInterface
|
class LoadHousehold extends Fixture implements DependentFixtureInterface
|
||||||
{
|
{
|
||||||
@@ -16,12 +20,15 @@ class LoadHousehold extends Fixture implements DependentFixtureInterface
|
|||||||
|
|
||||||
private EntityManagerInterface $em;
|
private EntityManagerInterface $em;
|
||||||
|
|
||||||
|
private NativeLoader $loader;
|
||||||
|
|
||||||
private CONST NUMBER_OF_HOUSEHOLD = 10;
|
private CONST NUMBER_OF_HOUSEHOLD = 10;
|
||||||
|
|
||||||
public function __construct(MembersEditorFactory $editorFactory, EntityManagerInterface $em)
|
public function __construct(MembersEditorFactory $editorFactory, EntityManagerInterface $em)
|
||||||
{
|
{
|
||||||
$this->editorFactory = $editorFactory;
|
$this->editorFactory = $editorFactory;
|
||||||
$this->em = $em;
|
$this->em = $em;
|
||||||
|
$this->loader = new NativeLoader();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function load(ObjectManager $manager)
|
public function load(ObjectManager $manager)
|
||||||
@@ -53,6 +60,8 @@ class LoadHousehold extends Fixture implements DependentFixtureInterface
|
|||||||
$household = new Household();
|
$household = new Household();
|
||||||
$manager->persist($household);
|
$manager->persist($household);
|
||||||
|
|
||||||
|
$this->addAddressToHousehold($household, clone $startDate, $manager);
|
||||||
|
|
||||||
$movement = $this->editorFactory->createEditor($household);
|
$movement = $this->editorFactory->createEditor($household);
|
||||||
|
|
||||||
// load adults
|
// load adults
|
||||||
@@ -89,6 +98,55 @@ class LoadHousehold extends Fixture implements DependentFixtureInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function addAddressToHousehold(Household $household, \DateTimeImmutable $date, ObjectManager $manager)
|
||||||
|
{
|
||||||
|
if (\random_int(0, 10) > 8) {
|
||||||
|
// 20% of household without address
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$nb = \random_int(1, 6);
|
||||||
|
|
||||||
|
$i = 0;
|
||||||
|
while ($i < $nb) {
|
||||||
|
$address = $this->createAddress();
|
||||||
|
$address->setValidFrom(\DateTime::createFromImmutable($date));
|
||||||
|
|
||||||
|
if (\random_int(0, 20) < 1) {
|
||||||
|
$date = $date->add(new \DateInterval('P'.\random_int(8, 52).'W'));
|
||||||
|
$address->setValidTo(\DateTime::createFromImmutable($date));
|
||||||
|
}
|
||||||
|
|
||||||
|
$household->addAddress($address);
|
||||||
|
$manager->persist($address);
|
||||||
|
|
||||||
|
$date = $date->add(new \DateInterval('P'.\random_int(8, 52).'W'));
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createAddress(): Address
|
||||||
|
{
|
||||||
|
$objectSet = $this->loader->loadData([
|
||||||
|
Address::class => [
|
||||||
|
'address1' => [
|
||||||
|
'street' => '<fr_FR:streetName()>',
|
||||||
|
'streetNumber' => '<fr_FR:buildingNumber()>',
|
||||||
|
'postCode' => $this->getPostalCode()
|
||||||
|
]
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $objectSet->getObjects()['address1'];
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getPostalCode(): PostalCode
|
||||||
|
{
|
||||||
|
$ref = LoadPostalCodes::$refs[\array_rand(LoadPostalCodes::$refs)];
|
||||||
|
|
||||||
|
return $this->getReference($ref);
|
||||||
|
}
|
||||||
|
|
||||||
private function preparePersonIds()
|
private function preparePersonIds()
|
||||||
{
|
{
|
||||||
$this->personIds = $this->em
|
$this->personIds = $this->em
|
||||||
|
@@ -438,6 +438,19 @@ class ChillPersonExtension extends Extension implements PrependExtensionInterfac
|
|||||||
Request::METHOD_DELETE=> \Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter::SEE
|
Request::METHOD_DELETE=> \Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter::SEE
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
|
'work' => [
|
||||||
|
'methods' => [
|
||||||
|
Request::METHOD_POST => true,
|
||||||
|
Request::METHOD_DELETE => false,
|
||||||
|
Request::METHOD_GET => false,
|
||||||
|
Request::METHOD_HEAD => false,
|
||||||
|
],
|
||||||
|
'controller_action' => 'workApi',
|
||||||
|
'roles' => [
|
||||||
|
Request::METHOD_POST => \Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter::SEE,
|
||||||
|
Request::METHOD_DELETE => 'ALWAYS_FAILS',
|
||||||
|
]
|
||||||
|
],
|
||||||
|
|
||||||
'confirm' => [
|
'confirm' => [
|
||||||
'methods' => [
|
'methods' => [
|
||||||
@@ -475,6 +488,7 @@ class ChillPersonExtension extends Extension implements PrependExtensionInterfac
|
|||||||
[
|
[
|
||||||
'class' => \Chill\PersonBundle\Entity\SocialWork\SocialIssue::class,
|
'class' => \Chill\PersonBundle\Entity\SocialWork\SocialIssue::class,
|
||||||
'name' => 'social_work_social_issue',
|
'name' => 'social_work_social_issue',
|
||||||
|
'controller' => \Chill\PersonBundle\Controller\SocialIssueApiController::class,
|
||||||
'base_path' => '/api/1.0/person/social-work/social-issue',
|
'base_path' => '/api/1.0/person/social-work/social-issue',
|
||||||
'base_role' => 'ROLE_USER',
|
'base_role' => 'ROLE_USER',
|
||||||
'actions' => [
|
'actions' => [
|
||||||
@@ -510,14 +524,61 @@ class ChillPersonExtension extends Extension implements PrependExtensionInterfac
|
|||||||
Request::METHOD_HEAD => \Chill\PersonBundle\Security\Authorization\PersonVoter::SEE,
|
Request::METHOD_HEAD => \Chill\PersonBundle\Security\Authorization\PersonVoter::SEE,
|
||||||
Request::METHOD_POST => \Chill\PersonBundle\Security\Authorization\PersonVoter::CREATE,
|
Request::METHOD_POST => \Chill\PersonBundle\Security\Authorization\PersonVoter::CREATE,
|
||||||
|
|
||||||
]
|
],
|
||||||
|
],
|
||||||
|
'address' => [
|
||||||
|
'methods' => [
|
||||||
|
Request::METHOD_POST => true,
|
||||||
|
Request::METHOD_DELETE => true,
|
||||||
|
Request::METHOD_GET => false,
|
||||||
|
Request::METHOD_HEAD => false,
|
||||||
|
],
|
||||||
|
'controller_action' => 'personAddressApi'
|
||||||
],
|
],
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'class' => \Chill\PersonBundle\Entity\Household\Household::class,
|
'class' => \Chill\PersonBundle\Entity\Household\Household::class,
|
||||||
|
'controller' => \Chill\PersonBundle\Controller\HouseholdApiController::class,
|
||||||
'name' => 'household',
|
'name' => 'household',
|
||||||
'base_path' => '/api/1.0/person/household',
|
'base_path' => '/api/1.0/person/household',
|
||||||
|
'base_role' => 'ROLE_USER',
|
||||||
|
'actions' => [
|
||||||
|
'_index' => [
|
||||||
|
'methods' => [
|
||||||
|
Request::METHOD_GET => true,
|
||||||
|
Request::METHOD_HEAD => true,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'_entity' => [
|
||||||
|
'methods' => [
|
||||||
|
Request::METHOD_GET => true,
|
||||||
|
Request::METHOD_HEAD => true,
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'address' => [
|
||||||
|
'methods' => [
|
||||||
|
Request::METHOD_POST => true,
|
||||||
|
Request::METHOD_DELETE => true,
|
||||||
|
Request::METHOD_GET => false,
|
||||||
|
Request::METHOD_HEAD => false,
|
||||||
|
],
|
||||||
|
'controller_action' => 'householdAddressApi'
|
||||||
|
],
|
||||||
|
'suggestHouseholdByAccompanyingPeriodParticipation' => [
|
||||||
|
'path' => '/suggest/by-person/{person_id}/through-accompanying-period-participation.{_format}',
|
||||||
|
'methods' => [
|
||||||
|
Request::METHOD_GET => true,
|
||||||
|
Request::METHOD_HEAD => true,
|
||||||
|
]
|
||||||
|
]
|
||||||
|
]
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'class' => \Chill\PersonBundle\Entity\SocialWork\SocialAction::class,
|
||||||
|
'name' => 'social_action',
|
||||||
|
'base_path' => '/api/1.0/person/social/social-action',
|
||||||
|
'controller' => \Chill\PersonBundle\Controller\SocialWorkSocialActionApiController::class,
|
||||||
// TODO: acl
|
// TODO: acl
|
||||||
'base_role' => 'ROLE_USER',
|
'base_role' => 'ROLE_USER',
|
||||||
'actions' => [
|
'actions' => [
|
||||||
@@ -531,6 +592,150 @@ class ChillPersonExtension extends Extension implements PrependExtensionInterfac
|
|||||||
Request::METHOD_HEAD => 'ROLE_USER',
|
Request::METHOD_HEAD => 'ROLE_USER',
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
|
'_index' => [
|
||||||
|
'methods' => [
|
||||||
|
Request::METHOD_GET => true,
|
||||||
|
Request::METHOD_HEAD => true,
|
||||||
|
],
|
||||||
|
'roles' => [
|
||||||
|
Request::METHOD_GET => 'ROLE_USER',
|
||||||
|
Request::METHOD_HEAD => 'ROLE_USER',
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'listBySocialIssue' => [
|
||||||
|
'single-collection' => 'collection',
|
||||||
|
'path' => '/by-social-issue/{id}.{_format}',
|
||||||
|
'methods' => [
|
||||||
|
Request::METHOD_GET => true,
|
||||||
|
Request::METHOD_HEAD => true,
|
||||||
|
],
|
||||||
|
'roles' => [
|
||||||
|
Request::METHOD_GET => 'ROLE_USER',
|
||||||
|
Request::METHOD_HEAD => 'ROLE_USER',
|
||||||
|
]
|
||||||
|
|
||||||
|
]
|
||||||
|
]
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'class' => \Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWork::class,
|
||||||
|
'name' => 'accompanying_period_work',
|
||||||
|
'base_path' => '/api/1.0/person/accompanying-course/work',
|
||||||
|
'controller' => \Chill\PersonBundle\Controller\AccompanyingCourseWorkApiController::class,
|
||||||
|
// TODO: acl
|
||||||
|
'base_role' => 'ROLE_USER',
|
||||||
|
'actions' => [
|
||||||
|
'_entity' => [
|
||||||
|
'methods' => [
|
||||||
|
Request::METHOD_GET => true,
|
||||||
|
Request::METHOD_HEAD => true,
|
||||||
|
Request::METHOD_PATCH => true,
|
||||||
|
Request::METHOD_PUT => true,
|
||||||
|
],
|
||||||
|
'roles' => [
|
||||||
|
Request::METHOD_GET => 'ROLE_USER',
|
||||||
|
Request::METHOD_HEAD => 'ROLE_USER',
|
||||||
|
Request::METHOD_PATCH => 'ROLE_USER',
|
||||||
|
Request::METHOD_PUT => 'ROLE_USER',
|
||||||
|
]
|
||||||
|
],
|
||||||
|
]
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'class' => \Chill\PersonBundle\Entity\SocialWork\Result::class,
|
||||||
|
'controller' => \Chill\PersonBundle\Controller\SocialWorkResultApiController::class,
|
||||||
|
'name' => 'social_work_result',
|
||||||
|
'base_path' => '/api/1.0/person/social-work/result',
|
||||||
|
'base_role' => 'ROLE_USER',
|
||||||
|
'actions' => [
|
||||||
|
'_entity' => [
|
||||||
|
'methods' => [
|
||||||
|
Request::METHOD_GET => true,
|
||||||
|
Request::METHOD_HEAD => true,
|
||||||
|
],
|
||||||
|
'roles' => [
|
||||||
|
Request::METHOD_GET => 'ROLE_USER',
|
||||||
|
Request::METHOD_HEAD => 'ROLE_USER',
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'_index' => [
|
||||||
|
'methods' => [
|
||||||
|
Request::METHOD_GET => true,
|
||||||
|
Request::METHOD_HEAD => true,
|
||||||
|
],
|
||||||
|
'roles' => [
|
||||||
|
Request::METHOD_GET => 'ROLE_USER',
|
||||||
|
Request::METHOD_HEAD => 'ROLE_USER',
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'by-social-action' => [
|
||||||
|
'single-collection' => 'collection',
|
||||||
|
'path' => '/by-social-action/{id}.{_format}',
|
||||||
|
'controller_action' => 'listBySocialAction',
|
||||||
|
'methods' => [
|
||||||
|
Request::METHOD_GET => true,
|
||||||
|
Request::METHOD_HEAD => true,
|
||||||
|
],
|
||||||
|
'roles' => [
|
||||||
|
Request::METHOD_GET => 'ROLE_USER',
|
||||||
|
Request::METHOD_HEAD => 'ROLE_USER',
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'by-goal' => [
|
||||||
|
'single-collection' => 'collection',
|
||||||
|
'path' => '/by-goal/{id}.{_format}',
|
||||||
|
'controller_action' => 'listByGoal',
|
||||||
|
'methods' => [
|
||||||
|
Request::METHOD_GET => true,
|
||||||
|
Request::METHOD_HEAD => true,
|
||||||
|
],
|
||||||
|
'roles' => [
|
||||||
|
Request::METHOD_GET => 'ROLE_USER',
|
||||||
|
Request::METHOD_HEAD => 'ROLE_USER',
|
||||||
|
]
|
||||||
|
],
|
||||||
|
]
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'class' => \Chill\PersonBundle\Entity\SocialWork\Goal::class,
|
||||||
|
'controller' => \Chill\PersonBundle\Controller\SocialWorkGoalApiController::class,
|
||||||
|
'name' => 'social_work_goal',
|
||||||
|
'base_path' => '/api/1.0/person/social-work/goal',
|
||||||
|
'base_role' => 'ROLE_USER',
|
||||||
|
'actions' => [
|
||||||
|
'_entity' => [
|
||||||
|
'methods' => [
|
||||||
|
Request::METHOD_GET => true,
|
||||||
|
Request::METHOD_HEAD => true,
|
||||||
|
],
|
||||||
|
'roles' => [
|
||||||
|
Request::METHOD_GET => 'ROLE_USER',
|
||||||
|
Request::METHOD_HEAD => 'ROLE_USER',
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'_index' => [
|
||||||
|
'methods' => [
|
||||||
|
Request::METHOD_GET => true,
|
||||||
|
Request::METHOD_HEAD => true,
|
||||||
|
],
|
||||||
|
'roles' => [
|
||||||
|
Request::METHOD_GET => 'ROLE_USER',
|
||||||
|
Request::METHOD_HEAD => 'ROLE_USER',
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'by-social-action' => [
|
||||||
|
'single-collection' => 'collection',
|
||||||
|
'path' => '/by-social-action/{id}.{_format}',
|
||||||
|
'controller_action' => 'listBySocialAction',
|
||||||
|
'methods' => [
|
||||||
|
Request::METHOD_GET => true,
|
||||||
|
Request::METHOD_HEAD => true,
|
||||||
|
],
|
||||||
|
'roles' => [
|
||||||
|
Request::METHOD_GET => 'ROLE_USER',
|
||||||
|
Request::METHOD_HEAD => 'ROLE_USER',
|
||||||
|
]
|
||||||
|
],
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
]
|
]
|
||||||
|
@@ -78,6 +78,7 @@ class Configuration implements ConfigurationInterface
|
|||||||
->append($this->addFieldNode('address'))
|
->append($this->addFieldNode('address'))
|
||||||
->append($this->addFieldNode('accompanying_period'))
|
->append($this->addFieldNode('accompanying_period'))
|
||||||
->append($this->addFieldNode('memo'))
|
->append($this->addFieldNode('memo'))
|
||||||
|
->append($this->addFieldNode('number_of_children'))
|
||||||
->arrayNode('alt_names')
|
->arrayNode('alt_names')
|
||||||
->defaultValue([])
|
->defaultValue([])
|
||||||
->arrayPrototype()
|
->arrayPrototype()
|
||||||
|
@@ -25,6 +25,7 @@ namespace Chill\PersonBundle\Entity;
|
|||||||
use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface;
|
use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface;
|
||||||
use Chill\MainBundle\Doctrine\Model\TrackCreationInterface;
|
use Chill\MainBundle\Doctrine\Model\TrackCreationInterface;
|
||||||
use Chill\MainBundle\Entity\Scope;
|
use Chill\MainBundle\Entity\Scope;
|
||||||
|
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWork;
|
||||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\ClosingMotive;
|
use Chill\PersonBundle\Entity\AccompanyingPeriod\ClosingMotive;
|
||||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\Comment;
|
use Chill\PersonBundle\Entity\AccompanyingPeriod\Comment;
|
||||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\Origin;
|
use Chill\PersonBundle\Entity\AccompanyingPeriod\Origin;
|
||||||
@@ -39,6 +40,7 @@ use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
|||||||
use Chill\MainBundle\Entity\User;
|
use Chill\MainBundle\Entity\User;
|
||||||
use Symfony\Component\Serializer\Annotation\Groups;
|
use Symfony\Component\Serializer\Annotation\Groups;
|
||||||
use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
|
use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
|
||||||
|
use Symfony\Component\Validator\Constraints as Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AccompanyingPeriod Class
|
* AccompanyingPeriod Class
|
||||||
@@ -280,6 +282,15 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface
|
|||||||
*/
|
*/
|
||||||
private \DateTimeInterface $updatedAt;
|
private \DateTimeInterface $updatedAt;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\OneToMany(
|
||||||
|
* targetEntity=AccompanyingPeriodWork::class,
|
||||||
|
* mappedBy="accompanyingPeriod"
|
||||||
|
* )
|
||||||
|
* @Assert\Valid(traverse=true)
|
||||||
|
*/
|
||||||
|
private Collection $works;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AccompanyingPeriod constructor.
|
* AccompanyingPeriod constructor.
|
||||||
*
|
*
|
||||||
@@ -292,6 +303,7 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface
|
|||||||
$this->scopes = new ArrayCollection();
|
$this->scopes = new ArrayCollection();
|
||||||
$this->socialIssues = new ArrayCollection();
|
$this->socialIssues = new ArrayCollection();
|
||||||
$this->comments = new ArrayCollection();
|
$this->comments = new ArrayCollection();
|
||||||
|
$this->works = new ArrayCollection();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -836,7 +848,6 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $recursiveSocialIssues;
|
return $recursiveSocialIssues;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -896,4 +907,28 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface
|
|||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return AccompanyingPeriodWork[]
|
||||||
|
*/
|
||||||
|
public function getWorks(): Collection
|
||||||
|
{
|
||||||
|
return $this->works;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addWork(AccompanyingPeriodWork $work): self
|
||||||
|
{
|
||||||
|
$this->works[] = $work;
|
||||||
|
$work->setAccompanyingPeriod($this);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function removeWork(AccompanyingPeriodWork $work): self
|
||||||
|
{
|
||||||
|
$this->work->removeElement($work);
|
||||||
|
$work->setAccompanyingPeriod(null);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -4,103 +4,168 @@ namespace Chill\PersonBundle\Entity\AccompanyingPeriod;
|
|||||||
|
|
||||||
use Chill\PersonBundle\Entity\SocialWork\Result;
|
use Chill\PersonBundle\Entity\SocialWork\Result;
|
||||||
use Chill\PersonBundle\Entity\SocialWork\SocialAction;
|
use Chill\PersonBundle\Entity\SocialWork\SocialAction;
|
||||||
|
use Chill\PersonBundle\Entity\Person;
|
||||||
use Chill\MainBundle\Entity\User;
|
use Chill\MainBundle\Entity\User;
|
||||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||||
use Chill\ThirdPartyBundle\Entity\ThirdParty;
|
use Chill\ThirdPartyBundle\Entity\ThirdParty;
|
||||||
|
use DateTimeInterface;
|
||||||
use Doctrine\Common\Collections\ArrayCollection;
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
use Doctrine\Common\Collections\Collection;
|
use Doctrine\Common\Collections\Collection;
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
use Symfony\Component\Serializer\Annotation as Serializer;
|
||||||
|
use Chill\MainBundle\Doctrine\Model\TrackCreationInterface;
|
||||||
|
use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface;
|
||||||
|
use Symfony\Component\Validator\Constraints as Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Entity
|
* @ORM\Entity
|
||||||
* @ORM\Table(name="chill_person_accompanying_period_work")
|
* @ORM\Table(name="chill_person_accompanying_period_work")
|
||||||
|
* @Serializer\DiscriminatorMap(
|
||||||
|
* typeProperty="type",
|
||||||
|
* mapping={
|
||||||
|
* "accompanying_period_work":AccompanyingPeriodWork::class
|
||||||
|
* }
|
||||||
|
* )
|
||||||
*/
|
*/
|
||||||
class AccompanyingPeriodWork
|
class AccompanyingPeriodWork implements TrackCreationInterface, TrackUpdateInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @ORM\Id
|
* @ORM\Id
|
||||||
* @ORM\GeneratedValue
|
* @ORM\GeneratedValue
|
||||||
* @ORM\Column(type="integer")
|
* @ORM\Column(type="integer")
|
||||||
|
* @Serializer\Groups({"read"})
|
||||||
*/
|
*/
|
||||||
private $id;
|
private ?int $id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="text")
|
* @ORM\Column(type="text")
|
||||||
|
* @Serializer\Groups({"read", "accompanying_period_work:edit"})
|
||||||
*/
|
*/
|
||||||
private $note;
|
private string $note = "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\ManyToOne(targetEntity=AccompanyingPeriod::class)
|
* @ORM\ManyToOne(targetEntity=AccompanyingPeriod::class)
|
||||||
|
* @Serializer\Groups({"read"})
|
||||||
*/
|
*/
|
||||||
private $accompanyingPeriod;
|
private ?AccompanyingPeriod $accompanyingPeriod = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\ManyToOne(targetEntity=SocialAction::class)
|
* @ORM\ManyToOne(targetEntity=SocialAction::class)
|
||||||
|
* @Serializer\Groups({"read"})
|
||||||
|
* @Serializer\Groups({"accompanying_period_work:create"})
|
||||||
*/
|
*/
|
||||||
private $socialAction;
|
private ?SocialAction $socialAction = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="datetime")
|
* @ORM\Column(type="datetime_immutable")
|
||||||
|
* @Serializer\Groups({"read"})
|
||||||
*/
|
*/
|
||||||
private $createdAt;
|
private ?\DateTimeImmutable $createdAt = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\ManyToOne(targetEntity=User::class)
|
* @ORM\ManyToOne(targetEntity=User::class)
|
||||||
* @ORM\JoinColumn(nullable=false)
|
* @ORM\JoinColumn(nullable=false)
|
||||||
|
* @Serializer\Groups({"read"})
|
||||||
*/
|
*/
|
||||||
private $createdBy;
|
private ?User $createdBy = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="datetime")
|
* @ORM\Column(type="datetime_immutable")
|
||||||
|
* @Serializer\Groups({"read"})
|
||||||
*/
|
*/
|
||||||
private $startDate;
|
private ?\DateTimeImmutable $updatedAt = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="datetime")
|
* @ORM\ManyToOne(targetEntity=User::class)
|
||||||
|
* @ORM\JoinColumn(nullable=false)
|
||||||
|
* @Serializer\Groups({"read"})
|
||||||
*/
|
*/
|
||||||
private $endDate;
|
private ?User $updatedBy = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="date_immutable")
|
||||||
|
* @Serializer\Groups({"accompanying_period_work:create"})
|
||||||
|
* @Serializer\Groups({"accompanying_period_work:edit"})
|
||||||
|
* @Serializer\Groups({"read"})
|
||||||
|
*/
|
||||||
|
private \DateTimeImmutable $startDate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="date_immutable", nullable=true, options={"default":null})
|
||||||
|
* @Serializer\Groups({"accompanying_period_work:create"})
|
||||||
|
* @Serializer\Groups({"accompanying_period_work:edit"})
|
||||||
|
* @Serializer\Groups({"read"})
|
||||||
|
* @Assert\GreaterThan(propertyPath="startDate",
|
||||||
|
* message="accompanying_course_work.The endDate should be greater than the start date"
|
||||||
|
* )
|
||||||
|
*/
|
||||||
|
private ?\DateTimeImmutable $endDate = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\ManyToOne(targetEntity=ThirdParty::class)
|
* @ORM\ManyToOne(targetEntity=ThirdParty::class)
|
||||||
|
* @Serializer\Groups({"read"})
|
||||||
|
* @Serializer\Groups({"accompanying_period_work:edit"})
|
||||||
*
|
*
|
||||||
* In schema : traitant
|
* In schema : traitant
|
||||||
*/
|
*/
|
||||||
private $handlingThierParty;
|
private ?ThirdParty $handlingThierParty = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="boolean")
|
* @ORM\Column(type="boolean")
|
||||||
*/
|
*/
|
||||||
private $createdAutomatically;
|
private bool $createdAutomatically = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="text")
|
* @ORM\Column(type="text")
|
||||||
*/
|
*/
|
||||||
private $createdAutomaticallyReason;
|
private string $createdAutomaticallyReason = "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\OneToMany(targetEntity=AccompanyingPeriodWorkGoal::class, mappedBy="accompanyingPeriodWork")
|
* @ORM\OneToMany(
|
||||||
|
* targetEntity=AccompanyingPeriodWorkGoal::class,
|
||||||
|
* mappedBy="accompanyingPeriodWork",
|
||||||
|
* cascade={"persist"},
|
||||||
|
* orphanRemoval=true
|
||||||
|
* )
|
||||||
|
* @Serializer\Groups({"read"})
|
||||||
|
* @Serializer\Groups({"accompanying_period_work:edit"})
|
||||||
*/
|
*/
|
||||||
private $goals;
|
private Collection $goals;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\ManyToMany(targetEntity=Result::class, inversedBy="accompanyingPeriodWorks")
|
* @ORM\ManyToMany(targetEntity=Result::class, inversedBy="accompanyingPeriodWorks")
|
||||||
* @ORM\JoinTable(name="chill_person_accompanying_period_work_result")
|
* @ORM\JoinTable(name="chill_person_accompanying_period_work_result")
|
||||||
|
* @Serializer\Groups({"read"})
|
||||||
|
* @Serializer\Groups({"accompanying_period_work:edit"})
|
||||||
*/
|
*/
|
||||||
private $results;
|
private Collection $results;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\ManyToMany(targetEntity=ThirdParty::class)
|
* @ORM\ManyToMany(targetEntity=ThirdParty::class)
|
||||||
* @ORM\JoinTable(name="chill_person_accompanying_period_work_third_party")
|
* @ORM\JoinTable(name="chill_person_accompanying_period_work_third_party")
|
||||||
*
|
*
|
||||||
* In schema : intervenants
|
* In schema : intervenants
|
||||||
|
* @Serializer\Groups({"read"})
|
||||||
|
* @Serializer\Groups({"accompanying_period_work:edit"})
|
||||||
*/
|
*/
|
||||||
private $thirdParties;
|
private Collection $thirdParties;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @ORM\ManyToMany(targetEntity=Person::class)
|
||||||
|
* @ORM\JoinTable(name="chill_person_accompanying_period_work_person")
|
||||||
|
* @Serializer\Groups({"read"})
|
||||||
|
* @Serializer\Groups({"accompanying_period_work:edit"})
|
||||||
|
* @Serializer\Groups({"accompanying_period_work:create"})
|
||||||
|
*/
|
||||||
|
private Collection $persons;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->goals = new ArrayCollection();
|
$this->goals = new ArrayCollection();
|
||||||
$this->results = new ArrayCollection();
|
$this->results = new ArrayCollection();
|
||||||
$this->thirdParties = new ArrayCollection();
|
$this->thirdParties = new ArrayCollection();
|
||||||
|
$this->persons = new ArrayCollection();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getId(): ?int
|
public function getId(): ?int
|
||||||
@@ -125,8 +190,17 @@ use Doctrine\ORM\Mapping as ORM;
|
|||||||
return $this->accompanyingPeriod;
|
return $this->accompanyingPeriod;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal: you should use `$accompanyingPeriod->removeWork($work);` or
|
||||||
|
* `$accompanyingPeriod->addWork($work);`
|
||||||
|
*/
|
||||||
public function setAccompanyingPeriod(?AccompanyingPeriod $accompanyingPeriod): self
|
public function setAccompanyingPeriod(?AccompanyingPeriod $accompanyingPeriod): self
|
||||||
{
|
{
|
||||||
|
if ($this->accompanyingPeriod instanceof AccompanyingPeriod &&
|
||||||
|
$accompanyingPeriod !== $this->accompanyingPeriod) {
|
||||||
|
throw new \LogicException("A work cannot change accompanyingPeriod");
|
||||||
|
}
|
||||||
|
|
||||||
$this->accompanyingPeriod = $accompanyingPeriod;
|
$this->accompanyingPeriod = $accompanyingPeriod;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
@@ -144,7 +218,7 @@ use Doctrine\ORM\Mapping as ORM;
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCreatedAt(): ?\DateTimeInterface
|
public function getCreatedAt(): ?\DateTimeImmutable
|
||||||
{
|
{
|
||||||
return $this->createdAt;
|
return $this->createdAt;
|
||||||
}
|
}
|
||||||
@@ -168,6 +242,30 @@ use Doctrine\ORM\Mapping as ORM;
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setUpdatedBy(User $user): TrackUpdateInterface
|
||||||
|
{
|
||||||
|
$this->updatedBy = $user;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setUpdatedAt(DateTimeInterface $datetime): TrackUpdateInterface
|
||||||
|
{
|
||||||
|
$this->updatedAt = $datetime;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUpdatedAt(): ?\DateTimeImmutable
|
||||||
|
{
|
||||||
|
return $this->updatedAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUpdatedBy(): ?User
|
||||||
|
{
|
||||||
|
return $this->updatedBy;
|
||||||
|
}
|
||||||
|
|
||||||
public function getStartDate(): ?\DateTimeInterface
|
public function getStartDate(): ?\DateTimeInterface
|
||||||
{
|
{
|
||||||
return $this->startDate;
|
return $this->startDate;
|
||||||
@@ -185,7 +283,7 @@ use Doctrine\ORM\Mapping as ORM;
|
|||||||
return $this->endDate;
|
return $this->endDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setEndDate(\DateTimeInterface $endDate): self
|
public function setEndDate(?\DateTimeInterface $endDate = null): self
|
||||||
{
|
{
|
||||||
$this->endDate = $endDate;
|
$this->endDate = $endDate;
|
||||||
|
|
||||||
@@ -240,7 +338,7 @@ use Doctrine\ORM\Mapping as ORM;
|
|||||||
{
|
{
|
||||||
if (!$this->goals->contains($goal)) {
|
if (!$this->goals->contains($goal)) {
|
||||||
$this->goals[] = $goal;
|
$this->goals[] = $goal;
|
||||||
$goal->setAccompanyingPeriodWork2($this);
|
$goal->setAccompanyingPeriodWork($this);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
@@ -250,8 +348,8 @@ use Doctrine\ORM\Mapping as ORM;
|
|||||||
{
|
{
|
||||||
if ($this->goals->removeElement($goal)) {
|
if ($this->goals->removeElement($goal)) {
|
||||||
// set the owning side to null (unless already changed)
|
// set the owning side to null (unless already changed)
|
||||||
if ($goal->getAccompanyingPeriodWork2() === $this) {
|
if ($goal->getAccompanyingPeriodWork() === $this) {
|
||||||
$goal->setAccompanyingPeriodWork2(null);
|
$goal->setAccompanyingPeriodWork(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -305,4 +403,25 @@ use Doctrine\ORM\Mapping as ORM;
|
|||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getPersons(): Collection
|
||||||
|
{
|
||||||
|
return $this->persons;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addPerson(Person $person): self
|
||||||
|
{
|
||||||
|
if (!$this->persons->contains($person)) {
|
||||||
|
$this->persons[] = $person;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function removePerson(Person $person): self
|
||||||
|
{
|
||||||
|
$this->persons->removeElement($person);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -7,10 +7,17 @@ use Chill\PersonBundle\Entity\SocialWork\Result;
|
|||||||
use Doctrine\Common\Collections\ArrayCollection;
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
use Doctrine\Common\Collections\Collection;
|
use Doctrine\Common\Collections\Collection;
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
use Symfony\Component\Serializer\Annotation as Serializer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Entity
|
* @ORM\Entity
|
||||||
* @ORM\Table(name="chill_person_accompanying_period_work_goal")
|
* @ORM\Table(name="chill_person_accompanying_period_work_goal")
|
||||||
|
* @Serializer\DiscriminatorMap(
|
||||||
|
* typeProperty="type",
|
||||||
|
* mapping={
|
||||||
|
* "accompanying_period_work_goal":AccompanyingPeriodWorkGoal::class
|
||||||
|
* }
|
||||||
|
* )
|
||||||
*/
|
*/
|
||||||
class AccompanyingPeriodWorkGoal
|
class AccompanyingPeriodWorkGoal
|
||||||
{
|
{
|
||||||
@@ -18,11 +25,14 @@ class AccompanyingPeriodWorkGoal
|
|||||||
* @ORM\Id
|
* @ORM\Id
|
||||||
* @ORM\GeneratedValue
|
* @ORM\GeneratedValue
|
||||||
* @ORM\Column(type="integer")
|
* @ORM\Column(type="integer")
|
||||||
|
* @Serializer\Groups({"read"})
|
||||||
*/
|
*/
|
||||||
private $id;
|
private $id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="text")
|
* @ORM\Column(type="text")
|
||||||
|
* @Serializer\Groups({"accompanying_period_work:edit"})
|
||||||
|
* @Serializer\Groups({"read"})
|
||||||
*/
|
*/
|
||||||
private $note;
|
private $note;
|
||||||
|
|
||||||
@@ -33,12 +43,16 @@ class AccompanyingPeriodWorkGoal
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\ManyToOne(targetEntity=Goal::class)
|
* @ORM\ManyToOne(targetEntity=Goal::class)
|
||||||
|
* @Serializer\Groups({"accompanying_period_work:edit"})
|
||||||
|
* @Serializer\Groups({"read"})
|
||||||
*/
|
*/
|
||||||
private $goal;
|
private $goal;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\ManyToMany(targetEntity=Result::class, inversedBy="accompanyingPeriodWorkGoals")
|
* @ORM\ManyToMany(targetEntity=Result::class, inversedBy="accompanyingPeriodWorkGoals")
|
||||||
* @ORM\JoinTable(name="chill_person_accompanying_period_work_goal_result")
|
* @ORM\JoinTable(name="chill_person_accompanying_period_work_goal_result")
|
||||||
|
* @Serializer\Groups({"accompanying_period_work:edit"})
|
||||||
|
* @Serializer\Groups({"read"})
|
||||||
*/
|
*/
|
||||||
private $results;
|
private $results;
|
||||||
|
|
||||||
@@ -71,6 +85,13 @@ class AccompanyingPeriodWorkGoal
|
|||||||
|
|
||||||
public function setAccompanyingPeriodWork(?AccompanyingPeriodWork $accompanyingPeriodWork): self
|
public function setAccompanyingPeriodWork(?AccompanyingPeriodWork $accompanyingPeriodWork): self
|
||||||
{
|
{
|
||||||
|
if ($this->accompanyingPeriodWork instanceof AccompanyingPeriodWork
|
||||||
|
&& $accompanyingPeriodWork !== $this->accompanyingPeriodWork
|
||||||
|
&& $accompanyingPeriodWork !== null
|
||||||
|
) {
|
||||||
|
throw new \LogicException("Change accompanying period work is not allowed");
|
||||||
|
}
|
||||||
|
|
||||||
$this->accompanyingPeriodWork = $accompanyingPeriodWork;
|
$this->accompanyingPeriodWork = $accompanyingPeriodWork;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
@@ -7,8 +7,12 @@ use Doctrine\ORM\Mapping as ORM;
|
|||||||
use Doctrine\Common\Collections\Collection;
|
use Doctrine\Common\Collections\Collection;
|
||||||
use Doctrine\Common\Collections\Criteria;
|
use Doctrine\Common\Collections\Criteria;
|
||||||
use Symfony\Component\Serializer\Annotation as Serializer;
|
use Symfony\Component\Serializer\Annotation as Serializer;
|
||||||
|
use Symfony\Component\Validator\Constraints as Assert;
|
||||||
|
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||||
use Chill\MainBundle\Entity\Address;
|
use Chill\MainBundle\Entity\Address;
|
||||||
use Chill\PersonBundle\Entity\Household\HouseholdMember;
|
use Chill\PersonBundle\Entity\Household\HouseholdMember;
|
||||||
|
use Chill\PersonBundle\Validator\Constraints\Household\MaxHolder;
|
||||||
|
use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Entity
|
* @ORM\Entity
|
||||||
@@ -18,6 +22,7 @@ use Chill\PersonBundle\Entity\Household\HouseholdMember;
|
|||||||
* @Serializer\DiscriminatorMap(typeProperty="type", mapping={
|
* @Serializer\DiscriminatorMap(typeProperty="type", mapping={
|
||||||
* "household"=Household::class
|
* "household"=Household::class
|
||||||
* })
|
* })
|
||||||
|
* @MaxHolder(groups={"household_memberships"})
|
||||||
*/
|
*/
|
||||||
class Household
|
class Household
|
||||||
{
|
{
|
||||||
@@ -37,6 +42,7 @@ class Household
|
|||||||
* cascade={"persist", "remove", "merge", "detach"})
|
* cascade={"persist", "remove", "merge", "detach"})
|
||||||
* @ORM\JoinTable(name="chill_person_household_to_addresses")
|
* @ORM\JoinTable(name="chill_person_household_to_addresses")
|
||||||
* @ORM\OrderBy({"validFrom" = "DESC"})
|
* @ORM\OrderBy({"validFrom" = "DESC"})
|
||||||
|
* @Serializer\Groups({"write"})
|
||||||
*/
|
*/
|
||||||
private Collection $addresses;
|
private Collection $addresses;
|
||||||
|
|
||||||
@@ -49,10 +55,26 @@ class Household
|
|||||||
*/
|
*/
|
||||||
private Collection $members;
|
private Collection $members;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\Embedded(class=CommentEmbeddable::class, columnPrefix="comment_members_")
|
||||||
|
*/
|
||||||
|
private CommentEmbeddable $commentMembers;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="boolean", name="waiting_for_birth", options={"default": false})
|
||||||
|
*/
|
||||||
|
private bool $waitingForBirth = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="date_immutable", name="waiting_for_birth_date", nullable=true, options={"default": null})
|
||||||
|
*/
|
||||||
|
private ?\DateTimeImmutable $waitingForBirthDate = null;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->addresses = new ArrayCollection();
|
$this->addresses = new ArrayCollection();
|
||||||
$this->members = new ArrayCollection();
|
$this->members = new ArrayCollection();
|
||||||
|
$this->commentMembers = new CommentEmbeddable();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getId(): ?int
|
public function getId(): ?int
|
||||||
@@ -66,6 +88,12 @@ class Household
|
|||||||
*/
|
*/
|
||||||
public function addAddress(Address $address)
|
public function addAddress(Address $address)
|
||||||
{
|
{
|
||||||
|
foreach ($this->getAddresses() as $a) {
|
||||||
|
if ($a->getValidFrom() < $address->getValidFrom() && $a->getValidTo() === NULL) {
|
||||||
|
$a->setValidTo($address->getValidFrom());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$this->addresses[] = $address;
|
$this->addresses[] = $address;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
@@ -83,6 +111,7 @@ class Household
|
|||||||
* By default, the addresses are ordered by date, descending (the most
|
* By default, the addresses are ordered by date, descending (the most
|
||||||
* recent first)
|
* recent first)
|
||||||
*
|
*
|
||||||
|
* @Assert\Callback(methods={"validate"})
|
||||||
* @return \Chill\MainBundle\Entity\Address[]
|
* @return \Chill\MainBundle\Entity\Address[]
|
||||||
*/
|
*/
|
||||||
public function getAddresses()
|
public function getAddresses()
|
||||||
@@ -90,6 +119,27 @@ class Household
|
|||||||
return $this->addresses;
|
return $this->addresses;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Serializer\Groups({ "read" })
|
||||||
|
* @Serializer\SerializedName("current_address")
|
||||||
|
*/
|
||||||
|
public function getCurrentAddress(\DateTime $at = null): ?Address
|
||||||
|
{
|
||||||
|
$at = $at === null ? new \DateTime('today') : $at;
|
||||||
|
|
||||||
|
$addrs = $this->getAddresses()->filter(function (Address $a) use ($at) {
|
||||||
|
return $a->getValidFrom() < $at && (
|
||||||
|
NULL === $a->getValidTo() || $at < $a->getValidTo()
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
if ($addrs->count() > 0) {
|
||||||
|
return $addrs->first();
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Collection|HouseholdMember[]
|
* @return Collection|HouseholdMember[]
|
||||||
*/
|
*/
|
||||||
@@ -98,7 +148,59 @@ class Household
|
|||||||
return $this->members;
|
return $this->members;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getMembersOnRange(\DateTimeImmutable $from, ?\DateTimeImmutable $to): Collection
|
||||||
|
{
|
||||||
|
$criteria = new Criteria();
|
||||||
|
$expr = Criteria::expr();
|
||||||
|
|
||||||
|
$criteria->where(
|
||||||
|
$expr->gte('startDate', $from)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (NULL !== $to) {
|
||||||
|
$criteria->andWhere(
|
||||||
|
$expr->orX(
|
||||||
|
$expr->lte('endDate', $to),
|
||||||
|
$expr->eq('endDate', NULL)
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->getMembers()
|
||||||
|
->matching($criteria)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMembersDuringMembership(HouseholdMember $membership)
|
||||||
|
{
|
||||||
|
return $this->getMembersOnRange(
|
||||||
|
$membership->getStartDate(),
|
||||||
|
$membership->getEndDate()
|
||||||
|
)->filter(
|
||||||
|
function(HouseholdMember $m) use ($membership) {
|
||||||
|
return $m !== $membership;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMembersHolder(): Collection
|
||||||
|
{
|
||||||
|
$criteria = new Criteria();
|
||||||
|
$expr = Criteria::expr();
|
||||||
|
|
||||||
|
$criteria->where(
|
||||||
|
$expr->eq('holder', true)
|
||||||
|
);
|
||||||
|
|
||||||
|
return $this->getMembers()->matching($criteria);
|
||||||
|
}
|
||||||
|
|
||||||
public function getCurrentMembers(?\DateTimeImmutable $now = null): Collection
|
public function getCurrentMembers(?\DateTimeImmutable $now = null): Collection
|
||||||
|
{
|
||||||
|
return $this->getMembers()->matching($this->buildCriteriaCurrentMembers($now));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function buildCriteriaCurrentMembers(?\DateTimeImmutable $now = null): Criteria
|
||||||
{
|
{
|
||||||
$criteria = new Criteria();
|
$criteria = new Criteria();
|
||||||
$expr = Criteria::expr();
|
$expr = Criteria::expr();
|
||||||
@@ -114,7 +216,53 @@ class Household
|
|||||||
$expr->gte('endDate', $date)
|
$expr->gte('endDate', $date)
|
||||||
));
|
));
|
||||||
|
|
||||||
return $this->getMembers()->matching($criteria);
|
return $criteria;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return HouseholdMember[]
|
||||||
|
*/
|
||||||
|
public function getCurrentMembersOrdered(?\DateTimeImmutable $now = null): Collection
|
||||||
|
{
|
||||||
|
$members = $this->getCurrentMembers($now);
|
||||||
|
|
||||||
|
$members->getIterator()
|
||||||
|
->uasort(
|
||||||
|
function (HouseholdMember $a, HouseholdMember $b) {
|
||||||
|
if ($a->getPosition()->getOrdering() < $b->getPosition()->getOrdering()) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if ($a->getPosition()->getOrdering() > $b->getPosition()->getOrdering()) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if ($a->isHolder() && !$b->isHolder()) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (!$a->isHolder() && $b->isHolder()) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return $members;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get current members ids
|
||||||
|
*
|
||||||
|
* Used in serialization
|
||||||
|
*
|
||||||
|
* @Serializer\Groups({"read"})
|
||||||
|
* @Serializer\SerializedName("current_members_id")
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function getCurrentMembersIds(?\DateTimeImmutable $now = null): Collection
|
||||||
|
{
|
||||||
|
return $this->getCurrentMembers($now)->map(
|
||||||
|
fn (HouseholdMember $m) => $m->getId()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -192,4 +340,54 @@ class Household
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getCommentMembers(): CommentEmbeddable
|
||||||
|
{
|
||||||
|
return $this->commentMembers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCommentMembers(CommentEmbeddable $commentMembers): self
|
||||||
|
{
|
||||||
|
$this->commentMembers = $commentMembers;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getWaitingForBirth(): bool
|
||||||
|
{
|
||||||
|
return $this->waitingForBirth;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setWaitingForBirth(bool $waitingForBirth): self
|
||||||
|
{
|
||||||
|
$this->waitingForBirth = $waitingForBirth;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getWaitingForBirthDate(): ?\DateTimeImmutable
|
||||||
|
{
|
||||||
|
return $this->waitingForBirthDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setWaitingForBirthDate(?\DateTimeImmutable $waitingForBirthDate): self
|
||||||
|
{
|
||||||
|
$this->waitingForBirthDate = $waitingForBirthDate;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function validate(ExecutionContextInterface $context, $payload)
|
||||||
|
{
|
||||||
|
$addresses = $this->getAddresses();
|
||||||
|
$cond = True;
|
||||||
|
for ($i=0; $i < count($addresses) - 1; $i++) {
|
||||||
|
if ($addresses[$i]->getValidFrom() != $addresses[$i + 1]->getValidTo()) {
|
||||||
|
$cond = False;
|
||||||
|
$context->buildViolation('The address are not sequentials. The validFrom date of one address should be equal to the validTo date of the previous address.')
|
||||||
|
->atPath('addresses')
|
||||||
|
->addViolation();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dump($cond);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -7,6 +7,7 @@ use Chill\PersonBundle\Entity\Person;
|
|||||||
use Chill\PersonBundle\Entity\Household\Household;
|
use Chill\PersonBundle\Entity\Household\Household;
|
||||||
use Chill\PersonBundle\Entity\Household\Position;
|
use Chill\PersonBundle\Entity\Household\Position;
|
||||||
use Symfony\Component\Serializer\Annotation as Serializer;
|
use Symfony\Component\Serializer\Annotation as Serializer;
|
||||||
|
use Symfony\Component\Validator\Constraints as Assert;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -28,18 +29,25 @@ class HouseholdMember
|
|||||||
/**
|
/**
|
||||||
* @ORM\ManyToOne(targetEntity=Position::class)
|
* @ORM\ManyToOne(targetEntity=Position::class)
|
||||||
* @Serializer\Groups({"read"})
|
* @Serializer\Groups({"read"})
|
||||||
|
* @Assert\NotNull(groups={"household_memberships"})
|
||||||
*/
|
*/
|
||||||
private ?Position $position = null;
|
private ?Position $position = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="date_immutable", nullable=true, options={"default": null})
|
* @ORM\Column(type="date_immutable", nullable=true, options={"default": null})
|
||||||
* @Serializer\Groups({"read"})
|
* @Serializer\Groups({"read"})
|
||||||
|
* @Assert\NotNull(groups={"household_memberships"})
|
||||||
*/
|
*/
|
||||||
private ?\DateTimeImmutable $startDate = null;
|
private ?\DateTimeImmutable $startDate = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="date_immutable", nullable= true, options={"default": null})
|
* @ORM\Column(type="date_immutable", nullable= true, options={"default": null})
|
||||||
* @Serializer\Groups({"read"})
|
* @Serializer\Groups({"read"})
|
||||||
|
* @Assert\GreaterThan(
|
||||||
|
* propertyPath="startDate",
|
||||||
|
* message="household_membership.The end date must be after start date",
|
||||||
|
* groups={"household_memberships"}
|
||||||
|
* )
|
||||||
*/
|
*/
|
||||||
private ?\DateTimeImmutable $endDate = null;
|
private ?\DateTimeImmutable $endDate = null;
|
||||||
|
|
||||||
@@ -67,6 +75,8 @@ class HouseholdMember
|
|||||||
* targetEntity="\Chill\PersonBundle\Entity\Person"
|
* targetEntity="\Chill\PersonBundle\Entity\Person"
|
||||||
* )
|
* )
|
||||||
* @Serializer\Groups({"read"})
|
* @Serializer\Groups({"read"})
|
||||||
|
* @Assert\Valid(groups={"household_memberships"})
|
||||||
|
* @Assert\NotNull(groups={"household_memberships"})
|
||||||
*/
|
*/
|
||||||
private ?Person $person = null;
|
private ?Person $person = null;
|
||||||
|
|
||||||
@@ -76,6 +86,8 @@ class HouseholdMember
|
|||||||
* @ORM\ManyToOne(
|
* @ORM\ManyToOne(
|
||||||
* targetEntity="\Chill\PersonBundle\Entity\Household\Household"
|
* targetEntity="\Chill\PersonBundle\Entity\Household\Household"
|
||||||
* )
|
* )
|
||||||
|
* @Assert\Valid(groups={"household_memberships"})
|
||||||
|
* @Assert\NotNull(groups={"household_memberships"})
|
||||||
*/
|
*/
|
||||||
private ?Household $household = null;
|
private ?Household $household = null;
|
||||||
|
|
||||||
@@ -194,4 +206,13 @@ class HouseholdMember
|
|||||||
{
|
{
|
||||||
return $this->holder;
|
return $this->holder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isCurrent(\DateTimeImmutable $at = null): bool
|
||||||
|
{
|
||||||
|
$at = NULL === $at ? new \DateTimeImmutable('now'): $at;
|
||||||
|
|
||||||
|
return $this->getStartDate() < $at && (
|
||||||
|
NULL === $this->getEndDate() || $at < $this->getEndDate()
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,72 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Chill\PersonBundle\Entity\Household;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Entity\Address;
|
||||||
|
use Chill\PersonBundle\Entity\Household\Household;
|
||||||
|
use Chill\PersonBundle\Entity\Person;
|
||||||
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\Entity(readOnly=true)
|
||||||
|
* @ORM\Table(name="view_chill_person_household_address")
|
||||||
|
*/
|
||||||
|
class PersonHouseholdAddress
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="date_immutable")
|
||||||
|
*/
|
||||||
|
private $validFrom;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="date_immutable", nullable=true)
|
||||||
|
*/
|
||||||
|
private $validTo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\Id
|
||||||
|
* @ORM\ManyToOne(targetEntity=Person::class)
|
||||||
|
* @ORM\JoinColumn(nullable=false)
|
||||||
|
*/
|
||||||
|
private $person;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\Id
|
||||||
|
* @ORM\ManyToOne(targetEntity=Household::class)
|
||||||
|
* @ORM\JoinColumn(nullable=false)
|
||||||
|
*/
|
||||||
|
private $household;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\Id
|
||||||
|
* @ORM\ManyToOne(targetEntity=Address::class)
|
||||||
|
* @ORM\JoinColumn(nullable=false)
|
||||||
|
*/
|
||||||
|
private $address;
|
||||||
|
|
||||||
|
public function getValidFrom(): ?\DateTimeInterface
|
||||||
|
{
|
||||||
|
return $this->validFrom;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getValidTo(): ?\DateTimeImmutable
|
||||||
|
{
|
||||||
|
return $this->validTo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPerson(): ?Person
|
||||||
|
{
|
||||||
|
return $this->person;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getHousehold(): ?Household
|
||||||
|
{
|
||||||
|
return $this->relation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAddress(): ?Address
|
||||||
|
{
|
||||||
|
return $this->address;
|
||||||
|
}
|
||||||
|
}
|
@@ -23,13 +23,17 @@ namespace Chill\PersonBundle\Entity;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
use ArrayIterator;
|
use ArrayIterator;
|
||||||
|
use Chill\MainBundle\Doctrine\Model\TrackCreationInterface;
|
||||||
|
use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface;
|
||||||
use Chill\MainBundle\Entity\Center;
|
use Chill\MainBundle\Entity\Center;
|
||||||
use Chill\MainBundle\Entity\Country;
|
use Chill\MainBundle\Entity\Country;
|
||||||
|
use Chill\MainBundle\Entity\User;
|
||||||
use Chill\PersonBundle\Entity\Household\Household;
|
use Chill\PersonBundle\Entity\Household\Household;
|
||||||
use Chill\PersonBundle\Entity\MaritalStatus;
|
use Chill\PersonBundle\Entity\MaritalStatus;
|
||||||
use Chill\PersonBundle\Entity\Household\HouseholdMember;
|
use Chill\PersonBundle\Entity\Household\HouseholdMember;
|
||||||
use Chill\MainBundle\Entity\HasCenterInterface;
|
use Chill\MainBundle\Entity\HasCenterInterface;
|
||||||
use Chill\MainBundle\Entity\Address;
|
use Chill\MainBundle\Entity\Address;
|
||||||
|
use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
use Doctrine\Common\Collections\Collection;
|
use Doctrine\Common\Collections\Collection;
|
||||||
@@ -37,6 +41,7 @@ use Doctrine\Common\Collections\ArrayCollection;
|
|||||||
use Doctrine\Common\Collections\Criteria;
|
use Doctrine\Common\Collections\Criteria;
|
||||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||||
use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
|
use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
|
||||||
|
use Chill\PersonBundle\Entity\Household\PersonHouseholdAddress;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Person Class
|
* Person Class
|
||||||
@@ -52,7 +57,7 @@ use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
|
|||||||
* "person"=Person::class
|
* "person"=Person::class
|
||||||
* })
|
* })
|
||||||
*/
|
*/
|
||||||
class Person implements HasCenterInterface
|
class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* The person's id
|
* The person's id
|
||||||
@@ -99,6 +104,14 @@ class Person implements HasCenterInterface
|
|||||||
*/
|
*/
|
||||||
private $birthdate; //to change in birthdate
|
private $birthdate; //to change in birthdate
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The person's deathdate
|
||||||
|
* @var \DateTimeImmutable
|
||||||
|
*
|
||||||
|
* @ORM\Column(type="date_immutable", nullable=true)
|
||||||
|
*/
|
||||||
|
private ?\DateTimeImmutable $deathdate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The person's place of birth
|
* The person's place of birth
|
||||||
* @var string
|
* @var string
|
||||||
@@ -142,6 +155,14 @@ class Person implements HasCenterInterface
|
|||||||
const MALE_GENDER = 'man';
|
const MALE_GENDER = 'man';
|
||||||
const FEMALE_GENDER = 'woman';
|
const FEMALE_GENDER = 'woman';
|
||||||
const BOTH_GENDER = 'both';
|
const BOTH_GENDER = 'both';
|
||||||
|
const NO_INFORMATION = 'unknown';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Comment on gender
|
||||||
|
* @var CommentEmbeddable
|
||||||
|
* @ORM\Embedded(class="Chill\MainBundle\Entity\Embeddable\CommentEmbeddable", columnPrefix="genderComment_")
|
||||||
|
*/
|
||||||
|
private CommentEmbeddable $genderComment;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The marital status of the person
|
* The marital status of the person
|
||||||
@@ -152,6 +173,21 @@ class Person implements HasCenterInterface
|
|||||||
*/
|
*/
|
||||||
private $maritalStatus;
|
private $maritalStatus;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The date of the last marital status change of the person
|
||||||
|
* @var \DateTime
|
||||||
|
*
|
||||||
|
* @ORM\Column(type="date", nullable=true)
|
||||||
|
*/
|
||||||
|
private $maritalStatusDate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Comment on marital status
|
||||||
|
* @var CommentEmbeddable
|
||||||
|
* @ORM\Embedded(class="Chill\MainBundle\Entity\Embeddable\CommentEmbeddable", columnPrefix="maritalStatusComment_")
|
||||||
|
*/
|
||||||
|
private CommentEmbeddable $maritalStatusComment;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contact information for contacting the person
|
* Contact information for contacting the person
|
||||||
* @var string
|
* @var string
|
||||||
@@ -239,6 +275,54 @@ class Person implements HasCenterInterface
|
|||||||
*/
|
*/
|
||||||
private $memo = ''; // TO-CHANGE in remark
|
private $memo = ''; // TO-CHANGE in remark
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Accept short text message (aka SMS)
|
||||||
|
* @var boolean
|
||||||
|
*
|
||||||
|
* @ORM\Column(type="boolean", options={"default" : false})
|
||||||
|
*/
|
||||||
|
private ?bool $acceptSMS = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Accept receiving email
|
||||||
|
* @var boolean
|
||||||
|
*
|
||||||
|
* @ORM\Column(type="boolean", options={"default" : false})
|
||||||
|
*/
|
||||||
|
private ?bool $acceptEmail = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Number of children
|
||||||
|
* @var int
|
||||||
|
*
|
||||||
|
* @ORM\Column(type="integer", nullable=true)
|
||||||
|
*/
|
||||||
|
private ?int $numberOfChildren = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\ManyToOne(targetEntity=User::class)
|
||||||
|
* @ORM\JoinColumn(nullable=true)
|
||||||
|
*/
|
||||||
|
private $createdBy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="datetime", nullable=true, options={"default": NULL})
|
||||||
|
*/
|
||||||
|
private \DateTimeInterface $createdAt;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\ManyToOne(
|
||||||
|
* targetEntity=User::class
|
||||||
|
* )
|
||||||
|
*/
|
||||||
|
private User $updatedBy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="datetime", nullable=true, options={"default": NULL})
|
||||||
|
*/
|
||||||
|
private \DateTimeInterface $updatedAt;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var boolean
|
* @var boolean
|
||||||
* @deprecated
|
* @deprecated
|
||||||
@@ -287,6 +371,14 @@ class Person implements HasCenterInterface
|
|||||||
*/
|
*/
|
||||||
private array $currentHouseholdAt = [];
|
private array $currentHouseholdAt = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\OneToMany(
|
||||||
|
* targetEntity=PersonHouseholdAddress::class,
|
||||||
|
* mappedBy="person"
|
||||||
|
* )
|
||||||
|
*/
|
||||||
|
private Collection $householdAddresses;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Person constructor.
|
* Person constructor.
|
||||||
*
|
*
|
||||||
@@ -300,12 +392,15 @@ class Person implements HasCenterInterface
|
|||||||
$this->altNames = new ArrayCollection();
|
$this->altNames = new ArrayCollection();
|
||||||
$this->otherPhoneNumbers = new ArrayCollection();
|
$this->otherPhoneNumbers = new ArrayCollection();
|
||||||
$this->householdParticipations = new ArrayCollection();
|
$this->householdParticipations = new ArrayCollection();
|
||||||
|
$this->householdAddresses = new ArrayCollection();
|
||||||
|
|
||||||
if ($opening === null) {
|
if ($opening === null) {
|
||||||
$opening = new \DateTime();
|
$opening = new \DateTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->open(new AccompanyingPeriod($opening));
|
$this->open(new AccompanyingPeriod($opening));
|
||||||
|
$this->genderComment = new CommentEmbeddable();
|
||||||
|
$this->maritalStatusComment = new CommentEmbeddable();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1209,16 +1304,69 @@ class Person implements HasCenterInterface
|
|||||||
return $this->householdParticipations;
|
return $this->householdParticipations;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCurrentHousehold(?\DateTimeImmutable $at = null): ?Household
|
/**
|
||||||
|
* Get participation where the person does share the household.
|
||||||
|
*
|
||||||
|
* Order by startDate, desc
|
||||||
|
*/
|
||||||
|
public function getHouseholdParticipationsShareHousehold(): Collection
|
||||||
{
|
{
|
||||||
$criteria = new Criteria();
|
$criteria = new Criteria();
|
||||||
$expr = Criteria::expr();
|
$expr = Criteria::expr();
|
||||||
$date = NULL === $at ? new \DateTimeImmutable('now') : $at;
|
|
||||||
|
$criteria
|
||||||
|
->where(
|
||||||
|
$expr->eq('shareHousehold', true)
|
||||||
|
)
|
||||||
|
->orderBy(['startDate' => Criteria::DESC])
|
||||||
|
;
|
||||||
|
|
||||||
|
return $this->getHouseholdParticipations()
|
||||||
|
->matching($criteria)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get participation where the person does not share the household.
|
||||||
|
*
|
||||||
|
* Order by startDate, desc
|
||||||
|
*/
|
||||||
|
public function getHouseholdParticipationsNotShareHousehold(): Collection
|
||||||
|
{
|
||||||
|
$criteria = new Criteria();
|
||||||
|
$expr = Criteria::expr();
|
||||||
|
|
||||||
|
$criteria
|
||||||
|
->where(
|
||||||
|
$expr->eq('shareHousehold', false)
|
||||||
|
)
|
||||||
|
->orderBy(['startDate' => Criteria::DESC])
|
||||||
|
;
|
||||||
|
|
||||||
|
return $this->getHouseholdParticipations()
|
||||||
|
->matching($criteria)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCurrentHousehold(?\DateTimeImmutable $at = null): ?Household
|
||||||
|
{
|
||||||
|
$participation = $this->getCurrentHouseholdParticipationShareHousehold($at);
|
||||||
|
|
||||||
|
return $participation instanceof HouseholdMember ?
|
||||||
|
$participation->getHousehold()
|
||||||
|
: null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCurrentHouseholdParticipationShareHousehold(?\DateTimeImmutable $at = null): ?HouseholdMember
|
||||||
|
{
|
||||||
|
$criteria = new Criteria();
|
||||||
|
$expr = Criteria::expr();
|
||||||
|
$date = NULL === $at ? new \DateTimeImmutable('today') : $at;
|
||||||
$datef = $date->format('Y-m-d');
|
$datef = $date->format('Y-m-d');
|
||||||
|
|
||||||
if (
|
if (
|
||||||
NULL !== ($this->currentHouseholdAt[$datef] ?? NULL)) {
|
NULL !== ($this->currentHouseholdParticipationAt[$datef] ?? NULL)) {
|
||||||
return $this->currentHouseholdAt[$datef];
|
return $this->currentHouseholdParticipationAt[$datef];
|
||||||
}
|
}
|
||||||
|
|
||||||
$criteria
|
$criteria
|
||||||
@@ -1227,7 +1375,7 @@ class Person implements HasCenterInterface
|
|||||||
$expr->lte('startDate', $date),
|
$expr->lte('startDate', $date),
|
||||||
$expr->orX(
|
$expr->orX(
|
||||||
$expr->isNull('endDate'),
|
$expr->isNull('endDate'),
|
||||||
$expr->gte('endDate', $date)
|
$expr->gt('endDate', $date)
|
||||||
),
|
),
|
||||||
$expr->eq('shareHousehold', true)
|
$expr->eq('shareHousehold', true)
|
||||||
)
|
)
|
||||||
@@ -1238,8 +1386,7 @@ class Person implements HasCenterInterface
|
|||||||
;
|
;
|
||||||
|
|
||||||
return $participations->count() > 0 ?
|
return $participations->count() > 0 ?
|
||||||
$this->currentHouseholdAt[$datef] = $participations->first()
|
$this->currentHouseholdParticipationAt[$datef] = $participations->first()
|
||||||
->getHousehold()
|
|
||||||
: null;
|
: null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1247,4 +1394,154 @@ class Person implements HasCenterInterface
|
|||||||
{
|
{
|
||||||
return NULL !== $this->getCurrentHousehold($at);
|
return NULL !== $this->getCurrentHousehold($at);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getHouseholdAddresses(): Collection
|
||||||
|
{
|
||||||
|
return $this->householdAddresses;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCurrentHouseholdAddress(?\DateTimeImmutable $at = null): ?Address
|
||||||
|
{
|
||||||
|
$at = $at === null ? new \DateTimeImmutable('today') : $at;
|
||||||
|
$criteria = new Criteria();
|
||||||
|
$expr = Criteria::expr();
|
||||||
|
|
||||||
|
$criteria->where(
|
||||||
|
$expr->lte('validFrom', $at)
|
||||||
|
)
|
||||||
|
->andWhere(
|
||||||
|
$expr->orX(
|
||||||
|
$expr->isNull('validTo'),
|
||||||
|
$expr->gte('validTo', $at)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$addrs = $this->getHouseholdAddresses()
|
||||||
|
->matching($criteria)
|
||||||
|
;
|
||||||
|
|
||||||
|
if ($addrs->count() > 0) {
|
||||||
|
return $addrs->first()->getAddress();
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getGenderComment(): CommentEmbeddable
|
||||||
|
{
|
||||||
|
return $this->genderComment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setGenderComment(CommentEmbeddable $genderComment): self
|
||||||
|
{
|
||||||
|
$this->genderComment = $genderComment;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMaritalStatusComment(): CommentEmbeddable
|
||||||
|
{
|
||||||
|
return $this->maritalStatusComment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setMaritalStatusComment(CommentEmbeddable $maritalStatusComment): self
|
||||||
|
{
|
||||||
|
$this->maritalStatusComment = $maritalStatusComment;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDeathdate(): ?\DateTimeInterface
|
||||||
|
{
|
||||||
|
return $this->deathdate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setDeathdate(?\DateTimeInterface $deathdate): self
|
||||||
|
{
|
||||||
|
$this->deathdate = $deathdate;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMaritalStatusDate(): ?\DateTimeInterface
|
||||||
|
{
|
||||||
|
return $this->maritalStatusDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setMaritalStatusDate(?\DateTimeInterface $maritalStatusDate): self
|
||||||
|
{
|
||||||
|
$this->maritalStatusDate = $maritalStatusDate;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAcceptSMS(): ?bool
|
||||||
|
{
|
||||||
|
return $this->acceptSMS;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setAcceptSMS(bool $acceptSMS): self
|
||||||
|
{
|
||||||
|
$this->acceptSMS = $acceptSMS;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAcceptEmail(): ?bool
|
||||||
|
{
|
||||||
|
return $this->acceptEmail;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setAcceptEmail(bool $acceptEmail): self
|
||||||
|
{
|
||||||
|
$this->acceptEmail = $acceptEmail;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getNumberOfChildren(): ?int
|
||||||
|
{
|
||||||
|
return $this->numberOfChildren;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setNumberOfChildren(int $numberOfChildren): self
|
||||||
|
{
|
||||||
|
$this->numberOfChildren = $numberOfChildren;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCreatedBy(): ?User
|
||||||
|
{
|
||||||
|
return $this->createdBy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCreatedBy(User $createdBy): self
|
||||||
|
{
|
||||||
|
$this->createdBy = $createdBy;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCreatedAt(\DateTimeInterface $datetime): self
|
||||||
|
{
|
||||||
|
$this->createdAt = $datetime;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setUpdatedBy(User $user): self
|
||||||
|
{
|
||||||
|
$this->updatedBy = $user;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setUpdatedAt(\DateTimeInterface $datetime): self
|
||||||
|
{
|
||||||
|
$this->updatedAt = $datetime;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -5,10 +5,17 @@ namespace Chill\PersonBundle\Entity\SocialWork;
|
|||||||
use Doctrine\Common\Collections\ArrayCollection;
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
use Doctrine\Common\Collections\Collection;
|
use Doctrine\Common\Collections\Collection;
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
use Symfony\Component\Serializer\Annotation as Serializer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Entity
|
* @ORM\Entity
|
||||||
* @ORM\Table(name="chill_person_social_work_goal")
|
* @ORM\Table(name="chill_person_social_work_goal")
|
||||||
|
* @Serializer\DiscriminatorMap(
|
||||||
|
* typeProperty="type",
|
||||||
|
* mapping={
|
||||||
|
* "social_work_goal":Goal::class
|
||||||
|
* }
|
||||||
|
* )
|
||||||
*/
|
*/
|
||||||
class Goal
|
class Goal
|
||||||
{
|
{
|
||||||
@@ -16,11 +23,13 @@ class Goal
|
|||||||
* @ORM\Id
|
* @ORM\Id
|
||||||
* @ORM\GeneratedValue
|
* @ORM\GeneratedValue
|
||||||
* @ORM\Column(type="integer")
|
* @ORM\Column(type="integer")
|
||||||
|
* @Serializer\Groups({"read"})
|
||||||
*/
|
*/
|
||||||
private $id;
|
private $id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="json")
|
* @ORM\Column(type="json")
|
||||||
|
* @Serializer\Groups({"read"})
|
||||||
*/
|
*/
|
||||||
private $title = [];
|
private $title = [];
|
||||||
|
|
||||||
@@ -46,6 +55,11 @@ class Goal
|
|||||||
$this->results = new ArrayCollection();
|
$this->results = new ArrayCollection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getId(): ?int
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
public function getTitle(): array
|
public function getTitle(): array
|
||||||
{
|
{
|
||||||
return $this->title;
|
return $this->title;
|
||||||
|
@@ -7,10 +7,17 @@ use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkGoal;
|
|||||||
use Doctrine\Common\Collections\ArrayCollection;
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
use Doctrine\Common\Collections\Collection;
|
use Doctrine\Common\Collections\Collection;
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
use Symfony\Component\Serializer\Annotation as Serializer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Entity
|
* @ORM\Entity
|
||||||
* @ORM\Table(name="chill_person_social_work_result")
|
* @ORM\Table(name="chill_person_social_work_result")
|
||||||
|
* @Serializer\DiscriminatorMap(
|
||||||
|
* typeProperty="type",
|
||||||
|
* mapping={
|
||||||
|
* "social_work_result":Result::class
|
||||||
|
* }
|
||||||
|
* )
|
||||||
*/
|
*/
|
||||||
class Result
|
class Result
|
||||||
{
|
{
|
||||||
@@ -18,11 +25,13 @@ class Result
|
|||||||
* @ORM\Id
|
* @ORM\Id
|
||||||
* @ORM\GeneratedValue
|
* @ORM\GeneratedValue
|
||||||
* @ORM\Column(type="integer")
|
* @ORM\Column(type="integer")
|
||||||
|
* @Serializer\Groups({"read"})
|
||||||
*/
|
*/
|
||||||
private $id;
|
private $id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="json")
|
* @ORM\Column(type="json")
|
||||||
|
* @Serializer\Groups({"read"})
|
||||||
*/
|
*/
|
||||||
private $title = [];
|
private $title = [];
|
||||||
|
|
||||||
|
@@ -5,10 +5,17 @@ namespace Chill\PersonBundle\Entity\SocialWork;
|
|||||||
use Doctrine\Common\Collections\ArrayCollection;
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
use Doctrine\Common\Collections\Collection;
|
use Doctrine\Common\Collections\Collection;
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
use Symfony\Component\Serializer\Annotation as Serializer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Entity
|
* @ORM\Entity
|
||||||
* @ORM\Table(name="chill_person_social_action")
|
* @ORM\Table(name="chill_person_social_action")
|
||||||
|
* @Serializer\DiscriminatorMap(
|
||||||
|
* typeProperty="type",
|
||||||
|
* mapping={
|
||||||
|
* "social_work_social_action":SocialAction::class
|
||||||
|
* }
|
||||||
|
* )
|
||||||
*/
|
*/
|
||||||
class SocialAction
|
class SocialAction
|
||||||
{
|
{
|
||||||
|
@@ -35,7 +35,8 @@ class HouseholdMemberType extends AbstractType
|
|||||||
}
|
}
|
||||||
$builder
|
$builder
|
||||||
->add('comment', ChillTextareaType::class, [
|
->add('comment', ChillTextareaType::class, [
|
||||||
'label' => 'household.Comment'
|
'label' => 'household.Comment',
|
||||||
|
'required' => false
|
||||||
])
|
])
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
40
src/Bundle/ChillPersonBundle/Form/HouseholdType.php
Normal file
40
src/Bundle/ChillPersonBundle/Form/HouseholdType.php
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Chill\PersonBundle\Form;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Form\Type\ChillDateType;
|
||||||
|
use Chill\MainBundle\Form\Type\CommentType;
|
||||||
|
use Chill\PersonBundle\Entity\Household\Household;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||||
|
use Symfony\Component\Form\AbstractType;
|
||||||
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
|
|
||||||
|
class HouseholdType extends AbstractType
|
||||||
|
{
|
||||||
|
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||||
|
{
|
||||||
|
$builder
|
||||||
|
->add('commentMembers', CommentType::class, [
|
||||||
|
'label' => 'household.comment_membership',
|
||||||
|
'required' => false
|
||||||
|
])
|
||||||
|
->add('waitingForBirth', CheckboxType::class, [
|
||||||
|
'required' => false,
|
||||||
|
'label' => 'household.expecting_birth'
|
||||||
|
])
|
||||||
|
->add('waitingForBirthDate', ChillDateType::class, [
|
||||||
|
'required' => false,
|
||||||
|
'label' => 'household.date_expecting_birth',
|
||||||
|
'input' => 'datetime_immutable'
|
||||||
|
])
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function configureOptions(OptionsResolver $resolver)
|
||||||
|
{
|
||||||
|
$resolver->setDefaults([
|
||||||
|
'data_class' => Household::class,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
@@ -34,9 +34,13 @@ use Chill\PersonBundle\Entity\PersonPhone;
|
|||||||
use Chill\PersonBundle\Form\Type\Select2MaritalStatusType;
|
use Chill\PersonBundle\Form\Type\Select2MaritalStatusType;
|
||||||
use Symfony\Component\Form\AbstractType;
|
use Symfony\Component\Form\AbstractType;
|
||||||
use Chill\MainBundle\Form\Type\ChillDateType;
|
use Chill\MainBundle\Form\Type\ChillDateType;
|
||||||
|
use Chill\MainBundle\Form\Type\CommentType;
|
||||||
use Symfony\Component\Form\Extension\Core\Type\EmailType;
|
use Symfony\Component\Form\Extension\Core\Type\EmailType;
|
||||||
use Symfony\Component\Form\Extension\Core\Type\TelType;
|
use Symfony\Component\Form\Extension\Core\Type\TelType;
|
||||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\DateType;
|
||||||
use Symfony\Component\Form\FormBuilderInterface;
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
|
|
||||||
@@ -82,8 +86,19 @@ class PersonType extends AbstractType
|
|||||||
->add('birthdate', ChillDateType::class, [
|
->add('birthdate', ChillDateType::class, [
|
||||||
'required' => false,
|
'required' => false,
|
||||||
])
|
])
|
||||||
|
->add('deathdate', DateType::class, [
|
||||||
|
'required' => false,
|
||||||
|
'input' => 'datetime_immutable',
|
||||||
|
'widget' => 'single_text'
|
||||||
|
])
|
||||||
->add('gender', GenderType::class, array(
|
->add('gender', GenderType::class, array(
|
||||||
'required' => true
|
'required' => true
|
||||||
|
))
|
||||||
|
->add('genderComment', CommentType::class, array(
|
||||||
|
'required' => false
|
||||||
|
))
|
||||||
|
->add('numberOfChildren', IntegerType::class, array(
|
||||||
|
'required' => false
|
||||||
));
|
));
|
||||||
|
|
||||||
if ($this->configAltNamesHelper->hasAltNames()) {
|
if ($this->configAltNamesHelper->hasAltNames()) {
|
||||||
@@ -111,7 +126,12 @@ class PersonType extends AbstractType
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($this->config['mobilenumber'] === 'visible') {
|
if ($this->config['mobilenumber'] === 'visible') {
|
||||||
$builder->add('mobilenumber', TelType::class, array('required' => false));
|
$builder
|
||||||
|
->add('mobilenumber', TelType::class, array('required' => false))
|
||||||
|
->add('acceptSMS', CheckboxType::class, array(
|
||||||
|
'value' => false,
|
||||||
|
'required' => true
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
$builder->add('otherPhoneNumbers', ChillCollectionType::class, [
|
$builder->add('otherPhoneNumbers', ChillCollectionType::class, [
|
||||||
@@ -130,7 +150,9 @@ class PersonType extends AbstractType
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
if ($this->config['email'] === 'visible') {
|
if ($this->config['email'] === 'visible') {
|
||||||
$builder->add('email', EmailType::class, array('required' => false));
|
$builder
|
||||||
|
->add('email', EmailType::class, array('required' => false))
|
||||||
|
->add('acceptEmail', CheckboxType::class, array('required' => false));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->config['country_of_birth'] === 'visible') {
|
if ($this->config['country_of_birth'] === 'visible') {
|
||||||
@@ -153,7 +175,14 @@ class PersonType extends AbstractType
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($this->config['marital_status'] === 'visible'){
|
if ($this->config['marital_status'] === 'visible'){
|
||||||
$builder->add('maritalStatus', Select2MaritalStatusType::class, array(
|
$builder
|
||||||
|
->add('maritalStatus', Select2MaritalStatusType::class, array(
|
||||||
|
'required' => false
|
||||||
|
))
|
||||||
|
->add('maritalStatusDate', ChillDateType::class, array(
|
||||||
|
'required' => false
|
||||||
|
))
|
||||||
|
->add('maritalStatusComment', CommentType::class, array(
|
||||||
'required' => false
|
'required' => false
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
@@ -3,6 +3,7 @@
|
|||||||
namespace Chill\PersonBundle\Household;
|
namespace Chill\PersonBundle\Household;
|
||||||
|
|
||||||
use Symfony\Component\Validator\ConstraintViolationListInterface;
|
use Symfony\Component\Validator\ConstraintViolationListInterface;
|
||||||
|
use Symfony\Component\Validator\ConstraintViolationList;
|
||||||
use Doctrine\Common\Collections\Criteria;
|
use Doctrine\Common\Collections\Criteria;
|
||||||
use Chill\PersonBundle\Entity\Household\HouseholdMember;
|
use Chill\PersonBundle\Entity\Household\HouseholdMember;
|
||||||
use Chill\PersonBundle\Entity\Household\Position;
|
use Chill\PersonBundle\Entity\Household\Position;
|
||||||
@@ -19,9 +20,11 @@ class MembersEditor
|
|||||||
private array $persistables = [];
|
private array $persistables = [];
|
||||||
private array $membershipsAffected = [];
|
private array $membershipsAffected = [];
|
||||||
|
|
||||||
|
public const VALIDATION_GROUP = 'household_memberships';
|
||||||
|
|
||||||
public function __construct(ValidatorInterface $validator, ?Household $household)
|
public function __construct(ValidatorInterface $validator, ?Household $household)
|
||||||
{
|
{
|
||||||
$this->validation = $validator;
|
$this->validator = $validator;
|
||||||
$this->household = $household;
|
$this->household = $household;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,12 +44,12 @@ class MembersEditor
|
|||||||
$this->household->addMember($membership);
|
$this->household->addMember($membership);
|
||||||
|
|
||||||
if ($position->getShareHousehold()) {
|
if ($position->getShareHousehold()) {
|
||||||
foreach ($person->getHouseholdParticipations() as $participation) {
|
foreach ($person->getHouseholdParticipationsShareHousehold() as $participation) {
|
||||||
if (FALSE === $participation->getShareHousehold()) {
|
if ($participation === $membership) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($participation === $membership) {
|
if ($participation->getStartDate() > $membership->getStartDate()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,7 +95,18 @@ class MembersEditor
|
|||||||
|
|
||||||
public function validate(): ConstraintViolationListInterface
|
public function validate(): ConstraintViolationListInterface
|
||||||
{
|
{
|
||||||
|
if ($this->hasHousehold()) {
|
||||||
|
$list = $this->validator
|
||||||
|
->validate($this->getHousehold(), null, [ self::VALIDATION_GROUP ]);
|
||||||
|
} else {
|
||||||
|
$list = new ConstraintViolationList();
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($this->membershipsAffected as $m) {
|
||||||
|
$list->addAll($this->validator->validate($m, null, [ self::VALIDATION_GROUP ]));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $list;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPersistable(): array
|
public function getPersistable(): array
|
||||||
@@ -100,6 +114,7 @@ class MembersEditor
|
|||||||
return $this->persistables;
|
return $this->persistables;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function getHousehold(): ?Household
|
public function getHousehold(): ?Household
|
||||||
{
|
{
|
||||||
return $this->household;
|
return $this->household;
|
||||||
|
@@ -60,6 +60,13 @@ class AccompanyingCourseMenuBuilder implements LocalMenuBuilderInterface
|
|||||||
'accompanying_period_id' => $period->getId()
|
'accompanying_period_id' => $period->getId()
|
||||||
]])
|
]])
|
||||||
->setExtras(['order' => 30]);
|
->setExtras(['order' => 30]);
|
||||||
|
|
||||||
|
$menu->addChild($this->translator->trans('Accompanying Course Actions'), [
|
||||||
|
'route' => 'chill_person_accompanying_period_work_list',
|
||||||
|
'routeParameters' => [
|
||||||
|
'id' => $period->getId()
|
||||||
|
]])
|
||||||
|
->setExtras(['order' => 40]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user