mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 13:54: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' ]);
|
||||
}
|
||||
|
||||
public function type(string $phonenumber): string
|
||||
{
|
||||
return $this->performTwilioLookup($phonenumber);
|
||||
}
|
||||
|
||||
public function format($phonenumber)
|
||||
{
|
||||
return $this->performTwilioFormat($phonenumber);
|
||||
|
@ -14,118 +14,95 @@ use Doctrine\ORM\Mapping as ORM;
|
||||
class PersonPhone
|
||||
{
|
||||
/**
|
||||
* @var integer
|
||||
*
|
||||
* @ORM\Id
|
||||
* @ORM\Column(name="id", type="integer")
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
private ?int $id;
|
||||
|
||||
/**
|
||||
* @var Person
|
||||
*
|
||||
* @ORM\ManyToOne(
|
||||
* targetEntity="Chill\PersonBundle\Entity\Person",
|
||||
* 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)
|
||||
*/
|
||||
private $phonenumber = '';
|
||||
private string $phonenumber = '';
|
||||
|
||||
/**
|
||||
* The description
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(type="text", nullable=true)
|
||||
*/
|
||||
private $description = '';
|
||||
private ?string $description = null;
|
||||
|
||||
/**
|
||||
* @var \DateTime
|
||||
* @ORM\Column(type="datetime", nullable=false)
|
||||
*/
|
||||
private $date;
|
||||
private \DateTime $date;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->date = new \DateTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getId(): int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Chill\PersonBundle\Entity\Person
|
||||
*/
|
||||
public function getPerson(): Person
|
||||
{
|
||||
return $this->person;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Chill\PersonBundle\Entity\Person $person
|
||||
*/
|
||||
public function setPerson(Person $person): void
|
||||
{
|
||||
$this->person = $person;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getType(): string
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
public function setType(string $type): void
|
||||
{
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
public function getPhonenumber(): string
|
||||
{
|
||||
return $this->phonenumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $phonenumber
|
||||
*/
|
||||
public function setPhonenumber(string $phonenumber): void
|
||||
{
|
||||
$this->phonenumber = $phonenumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription(): string
|
||||
public function getDescription(): ?string
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $description
|
||||
*/
|
||||
public function setDescription(string $description): void
|
||||
public function setDescription(?string $description): void
|
||||
{
|
||||
$this->description = $description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getDate(): \DateTime
|
||||
{
|
||||
return $this->date;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \DateTime $date
|
||||
*/
|
||||
public function setDate(\DateTime $date): void
|
||||
{
|
||||
$this->date = $date;
|
||||
|
@ -2,17 +2,27 @@
|
||||
|
||||
namespace Chill\PersonBundle\Form\Type;
|
||||
|
||||
use Chill\MainBundle\Phonenumber\PhonenumberHelper;
|
||||
use Chill\PersonBundle\Entity\PersonPhone;
|
||||
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\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class PersonPhoneType extends AbstractType
|
||||
{
|
||||
private PhonenumberHelper $phonenumberHelper;
|
||||
|
||||
public function __construct(PhonenumberHelper $phonenumberHelper)
|
||||
{
|
||||
$this->phonenumberHelper = $phonenumberHelper;
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder->add('phonenumber', TelType::class, [
|
||||
@ -23,17 +33,15 @@ class PersonPhoneType extends AbstractType
|
||||
$builder->add('description', TextType::class, [
|
||||
'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)
|
||||
{
|
||||
/*
|
||||
$resolver
|
||||
->setDefault('data_class', PersonPhone::class)
|
||||
->setDefault('validation_groups', ['general', 'creation'])
|
||||
;
|
||||
*/
|
||||
|
||||
$resolver
|
||||
->setDefaults([
|
||||
'data_class' => PersonPhone::class,
|
||||
|
@ -46,3 +46,9 @@ services:
|
||||
$translatableStringHelper: '@chill.main.helper.translatable_string'
|
||||
tags:
|
||||
- { 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