src/Containers/OscpvSection/ListContainer/Entities/PrivilegeEntity.php line 80

Open in your IDE?
  1. <?php
  2. namespace App\Containers\OscpvSection\ListContainer\Entities;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use ApiPlatform\Metadata\Delete;
  5. use ApiPlatform\Metadata\Get;
  6. use ApiPlatform\Metadata\GetCollection;
  7. use ApiPlatform\Metadata\Patch;
  8. use ApiPlatform\Metadata\Put;
  9. use ApiPlatform\Metadata\Post;
  10. use ApiPlatform\Metadata\ApiFilter;
  11. use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
  12. use ApiPlatform\Doctrine\Orm\Filter\NumericFilter;
  13. use ApiPlatform\Doctrine\Orm\Filter\RangeFilter;
  14. use ApiPlatform\Doctrine\Orm\Filter\DateFilter;
  15. use ApiPlatform\Doctrine\Orm\Filter\BooleanFilter;
  16. use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
  17. use Doctrine\ORM\Mapping as ORM;
  18. use Doctrine\DBAL\Types\Types;
  19. use Gedmo\Mapping\Annotation as Gedmo;
  20. use Symfony\Component\Serializer\Annotation\Groups;
  21. use App\Ship\ApiPlatform\Filter\SimpleSearchFilter;
  22. use App\Containers\OscpvSection\ListContainer\Data\Repositories\PrivilegeRepository;
  23. use App\Containers\OscpvSection\IndexContainer\Entities\TranslationEntity;
  24. /** 
  25.  * Льготы по классификации МТСБУ
  26. */
  27. #[ApiResource(
  28.     routePrefix'/oscpv/list',
  29.     normalizationContext: [
  30.         'groups' => 'read',
  31.         'enable_max_depth' => true
  32.     ],
  33.     operations: [
  34.         new Get(
  35.             uriTemplate'/privileges/{id}'requirements: ['id' => '\d+'],
  36.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_READONLY')"
  37.         ),
  38.         new Patch(
  39.             uriTemplate'/privileges/{id}'requirements: ['id' => '\d+'],
  40.             security"is_granted('ROLE_ADMIN')"
  41.         ),
  42.         // new Put(
  43.         //     uriTemplate: '/privileges/{id}', requirements: ['id' => '\d+'],
  44.         //     security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT')"
  45.         // ),
  46.         new Delete(
  47.             uriTemplate'/privileges/{id}'requirements: ['id' => '\d+'],
  48.             security"is_granted('ROLE_ADMIN')"
  49.         ),
  50.         new Post(
  51.             uriTemplate'/privileges',
  52.             security"is_granted('ROLE_ADMIN')"
  53.         ),
  54.         new GetCollection(
  55.             uriTemplate'/privileges',
  56.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_READONLY')"
  57.         )
  58.     ],
  59.     shortName'OSCPV_List_Privileges'
  60. )]
  61. #[ApiFilter(SearchFilter::class, properties: [
  62.     'id' => 'exact',
  63.     'externalCode' => 'partial',
  64.     'code' => 'partial',
  65.     'name' => 'partial'
  66. ])]
  67. #[ApiFilter(NumericFilter::class, properties: ['id'])]
  68. #[ApiFilter(RangeFilter::class, properties: ['id'])]
  69. #[ApiFilter(DateFilter::class, properties: ['createdAt''updatedAt'])]
  70. #[ApiFilter(OrderFilter::class)]
  71. #[ApiFilter(filterClassSimpleSearchFilter::class, properties: [
  72.     'name''code''externalCode'
  73. ])]
  74. #[ORM\Entity(repositoryClassPrivilegeRepository::class)]
  75. #[ORM\Table(name'`oscpv_list_privileges`')]
  76. #[Gedmo\TranslationEntity(class: TranslationEntity::class)]
  77. class PrivilegeEntity
  78. {   
  79.     #[ORM\Id]
  80.     #[ORM\GeneratedValue]
  81.     #[ORM\Column(typeTypes::INTEGER)]
  82.     #[Groups(['read'])]
  83.     private ?int $id null;
  84.     #[ORM\Column(typeTypes::STRINGlength255nullabletrueuniquetrue)]
  85.     #[Groups(['read'])]
  86.     private ?string $externalCode null;
  87.     // Код
  88.     #[ORM\Column(typeTypes::STRINGnullablefalseuniquetrue)]
  89.     #[Groups(['read'])]
  90.     private string $code;
  91.     // Название
  92.     #[ORM\Column(typeTypes::STRINGlength255nullablefalse)]
  93.     #[Gedmo\Translatable]
  94.     #[Groups(['read'])]
  95.     private string $name;
  96.     // Сортировка
  97.     #[ORM\Column(typeTypes::INTEGERoptions: ['default' => 500])]
  98.     #[Groups(['read'])]
  99.     private int $sorting 500;
  100.     #[Gedmo\Timestampable(on'create')]
  101.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLE)]
  102.     #[Groups(['read'])]
  103.     protected $createdAt;
  104.     #[Gedmo\Timestampable(on'update')]
  105.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLE)]
  106.     #[Groups(['read'])]
  107.     protected $updatedAt;
  108.     /**
  109.      * Used locale to override Translation listener`s locale
  110.      * this is not a mapped field of entity metadata, just a simple property
  111.      */
  112.     #[Gedmo\Locale]
  113.     private $locale;
  114.     public function getId(): ?int
  115.     {
  116.         return $this->id;
  117.     }
  118.     public function getExternalCode()
  119.     {
  120.         return $this->externalCode;
  121.     }
  122.     public function setExternalCode($code)
  123.     {
  124.         $this->externalCode $code;
  125.         return $this;
  126.     }
  127.     public function getCode()
  128.     {
  129.         return $this->code;
  130.     }
  131.     public function setCode($code)
  132.     {
  133.         $this->code $code;
  134.         return $this;
  135.     }
  136.     public function getName()
  137.     {
  138.         return $this->name;
  139.     }
  140.     public function setName($name)
  141.     {
  142.         $this->name $name;
  143.         return $this;
  144.     }
  145.     public function getSorting()
  146.     {
  147.         return $this->sorting;
  148.     }
  149.     public function setSorting($value)
  150.     {
  151.         $this->sorting $value;
  152.         return $this;
  153.     }
  154.     public function getCreatedAt()
  155.     {
  156.         return $this->createdAt;
  157.     }
  158.     public function getUpdatedAt()
  159.     {
  160.         return $this->updatedAt;
  161.     }
  162.     public function setTranslatableLocale($locale)
  163.     {
  164.         $this->locale $locale;
  165.     }
  166. }