src/Containers/SettingSection/ControlContainer/Entities/AdditionalCarEntity.php line 94

Open in your IDE?
  1. <?php
  2. namespace App\Containers\SettingSection\ControlContainer\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\BooleanFilter;
  15. use ApiPlatform\Doctrine\Orm\Filter\DateFilter;
  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\Containers\SettingSection\ControlContainer\Data\Repositories\AdditionalCarRepository;
  22. use App\Containers\SettingSection\IndexContainer\Entities\TranslationEntity;
  23. use App\Containers\SettingSection\ListContainer\Entities\CarBrandEntity;
  24. use App\Containers\SettingSection\ListContainer\Entities\CarModelEntity;
  25. use App\Containers\SettingSection\ListContainer\Entities\FuelTypeEntity;
  26. use App\Containers\SettingSection\ListContainer\Entities\CarTypeEntity;
  27. use App\Ship\ApiPlatform\Filter\SimpleSearchFilter;
  28. /** 
  29.  * Дополнительные авто
  30. */
  31. #[ApiResource(
  32.     routePrefix: '/control',
  33.     normalizationContext: ['groups' => ['read']],
  34.     operations: [
  35.         new Get(
  36.             uriTemplate: '/additional_cars/{id}', requirements: ['id' => '\d+'],
  37.             security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_READONLY') or is_granted('ROLE_DEPARTMENT_ADMIN')"
  38.         ),
  39.         new Patch(
  40.             uriTemplate: '/additional_cars/{id}', requirements: ['id' => '\d+'],
  41.             security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_DEPARTMENT_ADMIN')"
  42.         ),
  43.         // new Put(
  44.         //     uriTemplate: '/additional_cars/{id}', requirements: ['id' => '\d+'],
  45.         //     security: "is_granted('ROLE_ADMIN')"
  46.         // ),
  47.         new Delete(
  48.             uriTemplate: '/additional_cars/{id}', requirements: ['id' => '\d+'],
  49.             security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_DEPARTMENT_ADMIN')"
  50.         ),
  51.         new Post(
  52.             uriTemplate: '/additional_cars',
  53.             security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_DEPARTMENT_ADMIN')"
  54.         ),
  55.         new GetCollection(
  56.             uriTemplate: '/additional_cars',
  57.             security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_READONLY') or is_granted('ROLE_DEPARTMENT_ADMIN')"
  58.         ),
  59.     ],
  60.     shortName: 'Control_AdditionalCars'
  61. )]
  62. #[ApiFilter(SearchFilter::class, properties: [
  63.     'id' => 'exact',
  64.     'carNumber' => 'exact', 
  65.     'externalCode' => 'exact', 
  66.     'carVIN' => 'exact', 
  67.     'carBrand' => 'exact', 
  68.     'carBrand.name' => 'partial', 
  69.     'carBrand.codeAutoria' => 'partial', 
  70.     'carModel' => 'exact', 
  71.     'carModel.name' => 'partial', 
  72.     'carModel.codeAutoria' => 'partial', 
  73.     'carFuelType' => 'exact', 
  74.     'carFuelType.name' => 'partial', 
  75.     'carFuelType.codeAutoria' => 'partial', 
  76.     'carType' => 'exact', 
  77.     'carType.name' => 'partial', 
  78.     'carType.codeAutoria' => 'partial', 
  79.     'carColor' => 'exact', 
  80.     'carKOATUU' => 'exact'
  81. ])]
  82. #[ApiFilter(NumericFilter::class, properties: ['id'])]
  83. #[ApiFilter(RangeFilter::class, properties: ['id', 'carEngineVolume'])]
  84. #[ApiFilter(BooleanFilter::class, properties: ['isHijacked'])]
  85. #[ApiFilter(DateFilter::class, properties: ['dateProduction', 'createdAt', 'updatedAt'])]
  86. #[ApiFilter(OrderFilter::class)]
  87. #[ApiFilter(filterClass: SimpleSearchFilter::class, properties: ['carNumber', 'externalCode', 'carKOATUU'])]
  88. #[ORM\Entity(repositoryClass: AdditionalCarRepository::class)]
  89. #[ORM\Table(name: '`control_additional_cars`')]
  90. #[ORM\Index(columns: ['car_number', 'car_number_latin'], name: 'control_additional_cars_custom_idx')]
  91. #[Gedmo\TranslationEntity(class: TranslationEntity::class)]
  92. class AdditionalCarEntity
  93. {   
  94.     #[ORM\Id]
  95.     #[ORM\GeneratedValue]
  96.     #[ORM\Column(type: Types::INTEGER)]
  97.     #[Groups(['read'])]
  98.     private ?int $id = null;
  99.     #[ORM\Column(type: Types::STRING, length: 255, nullable: true, unique: true)]
  100.     #[Groups(['read'])]
  101.     private ?string $externalCode = null;
  102.     // Номер авто
  103.     #[ORM\Column(type: Types::STRING, length: 50, nullable: false)]
  104.     #[Groups(['read'])]
  105.     private string $carNumber;
  106.     // Номер авто (латиница)
  107.     #[ORM\Column(type: Types::STRING, length: 50, nullable: true)]
  108.     #[Groups(['read'])]
  109.     private ?string $carNumberLatin = null;
  110.     // Год выпуска
  111.     #[ORM\Column(type: Types::INTEGER, length: 4, nullable: false)]
  112.     #[Groups(['read'])]
  113.     private int $dateProduction;
  114.     // VIN
  115.     #[ORM\Column(type: Types::STRING, length: 150, nullable: true, unique: true)]
  116.     #[Groups(['read'])]
  117.     private ?string $carVIN = null;
  118.     // Марка
  119.     #[ORM\ManyToOne(targetEntity: CarBrandEntity::class)]
  120.     #[ORM\JoinColumn(name: 'car_brand_id', referencedColumnName: 'id', nullable: true)]
  121.     #[Groups(['read'])]
  122.     private ?CarBrandEntity $carBrand = null;
  123.     // Модель
  124.     #[ORM\ManyToOne(targetEntity: CarModelEntity::class)]
  125.     #[ORM\JoinColumn(name: 'car_model_id', referencedColumnName: 'id', nullable: true)]
  126.     #[Groups(['read'])]
  127.     private ?CarModelEntity $carModel = null;
  128.     // Объем двигателя
  129.     #[ORM\Column(type: Types::FLOAT, scale: 3, nullable: true)]
  130.     #[Groups(['read'])]
  131.     private ?float $carEngineVolume = null;
  132.     // Тип топлива
  133.     #[ORM\ManyToOne(targetEntity: FuelTypeEntity::class)]
  134.     #[ORM\JoinColumn(name: 'car_fuel_type_id', referencedColumnName: 'id', nullable: true)]
  135.     #[Groups(['read'])]
  136.     private ?FuelTypeEntity $carFuelType = null;
  137.     // Тип транспорта
  138.     #[ORM\ManyToOne(targetEntity: CarTypeEntity::class)]
  139.     #[ORM\JoinColumn(name: 'car_type_id', referencedColumnName: 'id', nullable: true)]
  140.     #[Groups(['read'])]
  141.     private ?CarTypeEntity $carType = null;
  142.     // Цвет
  143.     #[ORM\Column(type: Types::STRING, length: 150, nullable: true)]
  144.     #[Gedmo\Translatable]
  145.     #[Groups(['read'])]
  146.     private ?string $carColor = null;
  147.     // КОАТУУ
  148.     #[ORM\Column(type: Types::STRING, length: 50, nullable: true)]
  149.     #[Groups(['read'])]
  150.     private ?string $carKOATUU = null;
  151.     // Часто угоняемые
  152.     #[ORM\Column(type: Types::BOOLEAN, options: ['default' => false])]
  153.     #[Groups(['read'])]
  154.     private bool $isHijacked = false;
  155.     #[Gedmo\Timestampable(on: 'create')]
  156.     #[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
  157.     #[Groups(['read'])]
  158.     protected $createdAt;
  159.     #[Gedmo\Timestampable(on: 'update')]
  160.     #[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
  161.     #[Groups(['read'])]
  162.     protected $updatedAt;
  163.     /**
  164.      * Used locale to override Translation listener`s locale
  165.      * this is not a mapped field of entity metadata, just a simple property
  166.      */
  167.     #[Gedmo\Locale]
  168.     private $locale;
  169.     public function getId(): ?int
  170.     {
  171.         return $this->id;
  172.     }
  173.     public function getExternalCode()
  174.     {
  175.         return $this->externalCode;
  176.     }
  177.     public function setExternalCode($code)
  178.     {
  179.         $this->externalCode = $code;
  180.         return $this;
  181.     }
  182.     public function getCarNumber()
  183.     {
  184.         return $this->carNumber;
  185.     }
  186.     public function setCarNumber($number)
  187.     {
  188.         $this->carNumber = ($number !== null ? str_replace(' ','', trim($number)) : null);
  189.         return $this;
  190.     }
  191.     public function getCarNumberLatin()
  192.     {
  193.         return $this->carNumberLatin;
  194.     }
  195.     public function setCarNumberLatin($number)
  196.     {
  197.         $this->carNumberLatin = ($number !== null ? str_replace(' ','', trim($number)) : null);
  198.         return $this;
  199.     }
  200.     public function setDateProduction($year)
  201.     {
  202.         $this->dateProduction = $year;
  203.         return $this;
  204.     }
  205.     public function getDateProduction()
  206.     {
  207.         return $this->dateProduction;
  208.     }
  209.     public function getCarVIN()
  210.     {
  211.         return $this->carVIN;
  212.     }
  213.     public function setCarVIN($VIN)
  214.     {
  215.         $this->carVIN = $VIN;
  216.         return $this;
  217.     }
  218.     public function getCarBrand()
  219.     {
  220.         return $this->carBrand;
  221.     }
  222.     public function setCarBrand($brand)
  223.     {
  224.         $this->carBrand = $brand;
  225.         return $this;
  226.     }
  227.     public function getCarModel()
  228.     {
  229.         return $this->carModel;
  230.     }
  231.     public function setCarModel($model)
  232.     {
  233.         $this->carModel = $model;
  234.         return $this;
  235.     }
  236.     public function getCarEngineVolume()
  237.     {
  238.         return $this->carEngineVolume;
  239.     }
  240.     public function setCarEngineVolume($value)
  241.     {
  242.         $this->carEngineVolume = ($value !== null ? round($value, 3) : null);
  243.         return $this;
  244.     }
  245.     public function getCarFuelType()
  246.     {
  247.         return $this->carFuelType;
  248.     }
  249.     public function setCarFuelType($type)
  250.     {
  251.         $this->carFuelType = $type;
  252.         return $this;
  253.     }
  254.     public function getCarType()
  255.     {
  256.         return $this->carType;
  257.     }
  258.     public function setCarType($type)
  259.     {
  260.         $this->carType = $type;
  261.         return $this;
  262.     }
  263.     public function getCarColor()
  264.     {
  265.         return $this->carColor;
  266.     }
  267.     public function setCarColor($color)
  268.     {
  269.         $this->carColor = $color;
  270.         return $this;
  271.     }
  272.     public function getCarKOATUU()
  273.     {
  274.         return $this->carKOATUU;
  275.     }
  276.     public function setCarKOATUU($data)
  277.     {
  278.         $this->carKOATUU = $data;
  279.         return $this;
  280.     }
  281.     public function getIsHijacked()
  282.     {
  283.         return $this->isHijacked;
  284.     }
  285.     public function setIsHijacked($isHijacked)
  286.     {
  287.         $this->isHijacked = $isHijacked;
  288.         return $this;
  289.     }
  290.     public function getCreatedAt()
  291.     {
  292.         return $this->createdAt;
  293.     }
  294.     public function getUpdatedAt()
  295.     {
  296.         return $this->updatedAt;
  297.     }
  298.     public function setTranslatableLocale($locale)
  299.     {
  300.         $this->locale = $locale;
  301.     }
  302. }