daa0cb1e28
Auto Tag Develop / tag (push) Successful in 9s
- Nouvelles entites ConstructeurCategorie (referentiel M2M) et ConstructeurTelephone (1-N) - Constructeur : retrait colonne phone, ajout collections telephones/categories, groupes de serialisation constructeur:read/write - Migration : cree les 3 tables, migre la colonne phone existante vers constructeur_telephone, drop phone - Commande app:import-fournisseurs (dry-run par defaut, --force) : non destructive, find-or-create par nom, ne touche jamais un ID existant, ajout-seulement pour telephones/categories - MAJ MCP tools / MachineStructureController / audit subscriber / tests - Frontend : page constructeurs avec telephones multiples + categories (tableau, filtre, formulaire), composable useConstructeurCategories, composant ConstructeurCategorieSelect Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
93 lines
3.1 KiB
PHP
93 lines
3.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Entity;
|
|
|
|
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
|
|
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
|
|
use ApiPlatform\Metadata\ApiFilter;
|
|
use ApiPlatform\Metadata\ApiResource;
|
|
use ApiPlatform\Metadata\Delete;
|
|
use ApiPlatform\Metadata\Get;
|
|
use ApiPlatform\Metadata\GetCollection;
|
|
use ApiPlatform\Metadata\Patch;
|
|
use ApiPlatform\Metadata\Post;
|
|
use ApiPlatform\Metadata\Put;
|
|
use App\Entity\Trait\CuidEntityTrait;
|
|
use App\Repository\ConstructeurCategorieRepository;
|
|
use DateTimeImmutable;
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
use Doctrine\Common\Collections\Collection;
|
|
use Doctrine\DBAL\Types\Types;
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
|
use Symfony\Component\Serializer\Attribute\Groups;
|
|
use Symfony\Component\Validator\Constraints as Assert;
|
|
|
|
#[UniqueEntity(fields: ['name'], message: 'Une catégorie de fournisseur avec ce nom existe déjà.')]
|
|
#[ORM\Entity(repositoryClass: ConstructeurCategorieRepository::class)]
|
|
#[ORM\Table(name: 'constructeur_categorie')]
|
|
#[ORM\HasLifecycleCallbacks]
|
|
#[ApiResource(
|
|
description: 'Catégories de fournisseurs (ex. organisme de formation, transporteur, agence d\'intérim). Référentiel partagé : une même catégorie peut être rattachée à plusieurs fournisseurs.',
|
|
operations: [
|
|
new Get(security: "is_granted('ROLE_VIEWER')"),
|
|
new GetCollection(security: "is_granted('ROLE_VIEWER')"),
|
|
new Post(security: "is_granted('ROLE_GESTIONNAIRE')"),
|
|
new Put(security: "is_granted('ROLE_GESTIONNAIRE')"),
|
|
new Patch(security: "is_granted('ROLE_GESTIONNAIRE')"),
|
|
new Delete(security: "is_granted('ROLE_GESTIONNAIRE')"),
|
|
],
|
|
paginationClientItemsPerPage: true,
|
|
paginationMaximumItemsPerPage: 1000,
|
|
order: ['name' => 'ASC']
|
|
)]
|
|
#[ApiFilter(SearchFilter::class, properties: ['name' => 'partial'])]
|
|
#[ApiFilter(OrderFilter::class, properties: ['name'])]
|
|
class ConstructeurCategorie
|
|
{
|
|
use CuidEntityTrait;
|
|
|
|
#[ORM\Id]
|
|
#[ORM\Column(type: Types::STRING, length: 36)]
|
|
#[Groups(['constructeur:read'])]
|
|
private ?string $id = null;
|
|
|
|
#[ORM\Column(type: Types::STRING, length: 255, unique: true)]
|
|
#[Assert\NotBlank(message: 'Le nom est obligatoire.')]
|
|
#[Groups(['constructeur:read'])]
|
|
private ?string $name = null;
|
|
|
|
#[ORM\Column(type: Types::DATETIME_IMMUTABLE, name: 'createdAt')]
|
|
private DateTimeImmutable $createdAt;
|
|
|
|
#[ORM\Column(type: Types::DATETIME_IMMUTABLE, name: 'updatedAt')]
|
|
private DateTimeImmutable $updatedAt;
|
|
|
|
/**
|
|
* @var Collection<int, Constructeur>
|
|
*/
|
|
#[ORM\ManyToMany(targetEntity: Constructeur::class, mappedBy: 'categories')]
|
|
private Collection $constructeurs;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->createdAt = new DateTimeImmutable();
|
|
$this->updatedAt = new DateTimeImmutable();
|
|
$this->constructeurs = new ArrayCollection();
|
|
}
|
|
|
|
public function getName(): ?string
|
|
{
|
|
return $this->name;
|
|
}
|
|
|
|
public function setName(string $name): static
|
|
{
|
|
$this->name = $name;
|
|
|
|
return $this;
|
|
}
|
|
}
|