src/Containers/SettingSection/ListContainer/Entities/CarModelEntity.php line 81

Open in your IDE?
  1. <?php
  2. namespace App\Containers\SettingSection\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\OrderFilter;
  15. use Doctrine\ORM\Mapping as ORM;
  16. use Doctrine\DBAL\Types\Types;
  17. use Gedmo\Mapping\Annotation as Gedmo;
  18. use Symfony\Component\Serializer\Annotation\Groups;
  19. use App\Containers\SettingSection\ListContainer\Data\Repositories\CarModelRepository;
  20. use App\Containers\SettingSection\ListContainer\Entities\CarBrandEntity;
  21. //use App\Containers\SettingSection\IndexContainer\Entities\TranslationEntity;
  22. use App\Ship\ApiPlatform\Filter\SimpleSearchFilter;
  23. /** 
  24.  * Модели авто
  25. */
  26. #[ApiResource(
  27.     routePrefix'/list',
  28.     normalizationContext: ['groups' => 'read'],
  29.     operations: [
  30.         new Get(
  31.             uriTemplate'/car_models/{id}'requirements: ['id' => '\d+'],
  32.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_READONLY')"
  33.         ),
  34.         new Patch(
  35.             uriTemplate'/car_models/{id}'requirements: ['id' => '\d+'],
  36.             security"is_granted('ROLE_ADMIN')"
  37.         ),
  38.         // new Put(
  39.         //     uriTemplate: '/car_models/{id}', requirements: ['id' => '\d+'],
  40.         //     security: "is_granted('ROLE_ADMIN')"
  41.         // ),
  42.         new Delete(
  43.             uriTemplate'/car_models/{id}'requirements: ['id' => '\d+'],
  44.             security"is_granted('ROLE_ADMIN')"
  45.         ),
  46.         new Post(
  47.             uriTemplate'/car_models',
  48.             security"is_granted('ROLE_ADMIN')"
  49.         ),
  50.         new GetCollection(
  51.             uriTemplate'/car_models',
  52.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_READONLY')"
  53.         ),
  54.     ],
  55.     shortName'List_CarModels'
  56. )]
  57. #[ApiFilter(SearchFilter::class, properties: [
  58.     'id' => 'exact',
  59.     'name' => 'partial'
  60.     'codeAutoria' => 'partial'
  61.     'codeOpendataBot' => 'partial'
  62.     'code1C' => 'partial'
  63.     'name1C' => 'partial'
  64.     'carBrand' => 'exact',
  65.     'carBrand.name' => 'partial'
  66.     'carBrand.codeAutoria' => 'partial'
  67. ])]
  68. #[ApiFilter(NumericFilter::class, properties: ['id'])]
  69. #[ApiFilter(RangeFilter::class, properties: ['id'])]
  70. #[ApiFilter(OrderFilter::class)]
  71. #[ApiFilter(filterClassSimpleSearchFilter::class, properties: [
  72.     'name''codeAutoria''codeOpendataBot''code1C''name1C'
  73. ])]
  74. #[ORM\Entity(repositoryClassCarModelRepository::class)]
  75. #[ORM\Table(name'`list_car_models`')]
  76. #[ORM\Index(columns: ['code_autoria''code_opendata_bot'], name'list_car_models_custom_idx')]
  77. //#[Gedmo\TranslationEntity(class: TranslationEntity::class)]
  78. class CarModelEntity
  79. {   
  80.     #[ORM\Id]
  81.     #[ORM\GeneratedValue]
  82.     #[ORM\Column(typeTypes::INTEGER)]
  83.     #[Groups(['read'])]
  84.     private ?int $id null;
  85.     // Название
  86.     #[ORM\Column(typeTypes::STRINGlength255nullablefalse)]
  87.     //#[Gedmo\Translatable]
  88.     #[Groups(['read'])]
  89.     private string $name;
  90.     // Код АвтоРИА
  91.     #[ORM\Column(typeTypes::STRINGlength255nullablefalse)]
  92.     #[Groups(['read'])]
  93.     private string $codeAutoria;
  94.     // Код OpendataBot
  95.     #[ORM\Column(typeTypes::STRINGlength255nullabletrue)]
  96.     #[Groups(['read'])]
  97.     private ?string $codeOpendataBot null;
  98.     // Марка
  99.     #[ORM\ManyToOne(targetEntityCarBrandEntity::class)]
  100.     #[ORM\JoinColumn(name'car_brand_id'referencedColumnName'id'nullabletrue)]
  101.     #[Groups(['read'])]
  102.     private ?CarBrandEntity $carBrand null;
  103.     // Код 1С
  104.     #[ORM\Column(typeTypes::STRINGlength255nullabletrue)]
  105.     #[Groups(['read'])]
  106.     private ?string $code1C null;
  107.     // Название 1С
  108.     #[ORM\Column(typeTypes::STRINGlength255nullabletrue)]
  109.     #[Groups(['read'])]
  110.     private ?string $name1C null;
  111.     // Часто угоняемые
  112.     #[ORM\Column(typeTypes::BOOLEANoptions: ['default' => false])]
  113.     #[Groups(['read'])]
  114.     private bool $isHijacked false;
  115.     #[Gedmo\Timestampable(on'create')]
  116.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLE)]
  117.     protected $createdAt;
  118.     #[Gedmo\Timestampable(on'update')]
  119.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLE)]
  120.     protected $updatedAt;
  121.     /**
  122.      * Used locale to override Translation listener`s locale
  123.      * this is not a mapped field of entity metadata, just a simple property
  124.      */
  125.     // #[Gedmo\Locale]
  126.     // private $locale;
  127.     public function getId(): ?int
  128.     {
  129.         return $this->id;
  130.     }
  131.     public function getName()
  132.     {
  133.         return $this->name;
  134.     }
  135.     public function setName($name)
  136.     {
  137.         $this->name $name;
  138.         return $this;
  139.     }
  140.  
  141.     public function getCodeAutoria()
  142.     {
  143.         return $this->codeAutoria;
  144.     }
  145.     public function setCodeAutoria($code)
  146.     {
  147.         $this->codeAutoria $code;
  148.         return $this;
  149.     }
  150.     public function getCodeOpendataBot()
  151.     {
  152.         return $this->codeOpendataBot;
  153.     }
  154.     public function setCodeOpendataBot($code)
  155.     {
  156.         $this->codeOpendataBot $code;
  157.         return $this;
  158.     }
  159.     public function getCarBrand()
  160.     {
  161.         return $this->carBrand;
  162.     }
  163.     public function setCarBrand($brand)
  164.     {
  165.         $this->carBrand $brand;
  166.         return $this;
  167.     }
  168.     public function getCode1C()
  169.     {
  170.         return $this->code1C;
  171.     }
  172.     public function setCode1C($code)
  173.     {
  174.         $this->code1C $code;
  175.         return $this;
  176.     }
  177.     public function getName1C()
  178.     {
  179.         return $this->name1C;
  180.     }
  181.     public function setName1C($name)
  182.     {
  183.         $this->name1C $name;
  184.         return $this;
  185.     }
  186.     public function getIsHijacked()
  187.     {
  188.         return $this->isHijacked;
  189.     }
  190.     public function setIsHijacked($value)
  191.     {
  192.         $this->isHijacked $value;
  193.         return $this;
  194.     }
  195.     // public function setTranslatableLocale($locale)
  196.     // {
  197.     //     $this->locale = $locale;
  198.     // }
  199. }