<?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\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 Symfony\Component\Serializer\Annotation\MaxDepth;
use Symfony\Component\Serializer\Annotation\Context;
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
use App\Containers\ServiceSection\EventLogContainer\Data\Repositories\EventLogRepository;
use App\Containers\CrmSection\ClientContainer\Entities\ClientEntity;
use App\Containers\CompanySection\EmployeeContainer\Entities\EmployeeEntity;
use App\Containers\ServiceSection\EventLogContainer\Entities\EventTypeEntity;
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/{id}', requirements: ['id' => '\d+'],
security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_READONLY')"
),
new GetCollection(
uriTemplate: '/event_log',
security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_READONLY')"
)
],
shortName: 'Service_EventLog'
)]
#[ApiFilter(SearchFilter::class, properties: [
'id' => 'exact',
'employee' => 'exact',
'client' => 'exact',
'type' => 'exact',
'employee.name' => 'partial',
'employee.lastName' => 'partial',
'employee.patronymic' => 'partial',
'employee.phone' => 'exact',
'employee.email' => 'exact',
'employee.workPhone' => 'exact',
'client.name' => 'partial',
'client.lastName' => 'partial',
'client.patronymic' => 'partial',
'client.phone' => 'exact',
'client.email' => 'exact',
'type.name' => 'exact',
])]
#[ApiFilter(NumericFilter::class, properties: ['id'])]
#[ApiFilter(RangeFilter::class, properties: ['id'])]
#[ApiFilter(DateFilter::class, properties: ['date'])]
#[ApiFilter(OrderFilter::class)]
// #[ApiFilter(filterClass: SimpleSearchFilter::class, properties: [
// 'employee.phone', 'employee.email', 'client.workPhone',
// 'client.phone', 'client.email', 'client.inn'
// ])]
#[ORM\Entity(repositoryClass: EventLogRepository::class)]
#[ORM\Table(name: '`service_event_log`')]
#[Gedmo\TranslationEntity(class: TranslationEntity::class)]
class EventLogEntity
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: Types::INTEGER)]
#[Groups(['read'])]
private ?int $id = null;
// Дата события
#[Gedmo\Timestampable(on: 'create')]
#[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
#[Context(
normalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s'],
denormalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s']
)]
#[Groups(['read'])]
protected \DateTimeInterface $date;
// Тип обытия
#[ORM\ManyToOne(targetEntity: EventTypeEntity::class)]
#[ORM\JoinColumn(name: 'type_id', referencedColumnName: 'id', nullable: false)]
#[Groups(['read'])]
#[MaxDepth(1)]
private EventTypeEntity $type;
// Сотрудник
#[ORM\ManyToOne(targetEntity: EmployeeEntity::class)]
#[ORM\JoinColumn(name: 'employee_id', referencedColumnName: 'id', nullable: true)]
#[Groups(['read'])]
#[MaxDepth(2)]
private ?EmployeeEntity $employee = null;
// Клиент
#[ORM\ManyToOne(targetEntity: ClientEntity::class)]
#[ORM\JoinColumn(name: 'client_id', referencedColumnName: 'id', nullable: true)]
#[Groups(['read'])]
#[MaxDepth(2)]
private ?ClientEntity $client = null;
// IP
#[ORM\Column(type: Types::STRING, length: 100, nullable: true)]
#[Groups(['read'])]
private ?string $ip = null;
// Комментарий
#[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
#[Gedmo\Translatable]
#[Groups(['read'])]
private ?string $comment = null;
/**
* 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 getDate()
{
return $this->date;
}
public function setDate($date)
{
$this->date = $date;
return $this;
}
public function getType()
{
return $this->type;
}
public function setType($type)
{
$this->type = $type;
return $this;
}
public function getEmployee()
{
return $this->employee;
}
public function setEmployee($employee)
{
$this->employee = $employee;
return $this;
}
public function getClient()
{
return $this->client;
}
public function setClient($client)
{
$this->client = $client;
return $this;
}
public function getIp()
{
return $this->ip;
}
public function setIp($ip)
{
$this->ip = $ip;
return $this;
}
public function getComment()
{
return $this->comment;
}
public function setComment($comment)
{
$this->comment = $comment;
return $this;
}
public function setTranslatableLocale($locale)
{
$this->locale = $locale;
}
}