<?php
namespace App\Containers\SettingSection\ControlContainer\Entities;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Put;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Doctrine\Orm\Filter\NumericFilter;
use ApiPlatform\Doctrine\Orm\Filter\RangeFilter;
use ApiPlatform\Doctrine\Orm\Filter\BooleanFilter;
use ApiPlatform\Doctrine\Orm\Filter\DateFilter;
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\DBAL\Types\Types;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Serializer\Annotation\Groups;
use App\Containers\SettingSection\ControlContainer\Data\Repositories\AdditionalCarRepository;
use App\Containers\SettingSection\IndexContainer\Entities\TranslationEntity;
use App\Containers\SettingSection\ListContainer\Entities\CarBrandEntity;
use App\Containers\SettingSection\ListContainer\Entities\CarModelEntity;
use App\Containers\SettingSection\ListContainer\Entities\FuelTypeEntity;
use App\Containers\SettingSection\ListContainer\Entities\CarTypeEntity;
use App\Ship\ApiPlatform\Filter\SimpleSearchFilter;
/**
* Дополнительные авто
*/
#[ApiResource(
routePrefix: '/control',
normalizationContext: ['groups' => ['read']],
operations: [
new Get(
uriTemplate: '/additional_cars/{id}', requirements: ['id' => '\d+'],
security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_READONLY')"
),
new Patch(
uriTemplate: '/additional_cars/{id}', requirements: ['id' => '\d+'],
security: "is_granted('ROLE_ADMIN')"
),
// new Put(
// uriTemplate: '/additional_cars/{id}', requirements: ['id' => '\d+'],
// security: "is_granted('ROLE_ADMIN')"
// ),
new Delete(
uriTemplate: '/additional_cars/{id}', requirements: ['id' => '\d+'],
security: "is_granted('ROLE_ADMIN')"
),
new Post(
uriTemplate: '/additional_cars',
security: "is_granted('ROLE_ADMIN')"
),
new GetCollection(
uriTemplate: '/additional_cars',
security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_READONLY')"
),
],
shortName: 'Control_AdditionalCars'
)]
#[ApiFilter(SearchFilter::class, properties: [
'id' => 'exact',
'carNumber' => 'exact',
'externalCode' => 'exact',
'carVIN' => 'exact',
'carBrand' => 'exact',
'carBrand.name' => 'partial',
'carBrand.codeAutoria' => 'partial',
'carModel' => 'exact',
'carModel.name' => 'partial',
'carModel.codeAutoria' => 'partial',
'carFuelType' => 'exact',
'carFuelType.name' => 'partial',
'carFuelType.codeAutoria' => 'partial',
'carType' => 'exact',
'carType.name' => 'partial',
'carType.codeAutoria' => 'partial',
'carColor' => 'exact',
'carKOATUU' => 'exact'
])]
#[ApiFilter(NumericFilter::class, properties: ['id'])]
#[ApiFilter(RangeFilter::class, properties: ['id', 'carEngineVolume'])]
#[ApiFilter(BooleanFilter::class, properties: ['isHijacked'])]
#[ApiFilter(DateFilter::class, properties: ['dateProduction', 'createdAt', 'updatedAt'])]
#[ApiFilter(OrderFilter::class)]
#[ApiFilter(filterClass: SimpleSearchFilter::class, properties: ['carNumber', 'externalCode', 'carKOATUU'])]
#[ORM\Entity(repositoryClass: AdditionalCarRepository::class)]
#[ORM\Table(name: '`control_additional_cars`')]
#[ORM\Index(columns: ['car_number', 'car_number_latin'], name: 'control_additional_cars_custom_idx')]
#[Gedmo\TranslationEntity(class: TranslationEntity::class)]
class AdditionalCarEntity
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: Types::INTEGER)]
#[Groups(['read'])]
private ?int $id = null;
#[ORM\Column(type: Types::STRING, length: 255, nullable: true, unique: true)]
#[Groups(['read'])]
private ?string $externalCode = null;
// Номер авто
#[ORM\Column(type: Types::STRING, length: 50, nullable: false)]
#[Groups(['read'])]
private string $carNumber;
// Номер авто (латиница)
#[ORM\Column(type: Types::STRING, length: 50, nullable: true)]
#[Groups(['read'])]
private ?string $carNumberLatin = null;
// Год выпуска
#[ORM\Column(type: Types::INTEGER, length: 4, nullable: false)]
#[Groups(['read'])]
private int $dateProduction;
// VIN
#[ORM\Column(type: Types::STRING, length: 150, nullable: true, unique: true)]
#[Groups(['read'])]
private ?string $carVIN = null;
// Марка
#[ORM\ManyToOne(targetEntity: CarBrandEntity::class)]
#[ORM\JoinColumn(name: 'car_brand_id', referencedColumnName: 'id', nullable: true)]
#[Groups(['read'])]
private ?CarBrandEntity $carBrand = null;
// Модель
#[ORM\ManyToOne(targetEntity: CarModelEntity::class)]
#[ORM\JoinColumn(name: 'car_model_id', referencedColumnName: 'id', nullable: true)]
#[Groups(['read'])]
private ?CarModelEntity $carModel = null;
// Объем двигателя
#[ORM\Column(type: Types::FLOAT, scale: 3, nullable: true)]
#[Groups(['read'])]
private ?float $carEngineVolume = null;
// Тип топлива
#[ORM\ManyToOne(targetEntity: FuelTypeEntity::class)]
#[ORM\JoinColumn(name: 'car_fuel_type_id', referencedColumnName: 'id', nullable: true)]
#[Groups(['read'])]
private ?FuelTypeEntity $carFuelType = null;
// Тип транспорта
#[ORM\ManyToOne(targetEntity: CarTypeEntity::class)]
#[ORM\JoinColumn(name: 'car_type_id', referencedColumnName: 'id', nullable: true)]
#[Groups(['read'])]
private ?CarTypeEntity $carType = null;
// Цвет
#[ORM\Column(type: Types::STRING, length: 150, nullable: true)]
#[Gedmo\Translatable]
#[Groups(['read'])]
private ?string $carColor = null;
// КОАТУУ
#[ORM\Column(type: Types::STRING, length: 50, nullable: true)]
#[Groups(['read'])]
private ?string $carKOATUU = null;
// Часто угоняемые
#[ORM\Column(type: Types::BOOLEAN, options: ['default' => false])]
#[Groups(['read'])]
private bool $isHijacked = false;
#[Gedmo\Timestampable(on: 'create')]
#[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
#[Groups(['read'])]
protected $createdAt;
#[Gedmo\Timestampable(on: 'update')]
#[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
#[Groups(['read'])]
protected $updatedAt;
/**
* Used locale to override Translation listener`s locale
* this is not a mapped field of entity metadata, just a simple property
*/
#[Gedmo\Locale]
private $locale;
public function getId(): ?int
{
return $this->id;
}
public function getExternalCode()
{
return $this->externalCode;
}
public function setExternalCode($code)
{
$this->externalCode = $code;
return $this;
}
public function getCarNumber()
{
return $this->carNumber;
}
public function setCarNumber($number)
{
$this->carNumber = ($number !== null ? str_replace(' ','', trim($number)) : null);
return $this;
}
public function getCarNumberLatin()
{
return $this->carNumberLatin;
}
public function setCarNumberLatin($number)
{
$this->carNumberLatin = ($number !== null ? str_replace(' ','', trim($number)) : null);
return $this;
}
public function setDateProduction($year)
{
$this->dateProduction = $year;
return $this;
}
public function getDateProduction()
{
return $this->dateProduction;
}
public function getCarVIN()
{
return $this->carVIN;
}
public function setCarVIN($VIN)
{
$this->carVIN = $VIN;
return $this;
}
public function getCarBrand()
{
return $this->carBrand;
}
public function setCarBrand($brand)
{
$this->carBrand = $brand;
return $this;
}
public function getCarModel()
{
return $this->carModel;
}
public function setCarModel($model)
{
$this->carModel = $model;
return $this;
}
public function getCarEngineVolume()
{
return $this->carEngineVolume;
}
public function setCarEngineVolume($value)
{
$this->carEngineVolume = ($value !== null ? round($value, 3) : null);
return $this;
}
public function getCarFuelType()
{
return $this->carFuelType;
}
public function setCarFuelType($type)
{
$this->carFuelType = $type;
return $this;
}
public function getCarType()
{
return $this->carType;
}
public function setCarType($type)
{
$this->carType = $type;
return $this;
}
public function getCarColor()
{
return $this->carColor;
}
public function setCarColor($color)
{
$this->carColor = $color;
return $this;
}
public function getCarKOATUU()
{
return $this->carKOATUU;
}
public function setCarKOATUU($data)
{
$this->carKOATUU = $data;
return $this;
}
public function getIsHijacked()
{
return $this->isHijacked;
}
public function setIsHijacked($isHijacked)
{
$this->isHijacked = $isHijacked;
return $this;
}
public function getCreatedAt()
{
return $this->createdAt;
}
public function getUpdatedAt()
{
return $this->updatedAt;
}
public function setTranslatableLocale($locale)
{
$this->locale = $locale;
}
}