mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-14 06:14:23 +00:00
Add other phone number
This commit is contained in:
parent
50d686f086
commit
756ed616b6
@ -141,6 +141,11 @@ class PhonenumberHelper
|
|||||||
return \in_array($validation, [ 'landline', 'voip', 'mobile' ]);
|
return \in_array($validation, [ 'landline', 'voip', 'mobile' ]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function type(string $phonenumber): string
|
||||||
|
{
|
||||||
|
return $this->performTwilioLookup($phonenumber);
|
||||||
|
}
|
||||||
|
|
||||||
public function format($phonenumber)
|
public function format($phonenumber)
|
||||||
{
|
{
|
||||||
return $this->performTwilioFormat($phonenumber);
|
return $this->performTwilioFormat($phonenumber);
|
||||||
|
@ -14,118 +14,95 @@ use Doctrine\ORM\Mapping as ORM;
|
|||||||
class PersonPhone
|
class PersonPhone
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var integer
|
|
||||||
*
|
|
||||||
* @ORM\Id
|
* @ORM\Id
|
||||||
* @ORM\Column(name="id", type="integer")
|
* @ORM\Column(name="id", type="integer")
|
||||||
* @ORM\GeneratedValue(strategy="AUTO")
|
* @ORM\GeneratedValue(strategy="AUTO")
|
||||||
*/
|
*/
|
||||||
private $id;
|
private ?int $id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Person
|
|
||||||
*
|
|
||||||
* @ORM\ManyToOne(
|
* @ORM\ManyToOne(
|
||||||
* targetEntity="Chill\PersonBundle\Entity\Person",
|
* targetEntity="Chill\PersonBundle\Entity\Person",
|
||||||
* inversedBy="otherPhoneNumbers"
|
* inversedBy="otherPhoneNumbers"
|
||||||
* )
|
* )
|
||||||
*/
|
*/
|
||||||
private $person;
|
private Person $person;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="text", length=40, nullable=true)
|
||||||
|
*/
|
||||||
|
private ?string $type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The phonenumber
|
|
||||||
* @var string
|
|
||||||
*
|
|
||||||
* @ORM\Column(type="text", length=40, nullable=false)
|
* @ORM\Column(type="text", length=40, nullable=false)
|
||||||
*/
|
*/
|
||||||
private $phonenumber = '';
|
private string $phonenumber = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The description
|
|
||||||
* @var string
|
|
||||||
*
|
|
||||||
* @ORM\Column(type="text", nullable=true)
|
* @ORM\Column(type="text", nullable=true)
|
||||||
*/
|
*/
|
||||||
private $description = '';
|
private ?string $description = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \DateTime
|
|
||||||
* @ORM\Column(type="datetime", nullable=false)
|
* @ORM\Column(type="datetime", nullable=false)
|
||||||
*/
|
*/
|
||||||
private $date;
|
private \DateTime $date;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->date = new \DateTime();
|
$this->date = new \DateTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function getId(): int
|
public function getId(): int
|
||||||
{
|
{
|
||||||
return $this->id;
|
return $this->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return \Chill\PersonBundle\Entity\Person
|
|
||||||
*/
|
|
||||||
public function getPerson(): Person
|
public function getPerson(): Person
|
||||||
{
|
{
|
||||||
return $this->person;
|
return $this->person;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param \Chill\PersonBundle\Entity\Person $person
|
|
||||||
*/
|
|
||||||
public function setPerson(Person $person): void
|
public function setPerson(Person $person): void
|
||||||
{
|
{
|
||||||
$this->person = $person;
|
$this->person = $person;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getType(): string
|
||||||
* @return string
|
{
|
||||||
*/
|
return $this->type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setType(string $type): void
|
||||||
|
{
|
||||||
|
$this->type = $type;
|
||||||
|
}
|
||||||
|
|
||||||
public function getPhonenumber(): string
|
public function getPhonenumber(): string
|
||||||
{
|
{
|
||||||
return $this->phonenumber;
|
return $this->phonenumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $phonenumber
|
|
||||||
*/
|
|
||||||
public function setPhonenumber(string $phonenumber): void
|
public function setPhonenumber(string $phonenumber): void
|
||||||
{
|
{
|
||||||
$this->phonenumber = $phonenumber;
|
$this->phonenumber = $phonenumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getDescription(): ?string
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getDescription(): string
|
|
||||||
{
|
{
|
||||||
return $this->description;
|
return $this->description;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function setDescription(?string $description): void
|
||||||
* @param string $description
|
|
||||||
*/
|
|
||||||
public function setDescription(string $description): void
|
|
||||||
{
|
{
|
||||||
$this->description = $description;
|
$this->description = $description;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return \DateTime
|
|
||||||
*/
|
|
||||||
public function getDate(): \DateTime
|
public function getDate(): \DateTime
|
||||||
{
|
{
|
||||||
return $this->date;
|
return $this->date;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param \DateTime $date
|
|
||||||
*/
|
|
||||||
public function setDate(\DateTime $date): void
|
public function setDate(\DateTime $date): void
|
||||||
{
|
{
|
||||||
$this->date = $date;
|
$this->date = $date;
|
||||||
|
@ -2,17 +2,27 @@
|
|||||||
|
|
||||||
namespace Chill\PersonBundle\Form\Type;
|
namespace Chill\PersonBundle\Form\Type;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Phonenumber\PhonenumberHelper;
|
||||||
use Chill\PersonBundle\Entity\PersonPhone;
|
use Chill\PersonBundle\Entity\PersonPhone;
|
||||||
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\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\FormEvents;
|
||||||
use Symfony\Component\Form\FormInterface;
|
use Symfony\Component\Form\FormInterface;
|
||||||
use Symfony\Component\Form\FormView;
|
use Symfony\Component\Form\FormView;
|
||||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
|
|
||||||
class PersonPhoneType extends AbstractType
|
class PersonPhoneType extends AbstractType
|
||||||
{
|
{
|
||||||
|
private PhonenumberHelper $phonenumberHelper;
|
||||||
|
|
||||||
|
public function __construct(PhonenumberHelper $phonenumberHelper)
|
||||||
|
{
|
||||||
|
$this->phonenumberHelper = $phonenumberHelper;
|
||||||
|
}
|
||||||
|
|
||||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||||
{
|
{
|
||||||
$builder->add('phonenumber', TelType::class, [
|
$builder->add('phonenumber', TelType::class, [
|
||||||
@ -23,17 +33,15 @@ class PersonPhoneType extends AbstractType
|
|||||||
$builder->add('description', TextType::class, [
|
$builder->add('description', TextType::class, [
|
||||||
'required' => false,
|
'required' => false,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$builder->addEventListener(FormEvents::POST_SUBMIT, function(FormEvent $event) {
|
||||||
|
$type = $this->phonenumberHelper->type($event->getData()->getPhonenumber());
|
||||||
|
$event->getData()->setType($type);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function configureOptions(OptionsResolver $resolver)
|
public function configureOptions(OptionsResolver $resolver)
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
$resolver
|
|
||||||
->setDefault('data_class', PersonPhone::class)
|
|
||||||
->setDefault('validation_groups', ['general', 'creation'])
|
|
||||||
;
|
|
||||||
*/
|
|
||||||
|
|
||||||
$resolver
|
$resolver
|
||||||
->setDefaults([
|
->setDefaults([
|
||||||
'data_class' => PersonPhone::class,
|
'data_class' => PersonPhone::class,
|
||||||
|
@ -46,3 +46,9 @@ services:
|
|||||||
$translatableStringHelper: '@chill.main.helper.translatable_string'
|
$translatableStringHelper: '@chill.main.helper.translatable_string'
|
||||||
tags:
|
tags:
|
||||||
- { name: form.type }
|
- { name: form.type }
|
||||||
|
|
||||||
|
Chill\PersonBundle\Form\Type\PersonPhoneType:
|
||||||
|
arguments:
|
||||||
|
$phonenumberHelper: '@Chill\MainBundle\Phonenumber\PhonenumberHelper'
|
||||||
|
tags:
|
||||||
|
- { name: form.type }
|
||||||
|
@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Chill\Migrations\Person;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
use Doctrine\Migrations\AbstractMigration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auto-generated Migration: Please modify to your needs!
|
||||||
|
*/
|
||||||
|
final class Version20210325141540 extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function getDescription() : string
|
||||||
|
{
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function up(Schema $schema) : void
|
||||||
|
{
|
||||||
|
// this up() migration is auto-generated, please modify it to your needs
|
||||||
|
$this->addSql('ALTER TABLE chill_person_phone ADD type TEXT DEFAULT NULL');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(Schema $schema) : void
|
||||||
|
{
|
||||||
|
// this down() migration is auto-generated, please modify it to your need
|
||||||
|
$this->addSql('ALTER TABLE chill_person_phone DROP type');
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user