<?php
namespace App\Containers\SettingSection\ListContainer\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\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\ListContainer\Data\Repositories\CarModelRepository;
use App\Containers\SettingSection\ListContainer\Entities\CarBrandEntity;
//use App\Containers\SettingSection\IndexContainer\Entities\TranslationEntity;
use App\Ship\ApiPlatform\Filter\SimpleSearchFilter;
/**
* Модели авто
*/
#[ApiResource(
routePrefix: '/list',
normalizationContext: ['groups' => 'read'],
operations: [
new Get(
uriTemplate: '/car_models/{id}', requirements: ['id' => '\d+'],
security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_READONLY')"
),
new Patch(
uriTemplate: '/car_models/{id}', requirements: ['id' => '\d+'],
security: "is_granted('ROLE_ADMIN')"
),
// new Put(
// uriTemplate: '/car_models/{id}', requirements: ['id' => '\d+'],
// security: "is_granted('ROLE_ADMIN')"
// ),
new Delete(
uriTemplate: '/car_models/{id}', requirements: ['id' => '\d+'],
security: "is_granted('ROLE_ADMIN')"
),
new Post(
uriTemplate: '/car_models',
security: "is_granted('ROLE_ADMIN')"
),
new GetCollection(
uriTemplate: '/car_models',
security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_READONLY')"
),
],
shortName: 'List_CarModels'
)]
#[ApiFilter(SearchFilter::class, properties: [
'id' => 'exact',
'name' => 'partial',
'codeAutoria' => 'partial',
'codeOpendataBot' => 'partial',
'code1C' => 'partial',
'name1C' => 'partial',
'carBrand' => 'exact',
'carBrand.name' => 'partial',
'carBrand.codeAutoria' => 'partial'
])]
#[ApiFilter(NumericFilter::class, properties: ['id'])]
#[ApiFilter(RangeFilter::class, properties: ['id'])]
#[ApiFilter(OrderFilter::class)]
#[ApiFilter(filterClass: SimpleSearchFilter::class, properties: [
'name', 'codeAutoria', 'codeOpendataBot', 'code1C', 'name1C'
])]
#[ORM\Entity(repositoryClass: CarModelRepository::class)]
#[ORM\Table(name: '`list_car_models`')]
#[ORM\Index(columns: ['code_autoria', 'code_opendata_bot'], name: 'list_car_models_custom_idx')]
//#[Gedmo\TranslationEntity(class: TranslationEntity::class)]
class CarModelEntity
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: Types::INTEGER)]
#[Groups(['read'])]
private ?int $id = null;
// Название
#[ORM\Column(type: Types::STRING, length: 255, nullable: false)]
//#[Gedmo\Translatable]
#[Groups(['read'])]
private string $name;
// Код АвтоРИА
#[ORM\Column(type: Types::STRING, length: 255, nullable: false)]
#[Groups(['read'])]
private string $codeAutoria;
// Код OpendataBot
#[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
#[Groups(['read'])]
private ?string $codeOpendataBot = null;
// Марка
#[ORM\ManyToOne(targetEntity: CarBrandEntity::class)]
#[ORM\JoinColumn(name: 'car_brand_id', referencedColumnName: 'id', nullable: true)]
#[Groups(['read'])]
private ?CarBrandEntity $carBrand = null;
// Код 1С
#[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
#[Groups(['read'])]
private ?string $code1C = null;
// Название 1С
#[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
#[Groups(['read'])]
private ?string $name1C = 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)]
protected $createdAt;
#[Gedmo\Timestampable(on: 'update')]
#[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
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 getName()
{
return $this->name;
}
public function setName($name)
{
$this->name = $name;
return $this;
}
public function getCodeAutoria()
{
return $this->codeAutoria;
}
public function setCodeAutoria($code)
{
$this->codeAutoria = $code;
return $this;
}
public function getCodeOpendataBot()
{
return $this->codeOpendataBot;
}
public function setCodeOpendataBot($code)
{
$this->codeOpendataBot = $code;
return $this;
}
public function getCarBrand()
{
return $this->carBrand;
}
public function setCarBrand($brand)
{
$this->carBrand = $brand;
return $this;
}
public function getCode1C()
{
return $this->code1C;
}
public function setCode1C($code)
{
$this->code1C = $code;
return $this;
}
public function getName1C()
{
return $this->name1C;
}
public function setName1C($name)
{
$this->name1C = $name;
return $this;
}
public function getIsHijacked()
{
return $this->isHijacked;
}
public function setIsHijacked($value)
{
$this->isHijacked = $value;
return $this;
}
// public function setTranslatableLocale($locale)
// {
// $this->locale = $locale;
// }
}