Files
Ferme/src/Entity/BovineType.php
tristan 50dd660713 feat(bovine-type) : piloter l'affichage en réception via un champ display [#FER-30]
Ajoute un champ display (défaut false) sur BovineType : seuls les types
activés par un admin apparaissent à la sélection des races en réception.
Les types créés par la synchro inventaire restent masqués par défaut.

- Affichage des races en grille 4 colonnes (création réception)
- Édition réception : conserve les types déjà saisis même masqués
- Admin : badge "Affiché en réception" + checkbox dans le formulaire

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-21 11:33:17 +02:00

113 lines
3.0 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Entity;
use ApiPlatform\Doctrine\Orm\Filter\BooleanFilter;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Post;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Attribute\Groups;
#[ORM\Entity]
#[ApiFilter(SearchFilter::class, properties: [
'label' => 'ipartial',
'code' => 'ipartial',
])]
#[ApiFilter(BooleanFilter::class, properties: ['display'])]
#[ApiResource(
operations: [
new Get(
requirements: ['id' => '\d+'],
normalizationContext: ['groups' => ['bovine-type:read']],
),
new GetCollection(
normalizationContext: ['groups' => ['bovine-type:read']],
),
new Post(
normalizationContext: ['groups' => ['bovine-type:read']],
denormalizationContext: ['groups' => ['bovine-type:write']],
security: "is_granted('ROLE_ADMIN')",
),
new Patch(
requirements: ['id' => '\d+'],
normalizationContext: ['groups' => ['bovine-type:read']],
denormalizationContext: ['groups' => ['bovine-type:write']],
security: "is_granted('ROLE_ADMIN')",
),
],
security: "is_granted('ROLE_USER')",
)]
class BovineType
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
#[Groups(['bovine-type:read', 'reception:read', 'reception-bovine:read'])]
private ?int $id = null;
#[ORM\Column(length: 120)]
#[Groups(['bovine-type:read', 'bovine-type:write', 'reception:read', 'reception-bovine:read', 'bovine:read', 'building_case:read'])]
private ?string $label = null;
#[ORM\Column(length: 50)]
#[Groups(['bovine-type:read', 'bovine-type:write', 'reception:read', 'reception-bovine:read', 'bovine:read', 'building_case:read'])]
private ?string $code = null;
/**
* Détermine si le type bovin est proposé à la sélection lors d'une réception.
* Les types créés automatiquement par la synchro inventaire arrivent à false ;
* seul un admin peut les activer.
*/
#[ORM\Column(options: ['default' => false])]
#[Groups(['bovine-type:read', 'bovine-type:write'])]
private bool $display = false;
public function getId(): ?int
{
return $this->id;
}
public function getLabel(): ?string
{
return $this->label;
}
public function setLabel(string $label): static
{
$this->label = $label;
return $this;
}
public function getCode(): ?string
{
return $this->code;
}
public function setCode(string $code): static
{
$this->code = $code;
return $this;
}
public function isDisplay(): bool
{
return $this->display;
}
public function setDisplay(bool $display): static
{
$this->display = $display;
return $this;
}
}