src/Containers/ServiceSection/TravelContainer/Entities/TravelEntity.php line 221

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\Serializer\Normalizer\DateIntervalNormalizer;
  26. use Symfony\Component\Validator\Constraints as Assert;
  27. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  28. use App\Ship\ApiPlatform\Filter\SimpleSearchFilter;
  29. use App\Containers\ServiceSection\TravelContainer\Data\Repositories\TravelRepository;
  30. use App\Containers\CrmSection\ClientContainer\Entities\ClientEntity;
  31. use App\Containers\CrmSection\CarContainer\Entities\CarEntity;
  32. use App\Containers\CrmSection\ContractContainer\Entities\ContractEntity;
  33. use App\Containers\CrmSection\EquipmentContainer\Entities\ApplicationEntity;
  34. use App\Containers\ServiceSection\IndexContainer\Entities\TranslationEntity;
  35. use App\Containers\ServiceSection\TravelContainer\UI\ApiPlatform\Controllers\GetMapByTravelController;
  36. /** 
  37.  * История поездок
  38. */
  39. #[ApiResource(
  40.     routePrefix'/service',
  41.     normalizationContext: [
  42.         'groups' => ['travel:read''read'],
  43.         'enable_max_depth' => true
  44.     ],
  45.     denormalizationContext: [
  46.         'groups' => ['travel:create''travel:update']
  47.     ],
  48.     operations: [
  49.         new Get(
  50.             uriTemplate'/travels/{id}'requirements: ['id' => '\d+'],
  51.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_READONLY')"
  52.         ),
  53.         new Get(
  54.             uriTemplate'/travels/{id}/map'requirements: ['id' => '\d+'],
  55.             controllerGetMapByTravelController::class,
  56.             openapiContext: [
  57.                 'parameters' => [
  58.                     [
  59.                         'in' => 'path',
  60.                         'name' => 'id',
  61.                         'required' => true,
  62.                         'schema' => [
  63.                             'type' => 'string'
  64.                         ],
  65.                         'description' => 'TravelEntity identifier'
  66.                     ]
  67.                 ],
  68.                 'responses' => [
  69.                     '200' => [
  70.                         'description' => 'Service_Travels resource',
  71.                         'content' => [
  72.                             'application/ld+json' => [
  73.                                 'schema' => [
  74.                                     'type' => 'object',
  75.                                     'properties' => [
  76.                                         '@context' => [
  77.                                             'type' => 'string',
  78.                                             'readOnly' => true
  79.                                         ],
  80.                                         '@id' => [
  81.                                             'type' => 'string',
  82.                                             'readOnly' => true
  83.                                         ],
  84.                                         '@type' => [
  85.                                             'type' => 'string',
  86.                                             'readOnly' => true
  87.                                         ],
  88.                                         'id' => [
  89.                                             'type' => 'integer',
  90.                                             'readOnly' => true
  91.                                         ],
  92.                                         'contentUrl' => [
  93.                                             'type' => 'string',
  94.                                             'readOnly' => true
  95.                                         ]
  96.                                     ]
  97.                                 ]
  98.                             ],
  99.                             'application/json' => [
  100.                                 'schema' => [
  101.                                     'type' => 'object',
  102.                                     'properties' => [
  103.                                         '@context' => [
  104.                                             'type' => 'string',
  105.                                             'readOnly' => true
  106.                                         ],
  107.                                         '@id' => [
  108.                                             'type' => 'string',
  109.                                             'readOnly' => true
  110.                                         ],
  111.                                         '@type' => [
  112.                                             'type' => 'string',
  113.                                             'readOnly' => true
  114.                                         ],
  115.                                         'id' => [
  116.                                             'type' => 'integer',
  117.                                             'readOnly' => true
  118.                                         ],
  119.                                         'contentUrl' => [
  120.                                             'type' => 'string',
  121.                                             'readOnly' => true
  122.                                         ]
  123.                                     ]
  124.                                 ]
  125.                             ],
  126.                             'text/html' => [
  127.                                 'schema' => [
  128.                                     'type' => 'object',
  129.                                     'properties' => [
  130.                                         '@context' => [
  131.                                             'type' => 'string',
  132.                                             'readOnly' => true
  133.                                         ],
  134.                                         '@id' => [
  135.                                             'type' => 'string',
  136.                                             'readOnly' => true
  137.                                         ],
  138.                                         '@type' => [
  139.                                             'type' => 'string',
  140.                                             'readOnly' => true
  141.                                         ],
  142.                                         'id' => [
  143.                                             'type' => 'integer',
  144.                                             'readOnly' => true
  145.                                         ],
  146.                                         'contentUrl' => [
  147.                                             'type' => 'string',
  148.                                             'readOnly' => true
  149.                                         ]
  150.                                     ]
  151.                                 ]
  152.                             ]
  153.                         ]
  154.                     ],
  155.                     '404' => ['description' => 'Resource not found']
  156.                 ]
  157.             ],
  158.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_READONLY')"
  159.         ),
  160.         new Patch(
  161.             uriTemplate'/travels/{id}'requirements: ['id' => '\d+'],
  162.             security"is_granted('ROLE_ADMIN')"
  163.         ),
  164.         // new Put(
  165.         //     uriTemplate: '/travels/{id}', requirements: ['id' => '\d+'],
  166.         //     security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT')"
  167.         // ),
  168.         new Delete(
  169.             uriTemplate'/travels/{id}'requirements: ['id' => '\d+'],
  170.             security"is_granted('ROLE_ADMIN')"
  171.         ),
  172.         // new Post(
  173.         //     uriTemplate: '/travels',
  174.         //     security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT')"
  175.         // ),
  176.         new GetCollection(
  177.             uriTemplate'/travels',
  178.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_READONLY')"
  179.         ),
  180.     ],
  181.     shortName'Service_Travels'
  182. )]
  183. #[ApiFilter(SearchFilter::class, properties: [
  184.     'id' => 'exact',
  185.     'externalCode' => 'partial'
  186.     'application' => 'exact',
  187.     'application.carNumber' => 'partial',
  188.     'client' => 'exact',
  189.     'contract' => 'exact',
  190.     'contract.carNumber' => 'partial',
  191.     'car' => 'exact',
  192.     'car.carNumber' => 'partial'
  193. ])]
  194. #[ApiFilter(NumericFilter::class, properties: ['id''rating'])]
  195. #[ApiFilter(RangeFilter::class, properties: [
  196.     'id',
  197.     'rating',
  198.     'mileage',
  199.     'correctMileage',
  200.     'cityMileage',
  201.     'finalMileage',
  202.     'avgSpeed',
  203.     'maxSpeed'
  204. ])]
  205. #[ApiFilter(DateFilter::class, properties: [
  206.     'startDate',
  207.     'endDate',
  208.     'createdAt',
  209.     'updatedAt'
  210. ])]
  211. #[ApiFilter(OrderFilter::class)]
  212. #[ApiFilter(filterClassSimpleSearchFilter::class, properties: ['externalCode'])]
  213. #[ORM\Entity(repositoryClassTravelRepository::class)]
  214. #[ORM\Table(name'`service_travels`')]
  215. #[ORM\Index(columns: ['ext_start_timestamp''ext_end_timestamp''application_id'], name'service_travels_custom_idx')]
  216. #[Gedmo\TranslationEntity(class: TranslationEntity::class)]
  217. #[UniqueEntity(fields: ['externalCode'])]
  218. class TravelEntity
  219. {   
  220.     #[ORM\Id]
  221.     #[ORM\GeneratedValue]
  222.     #[ORM\Column(typeTypes::INTEGER)]
  223.     #[Groups(['travel:read'])]
  224.     private ?int $id null;
  225.     #[ORM\Column(typeTypes::STRINGlength255nullabletrueuniquetrue)]
  226.     #[Assert\Length(min0max255groups: ['travel:update''travel:create'])]
  227.     #[Groups(['travel:read''travel:update''travel:create'])]
  228.     #[ApiProperty(security"is_granted('ROLE_ADMIN')")]
  229.     private ?string $externalCode null;
  230.     #[ORM\Column(typeTypes::STRINGlength20nullablefalse)]
  231.     #[Assert\Length(min0max20groups: ['travel:update''travel:create'])]
  232.     #[Groups(['travel:read''travel:update''travel:create'])]
  233.     #[ApiProperty(security"is_granted('ROLE_ADMIN')")]
  234.     private string $extStartTimestamp;
  235.     #[ORM\Column(typeTypes::STRINGlength20nullablefalse)]
  236.     #[Assert\Length(min0max20groups: ['travel:update''travel:create'])]
  237.     #[Groups(['travel:read''travel:update''travel:create'])]
  238.     #[ApiProperty(security"is_granted('ROLE_ADMIN')")]
  239.     private string $extEndTimestamp;
  240.     // Клиент
  241.     #[ORM\ManyToOne(targetEntityClientEntity::class)]
  242.     #[ORM\JoinColumn(name'client_id'referencedColumnName'id'nullablefalse)]
  243.     #[Groups(['travel:read'])]
  244.     #[MaxDepth(1)]
  245.     private ClientEntity $client;
  246.     // Договор
  247.     #[ORM\ManyToOne(targetEntityContractEntity::class)]
  248.     #[ORM\JoinColumn(name'contract_id'referencedColumnName'id'nullablefalse)]
  249.     #[Groups(['travel:read'])]
  250.     #[MaxDepth(1)]
  251.     private ContractEntity $contract;
  252.     // Заявка
  253.     #[ORM\ManyToOne(targetEntityApplicationEntity::class)]
  254.     #[ORM\JoinColumn(name'application_id'referencedColumnName'id'nullablefalse)]
  255.     #[Assert\NotNull(groups: ['travel:update''travel:create'])]
  256.     #[Assert\NotBlank(groups: ['travel:update''travel:create'])]
  257.     #[Groups(['travel:read''travel:update''travel:create'])]
  258.     #[MaxDepth(1)]
  259.     private ApplicationEntity $application;
  260.     // Автомобиль
  261.     #[ORM\ManyToOne(targetEntityCarEntity::class)]
  262.     #[ORM\JoinColumn(name'car_id'referencedColumnName'id'nullablefalse)]
  263.     #[Groups(['travel:read'])]
  264.     #[MaxDepth(1)]
  265.     private CarEntity $car;
  266.     // Оценка
  267.     #[ORM\Column(typeTypes::FLOATscale2options: ['default' => 0.00])]
  268.     #[Groups(['travel:read''travel:update''travel:create'])]
  269.     private ?float $rating 0.00;
  270.     // Дата начала
  271.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLEnullabletrue)]
  272.     #[Context(
  273.         normalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s'],
  274.         denormalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s']
  275.     )]
  276.     #[Groups(['travel:read''travel:update''travel:create'])]
  277.     private ?\DateTimeInterface $startDate null;
  278.     // Адрес начала
  279.     #[ORM\Column(typeTypes::STRINGlength255nullabletrue)]
  280.     #[Assert\Length(min0max255groups: ['travel:update''travel:create'])]
  281.     #[Gedmo\Translatable]
  282.     #[Groups(['travel:read''travel:update''travel:create'])]
  283.     private ?string $startAddress null;
  284.     // GPS координаты начала
  285.     #[ORM\Column(typeTypes::JSONnullabletrue)]
  286.     #[Groups(['travel:read'])]
  287.     private ?string $startGPS null;
  288.     // Дата окончания
  289.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLEnullabletrue)]
  290.     #[Context(
  291.         normalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s'],
  292.         denormalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s']
  293.     )]
  294.     #[Groups(['travel:read''travel:update''travel:create'])]
  295.     private ?\DateTimeInterface $endDate null;
  296.     // Адрес окончания
  297.     #[ORM\Column(typeTypes::STRINGlength255nullabletrue)]
  298.     #[Assert\Length(min0max255groups: ['travel:update''travel:create'])]
  299.     #[Gedmo\Translatable]
  300.     #[Groups(['travel:read''travel:update''travel:create'])]
  301.     private ?string $endAddress null;
  302.     // GPS координаты окончания
  303.     #[ORM\Column(typeTypes::JSONnullabletrue)]
  304.     #[Groups(['travel:read'])]
  305.     private ?string $endGPS null;
  306.     // Продолжительность
  307.     #[ORM\Column(typeTypes::DATEINTERVALnullabletrue)]
  308.     #[Context(
  309.         normalizationContext: [DateIntervalNormalizer::FORMAT_KEY => '%H:%I:%S'],
  310.         denormalizationContext: [DateIntervalNormalizer::FORMAT_KEY => '%H:%I:%S']
  311.     )]
  312.     #[Groups(['travel:read'])]
  313.     private ?\DateInterval $duration null;
  314.     // Пробег (километры)
  315.     #[ORM\Column(typeTypes::FLOATscale4options: ['default' => 0.0000])]
  316.     #[Groups(['travel:read''travel:update''travel:create'])]
  317.     private ?float $mileage 0.0000;
  318.     // Скорректированный пробег (километры)
  319.     #[ORM\Column(typeTypes::FLOATscale4options: ['default' => 0.0000])]
  320.     #[Groups(['travel:read''travel:update''travel:create'])]
  321.     private ?float $correctMileage 0.0000;
  322.     // Городской пробег (километры)
  323.     #[ORM\Column(typeTypes::FLOATscale4options: ['default' => 0.0000])]
  324.     #[Groups(['travel:read''travel:update''travel:create'])]
  325.     private ?float $cityMileage 0.0000;
  326.     // Загородный пробег (километры)
  327.     #[ORM\Column(typeTypes::FLOATscale4options: ['default' => 0.0000])]
  328.     #[Groups(['travel:read''travel:update''travel:create'])]
  329.     private ?float $countryMileage 0.0000;
  330.     // Конечный пробег (километры)
  331.     #[ORM\Column(typeTypes::FLOATscale4options: ['default' => 0.0000])]
  332.     #[Groups(['travel:read''travel:update''travel:create'])]
  333.     private ?float $finalMileage 0.0000;
  334.     // Средняя скорость (км/ч)
  335.     #[ORM\Column(typeTypes::INTEGERoptions: ['default' => 0])]
  336.     #[Groups(['travel:read''travel:update''travel:create'])]
  337.     private ?int $avgSpeed 0;
  338.     // Максимальная скорость (км/ч)
  339.     #[ORM\Column(typeTypes::INTEGERoptions: ['default' => 0])]
  340.     #[Groups(['travel:read''travel:update''travel:create'])]
  341.     private ?int $maxSpeed 0;
  342.     // GPS координаты точки максимальной скорости
  343.     #[ORM\Column(typeTypes::JSONnullabletrue)]
  344.     #[Groups(['travel:read'])]
  345.     private ?string $maxSpeedGPS null;
  346.     // Нарушения
  347.     #[Groups(['travel:read'])]
  348.     public ?array $violations null;
  349.     #[Gedmo\Timestampable(on'create')]
  350.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLE)]
  351.     #[Groups(['travel:read'])]
  352.     protected $createdAt;
  353.     #[Gedmo\Timestampable(on'update')]
  354.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLE)]
  355.     #[Groups(['travel:read'])]
  356.     protected $updatedAt;
  357.     /**
  358.      * Used locale to override Translation listener`s locale
  359.      * this is not a mapped field of entity metadata, just a simple property
  360.      */
  361.     #[Gedmo\Locale]
  362.     private $locale;
  363.     public function getId(): ?int
  364.     {
  365.         return $this->id;
  366.     }
  367.     public function getExternalCode(): ?string
  368.     {
  369.         return $this->externalCode;
  370.     }
  371.     public function setExternalCode($code): ?self
  372.     {
  373.         $this->externalCode $code;
  374.         return $this;
  375.     }
  376.     public function getExtStartTimestamp(): ?string
  377.     {
  378.         return $this->extStartTimestamp;
  379.     }
  380.     public function setExtStartTimestamp($value): ?self
  381.     {
  382.         $this->extStartTimestamp $value;
  383.         return $this;
  384.     }
  385.     public function getExtEndTimestamp(): ?string
  386.     {
  387.         return $this->extEndTimestamp;
  388.     }
  389.     public function setExtEndTimestamp($value): ?self
  390.     {
  391.         $this->extEndTimestamp $value;
  392.         return $this;
  393.     }
  394.     public function getClient(): ?ClientEntity
  395.     {
  396.         return $this->client;
  397.     }
  398.     public function setClient($client): ?self
  399.     {
  400.         $this->client $client;
  401.         return $this;
  402.     }
  403.     public function getContract(): ?ContractEntity
  404.     {
  405.         return $this->contract;
  406.     }
  407.     public function setContract($contract): ?self
  408.     {
  409.         $this->contract $contract;
  410.         return $this;
  411.     }
  412.     public function getApplication(): ?ApplicationEntity
  413.     {
  414.         return $this->application;
  415.     }
  416.     public function setApplication($application): ?self
  417.     {
  418.         $this->application $application;
  419.         return $this;
  420.     }
  421.     public function getCar(): ?CarEntity
  422.     {
  423.         return $this->car;
  424.     }
  425.     public function setCar($car): ?self
  426.     {
  427.         $this->car $car;
  428.         return $this;
  429.     }
  430.     public function getRating(): ?float
  431.     {
  432.         return $this->rating;
  433.     }
  434.     public function setRating(?float $value): ?self
  435.     {
  436.         $this->rating = ($value round($value2) : 0.00);
  437.         return $this;
  438.     }
  439.     public function setStartDate(?\DateTimeImmutable $date): ?self
  440.     {
  441.         $this->startDate $date;
  442.         return $this;
  443.     }
  444.     public function getStartDate(): ?\DateTimeInterface
  445.     {
  446.         return $this->startDate;
  447.     }
  448.     public function getStartAddress(): ?string
  449.     {
  450.         return $this->startAddress;
  451.     }
  452.     public function setStartAddress($address): ?self
  453.     {
  454.         $this->startAddress $address;
  455.         return $this;
  456.     }
  457.     public function getStartGPS(): ?array
  458.     {
  459.         return json_decode($this->startGPS ?? '[]'true);
  460.     }
  461.     public function setStartGPS(mixed $value): ?self
  462.     {
  463.         $this->startGPS json_encode($value);
  464.         return $this;
  465.     }
  466.     public function setEndDate(?\DateTimeImmutable $date): ?self
  467.     {
  468.         $this->endDate $date;
  469.         return $this;
  470.     }
  471.     public function getEndDate(): ?\DateTimeInterface
  472.     {
  473.         return $this->endDate;
  474.     }
  475.     public function getEndAddress(): ?string
  476.     {
  477.         return $this->endAddress;
  478.     }
  479.     public function setEndAddress($address): ?self
  480.     {
  481.         $this->endAddress $address;
  482.         return $this;
  483.     }
  484.     public function getEndGPS(): ?array
  485.     {
  486.         return json_decode($this->endGPS ?? '[]'true);
  487.     }
  488.     public function setEndGPS(mixed $value): ?self
  489.     {
  490.         $this->endGPS json_encode($value);
  491.         return $this;
  492.     }
  493.     public function getMileage(): ?float
  494.     {
  495.         return $this->mileage;
  496.     }
  497.     public function setMileage(?float $value): ?self
  498.     {
  499.         $this->mileage = ($value round($value4) : 0.0000);
  500.         return $this;
  501.     }
  502.     public function getCorrectMileage(): ?float
  503.     {
  504.         return $this->correctMileage;
  505.     }
  506.     public function setCorrectMileage(?float $value): ?self
  507.     {
  508.         $this->correctMileage = ($value round($value4) : 0.0000);
  509.         return $this;
  510.     }
  511.     public function getCityMileage(): ?float
  512.     {
  513.         return $this->cityMileage;
  514.     }
  515.     public function setCityMileage(?float $value): ?self
  516.     {
  517.         $this->cityMileage = ($value round($value4) : 0.0000);
  518.         return $this;
  519.     }
  520.     public function getCountryMileage(): ?float
  521.     {
  522.         return $this->countryMileage;
  523.     }
  524.     public function setCountryMileage(?float $value): ?self
  525.     {
  526.         $this->countryMileage = ($value round($value4) : 0.0000);
  527.         return $this;
  528.     }
  529.     public function getFinalMileage(): ?float
  530.     {
  531.         return $this->finalMileage;
  532.     }
  533.     public function setFinalMileage(?float $value): ?self
  534.     {
  535.         $this->finalMileage = ($value round($value4) : 0.0000);
  536.         return $this;
  537.     }    
  538.     public function setDuration(?\DateInterval $value): ?self
  539.     {
  540.         $this->duration $value;
  541.         return $this;
  542.     }
  543.     public function getDuration(): ?\DateInterval
  544.     {
  545.         return $this->duration;
  546.     }
  547.     public function setAvgSpeed(?int $value): ?self
  548.     {
  549.         $this->avgSpeed $value;
  550.         return $this;
  551.     }
  552.     public function getAvgSpeed(): ?int
  553.     {
  554.         return $this->avgSpeed;
  555.     }
  556.     public function setMaxSpeed(?int $value): ?self
  557.     {
  558.         $this->maxSpeed $value;
  559.         return $this;
  560.     }
  561.     public function getMaxSpeed(): ?int
  562.     {
  563.         return $this->maxSpeed;
  564.     }
  565.     public function getMaxSpeedGPS(): ?array
  566.     {
  567.         return json_decode($this->maxSpeedGPS ?? '[]'true);
  568.     }
  569.     public function setMaxSpeedGPS(mixed $value): ?self
  570.     {
  571.         $this->maxSpeedGPS json_encode($value);
  572.         return $this;
  573.     }
  574.     public function getCreatedAt(): ?\DateTimeInterface
  575.     {
  576.         return $this->createdAt;
  577.     }
  578.     public function getUpdatedAt(): ?\DateTimeInterface
  579.     {
  580.         return $this->updatedAt;
  581.     }
  582.     public function setTranslatableLocale($locale)
  583.     {
  584.         $this->locale $locale;
  585.     }
  586. }