src/Containers/SettingSection/ListContainer/Entities/StatusEntity.php line 64

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