mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-19 13:15:00 +00:00
Refactor PersonIdentifierDefinition
: Replace fully qualified \Doctrine\DBAL\Types\Types
references with simplified Types
aliases.
This commit is contained in:
@@ -19,7 +19,6 @@ use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Entity\Address;
|
||||
use libphonenumber\PhoneNumber;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
use Chill\MainBundle\Validation\Constraint\PhonenumberConstraint;
|
||||
|
||||
/**
|
||||
* Immersion.
|
||||
|
@@ -22,7 +22,7 @@ class DateNormalizer implements ContextAwareNormalizerInterface, DenormalizerInt
|
||||
{
|
||||
public function __construct(private readonly RequestStack $requestStack, private readonly ParameterBagInterface $parameterBag) {}
|
||||
|
||||
public function denormalize($data, $type, $format = null, array $context = []): ?DateTimeInterface
|
||||
public function denormalize($data, $type, $format = null, array $context = []): ?\DateTimeInterface
|
||||
{
|
||||
if (null === $data) {
|
||||
return null;
|
||||
|
@@ -0,0 +1,42 @@
|
||||
<?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;
|
||||
|
||||
enum IdentifierPresenceEnum: string
|
||||
{
|
||||
/**
|
||||
* The person identifier is not editable by any user.
|
||||
*
|
||||
* The identifier is intended to be added by an import script, for instance.
|
||||
*/
|
||||
case NOT_EDITABLE = 'NOT_EDITABLE';
|
||||
|
||||
/**
|
||||
* The person identifier is present on the edit form only.
|
||||
*/
|
||||
case ON_EDIT = 'ON_EDIT';
|
||||
|
||||
/**
|
||||
* The person identifier is present on both person's creation form, and edit form.
|
||||
*/
|
||||
case ON_CREATION = 'ON_CREATION';
|
||||
|
||||
/**
|
||||
* The person identifier is required to create the person. It should not be empty.
|
||||
*/
|
||||
case REQUIRED = 'REQUIRED';
|
||||
|
||||
public function isEditableByUser(): bool
|
||||
{
|
||||
return IdentifierPresenceEnum::NOT_EDITABLE !== $this;
|
||||
}
|
||||
}
|
@@ -30,7 +30,7 @@ class PersonIdentifier
|
||||
#[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' => '[]'])]
|
||||
#[ORM\Column(name: 'canonical', type: \Doctrine\DBAL\Types\Types::TEXT, nullable: false, options: ['default' => ''])]
|
||||
private string $canonical = '';
|
||||
|
||||
public function __construct(
|
||||
|
@@ -11,6 +11,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\PersonBundle\Entity\Identifier;
|
||||
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity]
|
||||
@@ -18,23 +19,23 @@ use Doctrine\ORM\Mapping as ORM;
|
||||
class PersonIdentifierDefinition
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\Column(name: 'id', type: \Doctrine\DBAL\Types\Types::INTEGER)]
|
||||
#[ORM\Column(name: 'id', type: Types::INTEGER)]
|
||||
#[ORM\GeneratedValue]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column(name: 'active', type: \Doctrine\DBAL\Types\Types::BOOLEAN, nullable: false, options: ['default' => true])]
|
||||
#[ORM\Column(name: 'active', type: Types::BOOLEAN, nullable: false, options: ['default' => true])]
|
||||
private bool $active = true;
|
||||
|
||||
public function __construct(
|
||||
#[ORM\Column(name: 'label', type: \Doctrine\DBAL\Types\Types::JSON, nullable: false, options: ['default' => '[]'])]
|
||||
#[ORM\Column(name: 'label', type: Types::JSON, nullable: false, options: ['default' => '[]'])]
|
||||
private array $label,
|
||||
#[ORM\Column(name: 'engine', type: \Doctrine\DBAL\Types\Types::STRING, length: 100)]
|
||||
#[ORM\Column(name: 'engine', type: Types::STRING, length: 100)]
|
||||
private string $engine,
|
||||
#[ORM\Column(name: 'is_searchable', type: \Doctrine\DBAL\Types\Types::BOOLEAN, options: ['default' => false])]
|
||||
#[ORM\Column(name: 'is_searchable', type: Types::BOOLEAN, options: ['default' => false])]
|
||||
private bool $isSearchable = false,
|
||||
#[ORM\Column(name: 'is_editable_by_users', type: \Doctrine\DBAL\Types\Types::BOOLEAN, nullable: false, options: ['default' => false])]
|
||||
private bool $isEditableByUsers = false,
|
||||
#[ORM\Column(name: 'data', type: \Doctrine\DBAL\Types\Types::JSON, nullable: false, options: ['default' => '[]', 'jsonb' => true])]
|
||||
#[ORM\Column(name: 'presence', type: Types::STRING, nullable: false, enumType: IdentifierPresenceEnum::class, options: ['default' => IdentifierPresenceEnum::ON_EDIT])]
|
||||
private IdentifierPresenceEnum $presence = IdentifierPresenceEnum::ON_EDIT,
|
||||
#[ORM\Column(name: 'data', type: Types::JSON, nullable: false, options: ['default' => '[]', 'jsonb' => true])]
|
||||
private array $data = [],
|
||||
) {}
|
||||
|
||||
@@ -58,11 +59,6 @@ class PersonIdentifierDefinition
|
||||
return $this->engine;
|
||||
}
|
||||
|
||||
public function setEngine(string $engine): void
|
||||
{
|
||||
$this->engine = $engine;
|
||||
}
|
||||
|
||||
public function isSearchable(): bool
|
||||
{
|
||||
return $this->isSearchable;
|
||||
@@ -75,12 +71,7 @@ class PersonIdentifierDefinition
|
||||
|
||||
public function isEditableByUsers(): bool
|
||||
{
|
||||
return $this->isEditableByUsers;
|
||||
}
|
||||
|
||||
public function setIsEditableByUsers(bool $isEditableByUsers): void
|
||||
{
|
||||
$this->isEditableByUsers = $isEditableByUsers;
|
||||
return $this->presence->isEditableByUser();
|
||||
}
|
||||
|
||||
public function isActive(): bool
|
||||
@@ -104,4 +95,16 @@ class PersonIdentifierDefinition
|
||||
{
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
public function getPresence(): IdentifierPresenceEnum
|
||||
{
|
||||
return $this->presence;
|
||||
}
|
||||
|
||||
public function setPresence(IdentifierPresenceEnum $presence): self
|
||||
{
|
||||
$this->presence = $presence;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@@ -117,6 +117,10 @@ final class PersonJsonDenormalizer implements DenormalizerInterface, Denormalize
|
||||
|
||||
$worker = $this->personIdentifierManager->buildWorkerByPersonIdentifierDefinition($definitionId);
|
||||
|
||||
if (!$worker->getDefinition()->isEditableByUsers()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$personIdentifier = $person->getIdentifiers()->findFirst(fn (int $key, PersonIdentifier $personIdentifier) => $personIdentifier->getId() === $definitionId);
|
||||
if (null === $personIdentifier) {
|
||||
$personIdentifier = new PersonIdentifier($worker->getDefinition());
|
||||
|
@@ -0,0 +1,37 @@
|
||||
<?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\Migrations\Person;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
final class Version20250918095044 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Add more details about presence in PersonIdentifier';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$this->addSql('ALTER TABLE chill_person_identifier_definition ADD presence VARCHAR(255) DEFAULT \'ON_EDIT\' NOT NULL');
|
||||
$this->addSql('UPDATE chill_person_identifier_definition SET presence = \'NOT_EDITABLE\' WHERE is_editable_by_users IS FALSE');
|
||||
$this->addSql('ALTER TABLE chill_person_identifier_definition DROP is_editable_by_users');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->addSql('ALTER TABLE chill_person_identifier_definition ADD is_editable_by_users BOOLEAN DEFAULT false NOT NULL');
|
||||
$this->addSql('UPDATE chill_person_identifier_definition SET is_editable_by_users = true WHERE presence <> \'NOT_EDITABLE\' ');
|
||||
$this->addSql('ALTER TABLE chill_person_identifier_definition DROP presence');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user