<?php
namespace App\Containers\ServiceSection\EventLogContainer\Entities;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
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\ServiceSection\EventLogContainer\Data\Repositories\EventTypeRepository;
use App\Containers\CrmSection\IndexContainer\Entities\TranslationEntity;
use App\Ship\ApiPlatform\Filter\SimpleSearchFilter;
/**
* Типы событий
*/
#[ApiResource(
routePrefix: '/service',
normalizationContext: [
'groups' => 'read',
'enable_max_depth' => true
],
operations: [
new Get(
uriTemplate: '/event_log_types/{id}', requirements: ['id' => '\d+'],
security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_READONLY')"
),
new GetCollection(
uriTemplate: '/event_log_types',
security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_READONLY')"
)
],
shortName: 'Service_EventLog'
)]
#[ApiFilter(SearchFilter::class, properties: ['id' => 'exact', 'name' => 'partial', 'code' => 'partial'])]
#[ApiFilter(NumericFilter::class, properties: ['id', 'sorting'])]
#[ApiFilter(RangeFilter::class, properties: ['id', 'sorting'])]
#[ApiFilter(OrderFilter::class)]
#[ApiFilter(filterClass: SimpleSearchFilter::class, properties: ['name', 'code'])]
#[ORM\Entity(repositoryClass: EventTypeRepository::class)]
#[ORM\Table(name: '`service_event_log_types`')]
#[ORM\Index(columns: ['code'], name: 'service_event_log_types_custom_idx')]
#[Gedmo\TranslationEntity(class: TranslationEntity::class)]
class EventTypeEntity
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: Types::INTEGER)]
#[Groups(['read'])]
private ?int $id = null;
// Название
#[ORM\Column(type: Types::STRING, length: 50, nullable: true)]
#[Gedmo\Translatable]
#[Groups(['read'])]
private ?string $name = null;
// Сортування
#[ORM\Column(type: Types::INTEGER, length: 10, options: ['default' => 500])]
#[Groups(['read'])]
private ?int $sorting = 500;
// Код
#[ORM\Column(type: Types::STRING, length: 50, nullable: false, unique: true)]
#[Groups(['read'])]
private string $code;
#[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 getSorting()
{
return $this->sorting;
}
public function setSorting($sorting)
{
$this->sorting = $sorting;
return $this;
}
public function getCode()
{
return $this->code;
}
public function setCode($code)
{
$this->code = $code;
return $this;
}
public function setTranslatableLocale($locale)
{
$this->locale = $locale;
}
}