src/Containers/ServiceSection/TravelContainer/Entities/ViolationEntity.php line 108

Open in your IDE?
  1. <?php
  2. namespace App\Containers\ServiceSection\TravelContainer\Entities;
  3. use ApiPlatform\Metadata\ApiProperty;
  4. use ApiPlatform\Metadata\ApiResource;
  5. use ApiPlatform\Metadata\Delete;
  6. use ApiPlatform\Metadata\Get;
  7. use ApiPlatform\Metadata\GetCollection;
  8. use ApiPlatform\Metadata\Patch;
  9. // use ApiPlatform\Metadata\Put;
  10. // use ApiPlatform\Metadata\Post;
  11. use ApiPlatform\Metadata\ApiFilter;
  12. use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
  13. use ApiPlatform\Doctrine\Orm\Filter\NumericFilter;
  14. use ApiPlatform\Doctrine\Orm\Filter\RangeFilter;
  15. use ApiPlatform\Doctrine\Orm\Filter\DateFilter;
  16. // use ApiPlatform\Doctrine\Orm\Filter\BooleanFilter;
  17. use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
  18. use Doctrine\ORM\Mapping as ORM;
  19. use Doctrine\DBAL\Types\Types;
  20. use Gedmo\Mapping\Annotation as Gedmo;
  21. use Symfony\Component\Serializer\Annotation\Groups;
  22. use Symfony\Component\Serializer\Annotation\MaxDepth;
  23. use Symfony\Component\Serializer\Annotation\Context;
  24. use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
  25. use Symfony\Component\Validator\Constraints as Assert;
  26. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  27. use App\Ship\ApiPlatform\Filter\SimpleSearchFilter;
  28. use App\Containers\ServiceSection\TravelContainer\Data\Repositories\ViolationRepository;
  29. use App\Containers\CrmSection\ClientContainer\Entities\ClientEntity;
  30. use App\Containers\CrmSection\CarContainer\Entities\CarEntity;
  31. use App\Containers\CrmSection\ContractContainer\Entities\ContractEntity;
  32. use App\Containers\CrmSection\EquipmentContainer\Entities\ApplicationEntity;
  33. use App\Containers\ServiceSection\TravelContainer\Entities\TravelEntity;
  34. use App\Containers\ServiceSection\IndexContainer\Entities\TranslationEntity;
  35. /** 
  36.  * Нарушения
  37. */
  38. #[ApiResource(
  39.     routePrefix'/service',
  40.     normalizationContext: [
  41.         'groups' => ['violation:read''travel:read''read'],
  42.         'enable_max_depth' => true
  43.     ],
  44.     denormalizationContext: [
  45.         'groups' => ['violation:create''violation:update']
  46.     ],
  47.     operations: [
  48.         new Get(
  49.             uriTemplate'/violations/{id}'requirements: ['id' => '\d+'],
  50.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_READONLY')"
  51.         ),
  52.         new Patch(
  53.             uriTemplate'/violations/{id}'requirements: ['id' => '\d+'],
  54.             security"is_granted('ROLE_ADMIN')"
  55.         ),
  56.         // new Put(
  57.         //     uriTemplate: '/violations/{id}', requirements: ['id' => '\d+'],
  58.         //     security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT')"
  59.         // ),
  60.         new Delete(
  61.             uriTemplate'/violations/{id}'requirements: ['id' => '\d+'],
  62.             security"is_granted('ROLE_ADMIN')"
  63.         ),
  64.         // new Post(
  65.         //     uriTemplate: '/violations',
  66.         //     security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT')"
  67.         // ),
  68.         new GetCollection(
  69.             uriTemplate'/violations',
  70.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_READONLY')"
  71.         ),
  72.     ],
  73.     shortName'Service_Travels'
  74. )]
  75. #[ApiFilter(SearchFilter::class, properties: [
  76.     'id' => 'exact',
  77.     'externalCode' => 'partial'
  78.     'application' => 'exact',
  79.     'application.carNumber' => 'partial',
  80.     'client' => 'exact',
  81.     'contract' => 'exact',
  82.     'contract.carNumber' => 'partial',
  83.     'car' => 'exact',
  84.     'car.carNumber' => 'partial',
  85.     'travel' => 'exact'
  86. ])]
  87. #[ApiFilter(NumericFilter::class, properties: ['id'])]
  88. #[ApiFilter(RangeFilter::class, properties: [
  89.     'id',
  90.     'travel.id'
  91. ])]
  92. #[ApiFilter(DateFilter::class, properties: [
  93.     'startDate',
  94.     'endDate',
  95.     'createdAt',
  96.     'updatedAt'
  97. ])]
  98. #[ApiFilter(OrderFilter::class)]
  99. #[ApiFilter(filterClassSimpleSearchFilter::class, properties: ['externalCode'])]
  100. #[ORM\Entity(repositoryClassViolationRepository::class)]
  101. #[ORM\Table(name'`service_violations`')]
  102. #[ORM\Index(columns: ['ext_start_timestamp''ext_end_timestamp'], name'service_violations_custom_idx')]
  103. #[Gedmo\TranslationEntity(class: TranslationEntity::class)]
  104. #[UniqueEntity(fields: ['externalCode'])]
  105. class ViolationEntity
  106. {   
  107.     #[ORM\Id]
  108.     #[ORM\GeneratedValue]
  109.     #[ORM\Column(typeTypes::INTEGER)]
  110.     #[Groups(['violation:read'])]
  111.     private ?int $id null;
  112.     #[ORM\Column(typeTypes::STRINGlength255nullabletrueuniquetrue)]
  113.     #[Assert\Length(min0max255groups: ['violation:update''violation:create'])]
  114.     #[Groups(['violation:read''violation:update''violation:create'])]
  115.     #[ApiProperty(security"is_granted('ROLE_ADMIN')")]
  116.     private ?string $externalCode null;
  117.     #[ORM\Column(typeTypes::STRINGlength20nullablefalse)]
  118.     #[Assert\Length(min0max20groups: ['violation:update''violation:create'])]
  119.     #[Groups(['violation:read''violation:update''violation:create'])]
  120.     #[ApiProperty(security"is_granted('ROLE_ADMIN')")]
  121.     private string $extStartTimestamp;
  122.     #[ORM\Column(typeTypes::STRINGlength20nullablefalse)]
  123.     #[Assert\Length(min0max20groups: ['violation:update''violation:create'])]
  124.     #[Groups(['violation:read''violation:update''violation:create'])]
  125.     #[ApiProperty(security"is_granted('ROLE_ADMIN')")]
  126.     private string $extEndTimestamp;
  127.     // Клиент
  128.     #[ORM\ManyToOne(targetEntityClientEntity::class)]
  129.     #[ORM\JoinColumn(name'client_id'referencedColumnName'id'nullablefalse)]
  130.     #[Groups(['violation:read'])]
  131.     #[MaxDepth(1)]
  132.     private ClientEntity $client;
  133.     // Договор
  134.     #[ORM\ManyToOne(targetEntityContractEntity::class)]
  135.     #[ORM\JoinColumn(name'contract_id'referencedColumnName'id'nullablefalse)]
  136.     #[Groups(['violation:read'])]
  137.     #[MaxDepth(1)]
  138.     private ContractEntity $contract;
  139.     // Заявка
  140.     #[ORM\ManyToOne(targetEntityApplicationEntity::class)]
  141.     #[ORM\JoinColumn(name'application_id'referencedColumnName'id'nullablefalse)]
  142.     #[Assert\NotNull(groups: ['violation:update''violation:create'])]
  143.     #[Assert\NotBlank(groups: ['violation:update''violation:create'])]
  144.     #[Groups(['violation:read''violation:update''violation:create'])]
  145.     #[MaxDepth(1)]
  146.     private ApplicationEntity $application;
  147.     // Автомобиль
  148.     #[ORM\ManyToOne(targetEntityCarEntity::class)]
  149.     #[ORM\JoinColumn(name'car_id'referencedColumnName'id'nullablefalse)]
  150.     #[Groups(['violation:read'])]
  151.     #[MaxDepth(1)]
  152.     private CarEntity $car;
  153.     // Поездка
  154.     #[ORM\ManyToOne(targetEntityTravelEntity::class)]
  155.     #[ORM\JoinColumn(name'travel_id'referencedColumnName'id'nullablefalseonDelete'CASCADE')]
  156.     #[Groups(['violation:read'])]
  157.     #[MaxDepth(1)]
  158.     private TravelEntity $travel;
  159.     // Нарушение
  160.     #[ORM\Column(typeTypes::STRINGlength150nullablefalse)]
  161.     #[Assert\Length(min0max150groups: ['violation:update''violation:create'])]
  162.     #[Gedmo\Translatable]
  163.     #[Groups(['travel:read''violation:read''violation:update''violation:create'])]
  164.     private string $title;
  165.     // Дата начала
  166.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLEnullabletrue)]
  167.     #[Context(
  168.         normalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s'],
  169.         denormalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s']
  170.     )]
  171.     #[Groups(['travel:read''violation:read''violation:update''violation:create'])]
  172.     private ?\DateTimeInterface $startDate null;
  173.     // Адрес начала
  174.     #[ORM\Column(typeTypes::STRINGlength255nullabletrue)]
  175.     #[Assert\Length(min0max255groups: ['violation:update''violation:create'])]
  176.     #[Gedmo\Translatable]
  177.     #[Groups(['travel:read''violation:read''violation:update''violation:create'])]
  178.     private ?string $startAddress null;
  179.     // GPS координаты начала
  180.     #[ORM\Column(typeTypes::JSONnullabletrue)]
  181.     #[Groups(['travel:read''violation:read'])]
  182.     private $startGPS null;
  183.     // Дата окончания
  184.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLEnullabletrue)]
  185.     #[Context(
  186.         normalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s'],
  187.         denormalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s']
  188.     )]
  189.     #[Groups(['travel:read''violation:read''violation:update''violation:create'])]
  190.     private ?\DateTimeInterface $endDate;
  191.     // Адрес окончания
  192.     #[ORM\Column(typeTypes::STRINGlength255nullabletrue)]
  193.     #[Assert\Length(min0max255groups: ['violation:update''violation:create'])]
  194.     #[Gedmo\Translatable]
  195.     #[Groups(['travel:read''violation:read''violation:update''violation:create'])]
  196.     private ?string $endAddress null;
  197.     // GPS координаты окончания
  198.     #[ORM\Column(typeTypes::JSONnullabletrue)]
  199.     #[Groups(['travel:read''violation:read'])]
  200.     private $endGPS null;
  201.     // Значение
  202.     #[ORM\Column(typeTypes::STRINGlength50nullabletrue)]
  203.     #[Assert\Length(min0max50groups: ['violation:update''violation:create'])]
  204.     #[Gedmo\Translatable]
  205.     #[Groups(['travel:read''violation:read''violation:update''violation:create'])]
  206.     private ?string $value null;
  207.     // GPS координаты точки значения
  208.     #[ORM\Column(typeTypes::JSONnullabletrue)]
  209.     #[Groups(['travel:read'])]
  210.     private ?string $valueGPS null;
  211.     #[Gedmo\Timestampable(on'create')]
  212.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLE)]
  213.     #[Groups(['violation:read'])]
  214.     protected $createdAt;
  215.     #[Gedmo\Timestampable(on'update')]
  216.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLE)]
  217.     #[Groups(['violation:read'])]
  218.     protected $updatedAt;
  219.     /**
  220.      * Used locale to override Translation listener`s locale
  221.      * this is not a mapped field of entity metadata, just a simple property
  222.      */
  223.     #[Gedmo\Locale]
  224.     private $locale;
  225.     public function getId(): ?int
  226.     {
  227.         return $this->id;
  228.     }
  229.     public function getExternalCode(): ?string
  230.     {
  231.         return $this->externalCode;
  232.     }
  233.     public function setExternalCode($code): ?self
  234.     {
  235.         $this->externalCode $code;
  236.         return $this;
  237.     }
  238.     public function getExtStartTimestamp(): ?string
  239.     {
  240.         return $this->extStartTimestamp;
  241.     }
  242.     public function setExtStartTimestamp($value): ?self
  243.     {
  244.         $this->extStartTimestamp $value;
  245.         return $this;
  246.     }
  247.     public function getExtEndTimestamp(): ?string
  248.     {
  249.         return $this->extEndTimestamp;
  250.     }
  251.     public function setExtEndTimestamp($value): ?self
  252.     {
  253.         $this->extEndTimestamp $value;
  254.         return $this;
  255.     }
  256.     public function getClient(): ?ClientEntity
  257.     {
  258.         return $this->client;
  259.     }
  260.     public function setClient($client): ?self
  261.     {
  262.         $this->client $client;
  263.         return $this;
  264.     }
  265.     public function getContract(): ?ContractEntity
  266.     {
  267.         return $this->contract;
  268.     }
  269.     public function setContract($contract): ?self
  270.     {
  271.         $this->contract $contract;
  272.         return $this;
  273.     }
  274.     public function getApplication(): ?ApplicationEntity
  275.     {
  276.         return $this->application;
  277.     }
  278.     public function setApplication($application): ?self
  279.     {
  280.         $this->application $application;
  281.         return $this;
  282.     }
  283.     public function getCar(): ?CarEntity
  284.     {
  285.         return $this->car;
  286.     }
  287.     public function setCar($car): ?self
  288.     {
  289.         $this->car $car;
  290.         return $this;
  291.     }
  292.     public function getTravel(): ?TravelEntity
  293.     {
  294.         return $this->travel;
  295.     }
  296.     public function setTravel($travel): ?self
  297.     {
  298.         $this->travel $travel;
  299.         return $this;
  300.     }
  301.     public function getTitle(): ?string
  302.     {
  303.         return $this->title;
  304.     }
  305.     public function setTitle(?string $title): ?self
  306.     {
  307.         $this->title $title;
  308.         return $this;
  309.     }
  310.     public function setStartDate(?\DateTimeImmutable $date): ?self
  311.     {
  312.         $this->startDate $date;
  313.         return $this;
  314.     }
  315.     public function getStartDate(): ?\DateTimeInterface
  316.     {
  317.         return $this->startDate;
  318.     }
  319.     public function getStartAddress(): ?string
  320.     {
  321.         return $this->startAddress;
  322.     }
  323.     public function setStartAddress($address): ?self
  324.     {
  325.         $this->startAddress $address;
  326.         return $this;
  327.     }
  328.     public function getStartGPS()
  329.     {
  330.         return json_decode($this->startGPS ?? '[]'true);
  331.     }
  332.     public function setStartGPS(mixed $value): ?self
  333.     {
  334.         $this->startGPS json_encode($value);
  335.         return $this;
  336.     }
  337.     public function setEndDate(?\DateTimeImmutable $date): ?self
  338.     {
  339.         $this->endDate $date;
  340.         return $this;
  341.     }
  342.     public function getEndDate(): ?\DateTimeInterface
  343.     {
  344.         return $this->endDate;
  345.     }
  346.     public function getEndAddress(): ?string
  347.     {
  348.         return $this->endAddress;
  349.     }
  350.     public function setEndAddress($address): ?self
  351.     {
  352.         $this->endAddress $address;
  353.         return $this;
  354.     }
  355.     public function getEndGPS()
  356.     {
  357.         return json_decode($this->endGPS ?? '[]'true);
  358.     }
  359.     public function setEndGPS(mixed $value): ?self
  360.     {
  361.         $this->endGPS json_encode($value);
  362.         return $this;
  363.     }
  364.     public function getValue(): ?string
  365.     {
  366.         return $this->value;
  367.     }
  368.     public function setValue(?string $value): ?self
  369.     {
  370.         $this->value $value;
  371.         return $this;
  372.     }
  373.     public function getValueGPS()
  374.     {
  375.         return json_decode($this->valueGPS ?? '[]'true);
  376.     }
  377.     public function setValueGPS(mixed $value): ?self
  378.     {
  379.         $this->valueGPS json_encode($value);
  380.         return $this;
  381.     }
  382.     public function getCreatedAt(): ?\DateTimeInterface
  383.     {
  384.         return $this->createdAt;
  385.     }
  386.     public function getUpdatedAt(): ?\DateTimeInterface
  387.     {
  388.         return $this->updatedAt;
  389.     }
  390.     public function setTranslatableLocale($locale)
  391.     {
  392.         $this->locale $locale;
  393.     }
  394. }