diff --git a/src/Bundle/ChillPersonBundle/Entity/Person.php b/src/Bundle/ChillPersonBundle/Entity/Person.php index e908dc489..8c1b4148d 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Person.php +++ b/src/Bundle/ChillPersonBundle/Entity/Person.php @@ -368,19 +368,6 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI */ 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. * @@ -403,6 +390,24 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI */ 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 * @@ -426,19 +431,6 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI */ 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. * @@ -510,7 +502,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI } /** - * Add AccompanyingPeriodParticipation. + * Add AccompanyingPeriodParticipation * * @uses AccompanyingPeriod::addPerson */ @@ -522,6 +514,22 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI 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 */ @@ -552,7 +560,32 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI 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 */ public function addOtherPhoneNumber(PersonPhone $otherPhoneNumber) @@ -1225,14 +1258,6 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI return $this->memo; } - /** - * Get mobilenumber. - */ - public function getMobilenumber(): string - { - return $this->mobilenumber; - } - /** * Get nationality. * @@ -1293,14 +1318,6 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI return $this->otherPhoneNumbers; } - /** - * Get phonenumber. - */ - public function getPhonenumber(): string - { - return $this->phonenumber; - } - /** * Get placeOfBirth. * @@ -1423,22 +1440,6 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI 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. */ @@ -1735,20 +1736,6 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI return $this; } - /** - * Set mobilenumber. - * - * @param string $mobilenumber - * - * @return Person - */ - public function setMobilenumber(?string $mobilenumber = '') - { - $this->mobilenumber = (string) $mobilenumber; - - return $this; - } - /** * Set nationality. * @@ -1780,20 +1767,6 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI return $this; } - /** - * Set phonenumber. - * - * @param string $phonenumber - * - * @return Person - */ - public function setPhonenumber(?string $phonenumber = '') - { - $this->phonenumber = (string) $phonenumber; - - return $this; - } - /** * Set placeOfBirth. * diff --git a/src/Bundle/ChillPersonBundle/Entity/PersonPhone.php b/src/Bundle/ChillPersonBundle/Entity/PersonPhone.php index 400e39c88..a6a6d575f 100644 --- a/src/Bundle/ChillPersonBundle/Entity/PersonPhone.php +++ b/src/Bundle/ChillPersonBundle/Entity/PersonPhone.php @@ -13,6 +13,7 @@ namespace Chill\PersonBundle\Entity; use DateTime; use Doctrine\ORM\Mapping as ORM; +use Misd\PhoneNumberBundle\Validator\Constraints\PhoneNumber as AssertPhoneNumber; /** * Person Phones. @@ -51,7 +52,13 @@ class PersonPhone 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 = ''; diff --git a/src/Bundle/ChillPersonBundle/Form/PersonType.php b/src/Bundle/ChillPersonBundle/Form/PersonType.php index bafe21277..20fbbf884 100644 --- a/src/Bundle/ChillPersonBundle/Form/PersonType.php +++ b/src/Bundle/ChillPersonBundle/Form/PersonType.php @@ -12,6 +12,7 @@ declare(strict_types=1); namespace Chill\PersonBundle\Form; use Chill\CustomFieldsBundle\Form\Type\CustomFieldType; +use Chill\FormTypesBundle\Form\Types\PhoneNumberType; use Chill\MainBundle\Entity\Civility; use Chill\MainBundle\Form\Type\ChillCollectionType; use Chill\MainBundle\Form\Type\ChillDateType; @@ -25,18 +26,16 @@ use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Entity\PersonPhone; use Chill\PersonBundle\Form\Type\GenderType; use Chill\PersonBundle\Form\Type\PersonAltNameType; -use Chill\PersonBundle\Form\Type\PersonPhoneType; use Chill\PersonBundle\Form\Type\Select2MaritalStatusType; use Doctrine\ORM\EntityRepository; 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\CallbackTransformer; use Symfony\Component\Form\Extension\Core\Type\CheckboxType; use Symfony\Component\Form\Extension\Core\Type\DateType; 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\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -51,7 +50,7 @@ class PersonType extends AbstractType * * @var string[] */ - protected $config = []; + protected array $config; /** * @var ConfigPersonAltNamesHelper @@ -128,36 +127,54 @@ class PersonType extends AbstractType $builder->add('contactInfo', ChillTextareaType::class, ['required' => false]); } - if ('visible' === $this->config['phonenumber']) { - $builder->add('phonenumber', TelType::class, [ - 'required' => false, - // 'placeholder' => '+33623124554' //TODO placeholder for phone numbers - ]); - } - - if ('visible' === $this->config['mobilenumber']) { + if ($this->config['phonenumber'] === 'visible') { $builder - ->add('mobilenumber', TelType::class, ['required' => false]) - ->add('acceptSMS', CheckboxType::class, [ - 'required' => false, - ]); + ->add( + 'phonenumber', + 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' => PersonPhoneType::class, - 'button_add_label' => 'Add new phone', - 'button_remove_label' => 'Remove phone', - 'required' => false, - 'allow_add' => true, - 'allow_delete' => true, - 'by_reference' => false, - 'label' => false, - 'delete_empty' => static function (?PersonPhone $pp = null) { - return null === $pp || $pp->isEmpty(); - }, - 'error_bubbling' => false, - 'empty_collection_explain' => 'No additional phone numbers', - ]); + if ($this->config['mobilenumber'] === 'visible') { + $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_remove_label' => 'Remove phone', + 'required' => false, + 'allow_add' => true, + 'allow_delete' => true, + 'by_reference' => false, + 'label' => false, + 'delete_empty' => static function(?PersonPhone $pp = null): bool { + return NULL === $pp || $pp->isEmpty(); + }, + 'error_bubbling' => false + ] + ); if ('visible' === $this->config['email']) { $builder diff --git a/src/Bundle/ChillPersonBundle/Form/Type/PersonPhoneType.php b/src/Bundle/ChillPersonBundle/Form/Type/PersonPhoneType.php index 00243349f..7578bae1e 100644 --- a/src/Bundle/ChillPersonBundle/Form/Type/PersonPhoneType.php +++ b/src/Bundle/ChillPersonBundle/Form/Type/PersonPhoneType.php @@ -11,24 +11,24 @@ declare(strict_types=1); namespace Chill\PersonBundle\Form\Type; -use Chill\MainBundle\Phonenumber\PhonenumberHelper; +use Chill\FormTypesBundle\Service\PhoneNumberHelperInterface; use Chill\PersonBundle\Entity\PersonPhone; use Doctrine\ORM\EntityManagerInterface; +use libphonenumber\PhoneNumberFormat; 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\FormBuilderInterface; use Symfony\Component\Form\FormEvent; use Symfony\Component\Form\FormEvents; use Symfony\Component\OptionsResolver\OptionsResolver; -class PersonPhoneType extends AbstractType +final class PersonPhoneType extends AbstractType { + private PhoneNumberHelperInterface $phonenumberHelper; + private EntityManagerInterface $em; - private PhonenumberHelper $phonenumberHelper; - - public function __construct(PhonenumberHelper $phonenumberHelper, EntityManagerInterface $em) + public function __construct(PhoneNumberHelperInterface $phonenumberHelper, EntityManagerInterface $em) { $this->phonenumberHelper = $phonenumberHelper; $this->em = $em; @@ -36,10 +36,16 @@ class PersonPhoneType extends AbstractType public function buildForm(FormBuilderInterface $builder, array $options) { - $builder->add('phonenumber', TelType::class, [ - 'label' => 'Other phonenumber', - 'required' => true, - ]); + $builder + ->add( + 'phonenumber', + PhoneNumberType::class, + [ + 'label' => 'Other phonenumber', + 'required' => true, + 'format' => PhoneNumberFormat::NATIONAL, + ] + ); $builder->add('description', TextType::class, [ 'required' => false,