mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +00:00
Merge branch '327_pinned_comment' into issue321_layout_improvements_actionForm
This commit is contained in:
@@ -219,10 +219,9 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
|
||||
private ?string $telephone = null;
|
||||
|
||||
/**
|
||||
* @var array|null
|
||||
* @ORM\Column(name="types", type="json", nullable=true)
|
||||
*/
|
||||
private $types;
|
||||
private ?array $thirdPartyTypes = [];
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="updated_at", type="datetime_immutable", nullable=true)
|
||||
@@ -303,18 +302,18 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addType(?string $type): self
|
||||
public function addThirdPartyTypes(?string $type): self
|
||||
{
|
||||
if (null === $type) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
if (!in_array($type, $this->types ?? [], true)) {
|
||||
$this->types[] = $type;
|
||||
if (!in_array($type, $this->thirdPartyTypes ?? [], true)) {
|
||||
$this->thirdPartyTypes[] = $type;
|
||||
}
|
||||
|
||||
foreach ($this->children as $child) {
|
||||
$child->addType($type);
|
||||
$child->addThirdPartyTypes($type);
|
||||
}
|
||||
|
||||
return $this;
|
||||
@@ -329,7 +328,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
|
||||
}
|
||||
|
||||
if (is_string($typeAndCategory)) {
|
||||
$this->addType($typeAndCategory);
|
||||
$this->addThirdPartyTypes($typeAndCategory);
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -473,16 +472,16 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public function getTypes()
|
||||
public function getThirdPartyTypes()
|
||||
{
|
||||
return $this->types;
|
||||
return $this->thirdPartyTypes ?? [];
|
||||
}
|
||||
|
||||
public function getTypesAndCategories(): array
|
||||
{
|
||||
return array_merge(
|
||||
$this->getCategories()->toArray(),
|
||||
$this->getTypes() ?? []
|
||||
$this->getThirdPartyTypes() ?? []
|
||||
);
|
||||
}
|
||||
|
||||
@@ -574,18 +573,18 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeType(?string $type): self
|
||||
public function removeThirdPartyTypes(?string $type): self
|
||||
{
|
||||
if (null === $type) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
if (in_array($type, $this->types ?? [], true)) {
|
||||
$this->types = array_filter($this->types, fn ($e) => !in_array($e, $this->types, true));
|
||||
if (in_array($type, $this->thirdPartyTypes ?? [], true)) {
|
||||
$this->thirdPartyTypes = array_filter($this->thirdPartyTypes, fn ($e) => !in_array($e, $this->thirdPartyTypes, true));
|
||||
}
|
||||
|
||||
foreach ($this->children as $child) {
|
||||
$child->removeType($type);
|
||||
$child->removeThirdPartyTypes($type);
|
||||
}
|
||||
|
||||
return $this;
|
||||
@@ -600,7 +599,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
|
||||
}
|
||||
|
||||
if (is_string($typeAndCategory)) {
|
||||
$this->removeType($typeAndCategory);
|
||||
$this->removeThirdPartyTypes($typeAndCategory);
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -799,13 +798,13 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
|
||||
*
|
||||
* @return ThirdParty
|
||||
*/
|
||||
public function setTypes(?array $type = null)
|
||||
public function setThirdPartyTypes(?array $type = [])
|
||||
{
|
||||
// remove all keys from the input data
|
||||
$this->types = array_values($type);
|
||||
$this->thirdPartyTypes = array_values($type);
|
||||
|
||||
foreach ($this->children as $child) {
|
||||
$child->setTypes($type);
|
||||
$child->setThirdPartyTypes($type);
|
||||
}
|
||||
|
||||
return $this;
|
||||
@@ -814,7 +813,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
|
||||
public function setTypesAndCategories(array $typesAndCategories): self
|
||||
{
|
||||
$types = array_filter($typesAndCategories, static fn ($item) => !$item instanceof ThirdPartyCategory);
|
||||
$this->setTypes($types);
|
||||
$this->setThirdPartyTypes($types);
|
||||
|
||||
// handle categories
|
||||
foreach ($typesAndCategories as $t) {
|
||||
|
@@ -134,15 +134,6 @@ class ThirdPartyType extends AbstractType
|
||||
// Institutional ThirdParty (parent)
|
||||
} else {
|
||||
$builder
|
||||
->add('address', PickAddressType::class, [
|
||||
'label' => 'Address',
|
||||
])
|
||||
->add('address2', PickAddressType::class, [
|
||||
'label' => 'Address',
|
||||
'use_valid_from' => true,
|
||||
'use_valid_to' => true,
|
||||
'mapped' => false,
|
||||
])
|
||||
->add('nameCompany', TextType::class, [
|
||||
'label' => 'thirdparty.NameCompany',
|
||||
'required' => false,
|
||||
@@ -170,6 +161,9 @@ class ThirdPartyType extends AbstractType
|
||||
|
||||
if (ThirdParty::KIND_CHILD !== $options['kind']) {
|
||||
$builder
|
||||
->add('address', PickAddressType::class, [
|
||||
'label' => 'Address',
|
||||
])
|
||||
->add('typesAndCategories', PickThirdPartyTypeCategoryType::class, [
|
||||
'label' => 'thirdparty.Categories',
|
||||
])
|
||||
|
@@ -26,17 +26,19 @@
|
||||
<div class="form-check">
|
||||
<input class="form-check-input mt-0" type="radio" v-model="kind" value="company" id="tpartyKindInstitution">
|
||||
<label for="tpartyKindInstitution" class="required">
|
||||
<span class="badge rounded-pill bg-thirdparty-company" style="padding-top: 0;">
|
||||
{{ $t('tparty.company')}}
|
||||
</span>
|
||||
<badge-entity
|
||||
:entity="{ type: 'thirdparty', kind: 'company' }"
|
||||
:options="{ displayLong: true }">
|
||||
</badge-entity>
|
||||
</label>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<input class="form-check-input mt-0" type="radio" v-model="kind" value="contact" id="tpartyKindContact">
|
||||
<label for="tpartyKindContact" class="required">
|
||||
<span class="badge rounded-pill bg-thirdparty-contact" style="padding-top: 0;">
|
||||
{{ $t('tparty.contact')}}
|
||||
</span>
|
||||
<badge-entity
|
||||
:entity="{ type: 'thirdparty', kind: 'contact' }"
|
||||
:options="{ displayLong: true }">
|
||||
</badge-entity>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
@@ -97,26 +99,16 @@
|
||||
import ThirdPartyRenderBox from '../Entity/ThirdPartyRenderBox.vue';
|
||||
import AddAddress from 'ChillMainAssets/vuejs/Address/components/AddAddress';
|
||||
import { getThirdparty } from '../../_api/OnTheFly';
|
||||
|
||||
const i18n = {
|
||||
messages: {
|
||||
fr: {
|
||||
tparty: {
|
||||
contact: "Personne physique",
|
||||
company: "Personne morale"
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
import BadgeEntity from 'ChillMainAssets/vuejs/_components/BadgeEntity.vue';
|
||||
|
||||
export default {
|
||||
name: "OnTheFlyThirdParty",
|
||||
props: ['id', 'type', 'action'],
|
||||
components: {
|
||||
ThirdPartyRenderBox,
|
||||
AddAddress
|
||||
AddAddress,
|
||||
BadgeEntity
|
||||
},
|
||||
i18n,
|
||||
data() {
|
||||
return {
|
||||
//context: {}, <--
|
||||
|
@@ -28,7 +28,9 @@
|
||||
{{ form_widget(form.activeChildren) }}
|
||||
{% endif %}
|
||||
|
||||
{{ form_row(form.address) }}
|
||||
{% if form.address is defined %}
|
||||
{{ form_row(form.address) }}
|
||||
{% endif %}
|
||||
|
||||
{{ form_row(form.comment) }}
|
||||
|
||||
|
@@ -62,7 +62,3 @@
|
||||
{% endblock %}
|
||||
{% endembed %}
|
||||
{% endblock %}
|
||||
|
||||
{% block css %}
|
||||
{{ encore_entry_link_tags('page_3party_3party_index') }}
|
||||
{% endblock %}
|
||||
|
@@ -12,7 +12,7 @@
|
||||
{% block crud_content_header %}
|
||||
<h1>
|
||||
{{ 'Update third party %name%'|trans({ '%name%': thirdParty.name }) }}
|
||||
<span class="badge bg-{{ thirdParty.active ? 'success' : 'danger' }}"
|
||||
<span class="badge bg-{{ thirdParty.active ? 'success' : 'danger' }} float-end"
|
||||
title="{{ (thirdParty.active ? 'shown to users' : 'not shown to users')|trans }}">
|
||||
{{ (thirdParty.active ? 'Active' : 'Inactive')|trans }}
|
||||
</span>
|
||||
|
@@ -35,8 +35,8 @@ final class ThirdPartyTest extends TestCase
|
||||
$this->assertTrue($tp->getCategories()->contains($cat2));
|
||||
$this->assertCount(2, $tp->getCategories());
|
||||
|
||||
$this->assertCount(1, $tp->getTypes());
|
||||
$this->assertContains('type', $tp->getTypes());
|
||||
$this->assertCount(1, $tp->getThirdPartyTypes());
|
||||
$this->assertContains('type', $tp->getThirdPartyTypes());
|
||||
|
||||
$this->assertCount(3, $tp->getTypesAndCategories());
|
||||
$this->assertContains($cat1, $tp->getTypesAndCategories());
|
||||
@@ -54,8 +54,8 @@ final class ThirdPartyTest extends TestCase
|
||||
$this->assertFalse($tp->getCategories()->contains($cat2));
|
||||
$this->assertCount(1, $tp->getCategories());
|
||||
|
||||
$this->assertCount(0, $tp->getTypes());
|
||||
$this->assertNotContains('type', $tp->getTypes());
|
||||
$this->assertCount(0, $tp->getThirdPartyTypes());
|
||||
$this->assertNotContains('type', $tp->getThirdPartyTypes());
|
||||
|
||||
$this->assertCount(1, $tp->getTypesAndCategories());
|
||||
$this->assertContains($cat1, $tp->getTypesAndCategories());
|
||||
@@ -77,9 +77,9 @@ final class ThirdPartyTest extends TestCase
|
||||
$this->assertTrue($tp->getCategories()->contains($cat2));
|
||||
$this->assertCount(2, $tp->getCategories());
|
||||
|
||||
$this->assertCount(2, $tp->getTypes());
|
||||
$this->assertContains('type1', $tp->getTypes());
|
||||
$this->assertContains('type2', $tp->getTypes());
|
||||
$this->assertCount(2, $tp->getThirdPartyTypes());
|
||||
$this->assertContains('type1', $tp->getThirdPartyTypes());
|
||||
$this->assertContains('type2', $tp->getThirdPartyTypes());
|
||||
|
||||
$this->assertCount(4, $tp->getTypesAndCategories());
|
||||
$this->assertContains($cat1, $tp->getTypesAndCategories());
|
||||
@@ -93,9 +93,9 @@ final class ThirdPartyTest extends TestCase
|
||||
$this->assertFalse($tp->getCategories()->contains($cat2));
|
||||
$this->assertCount(1, $tp->getCategories());
|
||||
|
||||
$this->assertCount(1, $tp->getTypes());
|
||||
$this->assertContains('type1', $tp->getTypes());
|
||||
$this->assertNotContains('type2', $tp->getTypes());
|
||||
$this->assertCount(1, $tp->getThirdPartyTypes());
|
||||
$this->assertContains('type1', $tp->getThirdPartyTypes());
|
||||
$this->assertNotContains('type2', $tp->getThirdPartyTypes());
|
||||
|
||||
$this->assertCount(2, $tp->getTypesAndCategories());
|
||||
$this->assertContains($cat1, $tp->getTypesAndCategories());
|
||||
|
@@ -0,0 +1,54 @@
|
||||
<?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\ThirdPartyBundle\Entity\ThirdParty;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
final class ThirdPartyJsonDenormalizerTest extends KernelTestCase
|
||||
{
|
||||
private DenormalizerInterface $normalizer;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
self::bootKernel();
|
||||
|
||||
$this->normalizer = self::$container->get(DenormalizerInterface::class);
|
||||
}
|
||||
|
||||
public function testDenormalizeContact()
|
||||
{
|
||||
$str = <<<'JSON'
|
||||
{
|
||||
"type": "thirdparty",
|
||||
"name": "badaboum",
|
||||
"email": "badaboum@email.com",
|
||||
"telephone": "+32486540660",
|
||||
"kind": "contact"
|
||||
}
|
||||
JSON;
|
||||
|
||||
$actual = $this->normalizer->denormalize(json_decode($str, true), ThirdParty::class, 'json', [
|
||||
'groups' => ['write'],
|
||||
]);
|
||||
|
||||
$this->assertInstanceOf(ThirdParty::class, $actual);
|
||||
$this->assertEquals('badaboum', $actual->getName());
|
||||
$this->assertEquals('badaboum@email.com', $actual->getEmail());
|
||||
$this->assertEquals(ThirdParty::KIND_CONTACT, $actual->getKind());
|
||||
}
|
||||
}
|
@@ -44,8 +44,6 @@ final class ThirdpartyDocGenNormalizerTest extends KernelTestCase
|
||||
|
||||
$actual = $this->normalizer->normalize($thirdparty, 'docgen', ['groups' => ['docgen:read']]);
|
||||
|
||||
var_dump($actual);
|
||||
|
||||
$this->assertIsArray($actual);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user