mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-26 16:45:01 +00:00
- Update unique constraint on `PersonIdentifier` to use `canonical` instead of `value`. - Refactor repository method `findByDefinitionAndValue` to `findByDefinitionAndCanonical`, updating logic accordingly. - Adjust validation logic in `UniqueIdentifierConstraintValidator` to align with the new canonical-based approach. - Modify related integration and unit tests to support the changes. - Inject `PersonIdentifierManagerInterface` into the repository to handle canonical value generation.
87 lines
2.3 KiB
PHP
87 lines
2.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/*
|
|
* Chill is a software for social workers
|
|
*
|
|
* For the full copyright and license information, please view
|
|
* the LICENSE file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Chill\PersonBundle\Entity\Identifier;
|
|
|
|
use Chill\PersonBundle\Entity\Person;
|
|
use Chill\PersonBundle\PersonIdentifier\Validator\UniqueIdentifierConstraint;
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
|
|
#[ORM\Entity]
|
|
#[ORM\Table(name: 'chill_person_identifier')]
|
|
#[ORM\UniqueConstraint(name: 'chill_person_identifier_unique', columns: ['definition_id', 'canonical'])]
|
|
#[UniqueIdentifierConstraint]
|
|
class PersonIdentifier
|
|
{
|
|
#[ORM\Id]
|
|
#[ORM\Column(name: 'id', type: \Doctrine\DBAL\Types\Types::INTEGER)]
|
|
#[ORM\GeneratedValue]
|
|
private ?int $id = null;
|
|
|
|
#[ORM\ManyToOne(targetEntity: Person::class)]
|
|
#[ORM\JoinColumn(name: 'person_id', referencedColumnName: 'id', nullable: false, onDelete: 'CASCADE')]
|
|
private ?Person $person = null;
|
|
|
|
#[ORM\Column(name: 'value', type: \Doctrine\DBAL\Types\Types::JSON, nullable: false, options: ['default' => '[]', 'jsonb' => true])]
|
|
private array $value = [];
|
|
|
|
#[ORM\Column(name: 'canonical', type: \Doctrine\DBAL\Types\Types::TEXT, nullable: false, options: ['default' => ''])]
|
|
private string $canonical = '';
|
|
|
|
public function __construct(
|
|
#[ORM\ManyToOne(targetEntity: PersonIdentifierDefinition::class)]
|
|
#[ORM\JoinColumn(name: 'definition_id', referencedColumnName: 'id', nullable: false, onDelete: 'RESTRICT')]
|
|
private PersonIdentifierDefinition $definition,
|
|
) {}
|
|
|
|
public function getId(): ?int
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
public function setPerson(?Person $person): self
|
|
{
|
|
$this->person = $person;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getPerson(): Person
|
|
{
|
|
return $this->person;
|
|
}
|
|
|
|
public function getValue(): array
|
|
{
|
|
return $this->value;
|
|
}
|
|
|
|
public function setValue(array $value): void
|
|
{
|
|
$this->value = $value;
|
|
}
|
|
|
|
public function getCanonical(): string
|
|
{
|
|
return $this->canonical;
|
|
}
|
|
|
|
public function setCanonical(string $canonical): void
|
|
{
|
|
$this->canonical = $canonical;
|
|
}
|
|
|
|
public function getDefinition(): PersonIdentifierDefinition
|
|
{
|
|
return $this->definition;
|
|
}
|
|
}
|