src/Entity/ContactSubject.php line 58

  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM,
  4.     Doctrine\DBAL\Types\Types,
  5.     Doctrine\Common\Collections\ArrayCollection;
  6. use Symfony\Component\Serializer\Annotation\Groups,
  7.     Symfony\Component\Validator\Constraints as Assert;
  8. use ApiPlatform\Metadata\ApiResource,
  9.     ApiPlatform\Metadata\ApiProperty,
  10.     ApiPlatform\Metadata\Get,
  11.     ApiPlatform\Metadata\GetCollection,
  12.     ApiPlatform\Metadata\Post,
  13.     ApiPlatform\Metadata\Put,
  14.     ApiPlatform\Metadata\Delete,
  15.     ApiPlatform\Metadata\ApiFilter,
  16.     ApiPlatform\Doctrine\Orm\Filter\SearchFilter,
  17.     ApiPlatform\Doctrine\Orm\Filter\BooleanFilter,
  18.     ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
  19. use App\Entity\Trait\IdTrait,
  20.     App\Entity\Trait\UuidTrait,
  21.     App\Entity\Trait\OrdStatTrait,
  22.     App\Entity\Trait\TimestampableTrait,
  23.     App\Entity\Trait\TranslatableTrait,
  24.     App\Entity\Trait\Languages\SiteLanguagesTrait,
  25.     App\Entity\Interface\TranslatableInterface,
  26.     App\Entity\Interface\OrdStatableInterface,
  27.     App\Entity\Interface\LanguageableInterface,
  28.     App\Repository\ContactSubjectRepository,
  29.     App\Enum\Language;
  30. #[ApiResource(
  31.     description'Contact subjects',
  32.     normalizationContext: ['groups' => [
  33.         'read',
  34.         'read:' self::class,
  35.         'read:' self::class . 'Translation'
  36.     ]],
  37.     denormalizationContext: ['groups' => ['write']],
  38.     security'is_granted("' self::class . '")',
  39.     order: ['ord' => 'desc'],
  40.     operations: [
  41.         new GetCollection(),
  42.         new Post(),
  43.         new Get(),
  44.         new Put(),
  45.         new Delete(),
  46.     ],
  47.     extraProperties: ['standard_put' => false],
  48. )]
  49. #[ApiFilter(SearchFilter::class, properties: ['translations.title' => 'partial''nativeTitle' => 'partial'])]
  50. #[ApiFilter(BooleanFilter::class, properties: ['stat'])]
  51. #[ApiFilter(OrderFilter::class, properties: ['nativeTitle''ord'])]
  52. #[ORM\Entity(repositoryClassContactSubjectRepository::class)]
  53. class ContactSubject implements TranslatableInterfaceOrdStatableInterfaceLanguageableInterface
  54. {
  55.     use IdTrait,
  56.         UuidTrait,
  57.         OrdStatTrait,
  58.         TimestampableTrait,
  59.         TranslatableTrait,
  60.         SiteLanguagesTrait;
  61.     #[ApiProperty(description'E-mail')]
  62.     #[Groups(['read:' self::class, 'write'])]
  63.     #[Assert\NotBlank]
  64.     #[Assert\Email]
  65.     #[ORM\Column(typeTypes::STRINGlength255)]
  66.     private string $email;
  67.     public function __construct(?array $languages)
  68.     {
  69.         $this->setUuid();
  70.         $this->translations = new ArrayCollection();
  71.         $this->setLanguages($languages ?? Language::DEFAULT_SITE);
  72.         $this->createdAt = new \DateTimeImmutable();
  73.         $this->updatedAt = new \DateTimeImmutable();
  74.     }
  75.     public function getEmail(): string
  76.     {
  77.         return $this->email;
  78.     }
  79.     public function setEmail(string $email): self
  80.     {
  81.         $this->email $email;
  82.         return $this;
  83.     }
  84. }