mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Use new PhoneNumber form type.
This commit is contained in:
parent
348f649fef
commit
c9eaf3afac
@ -368,19 +368,6 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
|
|||||||
*/
|
*/
|
||||||
private $memo = ''; // TO-CHANGE in remark
|
private $memo = ''; // TO-CHANGE in remark
|
||||||
|
|
||||||
/**
|
|
||||||
* The person's mobile phone number.
|
|
||||||
*
|
|
||||||
* @ORM\Column(type="text")
|
|
||||||
* @Assert\Regex(
|
|
||||||
* pattern="/^([\+{1}])([0-9\s*]{4,20})$/",
|
|
||||||
* )
|
|
||||||
* @PhonenumberConstraint(
|
|
||||||
* type="mobile",
|
|
||||||
* )
|
|
||||||
*/
|
|
||||||
private string $mobilenumber = '';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The person's nationality.
|
* The person's nationality.
|
||||||
*
|
*
|
||||||
@ -403,6 +390,24 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
|
|||||||
*/
|
*/
|
||||||
private ?int $numberOfChildren = null;
|
private ?int $numberOfChildren = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="phone_number", nullable=true)
|
||||||
|
* @PhonenumberConstraint(
|
||||||
|
* type="landline",
|
||||||
|
* groups={"general", "creation"}
|
||||||
|
* )
|
||||||
|
*/
|
||||||
|
private ?PhoneNumber $phonenumber;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="phone_number", nullable=true)
|
||||||
|
* @PhonenumberConstraint(
|
||||||
|
* type="mobile",
|
||||||
|
* groups={"general", "creation"}
|
||||||
|
* )
|
||||||
|
*/
|
||||||
|
private ?PhoneNumber $mobilenumber;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Collection
|
* @var Collection
|
||||||
*
|
*
|
||||||
@ -426,19 +431,6 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
|
|||||||
*/
|
*/
|
||||||
private Collection $periodLocatedOn;
|
private Collection $periodLocatedOn;
|
||||||
|
|
||||||
/**
|
|
||||||
* The person's phonenumber.
|
|
||||||
*
|
|
||||||
* @ORM\Column(type="text")
|
|
||||||
* @Assert\Regex(
|
|
||||||
* pattern="/^([\+{1}])([0-9\s*]{4,20})$/",
|
|
||||||
* )
|
|
||||||
* @PhonenumberConstraint(
|
|
||||||
* type="landline",
|
|
||||||
* )
|
|
||||||
*/
|
|
||||||
private string $phonenumber = '';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The person's place of birth.
|
* The person's place of birth.
|
||||||
*
|
*
|
||||||
@ -510,7 +502,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add AccompanyingPeriodParticipation.
|
* Add AccompanyingPeriodParticipation
|
||||||
*
|
*
|
||||||
* @uses AccompanyingPeriod::addPerson
|
* @uses AccompanyingPeriod::addPerson
|
||||||
*/
|
*/
|
||||||
@ -522,6 +514,22 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set the Person file as open at the given date.
|
||||||
|
*
|
||||||
|
* For updating a opening's date, you should update AccompanyingPeriod instance
|
||||||
|
* directly.
|
||||||
|
*
|
||||||
|
* For closing a file, @see this::close
|
||||||
|
*
|
||||||
|
* To check if the Person and its accompanying period is consistent, use validation.
|
||||||
|
*/
|
||||||
|
public function open(AccompanyingPeriod $accompanyingPeriod) : void
|
||||||
|
{
|
||||||
|
$this->proxyAccompanyingPeriodOpenState = true;
|
||||||
|
$this->addAccompanyingPeriod($accompanyingPeriod);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
@ -552,7 +560,32 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setPhonenumber(?PhoneNumber $phonenumber = null): self
|
||||||
|
{
|
||||||
|
$this->phonenumber = $phonenumber;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPhonenumber(): ?PhoneNumber
|
||||||
|
{
|
||||||
|
return $this->phonenumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setMobilenumber(?PhoneNumber $mobilenumber = null): self
|
||||||
|
{
|
||||||
|
$this->mobilenumber = $mobilenumber;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMobilenumber(): ?PhoneNumber
|
||||||
|
{
|
||||||
|
return $this->mobilenumber;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @param PersonPhone $otherPhoneNumber
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function addOtherPhoneNumber(PersonPhone $otherPhoneNumber)
|
public function addOtherPhoneNumber(PersonPhone $otherPhoneNumber)
|
||||||
@ -1225,14 +1258,6 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
|
|||||||
return $this->memo;
|
return $this->memo;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get mobilenumber.
|
|
||||||
*/
|
|
||||||
public function getMobilenumber(): string
|
|
||||||
{
|
|
||||||
return $this->mobilenumber;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get nationality.
|
* Get nationality.
|
||||||
*
|
*
|
||||||
@ -1293,14 +1318,6 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
|
|||||||
return $this->otherPhoneNumbers;
|
return $this->otherPhoneNumbers;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get phonenumber.
|
|
||||||
*/
|
|
||||||
public function getPhonenumber(): string
|
|
||||||
{
|
|
||||||
return $this->phonenumber;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get placeOfBirth.
|
* Get placeOfBirth.
|
||||||
*
|
*
|
||||||
@ -1423,22 +1440,6 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
|
|||||||
return null !== $this->getCurrentHousehold($at);
|
return null !== $this->getCurrentHousehold($at);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* set the Person file as open at the given date.
|
|
||||||
*
|
|
||||||
* For updating a opening's date, you should update AccompanyingPeriod instance
|
|
||||||
* directly.
|
|
||||||
*
|
|
||||||
* For closing a file, @see this::close
|
|
||||||
*
|
|
||||||
* To check if the Person and its accompanying period is consistent, use validation.
|
|
||||||
*/
|
|
||||||
public function open(AccompanyingPeriod $accompanyingPeriod): void
|
|
||||||
{
|
|
||||||
$this->proxyAccompanyingPeriodOpenState = true;
|
|
||||||
$this->addAccompanyingPeriod($accompanyingPeriod);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove AccompanyingPeriod.
|
* Remove AccompanyingPeriod.
|
||||||
*/
|
*/
|
||||||
@ -1735,20 +1736,6 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set mobilenumber.
|
|
||||||
*
|
|
||||||
* @param string $mobilenumber
|
|
||||||
*
|
|
||||||
* @return Person
|
|
||||||
*/
|
|
||||||
public function setMobilenumber(?string $mobilenumber = '')
|
|
||||||
{
|
|
||||||
$this->mobilenumber = (string) $mobilenumber;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set nationality.
|
* Set nationality.
|
||||||
*
|
*
|
||||||
@ -1780,20 +1767,6 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set phonenumber.
|
|
||||||
*
|
|
||||||
* @param string $phonenumber
|
|
||||||
*
|
|
||||||
* @return Person
|
|
||||||
*/
|
|
||||||
public function setPhonenumber(?string $phonenumber = '')
|
|
||||||
{
|
|
||||||
$this->phonenumber = (string) $phonenumber;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set placeOfBirth.
|
* Set placeOfBirth.
|
||||||
*
|
*
|
||||||
|
@ -13,6 +13,7 @@ namespace Chill\PersonBundle\Entity;
|
|||||||
|
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
use Misd\PhoneNumberBundle\Validator\Constraints\PhoneNumber as AssertPhoneNumber;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Person Phones.
|
* Person Phones.
|
||||||
@ -51,7 +52,13 @@ class PersonPhone
|
|||||||
private Person $person;
|
private Person $person;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="text", length=40, nullable=false)
|
* @ORM\Column(type="text", length=40, nullable=true)
|
||||||
|
*/
|
||||||
|
private ?string $type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="phone_number", length=40, nullable=false)
|
||||||
|
* @AssertPhoneNumber
|
||||||
*/
|
*/
|
||||||
private string $phonenumber = '';
|
private string $phonenumber = '';
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ declare(strict_types=1);
|
|||||||
namespace Chill\PersonBundle\Form;
|
namespace Chill\PersonBundle\Form;
|
||||||
|
|
||||||
use Chill\CustomFieldsBundle\Form\Type\CustomFieldType;
|
use Chill\CustomFieldsBundle\Form\Type\CustomFieldType;
|
||||||
|
use Chill\FormTypesBundle\Form\Types\PhoneNumberType;
|
||||||
use Chill\MainBundle\Entity\Civility;
|
use Chill\MainBundle\Entity\Civility;
|
||||||
use Chill\MainBundle\Form\Type\ChillCollectionType;
|
use Chill\MainBundle\Form\Type\ChillCollectionType;
|
||||||
use Chill\MainBundle\Form\Type\ChillDateType;
|
use Chill\MainBundle\Form\Type\ChillDateType;
|
||||||
@ -25,18 +26,16 @@ use Chill\PersonBundle\Entity\Person;
|
|||||||
use Chill\PersonBundle\Entity\PersonPhone;
|
use Chill\PersonBundle\Entity\PersonPhone;
|
||||||
use Chill\PersonBundle\Form\Type\GenderType;
|
use Chill\PersonBundle\Form\Type\GenderType;
|
||||||
use Chill\PersonBundle\Form\Type\PersonAltNameType;
|
use Chill\PersonBundle\Form\Type\PersonAltNameType;
|
||||||
use Chill\PersonBundle\Form\Type\PersonPhoneType;
|
|
||||||
use Chill\PersonBundle\Form\Type\Select2MaritalStatusType;
|
use Chill\PersonBundle\Form\Type\Select2MaritalStatusType;
|
||||||
use Doctrine\ORM\EntityRepository;
|
use Doctrine\ORM\EntityRepository;
|
||||||
use Doctrine\ORM\QueryBuilder;
|
use Doctrine\ORM\QueryBuilder;
|
||||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
use libphonenumber\PhoneNumberFormat;
|
||||||
|
use Misd\PhoneNumberBundle\Form\Type\PhoneNumberType as MisdPhoneNumberType;
|
||||||
use Symfony\Component\Form\AbstractType;
|
use Symfony\Component\Form\AbstractType;
|
||||||
use Symfony\Component\Form\CallbackTransformer;
|
use Symfony\Component\Form\CallbackTransformer;
|
||||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||||
use Symfony\Component\Form\Extension\Core\Type\DateType;
|
use Symfony\Component\Form\Extension\Core\Type\DateType;
|
||||||
use Symfony\Component\Form\Extension\Core\Type\EmailType;
|
use Symfony\Component\Form\Extension\Core\Type\EmailType;
|
||||||
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
|
|
||||||
use Symfony\Component\Form\Extension\Core\Type\TelType;
|
|
||||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||||
use Symfony\Component\Form\FormBuilderInterface;
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
@ -51,7 +50,7 @@ class PersonType extends AbstractType
|
|||||||
*
|
*
|
||||||
* @var string[]
|
* @var string[]
|
||||||
*/
|
*/
|
||||||
protected $config = [];
|
protected array $config;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var ConfigPersonAltNamesHelper
|
* @var ConfigPersonAltNamesHelper
|
||||||
@ -128,23 +127,41 @@ class PersonType extends AbstractType
|
|||||||
$builder->add('contactInfo', ChillTextareaType::class, ['required' => false]);
|
$builder->add('contactInfo', ChillTextareaType::class, ['required' => false]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ('visible' === $this->config['phonenumber']) {
|
if ($this->config['phonenumber'] === 'visible') {
|
||||||
$builder->add('phonenumber', TelType::class, [
|
|
||||||
'required' => false,
|
|
||||||
// 'placeholder' => '+33623124554' //TODO placeholder for phone numbers
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ('visible' === $this->config['mobilenumber']) {
|
|
||||||
$builder
|
$builder
|
||||||
->add('mobilenumber', TelType::class, ['required' => false])
|
->add(
|
||||||
->add('acceptSMS', CheckboxType::class, [
|
'phonenumber',
|
||||||
|
PhoneNumberType::class,
|
||||||
|
[
|
||||||
'required' => false,
|
'required' => false,
|
||||||
]);
|
'format' => PhoneNumberFormat::INTERNATIONAL,
|
||||||
|
'widget' => MisdPhoneNumberType::WIDGET_COUNTRY_CHOICE,
|
||||||
|
'country_choices' => ['BE', 'GB', 'JE', 'FR', 'US'],
|
||||||
|
'preferred_country_choices' => ['BE', 'FR'],
|
||||||
|
]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$builder->add('otherPhoneNumbers', ChillCollectionType::class, [
|
if ($this->config['mobilenumber'] === 'visible') {
|
||||||
'entry_type' => PersonPhoneType::class,
|
$builder
|
||||||
|
->add(
|
||||||
|
'mobilenumber',
|
||||||
|
PhoneNumberType::class,
|
||||||
|
[
|
||||||
|
'required' => false,
|
||||||
|
'format' => PhoneNumberFormat::INTERNATIONAL,
|
||||||
|
'widget' => MisdPhoneNumberType::WIDGET_COUNTRY_CHOICE,
|
||||||
|
'country_choices' => ['BE', 'GB', 'JE', 'FR', 'US'],
|
||||||
|
'preferred_country_choices' => ['BE', 'FR'],
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$builder->add(
|
||||||
|
'otherPhoneNumbers',
|
||||||
|
ChillCollectionType::class,
|
||||||
|
[
|
||||||
|
'entry_type' => PhoneNumberType::class,
|
||||||
'button_add_label' => 'Add new phone',
|
'button_add_label' => 'Add new phone',
|
||||||
'button_remove_label' => 'Remove phone',
|
'button_remove_label' => 'Remove phone',
|
||||||
'required' => false,
|
'required' => false,
|
||||||
@ -152,12 +169,12 @@ class PersonType extends AbstractType
|
|||||||
'allow_delete' => true,
|
'allow_delete' => true,
|
||||||
'by_reference' => false,
|
'by_reference' => false,
|
||||||
'label' => false,
|
'label' => false,
|
||||||
'delete_empty' => static function (?PersonPhone $pp = null) {
|
'delete_empty' => static function(?PersonPhone $pp = null): bool {
|
||||||
return null === $pp || $pp->isEmpty();
|
return NULL === $pp || $pp->isEmpty();
|
||||||
},
|
},
|
||||||
'error_bubbling' => false,
|
'error_bubbling' => false
|
||||||
'empty_collection_explain' => 'No additional phone numbers',
|
]
|
||||||
]);
|
);
|
||||||
|
|
||||||
if ('visible' === $this->config['email']) {
|
if ('visible' === $this->config['email']) {
|
||||||
$builder
|
$builder
|
||||||
|
@ -11,24 +11,24 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Chill\PersonBundle\Form\Type;
|
namespace Chill\PersonBundle\Form\Type;
|
||||||
|
|
||||||
use Chill\MainBundle\Phonenumber\PhonenumberHelper;
|
use Chill\FormTypesBundle\Service\PhoneNumberHelperInterface;
|
||||||
use Chill\PersonBundle\Entity\PersonPhone;
|
use Chill\PersonBundle\Entity\PersonPhone;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
use libphonenumber\PhoneNumberFormat;
|
||||||
use Symfony\Component\Form\AbstractType;
|
use Symfony\Component\Form\AbstractType;
|
||||||
use Symfony\Component\Form\Extension\Core\Type\TelType;
|
|
||||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||||
use Symfony\Component\Form\FormBuilderInterface;
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
use Symfony\Component\Form\FormEvent;
|
use Symfony\Component\Form\FormEvent;
|
||||||
use Symfony\Component\Form\FormEvents;
|
use Symfony\Component\Form\FormEvents;
|
||||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
|
|
||||||
class PersonPhoneType extends AbstractType
|
final class PersonPhoneType extends AbstractType
|
||||||
{
|
{
|
||||||
|
private PhoneNumberHelperInterface $phonenumberHelper;
|
||||||
|
|
||||||
private EntityManagerInterface $em;
|
private EntityManagerInterface $em;
|
||||||
|
|
||||||
private PhonenumberHelper $phonenumberHelper;
|
public function __construct(PhoneNumberHelperInterface $phonenumberHelper, EntityManagerInterface $em)
|
||||||
|
|
||||||
public function __construct(PhonenumberHelper $phonenumberHelper, EntityManagerInterface $em)
|
|
||||||
{
|
{
|
||||||
$this->phonenumberHelper = $phonenumberHelper;
|
$this->phonenumberHelper = $phonenumberHelper;
|
||||||
$this->em = $em;
|
$this->em = $em;
|
||||||
@ -36,10 +36,16 @@ class PersonPhoneType extends AbstractType
|
|||||||
|
|
||||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||||
{
|
{
|
||||||
$builder->add('phonenumber', TelType::class, [
|
$builder
|
||||||
|
->add(
|
||||||
|
'phonenumber',
|
||||||
|
PhoneNumberType::class,
|
||||||
|
[
|
||||||
'label' => 'Other phonenumber',
|
'label' => 'Other phonenumber',
|
||||||
'required' => true,
|
'required' => true,
|
||||||
]);
|
'format' => PhoneNumberFormat::NATIONAL,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
$builder->add('description', TextType::class, [
|
$builder->add('description', TextType::class, [
|
||||||
'required' => false,
|
'required' => false,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user