handle kind as contacts

This commit is contained in:
Julien Fastré 2021-10-08 17:51:51 +02:00
parent 4d71a1c630
commit 0633fd812f
8 changed files with 148 additions and 58 deletions

View File

@ -8,8 +8,12 @@ use Chill\MainBundle\Pagination\PaginatorInterface;
use Chill\MainBundle\Templating\Listing\FilterOrderHelper;
use Chill\ThirdPartyBundle\Repository\ThirdPartyACLAwareRepositoryInterface;
use Chill\ThirdPartyBundle\Repository\ThirdPartyRepository;
use http\Exception\RuntimeException;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\Routing\Annotation\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Component\HttpFoundation\Request;
@ -45,15 +49,19 @@ final class ThirdPartyController extends CRUDController
protected ThirdPartyACLAwareRepositoryInterface $thirdPartyACLAwareRepository;
protected RequestStack $requestStack;
public function __construct(
AuthorizationHelper $authorizationHelper,
TranslatorInterface $translator,
PaginatorFactory $paginatorFactory,
RequestStack $requestStack,
ThirdPartyACLAwareRepositoryInterface $thirdPartyACLAwareRepository
) {
$this->authorizationHelper = $authorizationHelper;
$this->translator = $translator;
$this->paginatorFactory = $paginatorFactory;
$this->requestStack = $requestStack;
$this->thirdPartyACLAwareRepository = $thirdPartyACLAwareRepository;
}
@ -82,9 +90,38 @@ final class ThirdPartyController extends CRUDController
}
}
if ('new' === $action) {
if (!$request->query->has('kind')) {
return $this->render('@ChillThirdParty/ThirdParty/new_pick_kind.html.twig');
} else {
$kind = $request->query->getAlpha('kind', '');
if (!(ThirdParty::KIND_COMPANY === $kind || ThirdParty::KIND_CONTACT === $kind)) {
throw new BadRequestHttpException('This kind is not supported: '.$kind);
}
$entity->setKind($kind);
}
}
return null;
}
protected function createFormFor(string $action, $entity, string $formClass = null, array $formOptions = []): FormInterface
{
if ('new' === $action) {
return parent::createFormFor($action, $entity, $formClass, \array_merge(
$formOptions, [ 'kind' => $this->requestStack->getCurrentRequest()->query->getAlpha('kind')]
));
} elseif ('edit' === $action) {
return parent::createFormFor($action, $entity, $formClass, \array_merge(
$formOptions, [ 'kind' => $entity->getKind()]
));
}
return parent::createFormFor($action, $entity, $formClass, $formOptions);
}
protected function buildFilterOrderHelper(string $action, Request $request): ?FilterOrderHelper
{
return $this->getFilterOrderHelperFactory()

View File

@ -61,6 +61,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
const KIND_CONTACT = 'contact';
const KIND_COMPANY = 'company';
const KIND_CHILD = 'child';
/**
* @ORM\Column(name="kind", type="string", length="20", options={"default":""})

View File

@ -18,14 +18,11 @@ use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\CallbackTransformer;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Chill\ThirdPartyBundle\Security\Voter\ThirdPartyVoter;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Security\Core\Role\Role;
use Chill\ThirdPartyBundle\ThirdPartyType\ThirdPartyTypeManager;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
@ -64,7 +61,6 @@ class ThirdPartyType extends AbstractType
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name', TextType::class, [
'required' => true
@ -111,7 +107,7 @@ class ThirdPartyType extends AbstractType
;
// Contact Person ThirdParty (child)
if ($options['is_child']) {
if (ThirdParty::KIND_CONTACT === $options['kind'] || ThirdParty::KIND_CHILD === $options['kind']) {
$builder
->add('civility', EntityType::class, [
'label' => 'thirdparty.Civility',
@ -156,6 +152,27 @@ class ThirdPartyType extends AbstractType
'label' => 'thirdparty.Acronym',
'required' => false
])
->add('activeChildren', ChillCollectionType::class, [
'entry_type' => ThirdPartyType::class,
'entry_options' => [
'is_child' => true,
'block_name' => 'children',
'kind' => ThirdParty::KIND_CHILD,
],
'block_name' => 'active_children',
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false,
'button_add_label' => "Add a contact",
'button_remove_label' => "Remove a contact",
'empty_collection_explain' => "Any contact"
])
;
}
if (ThirdParty::KIND_CHILD !== $options['kind']) {
$builder
->add('categories', EntityType::class, [
'label' => 'thirdparty.Categories',
'class' => ThirdPartyCategory::class,
@ -170,20 +187,6 @@ class ThirdPartyType extends AbstractType
'multiple' => true,
'attr' => ['class' => 'select2']
])
->add('activeChildren', ChillCollectionType::class, [
'entry_type' => ThirdPartyType::class,
'entry_options' => [
'is_child' => true,
'block_name' => 'children'
],
'block_name' => 'active_children',
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false,
'button_add_label' => "Add a contact",
'button_remove_label' => "Remove a contact",
'empty_collection_explain' => "Any contact"
])
->add('active', ChoiceType::class, [
'label' => 'thirdparty.Status',
'choices' => [
@ -192,8 +195,7 @@ class ThirdPartyType extends AbstractType
],
'expanded' => true,
'multiple' => false
])
;
]);
// add the types
$types = [];
@ -242,6 +244,7 @@ class ThirdPartyType extends AbstractType
$resolver->setDefaults(array(
'data_class' => ThirdParty::class,
'is_child' => false,
'kind' => null
));
}
}

View File

@ -1,29 +1,31 @@
{% if form.civility is defined %}
{{ form_row(form.civility) }}
{% endif %}
{{ form_row(form.name) }}
{{ form_row(form.name) }}
{% if form.nameCompany is defined %}
{{ form_row(form.nameCompany) }}
{{ form_row(form.acronym) }}
{% endif %}
{% if form.nameCompany is defined %}
{{ form_row(form.nameCompany) }}
{{ form_row(form.acronym) }}
{% endif %}
{% if form.profession is defined %}
{{ form_row(form.profession) }}
{% endif %}
{% if form.profession is defined %}
{{ form_row(form.profession) }}
{% endif %}
{{ form_row(form.types) }}
{{ form_row(form.categories) }}
{{ form_row(form.types) }}
{{ form_row(form.categories) }}
{{ form_row(form.telephone) }}
{{ form_row(form.email) }}
{{ form_row(form.telephone) }}
{{ form_row(form.email) }}
<h2>{{ 'Contacts'|trans }}</h2>
{{ form_widget(form.activeChildren) }}
{{ form_row(form.contactDataAnonymous) }}
{% if form.activeChildren is defined %}
<h2>{{ 'Contacts'|trans }}</h2>
{{ form_widget(form.activeChildren) }}
{% endif %}
<div class="mb-3 row">
{{ form_label(form.address) }}
@ -54,6 +56,6 @@
</div>
{{ form_row(form.comment) }}
{{ form_row(form.centers) }}
{{ form_row(form.centers) }}
{{ form_row(form.active) }}
{{ form_row(form.active) }}

View File

@ -0,0 +1,37 @@
{% extends "@ChillMain/layout.html.twig" %}
{% block title 'thirdparty.Which kind of third party ?'|trans %}
{% block content %}
<div class="col-10 centered">
<h1>{{ block('title') }}</h1>
<div class="container" style="margin-top: 2rem;">
<div class="row">
<div class="col-md-4">
<a
href="{{ chill_path_forward_return_path('chill_crud_3party_3party_new', {'kind': 'company'}) }}"
class="btn btn-outline-chill-green-dark">
{{ 'thirdparty.A company'|trans }}
</a>
</div>
<div class="col-md-8">
<p>{{ 'thirdparty.a_company_explanation'|trans }}</p>
</div>
</div>
<div class="row">
<div class="col-md-4">
<a
href="{{ chill_path_forward_return_path('chill_crud_3party_3party_new', {'kind': 'contact'}) }}"
class="btn btn-outline-chill-green-dark">
{{ 'thirdparty.A contact'|trans }}
</a>
</div>
<div class="col-md-8">
<p>{{ 'thirdparty.a_contact_explanation'|trans }}</p>
</div>
</div>
</div>
</div>
{% endblock %}

View File

@ -28,7 +28,7 @@
{{ thirdParty.name }}
</dd>
{% if thirdParty.isLeaf == false %}
{% if thirdParty.kind == 'company' %}
<dt>{{ 'thirdparty.NameCompany'|trans }}</dt>
<dd>
{% if thirdParty.nameCompany == null %}
@ -99,20 +99,22 @@
{% endif %}
</dd>
<dt>{{ 'Contacts'|trans }}</dt>
<dd>
{% if thirdParty.activeChildren|length == 0 %}
<p class="chill-no-data-statement">{{ 'Any contacts associated'|trans }}</p>
{% else %}
<div class="flex-table">
{% for tp in thirdParty.activeChildren %}
<div class="item-bloc">
{{ tp|chill_entity_render_box({'render': 'bloc', 'addLink': false}) }}
{% if thirdParty.kind == 'company' %}
<dt>{{ 'Contacts'|trans }}</dt>
<dd>
{% if thirdParty.activeChildren|length == 0 %}
<p class="chill-no-data-statement">{{ 'Any contacts associated'|trans }}</p>
{% else %}
<div class="flex-table">
{% for tp in thirdParty.activeChildren %}
<div class="item-bloc">
{{ tp|chill_entity_render_box({'render': 'bloc', 'addLink': false}) }}
</div>
{% endfor %}
</div>
{% endfor %}
</div>
{% endif %}
</dd>
{% endif %}
</dd>
{% endif %}
<dt>{{ 'Centers'|trans }}</dt>
<dd>

View File

@ -41,11 +41,11 @@ final class Version20211007165001 extends AbstractMigration
NEW.canonicalized =
UNACCENT(
LOWER(
name ||
CASE WHEN COALESCE(name_company, '') <> '' THEN ' ' ELSE '' END ||
COALESCE(name_company, '') ||
CASE WHEN COALESCE(acronym, '') <> '' THEN ' ' ELSE '' END ||
COALESCE(acronym, '')
NEW.name ||
CASE WHEN COALESCE(NEW.name_company, '') <> '' THEN ' ' ELSE '' END ||
COALESCE(NEW.name_company, '') ||
CASE WHEN COALESCE(NEW.acronym, '') <> '' THEN ' ' ELSE '' END ||
COALESCE(NEW.acronym, '')
)
)
;

View File

@ -29,6 +29,14 @@ thirdparty.UpdateBy.short: ' par '
thirdparty.CreatedAt.long: Date de création
thirdparty.UpdatedAt.long: Date de la dernière modification
thirdparty.UpdateBy.long: Utilisateur qui a effectué la dernière modification
thirdparty.A company: Une institution
thirdparty.A contact: Une personne physique
thirdparty.a_company_explanation: >-
Les institutions peuvent compter un ou plusieurs contacts, interne à l'instution. Il est également possible de
leur associer un acronyme, et le nom d'un service.
thirdparty.a_contact_explanation: >-
Les personnes physiques ne disposent pas d'acronyme, de service, ou de contacts sous-jacents.
thirdparty.Which kind of third party ?: Quel type de tiers souhaitez-vous créer ?
New third party: Ajouter un nouveau tiers
Show third party %name%: Tiers "%name%"