diff --git a/src/Bundle/ChillThirdPartyBundle/Entity/ThirdParty.php b/src/Bundle/ChillThirdPartyBundle/Entity/ThirdParty.php index 288715a8b..7a3c59668 100644 --- a/src/Bundle/ChillThirdPartyBundle/Entity/ThirdParty.php +++ b/src/Bundle/ChillThirdPartyBundle/Entity/ThirdParty.php @@ -164,6 +164,12 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface */ private ?string $email = null; + /** + * @var bool + * @ORM\Column(name="contact_data_anonymous", type="boolean", options={"default":false}) + */ + private bool $contactDataAnonymous = false; + /** * @var Address|null * @ORM\ManyToOne(targetEntity="\Chill\MainBundle\Entity\Address", @@ -471,9 +477,9 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface * @param string $nameCompany * @return ThirdParty */ - public function setNameCompany(string $nameCompany): ThirdParty + public function setNameCompany(?string $nameCompany): ThirdParty { - $this->nameCompany = $nameCompany; + $this->nameCompany = (string) $nameCompany; return $this; } @@ -607,18 +613,18 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface } /** - * @return ThirdPartyCivility|null + * @return Civility|null */ - public function getCivility(): ?ThirdPartyCivility + public function getCivility(): ?Civility { return $this->civility; } /** - * @param ThirdPartyCivility $civility + * @param Civility $civility * @return $this */ - public function setCivility(ThirdPartyCivility $civility): ThirdParty + public function setCivility(Civility $civility): ThirdParty { $this->civility = $civility; return $this; diff --git a/src/Bundle/ChillThirdPartyBundle/Form/ThirdPartyType.php b/src/Bundle/ChillThirdPartyBundle/Form/ThirdPartyType.php index 5523dad6b..a0527a07e 100644 --- a/src/Bundle/ChillThirdPartyBundle/Form/ThirdPartyType.php +++ b/src/Bundle/ChillThirdPartyBundle/Form/ThirdPartyType.php @@ -3,13 +3,13 @@ namespace Chill\ThirdPartyBundle\Form; use Chill\MainBundle\Entity\Address; +use Chill\MainBundle\Entity\Civility; use Chill\MainBundle\Form\Type\ChillCollectionType; use Chill\MainBundle\Form\Type\PickCenterType; use Chill\MainBundle\Form\Type\ChillTextareaType; use Chill\MainBundle\Templating\TranslatableStringHelper; use Chill\ThirdPartyBundle\Entity\ThirdParty; use Chill\ThirdPartyBundle\Entity\ThirdPartyCategory; -use Chill\ThirdPartyBundle\Entity\ThirdPartyCivility; use Chill\ThirdPartyBundle\Entity\ThirdPartyProfession; use Doctrine\ORM\EntityRepository; use Doctrine\ORM\QueryBuilder; @@ -114,8 +114,8 @@ class ThirdPartyType extends AbstractType $builder ->add('civility', EntityType::class, [ 'label' => 'thirdparty.Civility', - 'class' => ThirdPartyCivility::class, - 'choice_label' => function (ThirdPartyCivility $civility): string { + 'class' => Civility::class, + 'choice_label' => function (Civility $civility): string { return $this->translatableStringHelper->localize($civility->getName()); }, 'query_builder' => function (EntityRepository $er): QueryBuilder { diff --git a/src/Bundle/ChillThirdPartyBundle/migrations/Version20211007165001.php b/src/Bundle/ChillThirdPartyBundle/migrations/Version20211007165001.php new file mode 100644 index 000000000..a577b4ff0 --- /dev/null +++ b/src/Bundle/ChillThirdPartyBundle/migrations/Version20211007165001.php @@ -0,0 +1,87 @@ +addSql(" + UPDATE chill_3party.third_party + SET canonicalized = + COALESCE( + UNACCENT( + LOWER( + name || + CASE WHEN name <> '' THEN ' ' ELSE '' END || + name_company || + CASE WHEN name_company <> '' THEN ' ' ELSE '' END || + acronym || + CASE WHEN acronym <> '' THEN ' ' ELSE '' END + ) + ), + '' + ) + "); + $this->addSql(" + CREATE OR REPLACE FUNCTION chill_3party.canonicalize() RETURNS TRIGGER + LANGUAGE plpgsql + AS + $$ + BEGIN + NEW.canonicalized = UNACCENT(LOWER( + NEW.name || + CASE WHEN NEW.name <> '' THEN ' ' ELSE '' END || + NEW.name_company || + CASE WHEN NEW.name_company <> '' THEN ' ' ELSE '' END || + NEW.acronym || + CASE WHEN NEW.acronym <> '' THEN ' ' ELSE '' END + )); + + return NEW; + END + $$ + "); + $this->addSql(" + CREATE TRIGGER canonicalize_fullname_on_insert + BEFORE INSERT + ON chill_3party.third_party + FOR EACH ROW + EXECUTE procedure chill_3party.canonicalize(); + "); + $this->addSql(" + CREATE TRIGGER canonicalize_fullname_on_update + BEFORE UPDATE + ON chill_3party.third_party + FOR EACH ROW + EXECUTE procedure chill_3party.canonicalize(); + "); + $this->addSql(" + CREATE INDEX chill_custom_canonicalized_trgm_idx_gist + ON chill_3party.third_party USING GIST (canonicalized gist_trgm_ops) + "); + } + + public function down(Schema $schema): void + { + $this->addSql('DROP TRIGGER canonicalize_fullname_on_update ON chill_3party.third_party'); + $this->addSql('DROP TRIGGER canonicalize_fullname_on_insert ON chill_3party.third_party'); + $this->addSql('DROP FUNCTION chill_3party.canonicalize()'); + $this->addSql(" + DROP INDEX chill_3party.chill_custom_canonicalized_trgm_idx_gist + "); + } +} diff --git a/src/Bundle/ChillThirdPartyBundle/migrations/Version20211007194942.php b/src/Bundle/ChillThirdPartyBundle/migrations/Version20211007194942.php new file mode 100644 index 000000000..7a6f5fb76 --- /dev/null +++ b/src/Bundle/ChillThirdPartyBundle/migrations/Version20211007194942.php @@ -0,0 +1,29 @@ +addSql('ALTER TABLE chill_3party.third_party ADD contact_data_anonymous BOOLEAN DEFAULT \'false\' NOT NULL;'); + } + + public function down(Schema $schema): void + { + $this->addSql('ALTER TABLE chill_3party.third_party DROP contact_data_anonymous'); + } +}