src/Containers/ServiceSection/EventLogContainer/Entities/EventLogEntity.php line 78

Open in your IDE?
  1. <?php
  2. namespace App\Containers\ServiceSection\EventLogContainer\Entities;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use ApiPlatform\Metadata\Get;
  5. use ApiPlatform\Metadata\GetCollection;
  6. use ApiPlatform\Metadata\ApiFilter;
  7. use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
  8. use ApiPlatform\Doctrine\Orm\Filter\NumericFilter;
  9. use ApiPlatform\Doctrine\Orm\Filter\RangeFilter;
  10. use ApiPlatform\Doctrine\Orm\Filter\DateFilter;
  11. use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
  12. use Doctrine\ORM\Mapping as ORM;
  13. use Doctrine\DBAL\Types\Types;
  14. use Gedmo\Mapping\Annotation as Gedmo;
  15. use Symfony\Component\Serializer\Annotation\Groups;
  16. use Symfony\Component\Serializer\Annotation\MaxDepth;
  17. use Symfony\Component\Serializer\Annotation\Context;
  18. use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
  19. use App\Containers\ServiceSection\EventLogContainer\Data\Repositories\EventLogRepository;
  20. use App\Containers\CrmSection\ClientContainer\Entities\ClientEntity;
  21. use App\Containers\CompanySection\EmployeeContainer\Entities\EmployeeEntity;
  22. use App\Containers\ServiceSection\EventLogContainer\Entities\EventTypeEntity;
  23. use App\Containers\CrmSection\IndexContainer\Entities\TranslationEntity;
  24. // use App\Ship\ApiPlatform\Filter\SimpleSearchFilter;
  25. /** 
  26.  * Журнал событий
  27. */
  28. #[ApiResource(
  29.     routePrefix'/service',
  30.     normalizationContext: [
  31.         'groups' => 'read',
  32.         'enable_max_depth' => true
  33.     ],
  34.     operations: [
  35.         new Get(
  36.             uriTemplate'/event_log/{id}'requirements: ['id' => '\d+'],
  37.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_READONLY')"
  38.         ),
  39.         new GetCollection(
  40.             uriTemplate'/event_log',
  41.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_READONLY')"
  42.         )
  43.     ],
  44.     shortName'Service_EventLog'
  45. )]
  46. #[ApiFilter(SearchFilter::class, properties: [
  47.     'id' => 'exact'
  48.     'employee' => 'exact',
  49.     'client' => 'exact',
  50.     'type' => 'exact',
  51.     'employee.name' => 'partial'
  52.     'employee.lastName' => 'partial'
  53.     'employee.patronymic' => 'partial',  
  54.     'employee.phone' => 'exact'
  55.     'employee.email' => 'exact',
  56.     'employee.workPhone' => 'exact',
  57.     'client.name' => 'partial'
  58.     'client.lastName' => 'partial'
  59.     'client.patronymic' => 'partial'
  60.     'client.phone' => 'exact'
  61.     'client.email' => 'exact'
  62.     'type.name' => 'exact'
  63. ])]
  64. #[ApiFilter(NumericFilter::class, properties: ['id'])]
  65. #[ApiFilter(RangeFilter::class, properties: ['id'])]
  66. #[ApiFilter(DateFilter::class, properties: ['date'])]
  67. #[ApiFilter(OrderFilter::class)]
  68. // #[ApiFilter(filterClass: SimpleSearchFilter::class, properties: [
  69. //     'employee.phone', 'employee.email', 'client.workPhone',
  70. //     'client.phone', 'client.email', 'client.inn'
  71. // ])]
  72. #[ORM\Entity(repositoryClassEventLogRepository::class)]
  73. #[ORM\Table(name'`service_event_log`')]
  74. #[Gedmo\TranslationEntity(class: TranslationEntity::class)]
  75. class EventLogEntity
  76. {   
  77.     #[ORM\Id]
  78.     #[ORM\GeneratedValue]
  79.     #[ORM\Column(typeTypes::INTEGER)]
  80.     #[Groups(['read'])]
  81.     private ?int $id null;
  82.     // Дата события
  83.     #[Gedmo\Timestampable(on'create')]
  84.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLE)]
  85.     #[Context(
  86.         normalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s'],
  87.         denormalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s']
  88.     )]
  89.     #[Groups(['read'])]
  90.     protected \DateTimeInterface $date;
  91.     // Тип обытия
  92.     #[ORM\ManyToOne(targetEntityEventTypeEntity::class)]
  93.     #[ORM\JoinColumn(name'type_id'referencedColumnName'id'nullablefalse)]
  94.     #[Groups(['read'])]
  95.     #[MaxDepth(1)]
  96.     private EventTypeEntity $type;
  97.     // Сотрудник
  98.     #[ORM\ManyToOne(targetEntityEmployeeEntity::class)]
  99.     #[ORM\JoinColumn(name'employee_id'referencedColumnName'id'nullabletrue)]
  100.     #[Groups(['read'])]
  101.     #[MaxDepth(2)]
  102.     private ?EmployeeEntity $employee null;
  103.     // Клиент
  104.     #[ORM\ManyToOne(targetEntityClientEntity::class)]
  105.     #[ORM\JoinColumn(name'client_id'referencedColumnName'id'nullabletrue)]
  106.     #[Groups(['read'])]
  107.     #[MaxDepth(2)]
  108.     private ?ClientEntity $client null;
  109.     // IP
  110.     #[ORM\Column(typeTypes::STRINGlength100nullabletrue)]
  111.     #[Groups(['read'])]
  112.     private ?string $ip null;
  113.     // Комментарий
  114.     #[ORM\Column(typeTypes::STRINGlength255nullabletrue)]
  115.     #[Gedmo\Translatable]
  116.     #[Groups(['read'])]
  117.     private ?string $comment null;
  118.     /**
  119.      * Used locale to override Translation listener`s locale
  120.      * this is not a mapped field of entity metadata, just a simple property
  121.      */
  122.     #[Gedmo\Locale]
  123.     private $locale;
  124.     public function getId(): ?int
  125.     {
  126.         return $this->id;
  127.     }
  128.     public function getDate()
  129.     {
  130.         return $this->date;
  131.     }
  132.     public function setDate($date)
  133.     {
  134.         $this->date $date;
  135.         return $this;
  136.     }
  137.     public function getType()
  138.     {
  139.         return $this->type;
  140.     }
  141.     public function setType($type)
  142.     {
  143.         $this->type $type;
  144.         return $this;
  145.     }
  146.     public function getEmployee()
  147.     {
  148.         return $this->employee;
  149.     }
  150.     public function setEmployee($employee)
  151.     {
  152.         $this->employee $employee;
  153.         return $this;
  154.     }
  155.     public function getClient()
  156.     {
  157.         return $this->client;
  158.     }
  159.     public function setClient($client)
  160.     {
  161.         $this->client $client;
  162.         return $this;
  163.     }
  164.     public function getIp()
  165.     {
  166.         return $this->ip;
  167.     }
  168.     public function setIp($ip)
  169.     {
  170.         $this->ip $ip;
  171.         return $this;
  172.     }
  173.     public function getComment()
  174.     {
  175.         return $this->comment;
  176.     }
  177.     public function setComment($comment)
  178.     {
  179.         $this->comment $comment;
  180.         return $this;
  181.     }
  182.     public function setTranslatableLocale($locale)
  183.     {
  184.         $this->locale $locale;
  185.     }
  186. }