adapt Thirdparty form and templates

This commit is contained in:
Mathieu Jaumotte 2021-07-19 18:47:10 +02:00
parent 3f9e215ea5
commit 587da94645
8 changed files with 234 additions and 61 deletions

View File

@ -96,18 +96,16 @@ class ThirdParty
/**
* Contact Persons: One Institutional ThirdParty has Many Contact Persons
* @var ThirdParty
* @ORM\OneToMany(targetEntity="Chill\ThirdPartyBundle\Entity\ThirdParty", mappedBy="parent")
*/
private $children;
private Collection $children;
/**
* Institutional ThirdParty: Many Contact Persons have One Institutional ThirdParty
* @var ThirdParty
* @ORM\ManyToOne(targetEntity="Chill\ThirdPartyBundle\Entity\ThirdParty", inversedBy="children")
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id")
*/
private $parent;
private ?ThirdParty $parent;
/**
* @var ThirdPartyCivility
@ -169,16 +167,14 @@ class ThirdParty
private $centers;
/**
* @var \DateTimeImmutable
* @ORM\Column(name="created_at", type="datetime", nullable=false)
* @ORM\Column(name="created_at", type="datetime_immutable", nullable=false)
*/
private $createdAt;
private \DateTimeImmutable $createdAt;
/**
* @var \DateTime
* @ORM\Column(name="updated_at", type="datetime", nullable=true)
*/
private $updatedAt;
private ?\DateTime $updatedAt;
/**
* @var User
@ -497,6 +493,11 @@ class ThirdParty
return $this;
}
public function isLeaf(): bool
{
return $this->children->count() !== 0;
}
/**
* @return Collection
*/
@ -526,18 +527,18 @@ class ThirdParty
}
/**
* @return ThirdParty
* @return ThirdParty|null
*/
public function getParent(): ThirdParty
public function getParent(): ?ThirdParty
{
return $this->parent;
}
/**
* @param ThirdParty $parent
* @param ThirdParty|null $parent
* @return $this
*/
public function setParent(ThirdParty $parent): ThirdParty
public function setParent(?ThirdParty $parent): ThirdParty
{
$this->parent = $parent;
return $this;
@ -598,9 +599,9 @@ class ThirdParty
}
/**
* @return \DateTime
* @return \DateTime|null
*/
public function getUpdatedAt(): \DateTime
public function getUpdatedAt(): ?\DateTime
{
return $this->updatedAt;
}
@ -616,9 +617,9 @@ class ThirdParty
}
/**
* @return User
* @return User|null
*/
public function getUpdatedBy(): User
public function getUpdatedBy(): ?User
{
return $this->updatedBy;
}

View File

@ -3,6 +3,11 @@
namespace Chill\ThirdPartyBundle\Form;
use Chill\MainBundle\Form\Type\ChillTextareaType;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\ThirdPartyBundle\Entity\ThirdPartyCategory;
use Chill\ThirdPartyBundle\Entity\ThirdPartyCivility;
use Chill\ThirdPartyBundle\Entity\ThirdPartyProfession;
use Doctrine\ORM\EntityRepository;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
@ -21,32 +26,24 @@ use Chill\MainBundle\Form\Type\AddressType;
class ThirdPartyType extends AbstractType
{
/**
*
* @var AuthorizationHelper
*/
protected $authorizationHelper;
protected AuthorizationHelper $authorizationHelper;
/**
*
* @var TokenStorageInterface
*/
protected $tokenStorage;
protected TokenStorageInterface $tokenStorage;
/**
*
* @var ThirdPartyTypeManager
*/
protected $typesManager;
protected ThirdPartyTypeManager $typesManager;
protected TranslatableStringHelper $translatableStringHelper;
public function __construct(
AuthorizationHelper $authorizationHelper,
TokenStorageInterface $tokenStorage,
ThirdPartyTypeManager $typesManager
ThirdPartyTypeManager $typesManager,
TranslatableStringHelper $translatableStringHelper
) {
$this->authorizationHelper = $authorizationHelper;
$this->tokenStorage = $tokenStorage;
$this->typesManager = $typesManager;
$this->translatableStringHelper = $translatableStringHelper;
}
/**
@ -60,26 +57,87 @@ class ThirdPartyType extends AbstractType
}
$builder
->add('civility', EntityType::class, [
'label' => 'thirdparty.Civility',
'class' => ThirdPartyCivility::class,
'choice_label' => function (ThirdPartyCivility $civility) {
return $this->translatableStringHelper->localize($civility->getName());
},
'query_builder' => function(EntityRepository $er) {
return $er->createQueryBuilder('c')
->where('c.active = true');
},
'placeholder' => 'thirdparty.choose civility',
'required' => true
])
->add('name', TextType::class, [
'required' => true
])
->add('telephone', TextType::class, [
'label' => 'Phonenumber',
->add('nameCompany', TextType::class, [
'label' => 'thirdparty.NameCompany',
'required' => false
])
->add('email', EmailType::class, [
->add('profession', EntityType::class, [
'label' => 'thirdparty.Profession',
'class' => ThirdPartyProfession::class,
'choice_label' => function (ThirdPartyProfession $profession) {
return $this->translatableStringHelper->localize($profession->getName());
},
'query_builder' => function (EntityRepository $er) {
return $er->createQueryBuilder('p')
->where('p.active = true');
},
'placeholder' => 'thirdparty.choose profession',
'required' => false
])
->add('comment', ChillTextareaType::class, [
->add('acronym', TextType::class, [
'label' => 'thirdparty.Acronym',
'required' => false
])
->add('categories', EntityType::class, [
'label' => 'thirdparty.Categories',
'class' => ThirdPartyCategory::class,
'choice_label' => function (ThirdPartyCategory $category) {
return $this->translatableStringHelper->localize($category->getName());
},
'query_builder' => function (EntityRepository $er) {
return $er->createQueryBuilder('c')
->where('c.active = true');
},
'required' => true,
'multiple' => true,
'attr' => ['class' => 'select2']
])
->add('type', ChoiceType::class, [
'choices' => $types,
'expanded' => true,
'multiple' => true,
'label' => 'thirdparty.Type'
])
->add('telephone', TextType::class, [
'label' => 'Phonenumber',
'required' => false
])
->add('email', EmailType::class, [
'required' => false
])
->add('address', AddressType::class, [
'has_valid_from' => false,
'null_if_empty' => true,
'required' => false
])
->add('active', ChoiceType::class, [
'label' => 'thirdparty.Status',
'choices' => [
'Active, shown to users' => true,
'Inactive, not shown to users' => false
@ -87,18 +145,18 @@ class ThirdPartyType extends AbstractType
'expanded' => true,
'multiple' => false
])
->add('comment', ChillTextareaType::class, [
'required' => false
])
->add('centers', EntityType::class, [
'choices' => $this->getReachableCenters($options),
'class' => \Chill\MainBundle\Entity\Center::class,
'multiple' => true,
'expanded' => true
'attr' => ['class' => 'select2']
])
->add('address', AddressType::class, [
'has_valid_from' => false,
'null_if_empty' => true,
'required' => false
])
;
;
}
/**

View File

@ -40,6 +40,9 @@
<th class="chill-pink">{{ 'Address'|trans }}
<i class="fa fa-fw fa-sort"></i>
</th>
<th class="chill-pink">{{ 'thirdparty.UpdatedAt.short'|trans }}
<i class="fa fa-fw fa-sort"></i>
</th>
<th class="chill-pink"></th>
</tr>
</thead>
@ -56,6 +59,13 @@
<td>
{{ tp.address|chill_entity_render_box({'multiline': false, 'with_valid_from': false}) }}
</td>
<td>
{% if tp.updatedAt != null %}
{{ tp.updatedAt|format_date('short') }}
{% else %}
{{ tp.createdAt|format_date('short') }}
{% endif %}
</td>
<td>
<ul class="record_actions">
{% if is_granted('CHILL_3PARTY_3PARTY_UPDATE', tp) %}

View File

@ -10,22 +10,42 @@
<h1>{{ 'Create third party'|trans }}</h1>
{{ form_start(form) }}
{% if thirdParty.isLeaf == true %}
{{ form_row(form.civility) }}
{% endif %}
{{ form_row(form.name) }}
{% if thirdParty.isLeaf == false %}
{{ form_row(form.nameCompany) }}
{{ form_row(form.acronym) }}
{% endif %}
{% if thirdParty.isLeaf == true %}
{{ form_row(form.profession) }}
{% endif %}
{{ form_row(form.categories) }}
{{ form_row(form.type) }}
{{ form_row(form.telephone) }}
{{ form_row(form.email) }}
{{ form_row(form.address) }}
{{ form_row(form.active) }}
{{ form_row(form.centers) }}
{{ form_row(form.comment) }}
{{ form_row(form.centers) }}
{{ form_row(form.active) }}
<ul class="record_actions">
<ul class="record_actions sticky-form-buttons">
<li class="cancel">
<a href="{{ chill_return_path_or('chill_3party_3party_index') }}" class="btn btn-cancel">
{{ 'Back to the list'|trans }}
</a>
</li>
<li>
</li>
<li>
{{ form_widget(form.submit, {'label': 'Create', 'attr': {'class': 'btn btn-new' }}) }}

View File

@ -20,24 +20,63 @@
</h1>
<dl class="chill_view_data">
<dt>{{ 'Name'|trans }}</dt>
<dd>{{ thirdParty.name }}</dd>
<dd>
{% if thirdParty.isLeaf == true %}{{ thirdParty.civility }}{% endif %}
{{ thirdParty.name }}
</dd>
{% if thirdParty.isLeaf == false %}
<dt>{{ 'thirdparty.NameCompany'|trans }}</dt>
<dd>
{% if thirdParty.nameCompany == null %}
<span class="chill-no-data-statement">{{ 'No nameCompany given'|trans }}</span>
{% else %}
{{ thirdParty.nameCompany }}
{% endif %}
</dd>
<dt>{{ 'thirdparty.Acronym'|trans }}</dt>
<dd>
{% if thirdParty.acronym == null %}
<span class="chill-no-data-statement">{{ 'No acronym given'|trans }}</span>
{% else %}
{{ thirdParty.acronym }}
{% endif %}
</dd>
{% endif %}
<dt>{{ 'Type'|trans }}</dt>
{% set types = [] %}
{% for t in thirdParty.type %}
{% set types = types|merge( [ ('chill_3party.key_label.'~t)|trans ] ) %}
{% endfor %}
<dd>{{ types|join(', ') }}</dd>
<dt>{{ 'Centers'|trans }}</dt>
<dd>{{ 'The party is visible in those centers'|trans }}&nbsp;: {{ thirdParty.centers|join(', ') }}</dd>
<dd>
{{ types|join(', ') }}
</dd>
<dt>{{ 'Phonenumber'|trans }}</dt>
<dd>{{ thirdParty.telephone|chill_print_or_message("thirdparty.No_phonenumber") }}</dd>
<dd>
{% if thirdParty.telephone == null %}
<span class="chill-no-data-statement">{{ 'No phone given'|trans }}</span>
{% else %}
<a href="{{ 'tel:' ~ thirdParty.telephone }}">
{{ thirdParty.telephone|chill_print_or_message("thirdparty.No_phonenumber") }}
</a>
{% endif %}
</dd>
<dt>{{ 'email'|trans }}<dt>
<dd>{{ thirdParty.email|chill_print_or_message("thirdparty.No_email") }}</dd>
<dd>
{% if thirdParty.email == null %}
<span class="chill-no-data-statement">{{ 'No email given'|trans }}</span>
{% else %}
<a href="{{ 'mailto:' ~ thirdParty.email }}">
{{ thirdParty.email|chill_print_or_message("thirdparty.No_email") }}
</a>
{% endif %}
</dd>
<dt>{{ 'Address'|trans }}</dt>
<dd>
@ -57,6 +96,9 @@
{% endif %}
</dd>
<dt>{{ 'Centers'|trans }}</dt>
<dd>{{ 'The party is visible in those centers'|trans }}&nbsp;: {{ thirdParty.centers|join(', ') }}</dd>
</dl>
<ul class="record_actions sticky-form-buttons">

View File

@ -15,24 +15,55 @@
</span>
</h1>
<div class="date-by">
{% if thirdParty.updatedAt != null %}
{{ 'thirdparty.UpdatedAt.short'|trans ~ thirdParty.updatedAt|format_date('short') }}
{% else %}
{{ 'thirdparty.CreatedAt.short'|trans ~ thirdParty.createdAt|format_date('short') }}
{% endif %}
{% if thirdParty.updatedBy != null %}
{{ 'thirdparty.UpdateBy.short'|trans ~ thirdParty.updatedBy.usernameCanonical }}
{% endif %}
</div>
{{ form_start(form) }}
{% if thirdParty.isLeaf == true %}
{{ form_row(form.civility) }}
{% endif %}
{{ form_row(form.name) }}
{% if thirdParty.isLeaf == false %}
{{ form_row(form.nameCompany) }}
{{ form_row(form.acronym) }}
{% endif %}
{% if thirdParty.isLeaf == true %}
{{ form_row(form.profession) }}
{% endif %}
{{ form_row(form.categories) }}
{{ form_row(form.type) }}
{{ form_row(form.telephone) }}
{{ form_row(form.email) }}
{{ form_row(form.address) }}
{{ form_row(form.active) }}
{{ form_row(form.centers) }}
{{ form_row(form.comment) }}
{{ form_row(form.centers) }}
{{ form_row(form.active) }}
<ul class="record_actions sticky-form-buttons">
<li class="cancel">
<a class="btn btn-cancel" href="{{ chill_path_forward_return_path('chill_3party_3party_index') }}">
{{ 'Back to the list'|trans }}
</a>
</li>
<li>
</li>
<li>
{{ form_widget(form.submit, {'label': 'Update', 'attr': {'class': 'btn btn-update' }}) }}
</li>

View File

@ -4,9 +4,10 @@ services:
$authorizationHelper: '@Chill\MainBundle\Security\Authorization\AuthorizationHelper'
$tokenStorage: '@Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface'
$typesManager: '@Chill\ThirdPartyBundle\ThirdPartyType\ThirdPartyTypeManager'
$translatableStringHelper: '@Chill\MainBundle\Templating\TranslatableStringHelper'
tags:
- { name: form.type }
Chill\ThirdPartyBundle\Form\Type\PickThirdPartyType:
arguments:
$em: '@Doctrine\ORM\EntityManagerInterface'
@ -14,4 +15,4 @@ services:
$translator: '@Symfony\Component\Translation\TranslatorInterface'
$typesManager: '@Chill\ThirdPartyBundle\ThirdPartyType\ThirdPartyTypeManager'
tags:
- { name: form.type }
- { name: form.type }

View File

@ -20,10 +20,15 @@ thirdparty.Children: Personnes de contact
thirdparty.Parent: Tiers institutionnel
thirdparty.Parents: Tiers institutionnels
thirdparty.Civility: Civilité
thirdparty.choose civility: --
thirdparty.Profession: Qualité
thirdparty.CreatedAt: Date de création
thirdparty.UpdatedAt: Date de la dernière modification
thirdparty.UpdateBy: Utilisateur qui a effectué la dernière modification
thirdparty.choose profession: --
thirdparty.CreatedAt.short: 'Créé le '
thirdparty.UpdatedAt.short: 'Modifié le '
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
New third party: Ajouter un nouveau tiers
Show third party %name%: Tiers "%name%"
@ -32,6 +37,7 @@ Update third party %name%: Mettre à jour "%name%"
List of third parties: Liste des tiers
Third party updated: Le tiers a été mis à jour
Third party created: Le tiers a été créé
thirdparty.Status: Statut
Active, shown to users: Actif, visible pour les utilisateurs
Active: Actif
shown to users: visible pour les utilisateurs
@ -39,6 +45,10 @@ Inactive, not shown to users: Inactif, invisible pour les utilisateurs
Inactive: Inactif
not shown to users: invisible pour les utilisateurs
No nameCompany given: Aucune raison sociale renseignée
No acronym given: Aucun sigle renseigné
No phone given: Aucun téléphone renseigné
No email given: Aucune adresse courriel renseignée
The party is visible in those centers: Le tiers est visible dans ces centres
No third parties: Aucun tiers