src/Entity/ReciprocalRelationshipType.php line 50

  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM,
  4.     Doctrine\DBAL\Types\Types;
  5. use Symfony\Component\Serializer\Annotation\Groups,
  6.     Symfony\Component\Validator\Constraints as Assert;
  7. use ApiPlatform\Metadata\ApiResource,
  8.     ApiPlatform\Metadata\ApiProperty,
  9.     ApiPlatform\Metadata\Get,
  10.     ApiPlatform\Metadata\GetCollection,
  11.     ApiPlatform\Metadata\Post,
  12.     ApiPlatform\Metadata\Put,
  13.     ApiPlatform\Metadata\Delete,
  14.     ApiPlatform\Metadata\ApiFilter,
  15.     ApiPlatform\Doctrine\Orm\Filter\SearchFilter,
  16.     ApiPlatform\Doctrine\Orm\Filter\BooleanFilter,
  17.     ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
  18. use App\Entity\Trait\IdTrait,
  19.     App\Entity\Trait\UuidTrait,
  20.     App\Entity\Trait\OrdStatTrait,
  21.     App\Entity\Trait\TimestampableTrait,
  22.     App\Entity\Interface\OrdStatableInterface,
  23.     App\Repository\ReciprocalRelationshipTypeRepository;
  24. use App\Enum\RelationshipType;
  25. #[ApiResource(
  26.     description'Reciprocal relationship types',
  27.     normalizationContext: ['groups' => ['read''read:' self::class]],
  28.     denormalizationContext: ['groups' => ['write']],
  29.     security'is_granted("' self::class . '")',
  30.     order: ['ord' => 'desc'],
  31.     operations: [
  32.         new GetCollection(),
  33.         new Post(),
  34.         new Get(),
  35.         new Put(),
  36.         new Delete(),
  37.     ],
  38.     extraProperties: ['standard_put' => false],
  39. )]
  40. #[ApiFilter(SearchFilter::class, properties: ['title' => 'partial'])]
  41. #[ApiFilter(BooleanFilter::class, properties: ['stat'])]
  42. #[ApiFilter(OrderFilter::class, properties: ['ord'])]
  43. #[ORM\Entity(repositoryClassReciprocalRelationshipTypeRepository::class)]
  44. class ReciprocalRelationshipType implements OrdStatableInterface
  45. {
  46.     use IdTrait,
  47.         UuidTrait,
  48.         OrdStatTrait,
  49.         TimestampableTrait;
  50.     #[ApiProperty(description'Title')]
  51.     #[Groups(['read''write'])]
  52.     #[Assert\NotBlank]
  53.     #[ORM\Column(typeTypes::STRINGlength255uniquetrue)]
  54.     private string $title;
  55.     #[ApiProperty(description'Description')]
  56.     #[Groups(['read:' self::class, 'write'])]
  57.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  58.     private ?string $description null;
  59.     #[ApiProperty(description'Type')]
  60.     #[Groups(['read:' self::class, 'write'])]
  61.     #[ORM\Column(
  62.         typeTypes::STRING,
  63.         enumTypeRelationshipType::class,
  64.         length255,
  65.         options: ['default' => RelationshipType::INTRA_WORK]
  66.     )]
  67.     private RelationshipType $type RelationshipType::INTRA_WORK;
  68.     public function __construct(string $title, ?string $descriptionRelationshipType $type)
  69.     {
  70.         $this->setUuid();
  71.         $this->title $title;
  72.         $this->description $description;
  73.         $this->type $type;
  74.         $this->createdAt = new \DateTimeImmutable();
  75.         $this->updatedAt = new \DateTimeImmutable();
  76.     }
  77.     public function getTitle(): string
  78.     {
  79.         return $this->title;
  80.     }
  81.     public function setTitle(string $title): self
  82.     {
  83.         $this->title $title;
  84.         return $this;
  85.     }
  86.     public function getDescription(): ?string
  87.     {
  88.         return $this->description;
  89.     }
  90.     public function setDescription(?string $description): self
  91.     {
  92.         $this->description $description;
  93.         return $this;
  94.     }
  95.     public function getType(): RelationshipType
  96.     {
  97.         return $this->type;
  98.     }
  99.     public function setType(RelationshipType $type): self
  100.     {
  101.         $this->type $type;
  102.         return $this;
  103.     }
  104. }