Merge branch 'master' into notification/completion

This commit is contained in:
Mathieu Jaumotte 2022-01-10 16:11:06 +01:00
commit 46ca74fc70
78 changed files with 1268 additions and 277 deletions

View File

@ -11,6 +11,8 @@ and this project adheres to
## Unreleased ## Unreleased
<!-- write down unreleased development here --> <!-- write down unreleased development here -->
* vuejs: translate in French all multiselect widgets
* [address] define address lines according postal standards for France and Belgium (default) and change AddressRender, chill_entity_render_box and AddressRenderBox.vue
* [household] change translations (champs-libres/departement-de-la-vendee/accent-suivi-developpement#109) * [household] change translations (champs-libres/departement-de-la-vendee/accent-suivi-developpement#109)
* [household] add address i18n in household component (champs-libres/departement-de-la-vendee/accent-suivi-developpement#158) * [household] add address i18n in household component (champs-libres/departement-de-la-vendee/accent-suivi-developpement#158)
* [household] add on the fly i18n in household component * [household] add on the fly i18n in household component
@ -20,6 +22,9 @@ and this project adheres to
* [household] household member editor: remove markNoAddress button (champs-libres/departement-de-la-vendee/accent-suivi-developpement#109) * [household] household member editor: remove markNoAddress button (champs-libres/departement-de-la-vendee/accent-suivi-developpement#109)
* [person]: ordering fields in add person (https://gitlab.com/champs-libres/departement-de-la-vendee/accent-suivi-developpement/-/issues/61) * [person]: ordering fields in add person (https://gitlab.com/champs-libres/departement-de-la-vendee/accent-suivi-developpement/-/issues/61)
* [person]: Add email and alt names in add person (https://gitlab.com/champs-libres/departement-de-la-vendee/accent-suivi-developpement/-/issues/61) * [person]: Add email and alt names in add person (https://gitlab.com/champs-libres/departement-de-la-vendee/accent-suivi-developpement/-/issues/61)
* [accompanyingCourse] Add a delete action and delete buttons to delete a accompanying course when step = DRAFT (https://gitlab.com/champs-libres/departement-de-la-vendee/accent-suivi-developpement/-/issues/64)
* [accompanyingCourse] Add a administrative location in the accompanying course, set the user current location as default, allow to select a location in a select field and do not allow to confirm the accompanying course if location is empty.
* [accompanyingCourse] Add the administrative location in the available variables for document generation
* AddAddress: optimize loading: wait for the user finish typing; * AddAddress: optimize loading: wait for the user finish typing;
* UserPicker: fix bug with deprecated role * UserPicker: fix bug with deprecated role
* docgen: add base context + tests * docgen: add base context + tests

View File

@ -60,6 +60,7 @@
"drupol/php-conventions": "^5", "drupol/php-conventions": "^5",
"fakerphp/faker": "^1.13", "fakerphp/faker": "^1.13",
"nelmio/alice": "^3.8", "nelmio/alice": "^3.8",
"phpspec/prophecy-phpunit": "^2.0",
"phpstan/phpstan-strict-rules": "^1.0", "phpstan/phpstan-strict-rules": "^1.0",
"phpunit/phpunit": ">= 7.5", "phpunit/phpunit": ">= 7.5",
"symfony/debug-bundle": "^5.1", "symfony/debug-bundle": "^5.1",

View File

@ -315,11 +315,6 @@ parameters:
count: 1 count: 1
path: src/Bundle/ChillMainBundle/Security/PasswordRecover/TokenManager.php path: src/Bundle/ChillMainBundle/Security/PasswordRecover/TokenManager.php
-
message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#"
count: 3
path: src/Bundle/ChillMainBundle/Templating/Entity/AddressRender.php
- -
message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#" message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#"
count: 1 count: 1

View File

@ -6,7 +6,6 @@
backupGlobals="false" backupGlobals="false"
colors="true" colors="true"
bootstrap="tests/app/tests/bootstrap.php" bootstrap="tests/app/tests/bootstrap.php"
stopOnFailure="true"
> >
<php> <php>
<ini name="error_reporting" value="-1" /> <ini name="error_reporting" value="-1" />

View File

@ -12,7 +12,7 @@
</div> </div>
<div v-if="getContext === 'accompanyingCourse' && suggestedEntities.length > 0"> <div v-if="getContext === 'accompanyingCourse' && suggestedEntities.length > 0">
<ul class="list-suggest add-items inline"> <ul class="list-suggest add-items inline">
<li v-for="p in suggestedEntities" @click="addSuggestedEntity(p)"> <li v-for="(p, i) in suggestedEntities" @click="addSuggestedEntity(p)" :key="`suggestedEntities-${i}`">
<span>{{ p.text }}</span> <span>{{ p.text }}</span>
</li> </li>
</ul> </ul>

View File

@ -15,13 +15,15 @@
:searchable="true" :searchable="true"
:placeholder="$t('activity.choose_location')" :placeholder="$t('activity.choose_location')"
:custom-label="customLabel" :custom-label="customLabel"
:select-label="$t('multiselect.select_label')"
:deselect-label="$t('multiselect.deselect_label')"
:selected-label="$t('multiselect.selected_label')"
:options="availableLocations" :options="availableLocations"
group-values="locations" group-values="locations"
group-label="locationGroup" group-label="locationGroup"
v-model="location" v-model="location"
> >
</VueMultiselect> </VueMultiselect>
<new-location v-bind:locations="locations"></new-location> <new-location v-bind:locations="locations"></new-location>
</div> </div>
</div> </div>
@ -32,7 +34,6 @@
import { mapState, mapGetters } from "vuex"; import { mapState, mapGetters } from "vuex";
import VueMultiselect from "vue-multiselect"; import VueMultiselect from "vue-multiselect";
import NewLocation from "./Location/NewLocation.vue"; import NewLocation from "./Location/NewLocation.vue";
import { getLocations, getLocationTypeByDefaultFor, getUserCurrentLocation } from "../api.js";
export default { export default {
name: "Location", name: "Location",

View File

@ -9,9 +9,9 @@
<check-social-issue <check-social-issue
v-for="issue in socialIssuesList" v-for="issue in socialIssuesList"
v-bind:key="issue.id" :key="issue.id"
v-bind:issue="issue" :issue="issue"
v-bind:selection="socialIssuesSelected" :selection="socialIssuesSelected"
@updateSelected="updateIssuesSelected"> @updateSelected="updateIssuesSelected">
</check-social-issue> </check-social-issue>
@ -21,18 +21,18 @@
label="text" label="text"
track-by="id" track-by="id"
open-direction="bottom" open-direction="bottom"
v-bind:close-on-select="true" :close-on-select="true"
v-bind:preserve-search="false" :preserve-search="false"
v-bind:reset-after="true" :reset-after="true"
v-bind:hide-selected="true" :hide-selected="true"
v-bind:taggable="false" :taggable="false"
v-bind:multiple="false" :multiple="false"
v-bind:searchable="true" :searchable="true"
v-bind:allow-empty="true" :allow-empty="true"
v-bind:show-labels="false" :show-labels="false"
v-bind:loading="issueIsLoading" :loading="issueIsLoading"
v-bind:placeholder="$t('activity.choose_other_social_issue')" :placeholder="$t('activity.choose_other_social_issue')"
v-bind:options="socialIssuesOther" :options="socialIssuesOther"
@select="addIssueInList"> @select="addIssueInList">
</VueMultiselect> </VueMultiselect>
</div> </div>
@ -58,9 +58,9 @@
<check-social-action <check-social-action
v-if="socialIssuesSelected.length || socialActionsSelected.length" v-if="socialIssuesSelected.length || socialActionsSelected.length"
v-for="action in socialActionsList" v-for="action in socialActionsList"
v-bind:key="action.id" :key="action.id"
v-bind:action="action" :action="action"
v-bind:selection="socialActionsSelected" :selection="socialActionsSelected"
@updateSelected="updateActionsSelected"> @updateSelected="updateActionsSelected">
</check-social-action> </check-social-action>
</template> </template>

View File

@ -1,4 +1,5 @@
import { personMessages } from 'ChillPersonAssets/vuejs/_js/i18n' import { personMessages } from 'ChillPersonAssets/vuejs/_js/i18n'
import { multiSelectMessages } from 'ChillMainAssets/vuejs/_js/i18n'
const activityMessages = { const activityMessages = {
fr: { fr: {
@ -33,12 +34,11 @@ const activityMessages = {
}, },
create_address: 'Créer une adresse', create_address: 'Créer une adresse',
edit_address: "Modifier l'adresse" edit_address: "Modifier l'adresse"
} }
} }
} }
Object.assign(activityMessages.fr, personMessages.fr); Object.assign(activityMessages.fr, personMessages.fr, multiSelectMessages.fr);
export { export {
activityMessages activityMessages

View File

@ -13,6 +13,9 @@
:close-on-select="false" :close-on-select="false"
:allow-empty="true" :allow-empty="true"
:model-value="value" :model-value="value"
:select-label="$t('multiselect.select_label')"
:deselect-label="$t('multiselect.deselect_label')"
:selected-label="$t('multiselect.selected_label')"
@select="selectUsers" @select="selectUsers"
@remove="unSelectUsers" @remove="unSelectUsers"
@close="coloriseSelectedValues" @close="coloriseSelectedValues"

View File

@ -1,3 +1,5 @@
import { multiSelectMessages } from 'ChillMainAssets/vuejs/_js/i18n'
const calendarUserSelectorMessages = { const calendarUserSelectorMessages = {
fr: { fr: {
choose_your_calendar_user: "Afficher les plages de disponibilités", choose_your_calendar_user: "Afficher les plages de disponibilités",
@ -5,9 +7,11 @@ const calendarUserSelectorMessages = {
show_my_calendar: "Afficher mon calendrier", show_my_calendar: "Afficher mon calendrier",
show_weekends: "Afficher les week-ends" show_weekends: "Afficher les week-ends"
} }
}; };
export { Object.assign(calendarUserSelectorMessages.fr, multiSelectMessages.fr);
export {
calendarUserSelectorMessages calendarUserSelectorMessages
}; };

View File

@ -276,7 +276,6 @@ final class DocGeneratorTemplateController extends AbstractController
fwrite($templateResource, $dataDecrypted); fwrite($templateResource, $dataDecrypted);
rewind($templateResource); rewind($templateResource);
} }
$datas = $context->getData($template, $entity, $contextGenerationData); $datas = $context->getData($template, $entity, $contextGenerationData);
try { try {

View File

@ -46,7 +46,6 @@ class RelatorioDriver implements DriverInterface
'template' => new DataPart($template, $templateName ?? uniqid('template_'), $resourceType), 'template' => new DataPart($template, $templateName ?? uniqid('template_'), $resourceType),
]; ];
$form = new FormDataPart($formFields); $form = new FormDataPart($formFields);
dump(json_encode($data));
try { try {
$response = $this->relatorioClient->request('POST', $this->url, [ $response = $this->relatorioClient->request('POST', $this->url, [

View File

@ -23,11 +23,7 @@
<input type="hidden" name="entityClassName" value="{{ contextManager.getContextByKey(entity.context).entityClass|e('html_attr') }}" /> <input type="hidden" name="entityClassName" value="{{ contextManager.getContextByKey(entity.context).entityClass|e('html_attr') }}" />
<input type="text" name="entityId" /> <input type="text" name="entityId" />
<ul class="record_actions"> <button type="submit" class="btn btn-mini btn-misc"><i class="fa fa-cog"></i>{{ 'docgen.test generate'|trans }}</button>
<li>
<button type="submit" class="btn btn-mini btn-neutral">{{ 'docgen.test generate'|trans }}</button>
</li>
</ul>
</form> </form>
</td> </td>
<td> <td>

View File

@ -11,9 +11,11 @@ declare(strict_types=1);
namespace Chill\DocGeneratorBundle\Serializer\Helper; namespace Chill\DocGeneratorBundle\Serializer\Helper;
use Symfony\Component\Serializer\Mapping\ClassMetadata;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
use function array_merge; use function array_merge;
use function is_array;
class NormalizeNullValueHelper class NormalizeNullValueHelper
{ {
@ -30,7 +32,7 @@ class NormalizeNullValueHelper
$this->discriminatorValue = $discriminatorValue; $this->discriminatorValue = $discriminatorValue;
} }
public function normalize(array $attributes, string $format = 'docgen', ?array $context = []) public function normalize(array $attributes, string $format = 'docgen', ?array $context = [], ?ClassMetadata $classMetadata = null)
{ {
$data = []; $data = [];
$data['isNull'] = true; $data['isNull'] = true;
@ -58,7 +60,7 @@ class NormalizeNullValueHelper
default: default:
$data[$key] = $this->normalizer->normalize(null, $format, array_merge( $data[$key] = $this->normalizer->normalize(null, $format, array_merge(
$context, $this->getContextForAttribute($key, $context, $classMetadata),
['docgen:expects' => $class] ['docgen:expects' => $class]
)); ));
@ -69,4 +71,25 @@ class NormalizeNullValueHelper
return $data; return $data;
} }
private function getContextForAttribute(string $key, array $initialContext, ?ClassMetadata $classMetadata): array
{
if (null === $classMetadata) {
return $initialContext;
}
$attributeMetadata = $classMetadata->getAttributesMetadata()[$key] ?? null;
if (null !== $attributeMetadata) {
/** @var \Symfony\Component\Serializer\Mapping\AttributeMetadata $attributeMetadata */
$initialContext = array_merge(
$initialContext,
$attributeMetadata->getNormalizationContextForGroups(
is_array($initialContext['groups']) ? $initialContext['groups'] : [$initialContext['groups']]
)
);
}
return $initialContext;
}
} }

View File

@ -196,7 +196,7 @@ class DocGenObjectNormalizer implements NormalizerAwareInterface, NormalizerInte
$normalizer = new NormalizeNullValueHelper($this->normalizer, $typeKey, $typeValue); $normalizer = new NormalizeNullValueHelper($this->normalizer, $typeKey, $typeValue);
return $normalizer->normalize($keys, $format, $context); return $normalizer->normalize($keys, $format, $context, $metadata);
} }
/** /**
@ -260,9 +260,13 @@ class DocGenObjectNormalizer implements NormalizerAwareInterface, NormalizerInte
/** @var AttributeMetadata $attribute */ /** @var AttributeMetadata $attribute */
$value = $this->propertyAccess->getValue($object, $attribute->getName()); $value = $this->propertyAccess->getValue($object, $attribute->getName());
$key = $attribute->getSerializedName() ?? $attribute->getName(); $key = $attribute->getSerializedName() ?? $attribute->getName();
$isTranslatable = $attribute->getNormalizationContextForGroups( $objectContext = array_merge(
$context,
$attribute->getNormalizationContextForGroups(
is_array($context['groups']) ? $context['groups'] : [$context['groups']] is_array($context['groups']) ? $context['groups'] : [$context['groups']]
)['is-translatable'] ?? false; )
);
$isTranslatable = $objectContext['is-translatable'] ?? false;
if ($isTranslatable) { if ($isTranslatable) {
$data[$key] = $this->translatableStringHelper $data[$key] = $this->translatableStringHelper
@ -273,7 +277,7 @@ class DocGenObjectNormalizer implements NormalizerAwareInterface, NormalizerInte
foreach ($value as $k => $v) { foreach ($value as $k => $v) {
$arr[$k] = $arr[$k] =
$this->normalizer->normalize($v, $format, array_merge( $this->normalizer->normalize($v, $format, array_merge(
$context, $objectContext,
$attribute->getNormalizationContextForGroups($expectedGroups) $attribute->getNormalizationContextForGroups($expectedGroups)
)); ));
} }
@ -281,11 +285,11 @@ class DocGenObjectNormalizer implements NormalizerAwareInterface, NormalizerInte
} elseif (is_object($value)) { } elseif (is_object($value)) {
$data[$key] = $data[$key] =
$this->normalizer->normalize($value, $format, array_merge( $this->normalizer->normalize($value, $format, array_merge(
$context, $objectContext,
$attribute->getNormalizationContextForGroups($expectedGroups) $attribute->getNormalizationContextForGroups($expectedGroups)
)); ));
} elseif (null === $value) { } elseif (null === $value) {
$data[$key] = $this->normalizeNullOutputValue($format, $context, $attribute, $reflection); $data[$key] = $this->normalizeNullOutputValue($format, $objectContext, $attribute, $reflection);
} else { } else {
$data[$key] = $value; $data[$key] = $value;
} }

View File

@ -14,6 +14,7 @@ namespace Chill\DocGeneratorBundle\tests\Serializer\Normalizer;
use Chill\MainBundle\Entity\Scope; use Chill\MainBundle\Entity\Scope;
use Chill\MainBundle\Entity\User; use Chill\MainBundle\Entity\User;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Serializer\Annotation as Serializer;
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer; use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
@ -33,6 +34,49 @@ final class DocGenObjectNormalizerTest extends KernelTestCase
$this->normalizer = self::$container->get(NormalizerInterface::class); $this->normalizer = self::$container->get(NormalizerInterface::class);
} }
public function testChangeContextOnAttribute()
{
$object = new TestableParentClass();
$actual = $this->normalizer->normalize(
$object,
'docgen',
['groups' => 'docgen:read']
);
$this->assertIsArray($actual);
$this->assertArrayHasKey('child', $actual);
$this->assertIsArray($actual['child']);
$this->assertArrayHasKey('foo', $actual['child']);
$this->assertEquals('bar', $actual['child']['foo']);
$this->assertArrayNotHasKey('baz', $actual['child']);
// test with child = null
$object->child = null;
$actual = $this->normalizer->normalize(
$object,
'docgen',
['groups' => 'docgen:read']
);
$this->assertIsArray($actual);
$this->assertArrayHasKey('child', $actual);
$this->assertIsArray($actual['child']);
$this->assertArrayHasKey('foo', $actual['child']);
$this->assertEquals('', $actual['child']['foo']);
$this->assertArrayNotHasKey('baz', $actual['child']);
$actual = $this->normalizer->normalize(
null,
'docgen',
['groups' => 'docgen:read', 'docgen:expects' => TestableParentClass::class],
);
$this->assertIsArray($actual);
$this->assertArrayHasKey('child', $actual);
$this->assertIsArray($actual['child']);
$this->assertArrayHasKey('foo', $actual['child']);
$this->assertEquals('', $actual['child']['foo']);
$this->assertArrayNotHasKey('baz', $actual['child']);
}
public function testNormalizationBasic() public function testNormalizationBasic()
{ {
$scope = new Scope(); $scope = new Scope();
@ -99,3 +143,30 @@ final class DocGenObjectNormalizerTest extends KernelTestCase
$this->assertEquals($expected, $normalized, 'test normalization fo an user with null center'); $this->assertEquals($expected, $normalized, 'test normalization fo an user with null center');
} }
} }
class TestableParentClass
{
/**
* @Serializer\Groups("docgen:read")
* @Serializer\Context(normalizationContext={"groups": "docgen:read:foo"}, groups={"docgen:read"})
*/
public ?TestableChildClass $child;
public function __construct()
{
$this->child = new TestableChildClass();
}
}
class TestableChildClass
{
/**
* @Serializer\Groups("docgen:read")
*/
public string $baz = 'bloup';
/**
* @Serializer\Groups("docgen:read:foo")
*/
public string $foo = 'bar';
}

View File

@ -13,6 +13,7 @@ namespace Chill\DocGeneratorBundle\tests\Service\Context;
use Chill\DocGeneratorBundle\Service\Context\BaseContextData; use Chill\DocGeneratorBundle\Service\Context\BaseContextData;
use Chill\MainBundle\Entity\User; use Chill\MainBundle\Entity\User;
use Prophecy\PhpUnit\ProphecyTrait;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Security\Core\Security; use Symfony\Component\Security\Core\Security;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
@ -23,6 +24,8 @@ use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
*/ */
final class BaseContextDataTest extends KernelTestCase final class BaseContextDataTest extends KernelTestCase
{ {
use ProphecyTrait;
protected function setUp(): void protected function setUp(): void
{ {
parent::setUp(); parent::setUp();

View File

@ -7,6 +7,7 @@ docgen:
Context: Contexte Context: Contexte
New template: Nouveau gabarit New template: Nouveau gabarit
Edit template: Modifier gabarit Edit template: Modifier gabarit
test generate: Tester la génération
With context: 'Avec le contexte :' With context: 'Avec le contexte :'

View File

@ -60,6 +60,8 @@ class Address
/** /**
* @var string|null * @var string|null
* *
* used for the CEDEX information
*
* @ORM\Column(type="string", length=255, nullable=true) * @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"write"}) * @Groups({"write"})
*/ */

View File

@ -6,8 +6,9 @@
v-model="value" v-model="value"
:placeholder="$t('select_address')" :placeholder="$t('select_address')"
:tag-placeholder="$t('create_address')" :tag-placeholder="$t('create_address')"
:select-label="$t('press_enter_to_select')" :select-label="$t('multiselect.select_label')"
:deselect-label="$t('create_address')" :deselect-label="$t('create_address')"
:selected-label="$t('multiselect.selected_label')"
@search-change="listenInputSearch" @search-change="listenInputSearch"
ref="addressSelector" ref="addressSelector"
@select="selectAddress" @select="selectAddress"

View File

@ -12,8 +12,9 @@
label="value" label="value"
:custom-label="transName" :custom-label="transName"
:placeholder="$t('select_city')" :placeholder="$t('select_city')"
:select-label="$t('press_enter_to_select')" :select-label="$t('multiselect.select_label')"
:deselect-label="$t('create_postal_code')" :deselect-label="$t('create_postal_code')"
:selected-label="$t('multiselect.selected_label')"
:taggable="true" :taggable="true"
:multiple="false" :multiple="false"
@tag="addPostcode" @tag="addPostcode"

View File

@ -5,12 +5,13 @@
id="countrySelect" id="countrySelect"
label="name" label="name"
track-by="id" track-by="id"
v-bind:custom-label="transName" :custom-label="transName"
v-bind:placeholder="$t('select_country')" :placeholder="$t('select_country')"
v-bind:options="sortedCountries" :options="sortedCountries"
v-model="value" v-model="value"
:select-label="$t('press_enter_to_select')" :select-label="$t('multiselect.select_label')"
:deselect-label="$t('press_enter_to_remove')" :deselect-label="$t('multiselect.deselect_label')"
:selected-label="$t('multiselect.selected_label')"
@select="selectCountry"> @select="selectCountry">
</VueMultiselect> </VueMultiselect>
</div> </div>

View File

@ -10,7 +10,7 @@
<h4 class="h3">{{ $t('address_suggestions') }}</h4> <h4 class="h3">{{ $t('address_suggestions') }}</h4>
<div class="flex-table AddressSuggestionList"> <div class="flex-table AddressSuggestionList">
<div v-for="a in context.suggestions" class="item-bloc"> <div v-for="(a, i) in context.suggestions" class="item-bloc" :key="`suggestions-${i}`">
<div class="float-button bottom"> <div class="float-button bottom">
<div class="box"> <div class="box">
<div class="action"> <div class="action">

View File

@ -1,7 +1,7 @@
import { multiSelectMessages } from 'ChillMainAssets/vuejs/_js/i18n'
const addressMessages = { const addressMessages = {
fr: { fr: {
press_enter_to_select: 'Appuyer sur Entrée pour sélectionner',
press_enter_to_remove: 'Appuyer sur Entrée pour désélectionner',
add_an_address_title: 'Créer une adresse', add_an_address_title: 'Créer une adresse',
edit_an_address_title: 'Modifier une adresse', edit_an_address_title: 'Modifier une adresse',
create_a_new_address: 'Créer une nouvelle adresse', create_a_new_address: 'Créer une nouvelle adresse',
@ -48,6 +48,8 @@ const addressMessages = {
} }
}; };
Object.assign(addressMessages.fr, multiSelectMessages.fr);
export { export {
addressMessages addressMessages
}; };

View File

@ -2,9 +2,15 @@
<component :is="component" class="chill-entity entity-address my-3"> <component :is="component" class="chill-entity entity-address my-3">
<component :is="component" class="address" :class="multiline"> <component :is="component" class="address" :class="multiline">
<div v-if="isMultiline === true">
<p v-for="(l, i) in address.lines" :key="`line-${i}`">
{{ l }}
</p>
</div>
<div v-else>
<p v-if="address.text" <p v-if="address.text"
class="street"> class="street">
{{ address.text }}, {{ address.text }}
</p> </p>
<p v-if="address.postcode" <p v-if="address.postcode"
class="postcode"> class="postcode">
@ -14,9 +20,10 @@
class="country"> class="country">
{{ address.country.name.fr }} {{ address.country.name.fr }}
</p> </p>
</div>
</component> </component>
<div v-if="isMultiline === true" class="address-more"> <!-- <div v-if="isMultiline === true" class="address-more">
<div v-if="address.floor"> <div v-if="address.floor">
<span class="floor"> <span class="floor">
<b>{{ $t('floor') }}</b>: {{ address.floor }} <b>{{ $t('floor') }}</b>: {{ address.floor }}
@ -52,7 +59,7 @@
<b>{{ $t('distribution') }}</b>: {{ address.distribution }} <b>{{ $t('distribution') }}</b>: {{ address.distribution }}
</span> </span>
</div> </div>
</div> </div> -->
<div v-if="useDatePane === true" class="address-more"> <div v-if="useDatePane === true" class="address-more">
<div v-if="address.validFrom"> <div v-if="address.validFrom">

View File

@ -84,3 +84,17 @@ const _createI18n = (appMessages) => {
}; };
export { _createI18n } export { _createI18n }
export const multiSelectMessages = {
fr: {
multiselect: {
placeholder: 'Choisir',
tag_placeholder: 'Créer un nouvel élément',
select_label: 'Appuyer sur "Entrée" pour sélectionner',
deselect_label: 'Appuyer sur "Entrée" pour désélectionner',
select_group_label: 'Appuyer sur "Entrée" pour sélectionner ce groupe',
deselect_group_label: 'Appuyer sur "Entrée" pour désélectionner ce groupe',
selected_label: 'Sélectionné'
}
}
};

View File

@ -9,57 +9,23 @@
* with_delimiter bool add a delimiter between fragments * with_delimiter bool add a delimiter between fragments
* has_no_address bool * has_no_address bool
* multiline bool multiline display * multiline bool multiline display
* extended_infos bool add extra informations (step, floor, etc.) * extended_infos bool add extra informations (step, floor, etc.) DEPRECATED
#} #}
{% macro raw(address, options, streetLine) %} {% macro raw(lines) %}
{% for l in lines %}
{% if address.street is not empty %} <p>{{ l }}</p>
<p>{{ streetLine }}</p> {% endfor %}
{% endif %}
{% if options['extended_infos'] %}
{{ _self.extended(address, options) }}
{% endif %}
{% if address.postCode is not empty %}
<p class="postcode">
<span class="code">{{ address.postCode.code }}</span>
<span class="name">{{ address.postCode.name }}</span>
</p>
<p class="country">{{ address.postCode.country.name|localize_translatable_string }}</p>
{% endif %}
{% endmacro %} {% endmacro %}
{% macro extended(address, options) %} {% macro inline(address, options, streetLine, lines) %}
{% if address.floor is not empty %}
<span class="floor">{{ 'address more.floor'|trans }} {{ address.floor }}</span>
{% endif %}
{% if address.corridor is not empty %}
<span class="corridor">{{ 'address more.corridor'|trans }} {{ address.corridor }}</span>
{% endif %}
{% if address.steps is not empty %}
<span class="steps">{{ 'address more.steps'|trans }} {{ address.steps }}</span>
{% endif %}
{% if address.buildingName is not empty %}
<span class="buildingName">{{ 'address more.buildingName'|trans }} {{ address.buildingName }}</span>
{% endif %}
{% if address.flat is not empty %}
<span class="flat">{{ 'address more.flat'|trans }} {{ address.flat }}</span>
{% endif %}
{% if address.extra is not empty %}
<span class="extra">{{ 'address more.extra'|trans }} {{ address.extra }}</span>
{% endif %}
{% if address.distribution is not empty %}
<span class="distribution">{{ 'address more.distribution'|trans }} {{ address.distribution }}</span>
{% endif %}
{% endmacro %}
{% macro inline(address, options, streetLine) %}
{% if options['has_no_address'] == true and address.isNoAddress == true %} {% if options['has_no_address'] == true and address.isNoAddress == true %}
{% if address.postCode is not empty %} {% if address.postCode is not empty %}
<p class="postcode"> <p class="postcode">
<span class="code">{{ address.postCode.code }}</span> <span class="code">{{ address.postCode.code }}</span>
<span class="name">{{ address.postCode.name }}</span> <span class="name">{{ address.postCode.name }}</span>
<span class="name">{{ address.distribution }}</span>
</p> </p>
<p class="country">{{ address.postCode.country.name|localize_translatable_string }}</p> <p class="country">{{ address.postCode.country.name|localize_translatable_string }}</p>
{% endif %} {% endif %}
@ -68,7 +34,7 @@
</span> </span>
{% else %} {% else %}
<span class="address{% if options['multiline'] %} multiline{% endif %}{% if options['with_delimiter'] %} delimiter{% endif %}"> <span class="address{% if options['multiline'] %} multiline{% endif %}{% if options['with_delimiter'] %} delimiter{% endif %}">
{{ _self.raw(address, options, streetLine) }} {{ _self.raw(lines) }}
</span> </span>
{% endif %} {% endif %}
{{ _self.validity(address, options) }} {{ _self.validity(address, options) }}
@ -97,7 +63,7 @@
{% if options['with_picto'] %} {% if options['with_picto'] %}
<i class="fa fa-li fa-map-marker"></i> <i class="fa fa-li fa-map-marker"></i>
{% endif %} {% endif %}
{{ _self.inline(address, options, streetLine) }} {{ _self.inline(address, options, streetLine, lines) }}
</li> </li>
{%- endif -%} {%- endif -%}
@ -106,7 +72,7 @@
{% if options['with_picto'] %} {% if options['with_picto'] %}
<i class="fa fa-fw fa-map-marker"></i> <i class="fa fa-fw fa-map-marker"></i>
{% endif %} {% endif %}
{{ _self.inline(address, options, streetLine) }} {{ _self.inline(address, options, streetLine, lines) }}
</span> </span>
{%- endif -%} {%- endif -%}
@ -118,6 +84,7 @@
<p class="postcode"> <p class="postcode">
<span class="code">{{ address.postCode.code }}</span> <span class="code">{{ address.postCode.code }}</span>
<span class="name">{{ address.postCode.name }}</span> <span class="name">{{ address.postCode.name }}</span>
<span class="name">{{ address.distribution }}</span>
</p> </p>
<p class="country">{{ address.postCode.country.name|localize_translatable_string }}</p> <p class="country">{{ address.postCode.country.name|localize_translatable_string }}</p>
</div> </div>
@ -131,7 +98,7 @@
{% if options['with_picto'] %} {% if options['with_picto'] %}
<i class="fa fa-fw fa-map-marker"></i> <i class="fa fa-fw fa-map-marker"></i>
{% endif %} {% endif %}
{{ _self.raw(address, options, streetLine) }} {{ _self.raw(lines) }}
</div> </div>
{% endif %} {% endif %}
{{ _self.validity(address, options) }} {{ _self.validity(address, options) }}

View File

@ -13,6 +13,7 @@ namespace Chill\MainBundle\Serializer\Normalizer;
use Chill\DocGeneratorBundle\Serializer\Helper\NormalizeNullValueHelper; use Chill\DocGeneratorBundle\Serializer\Helper\NormalizeNullValueHelper;
use Chill\MainBundle\Entity\Address; use Chill\MainBundle\Entity\Address;
use Chill\MainBundle\Templating\Entity\AddressRender;
use DateTimeInterface; use DateTimeInterface;
use Symfony\Component\Serializer\Exception\UnexpectedValueException; use Symfony\Component\Serializer\Exception\UnexpectedValueException;
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer; use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
@ -46,6 +47,13 @@ class AddressNormalizer implements ContextAwareNormalizerInterface, NormalizerAw
'validTo' => DateTimeInterface::class, 'validTo' => DateTimeInterface::class,
]; ];
private AddressRender $addressRender;
public function __construct(AddressRender $addressRender)
{
$this->addressRender = $addressRender;
}
/** /**
* @param Address $address * @param Address $address
* @param string|null $format * @param string|null $format
@ -53,19 +61,9 @@ class AddressNormalizer implements ContextAwareNormalizerInterface, NormalizerAw
public function normalize($address, $format = null, array $context = []) public function normalize($address, $format = null, array $context = [])
{ {
if ($address instanceof Address) { if ($address instanceof Address) {
$text = $address->isNoAddress() ? '' : $address->getStreet() . ', ' . $address->getStreetNumber();
if (null !== $address->getPostCode()->getCountry()->getCountryCode()) {
if ($address->getPostCode()->getCountry()->getCountryCode() === 'FR') {
$text = $address->isNoAddress() ? '' : $address->getStreetNumber() . ', ' . $address->getStreet();
} else {
$text = $address->isNoAddress() ? '' : $address->getStreetNumber() . ', ' . $address->getStreet();
}
}
$data = [ $data = [
'address_id' => $address->getId(), 'address_id' => $address->getId(),
'text' => $text, 'text' => $address->isNoAddress() ? null : $this->addressRender->renderStreetLine($address, []),
'street' => $address->getStreet(), 'street' => $address->getStreet(),
'streetNumber' => $address->getStreetNumber(), 'streetNumber' => $address->getStreetNumber(),
'postcode' => [ 'postcode' => [
@ -85,6 +83,7 @@ class AddressNormalizer implements ContextAwareNormalizerInterface, NormalizerAw
'buildingName' => $address->getBuildingName(), 'buildingName' => $address->getBuildingName(),
'distribution' => $address->getDistribution(), 'distribution' => $address->getDistribution(),
'extra' => $address->getExtra(), 'extra' => $address->getExtra(),
'lines' => $this->addressRender->renderLines($address),
]; ];
if ('json' === $format) { if ('json' === $format) {

View File

@ -12,6 +12,7 @@ declare(strict_types=1);
namespace Chill\MainBundle\Serializer\Normalizer; namespace Chill\MainBundle\Serializer\Normalizer;
use Chill\MainBundle\Entity\Center; use Chill\MainBundle\Entity\Center;
use Chill\MainBundle\Entity\Location;
use Chill\MainBundle\Entity\Scope; use Chill\MainBundle\Entity\Scope;
use Chill\MainBundle\Entity\User; use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Entity\UserJob; use Chill\MainBundle\Entity\UserJob;
@ -55,16 +56,21 @@ class UserNormalizer implements ContextAwareNormalizerInterface, NormalizerAware
$context, $context,
['docgen:expects' => Center::class, 'groups' => 'docgen:read'] ['docgen:expects' => Center::class, 'groups' => 'docgen:read']
); );
$locationContext = array_merge(
$context,
['docgen:expects' => Location::class, 'groups' => 'dogen:read']
);
if (null === $user && 'docgen' === $format) { if (null === $user && 'docgen' === $format) {
return array_merge(self::NULL_USER, [ return array_merge(self::NULL_USER, [
'user_job' => $this->normalizer->normalize(null, $format, $userJobContext), 'user_job' => $this->normalizer->normalize(null, $format, $userJobContext),
'main_center' => $this->normalizer->normalize(null, $format, $centerContext), 'main_center' => $this->normalizer->normalize(null, $format, $centerContext),
'main_scope' => $this->normalizer->normalize(null, $format, $scopeContext), 'main_scope' => $this->normalizer->normalize(null, $format, $scopeContext),
'current_location' => $this->normalizer->normalize(null, $format, $locationContext),
]); ]);
} }
return [ $data = [
'type' => 'user', 'type' => 'user',
'id' => $user->getId(), 'id' => $user->getId(),
'username' => $user->getUsername(), 'username' => $user->getUsername(),
@ -75,6 +81,12 @@ class UserNormalizer implements ContextAwareNormalizerInterface, NormalizerAware
'main_center' => $this->normalizer->normalize($user->getMainCenter(), $format, $centerContext), 'main_center' => $this->normalizer->normalize($user->getMainCenter(), $format, $centerContext),
'main_scope' => $this->normalizer->normalize($user->getMainScope(), $format, $scopeContext), 'main_scope' => $this->normalizer->normalize($user->getMainScope(), $format, $scopeContext),
]; ];
if ('docgen' === $format) {
$data['current_location'] = $this->normalizer->normalize($user->getCurrentLocation(), $format, $locationContext);
}
return $data;
} }
public function supportsNormalization($data, $format = null, array $context = []): bool public function supportsNormalization($data, $format = null, array $context = []): bool

View File

@ -12,6 +12,7 @@ declare(strict_types=1);
namespace Chill\MainBundle\Templating\Entity; namespace Chill\MainBundle\Templating\Entity;
use Chill\MainBundle\Entity\Address; use Chill\MainBundle\Entity\Address;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Symfony\Component\Templating\EngineInterface; use Symfony\Component\Templating\EngineInterface;
use function array_merge; use function array_merge;
@ -26,14 +27,18 @@ class AddressRender implements ChillEntityRenderInterface
'with_delimiter' => false, 'with_delimiter' => false,
'has_no_address' => false, 'has_no_address' => false,
'multiline' => true, 'multiline' => true,
/* deprecated */
'extended_infos' => false, 'extended_infos' => false,
]; ];
private EngineInterface $templating; private EngineInterface $templating;
public function __construct(EngineInterface $templating) private TranslatableStringHelper $translatableStringHelper;
public function __construct(EngineInterface $templating, TranslatableStringHelper $translatableStringHelper)
{ {
$this->templating = $templating; $this->templating = $templating;
$this->translatableStringHelper = $translatableStringHelper;
} }
/** /**
@ -50,43 +55,49 @@ class AddressRender implements ChillEntityRenderInterface
'streetLine' => $this->renderStreetLine($addr), 'streetLine' => $this->renderStreetLine($addr),
'render' => $options['render'] ?? 'bloc', 'render' => $options['render'] ?? 'bloc',
'options' => $options, 'options' => $options,
'lines' => $this->renderLines($addr),
]); ]);
} }
/** /**
* @param Address addr * @param Address addr
* @param mixed $addr * @param mixed $addr
*
* @return string[]
*/ */
public function renderString($addr, array $options): string public function renderLines($addr): array
{ {
$lines = []; $lines = [];
$lines[0] = $this->renderStreetLine($addr); if (null !== $addr->getPostCode()) {
if ($addr->getPostCode()->getCountry()->getCountryCode() === 'FR') {
if (!empty($addr->getPostcode())) { $lines[] = $this->renderIntraBuildingLine($addr);
$lines[1] = strtr('{postcode} {label}', [ $lines[] = $this->renderBuildingLine($addr);
'{postcode}' => $addr->getPostcode()->getCode(), $lines[] = $this->renderStreetLine($addr);
'{label}' => $addr->getPostcode()->getName(), $lines[] = $this->renderDeliveryLine($addr);
]); $lines[] = $this->renderCityLine($addr);
$lines[] = $this->renderCountryLine($addr);
} else {
$lines[] = $this->renderBuildingLine($addr);
$lines[] = $this->renderDeliveryLine($addr);
$lines[] = $this->renderStreetLine($addr);
$lines[] = $this->renderCityLine($addr);
$lines[] = $this->renderCountryLine($addr);
}
} }
return implode(' - ', $lines); return array_values(array_filter($lines, static fn ($l) => null !== $l));
} }
public function supports($entity, array $options): bool public function renderStreetLine(Address $addr): ?string
{ {
return $entity instanceof Address; if (null !== $addr->getStreet() && $addr->getStreet() !== '') {
}
private function renderStreetLine($addr): string
{
if (!empty($addr->getStreet())) {
$street = $addr->getStreet(); $street = $addr->getStreet();
} else { } else {
$street = ''; $street = '';
} }
if (!empty($addr->getStreetNumber())) { if (null !== $addr->getStreetNumber() && $addr->getStreetNumber() !== '') {
$streetNumber = $addr->getStreetNumber(); $streetNumber = $addr->getStreetNumber();
} else { } else {
$streetNumber = ''; $streetNumber = '';
@ -100,8 +111,111 @@ class AddressRender implements ChillEntityRenderInterface
} }
} }
if (',' === $res) { if ((',' === $res) || ('' === $res)) {
$res = ''; $res = null;
}
return $res;
}
/**
* @param Address addr
* @param mixed $addr
*/
public function renderString($addr, array $options): string
{
return implode(' - ', $this->renderLines($addr));
}
public function supports($entity, array $options): bool
{
return $entity instanceof Address;
}
private function renderBuildingLine(Address $addr): ?string
{
if (null !== $addr->getBuildingName() && $addr->getBuildingName() !== '') {
$building = $addr->getBuildingName();
} else {
$building = '';
}
$intraBuilding = $this->renderIntraBuildingLine($addr);
if (null === $intraBuilding) {
$intraBuilding = '';
}
$res = trim($building . ' - ' . $intraBuilding, ' - ');
if ('' === $res) {
$res = null;
}
if (null !== $addr->getPostCode()->getCountry()->getCountryCode()) {
if ($addr->getPostCode()->getCountry()->getCountryCode() === 'FR') {
$res = $addr->getBuildingName();
}
}
return $res;
}
private function renderCityLine($addr): string
{
if (null !== $addr->getPostcode()) {
$res = strtr('{postcode} {label}', [
'{postcode}' => $addr->getPostcode()->getCode(),
'{label}' => $addr->getPostcode()->getName(),
]);
if (null !== $addr->getPostCode()->getCountry()->getCountryCode()) {
if ($addr->getPostCode()->getCountry()->getCountryCode() === 'FR') {
if ($addr->getDistribution()) {
$res = $res . ' ' . $addr->getDistribution();
}
}
}
}
return $res ?? '';
}
private function renderCountryLine($addr): ?string
{
return $this->translatableStringHelper->localize(
$addr->getPostCode()->getCountry()->getName()
);
}
private function renderDeliveryLine($addr): ?string
{
return $addr->getExtra();
}
private function renderIntraBuildingLine($addr): ?string
{
$arr = [];
if ($addr->getFlat()) {
$arr[] = 'appart ' . $addr->getFlat();
}
if ($addr->getFloor()) {
$arr[] = 'ét ' . $addr->getFloor();
}
if ($addr->getCorridor()) {
$arr[] = 'coul ' . $addr->getCorridor();
}
if ($addr->getSteps()) {
$arr[] = 'esc ' . $addr->getSteps();
}
$res = implode(' - ', $arr);
if ('' === $res) {
$res = null;
} }
return $res; return $res;

View File

@ -15,6 +15,7 @@ use Chill\MainBundle\Entity\Address;
use Chill\MainBundle\Entity\Country; use Chill\MainBundle\Entity\Country;
use Chill\MainBundle\Entity\PostalCode; use Chill\MainBundle\Entity\PostalCode;
use Chill\MainBundle\Templating\Entity\AddressRender; use Chill\MainBundle\Templating\Entity\AddressRender;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Iterator; use Iterator;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Templating\EngineInterface; use Symfony\Component\Templating\EngineInterface;
@ -30,11 +31,11 @@ final class AddressRenderTest extends KernelTestCase
self::bootKernel(); self::bootKernel();
} }
public function addressDataProvider(): Iterator public function addressDataProviderBEWithBuilding(): Iterator
{ {
$addr = new Address(); $addr = new Address();
$country = (new Country()) $country = (new Country())
->setName(['fr' => 'Pays']) ->setName(['fr' => 'Belgium'])
->setCountryCode('BE'); ->setCountryCode('BE');
$postCode = new PostalCode(); $postCode = new PostalCode();
$postCode->setName('Locality') $postCode->setName('Locality')
@ -45,20 +46,279 @@ final class AddressRenderTest extends KernelTestCase
->setStreetNumber('5') ->setStreetNumber('5')
->setPostcode($postCode); ->setPostcode($postCode);
yield [$addr, 'Rue ABC, 5 - 012345 Locality']; $addr->setBuildingName('Résidence "Les Bleuets"');
yield [$addr, 'Résidence "Les Bleuets" - Rue ABC, 5 - 012345 Locality - Belgium'];
}
public function addressDataProviderBEWithSteps(): Iterator
{
$addr = new Address();
$country = (new Country())
->setName(['fr' => 'Belgium'])
->setCountryCode('BE');
$postCode = new PostalCode();
$postCode->setName('Locality')
->setCode('012345')
->setCountry($country);
$addr->setStreet('Rue ABC')
->setStreetNumber('5')
->setPostcode($postCode);
$addr->setSteps('4');
yield [$addr, 'esc 4 - Rue ABC, 5 - 012345 Locality - Belgium'];
}
public function addressDataProviderFRWithBuilding(): Iterator
{
$addr = new Address();
$country = (new Country())
->setName(['fr' => 'France'])
->setCountryCode('FR');
$postCode = new PostalCode();
$postCode->setName('Locality')
->setCode('012345')
->setCountry($country);
$addr->setStreet('Rue ABC')
->setStreetNumber('5')
->setPostcode($postCode);
$addr->setBuildingName('Résidence "Les Bleuets"');
yield [$addr, 'Résidence "Les Bleuets" - 5, Rue ABC - 012345 Locality - France'];
}
public function addressDataProviderFRWithSteps(): Iterator
{
$addr = new Address();
$country = (new Country())
->setName(['fr' => 'France'])
->setCountryCode('FR');
$postCode = new PostalCode();
$postCode->setName('Locality')
->setCode('012345')
->setCountry($country);
$addr->setStreet('Rue ABC')
->setStreetNumber('5')
->setPostcode($postCode);
$addr->setSteps('4');
yield [$addr, 'esc 4 - 5, Rue ABC - 012345 Locality - France'];
}
public function complexAddressDataProviderBE(): Iterator
{
$addr = new Address();
$country = (new Country())
->setName(['fr' => 'Belgium'])
->setCountryCode('BE');
$postCode = new PostalCode();
$postCode->setName('Locality')
->setCode('012345')
->setCountry($country);
$addr->setStreet('Rue ABC')
->setStreetNumber('5')
->setPostcode($postCode);
$addr->setBuildingName('Résidence "Les Bleuets"');
$addr->setFlat('1');
$addr->setFloor('2');
$addr->setCorridor('3');
$addr->setSteps('4');
yield [$addr, 'Résidence "Les Bleuets" - appart 1 - ét 2 - coul 3 - esc 4 - Rue ABC, 5 - 012345 Locality - Belgium'];
}
public function complexAddressDataProviderFR(): Iterator
{
$addr = new Address();
$country = (new Country())
->setName(['fr' => 'France'])
->setCountryCode('FR');
$postCode = new PostalCode();
$postCode->setName('Locality')
->setCode('012345')
->setCountry($country);
$addr->setStreet('Rue ABC')
->setStreetNumber('5')
->setPostcode($postCode);
$addr->setBuildingName('Résidence "Les Bleuets"');
$addr->setFlat('1');
$addr->setFloor('2');
$addr->setCorridor('3');
$addr->setSteps('4');
$addr->setExtra('A droite de la porte');
$addr->setDistribution('CEDEX');
yield [$addr, 'appart 1 - ét 2 - coul 3 - esc 4 - Résidence "Les Bleuets" - 5, Rue ABC - A droite de la porte - 012345 Locality CEDEX - France'];
}
public function noFullAddressDataProviderBE(): Iterator
{
$addr = new Address();
$country = (new Country())
->setName(['fr' => 'Belgium'])
->setCountryCode('BE');
$postCode = new PostalCode();
$postCode->setName('Locality')
->setCode('012345')
->setCountry($country);
$addr->setPostcode($postCode)
->setIsNoAddress(true);
yield [$addr, '012345 Locality - Belgium'];
}
public function simpleAddressDataProviderBE(): Iterator
{
$addr = new Address();
$country = (new Country())
->setName(['fr' => 'Belgium'])
->setCountryCode('BE');
$postCode = new PostalCode();
$postCode->setName('Locality')
->setCode('012345')
->setCountry($country);
$addr->setStreet('Rue ABC')
->setStreetNumber('5')
->setPostcode($postCode);
yield [$addr, 'Rue ABC, 5 - 012345 Locality - Belgium'];
}
public function simpleAddressDataProviderFR(): Iterator
{
$addr = new Address();
$country = (new Country())
->setName(['fr' => 'France'])
->setCountryCode('FR');
$postCode = new PostalCode();
$postCode->setName('Locality')
->setCode('012345')
->setCountry($country);
$addr->setStreet('Rue ABC')
->setStreetNumber('5')
->setPostcode($postCode);
yield [$addr, '5, Rue ABC - 012345 Locality - France'];
} }
/** /**
* @dataProvider addressDataProvider * @dataProvider complexAddressDataProviderBE
*/ */
public function testRenderString(Address $addr, string $expectedString): void public function testRenderComplexAddressBE(Address $addr, string $expectedString): void
{ {
$engine = self::$container->get(EngineInterface::class); $engine = self::$container->get(EngineInterface::class);
$renderer = new AddressRender($engine); $translatableStringHelper = self::$container->get(TranslatableStringHelper::class);
$renderer = new AddressRender($engine, $translatableStringHelper);
$this->assertEquals($expectedString, $renderer->renderString($addr, [])); $this->assertEquals($expectedString, $renderer->renderString($addr, []));
}
return; /**
$this->assertIsString($renderer->renderBox($addr, [])); * @dataProvider complexAddressDataProviderFR
*/
public function testRenderComplexAddressFR(Address $addr, string $expectedString): void
{
$engine = self::$container->get(EngineInterface::class);
$translatableStringHelper = self::$container->get(TranslatableStringHelper::class);
$renderer = new AddressRender($engine, $translatableStringHelper);
$this->assertEquals($expectedString, $renderer->renderString($addr, []));
}
/**
* @dataProvider noFullAddressDataProviderBE
*/
public function testRenderNoFullAddressBE(Address $addr, string $expectedString): void
{
$engine = self::$container->get(EngineInterface::class);
$translatableStringHelper = self::$container->get(TranslatableStringHelper::class);
$renderer = new AddressRender($engine, $translatableStringHelper);
$this->assertEquals($expectedString, $renderer->renderString($addr, []));
}
/**
* @dataProvider simpleAddressDataProviderBE
*/
public function testRenderStringSimpleAddressBE(Address $addr, string $expectedString): void
{
$engine = self::$container->get(EngineInterface::class);
$translatableStringHelper = self::$container->get(TranslatableStringHelper::class);
$renderer = new AddressRender($engine, $translatableStringHelper);
$this->assertEquals($expectedString, $renderer->renderString($addr, []));
}
/**
* @dataProvider simpleAddressDataProviderFR
*/
public function testRenderStringSimpleAddressFR(Address $addr, string $expectedString): void
{
$engine = self::$container->get(EngineInterface::class);
$translatableStringHelper = self::$container->get(TranslatableStringHelper::class);
$renderer = new AddressRender($engine, $translatableStringHelper);
$this->assertEquals($expectedString, $renderer->renderString($addr, []));
}
/**
* @dataProvider addressDataProviderBEWithBuilding
*/
public function testRenderWithBuildingAddressBE(Address $addr, string $expectedString): void
{
$engine = self::$container->get(EngineInterface::class);
$translatableStringHelper = self::$container->get(TranslatableStringHelper::class);
$renderer = new AddressRender($engine, $translatableStringHelper);
$this->assertEquals($expectedString, $renderer->renderString($addr, []));
}
/**
* @dataProvider addressDataProviderFRWithBuilding
*/
public function testRenderWithBuildingAddressFR(Address $addr, string $expectedString): void
{
$engine = self::$container->get(EngineInterface::class);
$translatableStringHelper = self::$container->get(TranslatableStringHelper::class);
$renderer = new AddressRender($engine, $translatableStringHelper);
$this->assertEquals($expectedString, $renderer->renderString($addr, []));
}
/**
* @dataProvider addressDataProviderBEWithSteps
*/
public function testRenderWithStepsAddressBE(Address $addr, string $expectedString): void
{
$engine = self::$container->get(EngineInterface::class);
$translatableStringHelper = self::$container->get(TranslatableStringHelper::class);
$renderer = new AddressRender($engine, $translatableStringHelper);
$this->assertEquals($expectedString, $renderer->renderString($addr, []));
}
/**
* @dataProvider addressDataProviderFRWithSteps
*/
public function testRenderWithStepsAddressFR(Address $addr, string $expectedString): void
{
$engine = self::$container->get(EngineInterface::class);
$translatableStringHelper = self::$container->get(TranslatableStringHelper::class);
$renderer = new AddressRender($engine, $translatableStringHelper);
$this->assertEquals($expectedString, $renderer->renderString($addr, []));
} }
} }

View File

@ -19,6 +19,7 @@ use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkRepos
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;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\HttpFoundation\Exception\BadRequestException; use Symfony\Component\HttpFoundation\Exception\BadRequestException;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
@ -110,6 +111,60 @@ class AccompanyingCourseController extends Controller
]); ]);
} }
/**
* Delete page of Accompanying Course section.
*
* @Route("/{_locale}/parcours/{accompanying_period_id}/delete", name="chill_person_accompanying_course_delete")
* @ParamConverter("accompanyingCourse", options={"id": "accompanying_period_id"})
*/
public function deleteAction(Request $request, AccompanyingPeriod $accompanyingCourse)
{
$em = $this->getDoctrine()->getManager();
$person_id = $request->query->get('person_id');
$form = $this->createFormBuilder()
->setAction($this->generateUrl('chill_person_accompanying_course_delete', [
'accompanying_period_id' => $accompanyingCourse->getId(),
'person_id' => $person_id,
]))
->setMethod('DELETE')
->add('submit', SubmitType::class, ['label' => 'Delete'])
->getForm();
if ($request->getMethod() === Request::METHOD_DELETE) {
$form->handleRequest($request);
if ($form->isValid()) {
$em->remove($accompanyingCourse);
$em->flush();
$this->addFlash('success', $this->get('translator')
->trans('The accompanying course has been successfully removed.'));
if (null !== $person_id) {
return $this->redirectToRoute('chill_person_accompanying_period_list', [
'person_id' => $person_id,
]);
}
return $this->redirectToRoute('chill_main_homepage');
}
}
if (null !== $person_id) {
$view = '@ChillPerson/AccompanyingCourse/confirm_delete_person.html.twig';
} else {
$view = '@ChillPerson/AccompanyingCourse/confirm_delete_accompanying_course.html.twig';
}
return $this->render($view, [
'accompanyingCourse' => $accompanyingCourse,
'person_id' => $person_id,
'delete_form' => $form->createView(),
]);
}
/** /**
* Edit page of Accompanying Course section. * Edit page of Accompanying Course section.
* *
@ -208,6 +263,9 @@ class AccompanyingCourseController extends Controller
} }
} }
$userLocation = $this->getUser()->getCurrentLocation();
$period->setAdministrativeLocation($userLocation);
$this->denyAccessUnlessGranted(AccompanyingPeriodVoter::CREATE, $period); $this->denyAccessUnlessGranted(AccompanyingPeriodVoter::CREATE, $period);
$em->persist($period); $em->persist($period);

View File

@ -17,6 +17,7 @@ use Chill\MainBundle\Entity\Address;
use Chill\MainBundle\Entity\Center; use Chill\MainBundle\Entity\Center;
use Chill\MainBundle\Entity\HasCentersInterface; use Chill\MainBundle\Entity\HasCentersInterface;
use Chill\MainBundle\Entity\HasScopesInterface; use Chill\MainBundle\Entity\HasScopesInterface;
use Chill\MainBundle\Entity\Location;
use Chill\MainBundle\Entity\Scope; use Chill\MainBundle\Entity\Scope;
use Chill\MainBundle\Entity\User; use Chill\MainBundle\Entity\User;
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWork; use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWork;
@ -118,6 +119,13 @@ class AccompanyingPeriod implements
*/ */
private ?Address $addressLocation = null; private ?Address $addressLocation = null;
/**
* @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\Location")
* @Groups({"read", "write"})
* @Assert\NotBlank(groups={AccompanyingPeriod::STEP_CONFIRMED})
*/
private ?Location $administrativeLocation = null;
/** /**
* @var DateTime * @var DateTime
* *
@ -507,6 +515,11 @@ class AccompanyingPeriod implements
return $this->addressLocation; return $this->addressLocation;
} }
public function getAdministrativeLocation(): ?Location
{
return $this->administrativeLocation;
}
/** /**
* Get a list of person which have an adresse available for a valid location. * Get a list of person which have an adresse available for a valid location.
* *
@ -980,6 +993,13 @@ class AccompanyingPeriod implements
return $this; return $this;
} }
public function setAdministrativeLocation(?Location $administrativeLocation): AccompanyingPeriod
{
$this->administrativeLocation = $administrativeLocation;
return $this;
}
/** /**
* Set closingDate. * Set closingDate.
* *

View File

@ -39,32 +39,32 @@ class AccompanyingPeriodWorkGoal
/** /**
* @ORM\ManyToOne(targetEntity=Goal::class) * @ORM\ManyToOne(targetEntity=Goal::class)
* @Serializer\Groups({"accompanying_period_work:edit"}) * @Serializer\Groups({"accompanying_period_work:edit"})
* @Serializer\Groups({"read"}) * @Serializer\Groups({"read", "docgen:read"})
*/ */
private $goal; private ?Goal $goal = null;
/** /**
* @ORM\Id * @ORM\Id
* @ORM\GeneratedValue * @ORM\GeneratedValue
* @ORM\Column(type="integer") * @ORM\Column(type="integer")
* @Serializer\Groups({"read"}) * @Serializer\Groups({"read", "docgen:read"})
*/ */
private $id; private ?int $id = null;
/** /**
* @ORM\Column(type="text") * @ORM\Column(type="text")
* @Serializer\Groups({"accompanying_period_work:edit"}) * @Serializer\Groups({"accompanying_period_work:edit"})
* @Serializer\Groups({"read"}) * @Serializer\Groups({"read"})
*/ */
private $note; private ?string $note = null;
/** /**
* @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({"accompanying_period_work:edit"})
* @Serializer\Groups({"read"}) * @Serializer\Groups({"read", "docgen:read"})
*/ */
private $results; private Collection $results;
public function __construct() public function __construct()
{ {

View File

@ -28,7 +28,7 @@ class Relation
* @ORM\Id * @ORM\Id
* @ORM\GeneratedValue * @ORM\GeneratedValue
* @ORM\Column(type="integer") * @ORM\Column(type="integer")
* @Serializer\Groups({"read"}) * @Serializer\Groups({"read", "docgen:read"})
*/ */
private ?int $id = null; private ?int $id = null;

View File

@ -8,6 +8,7 @@
<persons-associated></persons-associated> <persons-associated></persons-associated>
<course-location></course-location> <course-location></course-location>
<origin-demand></origin-demand> <origin-demand></origin-demand>
<admin-location></admin-location>
<requestor v-bind:isAnonymous="accompanyingCourse.requestorAnonymous"></requestor> <requestor v-bind:isAnonymous="accompanyingCourse.requestorAnonymous"></requestor>
<social-issue></social-issue> <social-issue></social-issue>
<scopes></scopes> <scopes></scopes>
@ -28,6 +29,7 @@ import { mapGetters, mapState } from 'vuex'
import Banner from './components/Banner.vue'; import Banner from './components/Banner.vue';
import StickyNav from './components/StickyNav.vue'; import StickyNav from './components/StickyNav.vue';
import OriginDemand from './components/OriginDemand.vue'; import OriginDemand from './components/OriginDemand.vue';
import AdminLocation from './components/AdminLocation.vue';
import PersonsAssociated from './components/PersonsAssociated.vue'; import PersonsAssociated from './components/PersonsAssociated.vue';
import Requestor from './components/Requestor.vue'; import Requestor from './components/Requestor.vue';
import SocialIssue from './components/SocialIssue.vue'; import SocialIssue from './components/SocialIssue.vue';
@ -44,6 +46,7 @@ export default {
Banner, Banner,
StickyNav, StickyNav,
OriginDemand, OriginDemand,
AdminLocation,
PersonsAssociated, PersonsAssociated,
Requestor, Requestor,
SocialIssue, SocialIssue,

View File

@ -0,0 +1,103 @@
<template>
<div class="vue-component">
<h2><a id="section-40"></a>{{ $t('admin_location.title') }}</h2>
<div class="mb-4">
<label for="selectAdminLocation">
{{ $t('admin_location.title') }}
</label>
<VueMultiselect
name="selectAdminLocation"
label="text"
:custom-label="customLabel"
track-by="id"
:multiple="false"
:searchable="true"
:placeholder="$t('admin_location.placeholder')"
v-model="value"
:options="options"
group-values="locations"
group-label="locationCategories"
@select="updateAdminLocation">
</VueMultiselect>
</div>
<div v-if="!isAdminLocationValid" class="alert alert-warning to-confirm">
{{ $t('admin_location.not_valid') }}
</div>
</div>
</template>
<script>
import VueMultiselect from 'vue-multiselect';
import { makeFetch } from 'ChillMainAssets/lib/api/apiMethods';
import { mapState, mapGetters } from 'vuex';
export default {
name: 'AdminLocation',
components: { VueMultiselect },
data() {
return {
options: []
}
},
computed: {
...mapState({
value: state => state.accompanyingCourse.administrativeLocation,
}),
...mapGetters([
'isAdminLocationValid'
])
},
mounted() {
this.getOptions();
},
methods: {
getOptions() {
const url = `/api/1.0/main/location.json`;
makeFetch('GET', url)
.then(response => {
let options = response.results;
let uniqueLocationTypeId = [...new Set(options.map(o => o.locationType.id))];
let results = [];
for (let id of uniqueLocationTypeId) {
results.push({
locationCategories: options.filter(o => o.locationType.id === id)[0].locationType.title.fr,
locations: options.filter(o => o.locationType.id === id)
})
}
this.options = results;
return response;
})
.catch((error) => {
this.$toast.open({message: error.txt})
})
},
updateAdminLocation(value) {
this.$store.dispatch('updateAdminLocation', value)
.catch(({name, violations}) => {
if (name === 'ValidationException' || name === 'AccessException') {
violations.forEach((violation) => this.$toast.open({message: violation}));
} else {
this.$toast.open({message: 'An error occurred'})
}
});
},
customLabel(value) {
return value.locationType
? value.name
? `${value.name} (${value.locationType.title.fr})`
: value.locationType.title.fr
: '';
},
}
}
</script>
<style src="vue-multiselect/dist/vue-multiselect.css"></style>
<style lang="css" scoped>
label {
display: none;
}
</style>

View File

@ -1,9 +1,9 @@
<template> <template>
<span v-for="h in personsByHousehold()" :class="{ 'household': householdExists(h.id), 'no-household': !householdExists(h.id) }"> <span v-for="h in personsByHousehold()" :class="{ 'household': householdExists(h.id), 'no-household': !householdExists(h.id) }" :key="h.id">
<a v-if="householdExists(h.id)" :href="householdLink(h.id)"> <a v-if="householdExists(h.id)" :href="householdLink(h.id)">
<i class="fa fa-home fa-fw text-light" :title="$t('persons_associated.show_household_number', { id: h.id })"></i> <i class="fa fa-home fa-fw text-light" :title="$t('persons_associated.show_household_number', { id: h.id })"></i>
</a> </a>
<span v-for="person in h.persons" class="me-1"> <span v-for="person in h.persons" class="me-1" :key="person.id">
<on-the-fly :type="person.type" :id="person.id" :buttonText="person.text" :displayBadge="'true' === 'true'" action="show"></on-the-fly> <on-the-fly :type="person.type" :id="person.id" :buttonText="person.text" :displayBadge="'true' === 'true'" action="show"></on-the-fly>
</span> </span>
</span> </span>

View File

@ -1,6 +1,6 @@
<template> <template>
<div class="vue-component"> <div class="vue-component">
<h2><a id="section-90"></a>{{ $t('comment.title') }}</h2> <h2><a id="section-100"></a>{{ $t('comment.title') }}</h2>
<!--div class="error flash_message" v-if="errors.length > 0"> <!--div class="error flash_message" v-if="errors.length > 0">
{{ errors[0] }} {{ errors[0] }}

View File

@ -1,6 +1,6 @@
<template> <template>
<div class="vue-component"> <div class="vue-component">
<h2><a id="section-100"></a> <h2><a id="section-110"></a>
{{ $t('confirm.title') }} {{ $t('confirm.title') }}
</h2> </h2>
<div> <div>
@ -24,6 +24,11 @@
{{ $t('confirm.ok') }} {{ $t('confirm.ok') }}
</button> </button>
</li> </li>
<li>
<a class="btn btn-delete" :href="deleteLink">
{{ $t('confirm.delete') }}
</a>
</li>
</ul> </ul>
</div> </div>
@ -37,6 +42,11 @@
{{ $t('confirm.ok') }} {{ $t('confirm.ok') }}
</button> </button>
</li> </li>
<li>
<a class="btn btn-delete" :href="deleteLink">
{{ $t('confirm.delete') }}
</a>
</li>
</ul> </ul>
</div> </div>
@ -89,13 +99,17 @@ export default {
msg: 'confirm.origin_not_valid', msg: 'confirm.origin_not_valid',
anchor: '#section-30' anchor: '#section-30'
}, },
adminLocation: {
msg: 'confirm.adminLocation_not_valid',
anchor: '#section-40'
},
socialIssue: { socialIssue: {
msg: 'confirm.socialIssue_not_valid', msg: 'confirm.socialIssue_not_valid',
anchor: '#section-50' anchor: '#section-60'
}, },
scopes: { scopes: {
msg: 'confirm.set_a_scope', msg: 'confirm.set_a_scope',
anchor: '#section-60' anchor: '#section-70'
} }
} }
} }
@ -108,10 +122,14 @@ export default {
'isParticipationValid', 'isParticipationValid',
'isSocialIssueValid', 'isSocialIssueValid',
'isOriginValid', 'isOriginValid',
'isAdminLocationValid',
'isLocationValid', 'isLocationValid',
'validationKeys', 'validationKeys',
'isValidToBeConfirmed' 'isValidToBeConfirmed'
]) ]),
deleteLink() {
return `/fr/parcours/${this.accompanyingCourse.id}/delete`; //TODO locale
},
}, },
methods: { methods: {
confirmCourse() { confirmCourse() {

View File

@ -4,7 +4,7 @@
{{ $t('courselocation.title') }} {{ $t('courselocation.title') }}
</h2> </h2>
<div v-for="error in displayErrors" class="alert alert-danger my-2"> <div v-for="error in displayErrors" class="alert alert-danger my-2" :key="error">
{{ error }} {{ error }}
</div> </div>

View File

@ -4,7 +4,7 @@
<div class="mb-4"> <div class="mb-4">
<label for="selectOrigin"> <label for="selectOrigin">
{{ $t('origin.label.fr') }} {{ $t('origin.title') }}
</label> </label>
<VueMultiselect <VueMultiselect
@ -17,6 +17,9 @@
:placeholder="$t('origin.placeholder')" :placeholder="$t('origin.placeholder')"
v-model="value" v-model="value"
:options="options" :options="options"
:select-label="$t('multiselect.select_label')"
:deselect-label="$t('multiselect.deselect_label')"
:selected-label="$t('multiselect.selected_label')"
@select="updateOrigin"> @select="updateOrigin">
</VueMultiselect> </VueMultiselect>
</div> </div>

View File

@ -1,6 +1,6 @@
<template> <template>
<div class="vue-component"> <div class="vue-component">
<h2><a id="section-70"></a>{{ $t('referrer.title') }}</h2> <h2><a id="section-80"></a>{{ $t('referrer.title') }}</h2>
<div> <div>
<label class="col-form-label" for="selectReferrer"> <label class="col-form-label" for="selectReferrer">
@ -11,17 +11,20 @@
name="selectReferrer" name="selectReferrer"
label="text" label="text"
track-by="id" track-by="id"
v-bind:multiple="false" :multiple="false"
v-bind:searchable="true" :searchable="true"
v-bind:placeholder="$t('referrer.placeholder')" :placeholder="$t('referrer.placeholder')"
v-model="value" v-model="value"
v-bind:options="users" v-bind:options="users"
:select-label="$t('multiselect.select_label')"
:deselect-label="$t('multiselect.deselect_label')"
:selected-label="$t('multiselect.selected_label')"
@select="updateReferrer"> @select="updateReferrer">
</VueMultiselect> </VueMultiselect>
<template v-if="referrersSuggested.length > 0"> <template v-if="referrersSuggested.length > 0">
<ul class="list-suggest add-items inline"> <ul class="list-suggest add-items inline">
<li v-for="u in referrersSuggested" @click="updateReferrer(u)"> <li v-for="(u, i) in referrersSuggested" @click="updateReferrer(u)" :key="`referrer-${i}`">
<span> <span>
<user-render-box-badge :user="u"></user-render-box-badge> <user-render-box-badge :user="u"></user-render-box-badge>
</span> </span>

View File

@ -1,7 +1,7 @@
<template> <template>
<div class="vue-component"> <div class="vue-component">
<h2><a id="section-40"></a>{{ $t('requestor.title') }}</h2> <h2><a id="section-50"></a>{{ $t('requestor.title') }}</h2>
<div v-if="accompanyingCourse.requestor && isAnonymous" class="flex-table"> <div v-if="accompanyingCourse.requestor && isAnonymous" class="flex-table">

View File

@ -1,7 +1,7 @@
<template> <template>
<div class="vue-component"> <div class="vue-component">
<h2><a id="section-80"></a>{{ $t('resources.title')}}</h2> <h2><a id="section-90"></a>{{ $t('resources.title')}}</h2>
<div v-if="resources.length > 0"> <div v-if="resources.length > 0">
<label class="col-form-label">{{ $tc('resources.counter', counter) }}</label> <label class="col-form-label">{{ $tc('resources.counter', counter) }}</label>

View File

@ -1,6 +1,6 @@
<template> <template>
<div class="vue-component"> <div class="vue-component">
<h2><a id="section-60"></a>{{ $t('scopes.title') }}</h2> <h2><a id="section-70"></a>{{ $t('scopes.title') }}</h2>
<div class="mb-4"> <div class="mb-4">
<div class="form-check" v-for="s in scopes" :key="s.id"> <div class="form-check" v-for="s in scopes" :key="s.id">

View File

@ -1,6 +1,6 @@
<template> <template>
<div class="vue-component"> <div class="vue-component">
<h2><a id="section-50"></a>{{ $t('social_issue.title') }}</h2> <h2><a id="section-60"></a>{{ $t('social_issue.title') }}</h2>
<div class="my-4"> <div class="my-4">
<!--label for="field">{{ $t('social_issue.label') }}</label <!--label for="field">{{ $t('social_issue.label') }}</label

View File

@ -37,6 +37,12 @@ const appMessages = {
placeholder: "Renseignez l'origine de la demande", placeholder: "Renseignez l'origine de la demande",
not_valid: "Indiquez une origine à la demande", not_valid: "Indiquez une origine à la demande",
}, },
admin_location: {
title: "Localisation administrative",
label: "Localisation administrative",
placeholder: "Renseignez la localisation administrative",
not_valid: "Indiquez une localisation administrative",
},
persons_associated: { persons_associated: {
title: "Usagers concernés", title: "Usagers concernés",
counter: "Il n'y a pas encore d'usagers | 1 usager | {count} usagers", counter: "Il n'y a pas encore d'usagers | 1 usager | {count} usagers",
@ -127,10 +133,12 @@ const appMessages = {
socialIssue_not_valid: "sélectionnez au minimum une problématique sociale", socialIssue_not_valid: "sélectionnez au minimum une problématique sociale",
location_not_valid: "indiquez au minimum une localisation temporaire du parcours", location_not_valid: "indiquez au minimum une localisation temporaire du parcours",
origin_not_valid: "Indiquez une origine à la demande", origin_not_valid: "Indiquez une origine à la demande",
adminLocation_not_valid: "Indiquez une localisation administrative à la demande",
set_a_scope: "indiquez au moins un service", set_a_scope: "indiquez au moins un service",
sure: "Êtes-vous sûr ?", sure: "Êtes-vous sûr ?",
sure_description: "Une fois le changement confirmé, il ne sera plus possible de le remettre à l'état de brouillon !", sure_description: "Une fois le changement confirmé, il ne sera plus possible de le remettre à l'état de brouillon !",
ok: "Confirmer le parcours" ok: "Confirmer le parcours",
delete: "Supprimer le parcours"
}, },
// catch errors // catch errors
'Error while updating AccompanyingPeriod Course.': "Erreur du serveur lors de la mise à jour du parcours d'accompagnement.", 'Error while updating AccompanyingPeriod Course.': "Erreur du serveur lors de la mise à jour du parcours d'accompagnement.",

View File

@ -49,6 +49,9 @@ let initPromise = Promise.all([scopesPromise, accompanyingCoursePromise])
isOriginValid(state) { isOriginValid(state) {
return state.accompanyingCourse.origin !== null; return state.accompanyingCourse.origin !== null;
}, },
isAdminLocationValid(state) {
return state.accompanyingCourse.administrativeLocation !== null;
},
isLocationValid(state) { isLocationValid(state) {
return state.accompanyingCourse.location !== null; return state.accompanyingCourse.location !== null;
}, },
@ -62,6 +65,7 @@ let initPromise = Promise.all([scopesPromise, accompanyingCoursePromise])
if (!getters.isLocationValid) { keys.push('location'); } if (!getters.isLocationValid) { keys.push('location'); }
if (!getters.isSocialIssueValid) { keys.push('socialIssue'); } if (!getters.isSocialIssueValid) { keys.push('socialIssue'); }
if (!getters.isOriginValid) { keys.push('origin'); } if (!getters.isOriginValid) { keys.push('origin'); }
if (!getters.isAdminLocationValid) { keys.push('adminLocation'); }
if (!getters.isScopeValid) { keys.push('scopes'); } if (!getters.isScopeValid) { keys.push('scopes'); }
//console.log('getter keys', keys); //console.log('getter keys', keys);
return keys; return keys;
@ -177,6 +181,9 @@ let initPromise = Promise.all([scopesPromise, accompanyingCoursePromise])
//console.log('value', value); //console.log('value', value);
state.accompanyingCourse.origin = value; state.accompanyingCourse.origin = value;
}, },
updateAdminLocation(state, value) {
state.accompanyingCourse.administrativeLocation = value;
},
updateReferrer(state, value) { updateReferrer(state, value) {
//console.log('value', value); //console.log('value', value);
state.accompanyingCourse.user = value; state.accompanyingCourse.user = value;
@ -607,6 +614,19 @@ let initPromise = Promise.all([scopesPromise, accompanyingCoursePromise])
throw error; throw error;
}) })
}, },
updateAdminLocation({ commit }, payload) {
const url = `/api/1.0/person/accompanying-course/${id}.json`
const body = { type: "accompanying_period", administrativeLocation: { id: payload.id, type: payload.type }}
return makeFetch('PATCH', url, body)
.then((response) => {
commit('updateAdminLocation', response.administrativeLocation);
})
.catch((error) => {
commit('catchError', error);
throw error;
})
},
updateReferrer({ commit }, payload) { updateReferrer({ commit }, payload) {
const url = `/api/1.0/person/accompanying-course/${id}.json` const url = `/api/1.0/person/accompanying-course/${id}.json`
const body = { type: "accompanying_period", user: { id: payload.id, type: payload.type }} const body = { type: "accompanying_period", user: { id: payload.id, type: payload.type }}

View File

@ -7,7 +7,7 @@
<div id="picking"> <div id="picking">
<p>{{ $t('pick_social_issue_linked_with_action') }}</p> <p>{{ $t('pick_social_issue_linked_with_action') }}</p>
<div v-for="si in socialIssues"> <div v-for="si in socialIssues" :key="si.id">
<input type="radio" v-bind:value="si.id" name="socialIssue" v-model="socialIssuePicked"><span class="badge bg-chill-l-gray text-dark">{{ si.text }}</span> <input type="radio" v-bind:value="si.id" name="socialIssue" v-model="socialIssuePicked"><span class="badge bg-chill-l-gray text-dark">{{ si.text }}</span>
</div> </div>
<div class="my-3"> <div class="my-3">

View File

@ -2,6 +2,7 @@
<ol class="breadcrumb"> <ol class="breadcrumb">
<li <li
v-for="s in steps" v-for="s in steps"
:key="s"
class="breadcrumb-item" :class="{ active: step === s }" class="breadcrumb-item" :class="{ active: step === s }"
> >
{{ $t('household_members_editor.app.steps.'+s) }} {{ $t('household_members_editor.app.steps.'+s) }}

View File

@ -9,7 +9,7 @@
<div v-else> <div v-else>
<p> <p>
{{ $t('household_members_editor.concerned.persons_will_be_moved') }}&nbsp;: {{ $t('household_members_editor.concerned.persons_will_be_moved') }}&nbsp;:
<span v-for="c in concerned" :key=c.person.id> <span v-for="c in concerned" :key="c.person.id">
<person-render-box render="badge" :options="{addLink: false}" :person="c.person"></person-render-box> <person-render-box render="badge" :options="{addLink: false}" :person="c.person"></person-render-box>
<button class="btn" @click="removePerson(c.person)" v-if="c.allowRemove" style="padding-left:0;"> <button class="btn" @click="removePerson(c.person)" v-if="c.allowRemove" style="padding-left:0;">
<span class="fa-stack fa-lg" :title="$t('household_members_editor.concerned.remove_concerned')"> <span class="fa-stack fa-lg" :title="$t('household_members_editor.concerned.remove_concerned')">
@ -21,7 +21,7 @@
</p> </p>
<div class="alert alert-info" v-if="concernedPersonsWithHouseholds.length > 0"> <div class="alert alert-info" v-if="concernedPersonsWithHouseholds.length > 0">
<p>{{ $t('household_members_editor.concerned.persons_with_household') }}</p> <p>{{ $t('household_members_editor.concerned.persons_with_household') }}</p>
<ul v-for="c in concernedPersonsWithHouseholds" :key=c.person.id> <ul v-for="c in concernedPersonsWithHouseholds" :key="c.person.id">
<li> <li>
{{ c.person.text }} {{ c.person.text }}
{{ $t('household_members_editor.concerned.already_belongs_to_household') }} {{ $t('household_members_editor.concerned.already_belongs_to_household') }}

View File

@ -8,10 +8,10 @@
</p> </p>
<ul> <ul>
<li v-for="(msg, index) in warnings" class="warning"> <li v-for="(msg, i) in warnings" class="warning" :key="i">
{{ $t(msg.m, msg.a) }} {{ $t(msg.m, msg.a) }}
</li> </li>
<li v-for="msg in errors" class="error"> <li v-for="(msg, i) in errors" class="error" :key="i">
{{ msg }} {{ msg }}
</li> </li>
</ul> </ul>

View File

@ -39,7 +39,7 @@
aria-labelledby="heading_household_suggestions" data-bs-parent="#householdSuggestions"> aria-labelledby="heading_household_suggestions" data-bs-parent="#householdSuggestions">
<div v-if="showHouseholdSuggestion"> <div v-if="showHouseholdSuggestion">
<div class="flex-table householdSuggestionList"> <div class="flex-table householdSuggestionList">
<div v-for="s in getSuggestions" class="item-bloc"> <div v-for="(s, i) in getSuggestions" class="item-bloc" :key="`householdSuggestions-${i}`">
<household-render-box :household="s.household"></household-render-box> <household-render-box :household="s.household"></household-render-box>
<ul class="record_actions"> <ul class="record_actions">
<li> <li>

View File

@ -24,7 +24,8 @@
</button> </button>
</div> </div>
<div <div
v-for="position in positions" v-for="(position, i) in positions"
:key="`position-${i}`"
class="position" class="position"
> >
<button <button

View File

@ -23,7 +23,7 @@
<div class="my-4 legend"> <div class="my-4 legend">
<h3>{{ $t('visgraph.Legend') }}</h3> <h3>{{ $t('visgraph.Legend') }}</h3>
<div class="list-group"> <div class="list-group">
<label class="list-group-item" v-for="layer in legendLayers"> <label class="list-group-item" v-for="(layer, i) in legendLayers" :key="`layer-${i}`">
<input <input
class="form-check-input me-1" class="form-check-input me-1"
type="checkbox" type="checkbox"

View File

@ -0,0 +1,31 @@
{% macro insert_onthefly(type, entity) %}
{% include '@ChillMain/OnTheFly/_insert_vue_onthefly.html.twig' with {
action: 'show', displayBadge: true,
targetEntity: { name: type, id: entity.id },
buttonText: entity|chill_entity_render_string
} %}
{% endmacro %}
<div>
{% if accompanyingCourse.participations is not empty %}
<div class="col mb-4">
<h4 class="item-key">{{ 'Persons associated'|trans }}</h4>
{% for r in accompanyingCourse.participations %}
{{ _self.insert_onthefly('person', r.person) }}
{% endfor %}
</div>
{% endif %}
{% if accompanyingCourse.socialIssues is not empty %}
<div class="col mb-4">
<h4 class="item-key">{{ 'Social issues'|trans }}</h4>
{% for s in accompanyingCourse.socialIssues %}
{{ s|chill_entity_render_box }}
{% endfor %}
</div>
{% endif %}
</div>

View File

@ -0,0 +1,18 @@
{% extends '@ChillPerson/AccompanyingCourse/layout.html.twig' %}
{% block title %}{{ 'Delete accompanying period'|trans }}{% endblock %}
{% block content %}
{% include '@ChillPerson/AccompanyingCourse/_confirm_delete.html.twig' %}
{{ include('@ChillMain/Util/confirmation_template.html.twig',
{
'title' : 'Delete accompanying period'|trans,
'confirm_question' : 'Are you sure you want to remove the accompanying period "%id%" ?'|trans({ '%id%' : accompanyingCourse.id } ),
'cancel_route' : 'chill_person_accompanying_course_edit',
'cancel_parameters' : {'accompanying_period_id' : accompanyingCourse.id},
'form' : delete_form
} ) }}
{% endblock %}

View File

@ -0,0 +1,18 @@
{% extends '@ChillPerson/AccompanyingCourse/layout.html.twig' %}
{% block title %}{{ 'Delete accompanying period'|trans }}{% endblock %}
{% block content %}
{% include '@ChillPerson/AccompanyingCourse/_confirm_delete.html.twig' %}
{{ include('@ChillMain/Util/confirmation_template.html.twig',
{
'title' : 'Delete accompanying period'|trans,
'confirm_question' : 'Are you sure you want to remove the accompanying period "%id%" ?'|trans({ '%id%' : accompanyingCourse.id } ),
'cancel_route' : 'chill_person_accompanying_period_list',
'cancel_parameters' : {'person_id' : person_id},
'form' : delete_form
} ) }}
{% endblock %}

View File

@ -154,6 +154,15 @@
</div> </div>
{% endif %} {% endif %}
{% if accompanyingCourse.administrativeLocation is not null %}
<div class="mbloc col col-sm-6 col-lg-4">
<div class="administrative-location">
<h4 class="item-key">{{ 'accompanying_course.administrative_location'|trans }}</h4>
{{ accompanyingCourse.administrativeLocation.name }} ({{ accompanyingCourse.administrativeLocation.locationType.title|localize_translatable_string }})
</div>
</div>
{% endif %}
</div> </div>
<div class="social-actions my-4"> <div class="social-actions my-4">

View File

@ -1,9 +1,15 @@
{% macro recordAction(period) %} {% macro recordAction(period, person = null) %}
{# TODO if enable_accompanying_course_with_multiple_persons is true ... #} {# TODO if enable_accompanying_course_with_multiple_persons is true ... #}
<li> <li>
<a href="{{ path('chill_person_accompanying_course_index', { 'accompanying_period_id': period.id }) }}" <a href="{{ path('chill_person_accompanying_course_index', { 'accompanying_period_id': period.id }) }}"
class="btn btn-show" title="{{ 'See accompanying period'|trans }}">{# {{ 'See this period'|trans }} #}</a> class="btn btn-show" title="{{ 'See accompanying period'|trans }}">{# {{ 'See this period'|trans }} #}</a>
</li> </li>
{% if period.step == 'DRAFT' %}
<li>
<a href="{{ path('chill_person_accompanying_course_delete', { 'accompanying_period_id': period.id, 'person_id' : person.id }) }}"
class="btn btn-delete" title="{{ 'Delete accompanying period'|trans }}">{# {{ 'Delete this period'|trans }} #}</a>
</li>
{% endif %}
{# DISABLED if new accompanying course, this is not necessary {# DISABLED if new accompanying course, this is not necessary
{% if person is defined %} {% if person is defined %}
<li> <li>
@ -39,7 +45,7 @@
{% for period in accompanying_periods %} {% for period in accompanying_periods %}
{% include 'ChillPersonBundle:AccompanyingPeriod:_list_item.html.twig' with { {% include 'ChillPersonBundle:AccompanyingPeriod:_list_item.html.twig' with {
'recordAction': _self.recordAction(period) 'recordAction': _self.recordAction(period, person)
} %} } %}
{% endfor %} {% endfor %}

View File

@ -13,6 +13,7 @@ namespace Chill\PersonBundle\Serializer\Normalizer;
use Chill\DocGeneratorBundle\Serializer\Helper\NormalizeNullValueHelper; use Chill\DocGeneratorBundle\Serializer\Helper\NormalizeNullValueHelper;
use Chill\MainBundle\Entity\Address; use Chill\MainBundle\Entity\Address;
use Chill\MainBundle\Entity\Location;
use Chill\MainBundle\Entity\Scope; use Chill\MainBundle\Entity\Scope;
use Chill\MainBundle\Entity\User; use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Security\Resolver\ScopeResolverDispatcher; use Chill\MainBundle\Security\Resolver\ScopeResolverDispatcher;
@ -68,6 +69,7 @@ class AccompanyingPeriodDocGenNormalizer implements ContextAwareNormalizerInterf
'resources' => Collection::class, 'resources' => Collection::class,
'location' => Address::class, 'location' => Address::class,
'locationPerson' => Person::class, 'locationPerson' => Person::class,
'administrativeLocation' => Location::class,
]; ];
private ClosingMotiveRender $closingMotiveRender; private ClosingMotiveRender $closingMotiveRender;
@ -111,6 +113,7 @@ class AccompanyingPeriodDocGenNormalizer implements ContextAwareNormalizerInterf
$dateContext = array_merge($context, ['docgen:expects' => DateTime::class, 'groups' => 'docgen:read']); $dateContext = array_merge($context, ['docgen:expects' => DateTime::class, 'groups' => 'docgen:read']);
$userContext = array_merge($context, ['docgen:expects' => User::class, 'groups' => 'docgen:read']); $userContext = array_merge($context, ['docgen:expects' => User::class, 'groups' => 'docgen:read']);
$participationContext = array_merge($context, ['docgen:expects' => AccompanyingPeriodParticipation::class, 'groups' => 'docgen:read']); $participationContext = array_merge($context, ['docgen:expects' => AccompanyingPeriodParticipation::class, 'groups' => 'docgen:read']);
$administrativeLocationContext = array_merge($context, ['docgen:expects' => Location::class, 'groups' => 'docgen:read']);
return [ return [
'id' => $period->getId(), 'id' => $period->getId(),
@ -153,8 +156,10 @@ class AccompanyingPeriodDocGenNormalizer implements ContextAwareNormalizerInterf
'requestorKind' => $period->getRequestorKind(), 'requestorKind' => $period->getRequestorKind(),
'hasLocation' => $period->getLocation() !== null, 'hasLocation' => $period->getLocation() !== null,
'hasLocationPerson' => $period->getPersonLocation() !== null, 'hasLocationPerson' => $period->getPersonLocation() !== null,
'hasAdministrativeLocation' => $period->getAdministrativeLocation() !== null,
'locationPerson' => $this->normalizer->normalize($period->getPersonLocation(), $format, array_merge($context, ['docgen:expects' => Person::class])), 'locationPerson' => $this->normalizer->normalize($period->getPersonLocation(), $format, array_merge($context, ['docgen:expects' => Person::class])),
'location' => $this->normalizer->normalize($period->getLocation(), $format, $addressContext), 'location' => $this->normalizer->normalize($period->getLocation(), $format, $addressContext),
'administrativeLocation' => $this->normalizer->normalize($period->getAdministrativeLocation(), $format, $administrativeLocationContext),
]; ];
} }
@ -172,6 +177,7 @@ class AccompanyingPeriodDocGenNormalizer implements ContextAwareNormalizerInterf
'confidential' => false, 'confidential' => false,
'hasLocation' => false, 'hasLocation' => false,
'hasLocationPerson' => false, 'hasLocationPerson' => false,
'hasAdministrativeLocation' => false,
] ]
); );
} }

View File

@ -151,7 +151,7 @@ class PersonDocGenNormalizer implements
$normalizer = new NormalizeNullValueHelper($this->normalizer, 'type', 'person'); $normalizer = new NormalizeNullValueHelper($this->normalizer, 'type', 'person');
$attributes = [ $attributes = [
'firstname', 'lastname', 'altNames', 'text', 'firstname', 'lastname', 'age', 'altNames', 'text',
'civility' => Civility::class, 'civility' => Civility::class,
'birthdate' => DateTimeInterface::class, 'birthdate' => DateTimeInterface::class,
'deathdate' => DateTimeInterface::class, 'deathdate' => DateTimeInterface::class,

View File

@ -306,6 +306,7 @@ final class AccompanyingCourseApiControllerTest extends WebTestCase
*/ */
public function testAccompanyingCourseAddParticipation(int $personId, int $periodId) public function testAccompanyingCourseAddParticipation(int $personId, int $periodId)
{ {
$this->markTestIncomplete('fix test with validation');
$this->client->request( $this->client->request(
Request::METHOD_POST, Request::METHOD_POST,
sprintf('/api/1.0/person/accompanying-course/%d/participation.json', $periodId), sprintf('/api/1.0/person/accompanying-course/%d/participation.json', $periodId),
@ -377,6 +378,7 @@ final class AccompanyingCourseApiControllerTest extends WebTestCase
*/ */
public function testAccompanyingCourseAddRemoveSocialIssue(AccompanyingPeriod $period, SocialIssue $si) public function testAccompanyingCourseAddRemoveSocialIssue(AccompanyingPeriod $period, SocialIssue $si)
{ {
$this->markTestIncomplete('fix test with validation');
$this->client->request( $this->client->request(
Request::METHOD_POST, Request::METHOD_POST,
sprintf('/api/1.0/person/accompanying-course/%d/socialissue.json', $period->getId()), sprintf('/api/1.0/person/accompanying-course/%d/socialissue.json', $period->getId()),
@ -437,6 +439,7 @@ final class AccompanyingCourseApiControllerTest extends WebTestCase
*/ */
public function testAccompanyingPeriodPatch(int $personId, int $periodId) public function testAccompanyingPeriodPatch(int $personId, int $periodId)
{ {
$this->markTestIncomplete('fix test with validation');
$period = self::$container->get(AccompanyingPeriodRepository::class) $period = self::$container->get(AccompanyingPeriodRepository::class)
->find($periodId); ->find($periodId);
$initialValueEmergency = $period->isEmergency(); $initialValueEmergency = $period->isEmergency();
@ -475,6 +478,7 @@ final class AccompanyingCourseApiControllerTest extends WebTestCase
*/ */
public function testCommentWithValidData(AccompanyingPeriod $period, $personId, $thirdPartyId) public function testCommentWithValidData(AccompanyingPeriod $period, $personId, $thirdPartyId)
{ {
$this->markTestIncomplete('fix test with validation');
$em = self::$container->get(EntityManagerInterface::class); $em = self::$container->get(EntityManagerInterface::class);
$this->client->request( $this->client->request(
@ -515,6 +519,7 @@ final class AccompanyingCourseApiControllerTest extends WebTestCase
*/ */
public function testConfirm(AccompanyingPeriod $period) public function testConfirm(AccompanyingPeriod $period)
{ {
$this->markTestIncomplete('fix test with validation');
$this->client->request( $this->client->request(
Request::METHOD_POST, Request::METHOD_POST,
sprintf('/api/1.0/person/accompanying-course/%d/confirm.json', $period->getId()) sprintf('/api/1.0/person/accompanying-course/%d/confirm.json', $period->getId())
@ -551,6 +556,7 @@ final class AccompanyingCourseApiControllerTest extends WebTestCase
*/ */
public function testRequestorWithValidData(AccompanyingPeriod $period, $personId, $thirdPartyId) public function testRequestorWithValidData(AccompanyingPeriod $period, $personId, $thirdPartyId)
{ {
$this->markTestIncomplete('fix test with validation');
$em = self::$container->get(EntityManagerInterface::class); $em = self::$container->get(EntityManagerInterface::class);
// post a person // post a person
@ -634,6 +640,7 @@ final class AccompanyingCourseApiControllerTest extends WebTestCase
*/ */
public function testResourceWithValidData(AccompanyingPeriod $period, $personId, $thirdPartyId) public function testResourceWithValidData(AccompanyingPeriod $period, $personId, $thirdPartyId)
{ {
$this->markTestIncomplete('fix test with validation');
$em = self::$container->get(EntityManagerInterface::class); $em = self::$container->get(EntityManagerInterface::class);
// post a person // post a person

View File

@ -166,7 +166,7 @@ final class PersonControllerCreateTest extends WebTestCase
$form = $this->fillAValidCreationForm($form, 'Charline', 'dd'); $form = $this->fillAValidCreationForm($form, 'Charline', 'dd');
$client->submit($form); $client->submit($form);
$this->assertContains( $this->assertStringContainsString(
'DEPARDIEU', 'DEPARDIEU',
$client->getCrawler()->text(), $client->getCrawler()->text(),
'check that the page has detected the lastname of a person existing in database' 'check that the page has detected the lastname of a person existing in database'
@ -177,7 +177,7 @@ final class PersonControllerCreateTest extends WebTestCase
$form = $this->fillAValidCreationForm($form, 'dd', 'Charline'); $form = $this->fillAValidCreationForm($form, 'dd', 'Charline');
$client->submit($form); $client->submit($form);
$this->assertContains( $this->assertStringContainsString(
'DEPARDIEU', 'DEPARDIEU',
$client->getCrawler()->text(), $client->getCrawler()->text(),
'check that the page has detected the lastname of a person existing in database' 'check that the page has detected the lastname of a person existing in database'

View File

@ -83,10 +83,10 @@ final class PersonControllerViewTest extends WebTestCase
$this->assertGreaterThan(0, $crawler->filter('html:contains("TESTED PERSON")')->count()); $this->assertGreaterThan(0, $crawler->filter('html:contains("TESTED PERSON")')->count());
$this->assertGreaterThan(0, $crawler->filter('html:contains("Réginald")')->count()); $this->assertGreaterThan(0, $crawler->filter('html:contains("Réginald")')->count());
$this->assertContains('Email addresses', $crawler->text()); $this->assertStringContainsString('Email addresses', $crawler->text());
$this->assertContains('Phonenumber', $crawler->text()); $this->assertStringContainsString('Phonenumber', $crawler->text());
$this->assertContains('Langues parlées', $crawler->text()); $this->assertStringContainsString('Langues parlées', $crawler->text());
$this->assertContains(/* Etat */ 'civil', $crawler->text()); $this->assertStringContainsString(/* Etat */ 'civil', $crawler->text());
} }
/** /**

View File

@ -94,10 +94,15 @@ final class AccompanyingPeriodDocGenNormalizerTest extends KernelTestCase
'hasRequestorThirdParty' => false, 'hasRequestorThirdParty' => false,
'requestorPerson' => '@ignored', 'requestorPerson' => '@ignored',
'requestorThirdParty' => '@ignored', 'requestorThirdParty' => '@ignored',
'administrativeLocation' => '@ignored',
'hasAdministrativeLocation' => false,
'hasLocation' => false,
'hasLocationPerson' => false,
'location' => '@ignored',
'locationPerson' => '@ignored',
]; ];
$this->assertIsArray($data); $this->assertIsArray($data);
$this->markTestSkipped('still in specification');
$this->assertEqualsCanonicalizing(array_keys($expected), array_keys($data)); $this->assertEqualsCanonicalizing(array_keys($expected), array_keys($data));
foreach ($expected as $key => $item) { foreach ($expected as $key => $item) {
@ -149,10 +154,15 @@ final class AccompanyingPeriodDocGenNormalizerTest extends KernelTestCase
'requestorPerson' => '@ignored', 'requestorPerson' => '@ignored',
'requestorThirdParty' => '@ignored', 'requestorThirdParty' => '@ignored',
'isNull' => true, 'isNull' => true,
'administrativeLocation' => '@ignored',
'hasAdministrativeLocation' => false,
'hasLocation' => false,
'hasLocationPerson' => false,
'location' => '@ignored',
'locationPerson' => '@ignored',
]; ];
$this->assertIsArray($data); $this->assertIsArray($data);
$this->markTestSkipped('still in specification');
$this->assertEqualsCanonicalizing(array_keys($expected), array_keys($data)); $this->assertEqualsCanonicalizing(array_keys($expected), array_keys($data));
foreach ($expected as $key => $item) { foreach ($expected as $key => $item) {

View File

@ -23,6 +23,7 @@ use Chill\PersonBundle\Repository\Relationships\RelationshipRepository;
use Chill\PersonBundle\Serializer\Normalizer\PersonDocGenNormalizer; use Chill\PersonBundle\Serializer\Normalizer\PersonDocGenNormalizer;
use Chill\PersonBundle\Templating\Entity\PersonRender; use Chill\PersonBundle\Templating\Entity\PersonRender;
use Prophecy\Argument; use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
use Symfony\Contracts\Translation\TranslatorInterface; use Symfony\Contracts\Translation\TranslatorInterface;
@ -34,6 +35,8 @@ use function array_merge;
*/ */
final class PersonDocGenNormalizerTest extends KernelTestCase final class PersonDocGenNormalizerTest extends KernelTestCase
{ {
use ProphecyTrait;
private const BLANK = [ private const BLANK = [
'firstname' => '', 'firstname' => '',
'lastname' => '', 'lastname' => '',
@ -88,6 +91,7 @@ final class PersonDocGenNormalizerTest extends KernelTestCase
public function testNormalizationNullOrNotNullHaveSameKeys() public function testNormalizationNullOrNotNullHaveSameKeys()
{ {
$this->markTestSkipped();
$period = new Person(); $period = new Person();
$notNullData = $this->buildPersonNormalizer()->normalize($period, 'docgen', ['docgen:expects' => Person::class]); $notNullData = $this->buildPersonNormalizer()->normalize($period, 'docgen', ['docgen:expects' => Person::class]);
$nullData = $this->buildPersonNormalizer()->normalize(null, 'docgen', ['docgen:expects' => Person::class]); $nullData = $this->buildPersonNormalizer()->normalize(null, 'docgen', ['docgen:expects' => Person::class]);
@ -126,6 +130,7 @@ final class PersonDocGenNormalizerTest extends KernelTestCase
public function testNormalizePersonWithHousehold() public function testNormalizePersonWithHousehold()
{ {
$this->markTestSkipped();
$household = new Household(); $household = new Household();
$person = new Person(); $person = new Person();
$person $person
@ -166,6 +171,7 @@ final class PersonDocGenNormalizerTest extends KernelTestCase
public function testNormalizePersonWithRelationships() public function testNormalizePersonWithRelationships()
{ {
$this->markTestSkipped();
$person = (new Person())->setFirstName('Renaud')->setLastName('megane'); $person = (new Person())->setFirstName('Renaud')->setLastName('megane');
$father = (new Person())->setFirstName('Clément')->setLastName('megane'); $father = (new Person())->setFirstName('Clément')->setLastName('megane');
$mother = (new Person())->setFirstName('Mireille')->setLastName('Mathieu'); $mother = (new Person())->setFirstName('Mireille')->setLastName('Mathieu');
@ -199,6 +205,55 @@ final class PersonDocGenNormalizerTest extends KernelTestCase
$this->assertCount(3, $actual['relations']); $this->assertCount(3, $actual['relations']);
} }
/**
* Test that the @see{PersonDocGenNormalizer::class} works without interaction with other
* serializers.
*
* @dataProvider generateData
*
* @param mixed $expected
* @param mixed $msg
*/
public function testNormalizeUsingNormalizer(?Person $person, $expected, $msg)
{
$normalizer = $this->buildNormalizer();
$this->assertTrue($normalizer->supportsNormalization($person, 'docgen', [
'docgen:expects' => Person::class,
'groups' => ['docgen:read'],
]), $msg);
$this->assertIsArray($normalizer->normalize($person, 'docgen', [
'docgen:expects' => Person::class,
'groups' => ['docgen:read'],
]), $msg);
}
private function buildNormalizer(
?PersonRender $personRender = null,
?RelationshipRepository $relationshipRepository = null,
?TranslatorInterface $translator = null,
?TranslatableStringHelper $translatableStringHelper = null,
?NormalizerInterface $normalizer = null
): PersonDocGenNormalizer {
$personDocGenNormalizer = new PersonDocGenNormalizer(
$personRender ?? self::$container->get(PersonRender::class),
$relationshipRepository ?? self::$container->get(RelationshipRepository::class),
$translator ?? self::$container->get(TranslatorInterface::class),
$translatableStringHelper ?? self::$container->get(TranslatableStringHelperInterface::class)
);
if (null === $normalizer) {
$normalizer = $this->prophesize(NormalizerInterface::class);
$normalizer->normalize(Argument::any(), 'docgen', Argument::any())
->willReturn(['fake' => true]);
}
$personDocGenNormalizer->setNormalizer($normalizer->reveal());
return $personDocGenNormalizer;
}
private function buildPersonNormalizer( private function buildPersonNormalizer(
?PersonRender $personRender = null, ?PersonRender $personRender = null,
?RelationshipRepository $relationshipRepository = null, ?RelationshipRepository $relationshipRepository = null,

View File

@ -18,6 +18,7 @@ use Chill\PersonBundle\Entity\Relationships\Relationship;
use Chill\PersonBundle\Serializer\Normalizer\RelationshipDocGenNormalizer; use Chill\PersonBundle\Serializer\Normalizer\RelationshipDocGenNormalizer;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Prophecy\Argument; use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
use function is_object; use function is_object;
@ -27,6 +28,8 @@ use function is_object;
*/ */
final class RelationshipDocGenNormalizerTest extends TestCase final class RelationshipDocGenNormalizerTest extends TestCase
{ {
use ProphecyTrait;
public function testNormalizeRelationshipNull() public function testNormalizeRelationshipNull()
{ {
$relationship = null; $relationship = null;

View File

@ -76,7 +76,7 @@ final class TimelineAccompanyingPeriodTest extends WebTestCase
$crawler->filter('.timeline div')->count(), $crawler->filter('.timeline div')->count(),
'the timeline page contains multiple div inside a .timeline element' 'the timeline page contains multiple div inside a .timeline element'
); );
$this->assertContains( $this->assertStringContainsString(
'est ouvert', 'est ouvert',
$crawler->filter('.timeline')->text(), $crawler->filter('.timeline')->text(),
"the text 'est ouvert' is present" "the text 'est ouvert' is present"

View File

@ -17,6 +17,7 @@ use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Validator\Constraints\Person\PersonHasCenter; use Chill\PersonBundle\Validator\Constraints\Person\PersonHasCenter;
use Chill\PersonBundle\Validator\Constraints\Person\PersonHasCenterValidator; use Chill\PersonBundle\Validator\Constraints\Person\PersonHasCenterValidator;
use Prophecy\Argument; use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase; use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
@ -26,6 +27,8 @@ use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
*/ */
final class PersonHasCenterValidatorTest extends ConstraintValidatorTestCase final class PersonHasCenterValidatorTest extends ConstraintValidatorTestCase
{ {
use ProphecyTrait;
public function testValidateRequired() public function testValidateRequired()
{ {
$constraint = $this->getConstraint(); $constraint = $this->getConstraint();

View File

@ -37,7 +37,7 @@ final class PersonValidationTest extends KernelTestCase
{ {
$person = (new Person()) $person = (new Person())
->setBirthdate(new Datetime('+2 months')); ->setBirthdate(new Datetime('+2 months'));
$errors = $this->validator->validate($person, null, ['creation']); $errors = $this->validator->validate($person, null);
foreach ($errors->getIterator() as $error) { foreach ($errors->getIterator() as $error) {
if (Birthdate::BIRTHDATE_INVALID_CODE === $error->getCode()) { if (Birthdate::BIRTHDATE_INVALID_CODE === $error->getCode()) {
@ -59,7 +59,7 @@ final class PersonValidationTest extends KernelTestCase
{ {
$person = (new Person()) $person = (new Person())
->setFirstname(str_repeat('a', 500)); ->setFirstname(str_repeat('a', 500));
$errors = $this->validator->validate($person, null, ['creation']); $errors = $this->validator->validate($person, null);
foreach ($errors->getIterator() as $error) { foreach ($errors->getIterator() as $error) {
if (Length::TOO_LONG_ERROR === $error->getCode()) { if (Length::TOO_LONG_ERROR === $error->getCode()) {

View File

@ -0,0 +1,40 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Chill\Migrations\Person;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Add location to AccompanyingPeriod.
*/
final class Version20211223150721 extends AbstractMigration
{
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE chill_person_accompanying_period DROP CONSTRAINT FK_E260A86830F20868');
$this->addSql('DROP INDEX IDX_E260A86830F20868');
$this->addSql('ALTER TABLE chill_person_accompanying_period DROP administrativeLocation_id');
}
public function getDescription(): string
{
return 'Add location to AccompanyingPeriod';
}
public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE chill_person_accompanying_period ADD administrativeLocation_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE chill_person_accompanying_period ADD CONSTRAINT FK_E260A86830F20868 FOREIGN KEY (administrativeLocation_id) REFERENCES chill_main_location (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('CREATE INDEX IDX_E260A86830F20868 ON chill_person_accompanying_period (administrativeLocation_id)');
}
}

View File

@ -216,6 +216,9 @@ Add to household now: Ajouter à un ménage
Any resource for this accompanying course: Aucun interlocuteur privilégié pour ce parcours Any resource for this accompanying course: Aucun interlocuteur privilégié pour ce parcours
course.draft: Brouillon course.draft: Brouillon
Origin: Origine de la demande Origin: Origine de la demande
Delete accompanying period: Supprimer la période d'accompagnement
Are you sure you want to remove the accompanying period "%id%" ?: Êtes-vous sûr de vouloir supprimer la période d'accompagnement %id% ?
The accompanying course has been successfully removed.: La période d'accompagnement a été supprimée.
# pickAPersonType # pickAPersonType
Pick a person: Choisir une personne Pick a person: Choisir une personne
@ -408,6 +411,8 @@ Choose a person to locate by: Localiser auprès d'un usager concerné
Associate at least one member with an household, and set an address to this household: Associez au moins un membre du parcours à un ménage, et indiquez une adresse à ce ménage. Associate at least one member with an household, and set an address to this household: Associez au moins un membre du parcours à un ménage, et indiquez une adresse à ce ménage.
Locate by: Localiser auprès de Locate by: Localiser auprès de
fix it: Compléter fix it: Compléter
accompanying_course:
administrative_location: Localisation administrative
# Accompanying Course comments # Accompanying Course comments
Accompanying Course Comment: Commentaire Accompanying Course Comment: Commentaire

View File

@ -68,7 +68,7 @@ final class SingleTaskControllerTest extends WebTestCase
$crawler = $client->followRedirect(); $crawler = $client->followRedirect();
$this->assertContains( $this->assertStringContainsString(
$title, $title,
$crawler->text(), $crawler->text(),
'Assert that newly created task title is shown in list page' 'Assert that newly created task title is shown in list page'

View File

@ -24,6 +24,7 @@ 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\Context;
use Symfony\Component\Serializer\Annotation\DiscriminatorMap; use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
use Symfony\Component\Serializer\Annotation\Groups; use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert; use Symfony\Component\Validator\Constraints as Assert;
@ -64,7 +65,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
* @var string * @var string
* @ORM\Column(name="acronym", type="string", length=64, nullable=true) * @ORM\Column(name="acronym", type="string", length=64, nullable=true)
* @Assert\Length(min="2") * @Assert\Length(min="2")
* @Groups({"read", "write", "docgen:read"}) * @Groups({"read", "write", "docgen:read", "docgen:read:3party:parent"})
*/ */
private ?string $acronym = ''; private ?string $acronym = '';
@ -79,7 +80,8 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
* @ORM\ManyToOne(targetEntity="\Chill\MainBundle\Entity\Address", * @ORM\ManyToOne(targetEntity="\Chill\MainBundle\Entity\Address",
* cascade={"persist", "remove"}) * cascade={"persist", "remove"})
* @ORM\JoinColumn(nullable=true, onDelete="SET NULL") * @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
* @Groups({"read", "write", "docgen:read"}) * @Groups({"read", "write", "docgen:read", "docgen:read:3party:parent"})
* @Context(normalizationContext={"groups": "docgen:read"}, groups={"docgen:read:3party:parent"})
*/ */
private ?Address $address = null; private ?Address $address = null;
@ -98,7 +100,8 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
* @ORM\JoinTable(name="chill_3party.thirdparty_category", * @ORM\JoinTable(name="chill_3party.thirdparty_category",
* joinColumns={@ORM\JoinColumn(name="thirdparty_id", referencedColumnName="id")}, * joinColumns={@ORM\JoinColumn(name="thirdparty_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="category_id", referencedColumnName="id")}) * inverseJoinColumns={@ORM\JoinColumn(name="category_id", referencedColumnName="id")})
* @Groups({"docgen:read"}) * @Groups({"docgen:read", "docgen:read:3party:parent"})
* @Context(normalizationContext={"groups": "docgen:read"}, groups={"docgen:read:3party:parent"})
*/ */
private Collection $categories; private Collection $categories;
@ -123,7 +126,8 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
* @var Civility * @var Civility
* @ORM\ManyToOne(targetEntity=Civility::class) * @ORM\ManyToOne(targetEntity=Civility::class)
* ORM\JoinColumn(name="civility", referencedColumnName="id", nullable=true) * ORM\JoinColumn(name="civility", referencedColumnName="id", nullable=true)
* @Groups({"docgen:read", "read"}) * @Groups({"docgen:read", "read", "docgen:read:3party:parent"})
* @Context(normalizationContext={"groups": "docgen:read"}, groups={"docgen:read:3party:parent"})
*/ */
private ?Civility $civility = null; private ?Civility $civility = null;
@ -135,7 +139,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
/** /**
* @ORM\Column(name="contact_data_anonymous", type="boolean", options={"default": false}) * @ORM\Column(name="contact_data_anonymous", type="boolean", options={"default": false})
* @Groups({"read", "docgen:read"}) * @Groups({"read", "docgen:read", "docgen:read:3party:parent"})
*/ */
private bool $contactDataAnonymous = false; private bool $contactDataAnonymous = false;
@ -153,7 +157,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
/** /**
* @ORM\Column(name="email", type="string", length=255, nullable=true) * @ORM\Column(name="email", type="string", length=255, nullable=true)
* @Assert\Email(checkMX=false) * @Assert\Email(checkMX=false)
* @Groups({"read", "write", "docgen:read"}) * @Groups({"read", "write", "docgen:read", "docgen:read:3party:parent"})
*/ */
private ?string $email = null; private ?string $email = null;
@ -162,7 +166,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
* @ORM\Column(name="id", type="integer") * @ORM\Column(name="id", type="integer")
* @ORM\Id * @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO") * @ORM\GeneratedValue(strategy="AUTO")
* @Groups({"read", "write", "docgen:read"}) * @Groups({"read", "write", "docgen:read", "docgen:read:3party:parent"})
*/ */
private ?int $id = null; private ?int $id = null;
@ -176,7 +180,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
* @var string * @var string
* @ORM\Column(name="name", type="string", length=255) * @ORM\Column(name="name", type="string", length=255)
* @Assert\Length(min="2") * @Assert\Length(min="2")
* @Groups({"read", "write", "docgen:read"}) * @Groups({"read", "write", "docgen:read", "docgen:read:3party:parent"})
*/ */
private ?string $name = ''; private ?string $name = '';
@ -186,7 +190,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
* @var string * @var string
* @ORM\Column(name="name_company", type="string", length=255, nullable=true) * @ORM\Column(name="name_company", type="string", length=255, nullable=true)
* @Assert\Length(min="3") * @Assert\Length(min="3")
* @Groups({"read", "write", "docgen:read"}) * @Groups({"read", "write", "docgen:read", "docgen:read:3party:parent"})
*/ */
private ?string $nameCompany = ''; private ?string $nameCompany = '';
@ -196,6 +200,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
* @ORM\ManyToOne(targetEntity="Chill\ThirdPartyBundle\Entity\ThirdParty", inversedBy="children") * @ORM\ManyToOne(targetEntity="Chill\ThirdPartyBundle\Entity\ThirdParty", inversedBy="children")
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id") * @ORM\JoinColumn(name="parent_id", referencedColumnName="id")
* @Groups({"read", "docgen:read"}) * @Groups({"read", "docgen:read"})
* @Context(normalizationContext={"groups": "docgen:read:3party:parent"}, groups={"docgen:read"})
*/ */
private ?ThirdParty $parent = null; private ?ThirdParty $parent = null;
@ -205,7 +210,8 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
* @var ThirdPartyProfession * @var ThirdPartyProfession
* @ORM\ManyToOne(targetEntity="Chill\ThirdPartyBundle\Entity\ThirdPartyProfession") * @ORM\ManyToOne(targetEntity="Chill\ThirdPartyBundle\Entity\ThirdPartyProfession")
* ORM\JoinColumn(name="profession", referencedColumnName="id", nullable=true) * ORM\JoinColumn(name="profession", referencedColumnName="id", nullable=true)
* @Groups({"docgen:read"}) * @Groups({"docgen:read", "docgen:read:3party:parent"})
* @Context(normalizationContext={"groups": "docgen:read"}, groups={"docgen:read:3party:parent"})
*/ */
private ?ThirdPartyProfession $profession = null; private ?ThirdPartyProfession $profession = null;
@ -215,7 +221,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
* message="Invalid phone number: it should begin with the international prefix starting with ""+"", hold only digits and be smaller than 20 characters. Ex: +33123456789" * message="Invalid phone number: it should begin with the international prefix starting with ""+"", hold only digits and be smaller than 20 characters. Ex: +33123456789"
* ) * )
* @PhonenumberConstraint(type="any") * @PhonenumberConstraint(type="any")
* @Groups({"read", "write", "dogen:read"}) * @Groups({"read", "write", "dogen:read", "docgen:read:3party:parent"})
*/ */
private ?string $telephone = null; private ?string $telephone = null;
@ -498,7 +504,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
} }
/** /**
* @Groups({"read", "docgen:read"}) * @Groups({"read", "docgen:read", "docgen:read:3party:parent"})
*/ */
public function isChild(): bool public function isChild(): bool
{ {

View File

@ -0,0 +1,101 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Chill\ThirdPartyBundle\Test\Serializer\Normalizer;
use Chill\MainBundle\Entity\Civility;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use Chill\ThirdPartyBundle\Entity\ThirdPartyCategory;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
/**
* @internal
* @coversNothing
*/
final class ThirdPartyDocGenNormalizerTest extends KernelTestCase
{
private NormalizerInterface $normalizer;
protected function setUp(): void
{
self::bootKernel();
$this->normalizer = self::$container->get(NormalizerInterface::class);
}
public function testAvoidRecursionWithNullParent()
{
$thirdparty = new ThirdParty();
$thirdparty
->setAcronym('ABCD')
->setName('test')
->setCivility((new Civility())->setName(['fr' => 'Monsieur'])->setAbbreviation(['fr' => 'M.']))
->setEmail('info@cl.coop')
->addTypesAndCategories('kind')
->addTypesAndCategories((new ThirdPartyCategory())->setName(['fr' => 'category']))
->setParent(new ThirdParty());
$actual = $this->normalizer->normalize($thirdparty, 'docgen', ['groups' => ['docgen:read']]);
$this->assertIsArray($actual);
$this->assertArrayHasKey('parent', $actual);
$this->assertIsArray($actual['parent']);
$this->assertArrayNotHasKey('parent', $actual['parent']);
// check that other keys exists for parent
$this->assertArrayHasKey('acronym', $actual['parent']);
$this->assertEquals('', $actual['parent']['acronym']);
$thirdparty = new ThirdParty();
$thirdparty
->setAcronym('ABCD')
->setName('test')
->setCivility((new Civility())->setName(['fr' => 'Monsieur'])->setAbbreviation(['fr' => 'M.']))
->setEmail('info@cl.coop')
->addTypesAndCategories('kind')
->addTypesAndCategories((new ThirdPartyCategory())->setName(['fr' => 'category']));
$actual = $this->normalizer->normalize($thirdparty, 'docgen', ['groups' => ['docgen:read']]);
$this->assertIsArray($actual);
$this->assertArrayHasKey('parent', $actual);
$this->assertIsArray($actual['parent']);
$this->assertArrayNotHasKey('parent', $actual['parent']);
// check that other keys exists for parent
$this->assertArrayHasKey('acronym', $actual['parent']);
$this->assertEquals('', $actual['parent']['acronym']);
$actual = $this->normalizer->normalize(null, 'docgen', ['groups' => ['docgen:read'], 'docgen:expects' => ThirdParty::class]);
$this->assertIsArray($actual);
$this->assertArrayHasKey('parent', $actual);
$this->assertIsArray($actual['parent']);
$this->assertArrayNotHasKey('parent', $actual['parent']);
// check that other keys exists for parent
$this->assertArrayHasKey('acronym', $actual['parent']);
$this->assertEquals('', $actual['parent']['acronym']);
}
public function testNormalize()
{
$thirdparty = new ThirdParty();
$thirdparty
->setAcronym('ABCD')
->setName('test')
->setCivility((new Civility())->setName(['fr' => 'Monsieur'])->setAbbreviation(['fr' => 'M.']))
->setEmail('info@cl.coop')
->addTypesAndCategories('kind')
->addTypesAndCategories((new ThirdPartyCategory())->setName(['fr' => 'category']));
$actual = $this->normalizer->normalize($thirdparty, 'docgen', ['groups' => ['docgen:read']]);
$this->assertIsArray($actual);
}
}

View File

@ -1,49 +0,0 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Chill\ThirdPartyBundle\Test\Serializer\Normalizer;
use Chill\MainBundle\Entity\Civility;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use Chill\ThirdPartyBundle\Entity\ThirdPartyCategory;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
/**
* @internal
* @coversNothing
*/
final class ThirdpartyDocGenNormalizerTest extends KernelTestCase
{
private NormalizerInterface $normalizer;
protected function setUp(): void
{
self::bootKernel();
$this->normalizer = self::$container->get(NormalizerInterface::class);
}
public function testNormalize()
{
$thirdparty = new ThirdParty();
$thirdparty
->setAcronym('ABCD')
->setName('test')
->setCivility((new Civility())->setName(['fr' => 'Monsieur'])->setAbbreviation(['fr' => 'M.']))
->setEmail('info@cl.coop')
->addTypesAndCategories('kind')
->addTypesAndCategories((new ThirdPartyCategory())->setName(['fr' => 'category']));
$actual = $this->normalizer->normalize($thirdparty, 'docgen', ['groups' => ['docgen:read']]);
$this->assertIsArray($actual);
}
}