src/Containers/OscpvSection/ReminderContainer/Entities/ReminderEntity.php line 87

Open in your IDE?
  1. <?php
  2. namespace App\Containers\OscpvSection\ReminderContainer\Entities;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use ApiPlatform\Metadata\Get;
  5. use ApiPlatform\Metadata\Delete;
  6. use ApiPlatform\Metadata\GetCollection;
  7. use ApiPlatform\Metadata\Patch;
  8. use ApiPlatform\Metadata\Put;
  9. use ApiPlatform\Metadata\Post;
  10. use ApiPlatform\Metadata\ApiFilter;
  11. use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
  12. use ApiPlatform\Doctrine\Orm\Filter\NumericFilter;
  13. use ApiPlatform\Doctrine\Orm\Filter\RangeFilter;
  14. use ApiPlatform\Doctrine\Orm\Filter\DateFilter;
  15. use ApiPlatform\Doctrine\Orm\Filter\BooleanFilter;
  16. use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
  17. use Symfony\Component\Serializer\Annotation\Groups;
  18. use Symfony\Component\Serializer\Annotation\MaxDepth;
  19. use Symfony\Component\Serializer\Annotation\Context;
  20. use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
  21. use Doctrine\ORM\Mapping as ORM;
  22. use Doctrine\DBAL\Types\Types;
  23. use Gedmo\Mapping\Annotation as Gedmo;
  24. use App\Containers\OscpvSection\ReminderContainer\Data\Repositories\ReminderRepository;
  25. use App\Containers\CrmSection\ClientContainer\Entities\ClientEntity;
  26. use App\Containers\CrmSection\CarContainer\Entities\CarEntity;
  27. use App\Ship\ApiPlatform\Filter\SimpleSearchFilter;
  28. /** 
  29.  * Напоминания
  30. */
  31. #[ApiResource(
  32.     routePrefix'/oscpv',
  33.     normalizationContext: [
  34.         'groups' => 'read',
  35.         'enable_max_depth' => true
  36.     ],
  37.     operations: [
  38.         new Get(
  39.             uriTemplate'/reminders/{id}'requirements: ['id' => '\d+'],
  40.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_READONLY')"
  41.         ),
  42.         new Patch(
  43.             uriTemplate'/reminders/{id}'requirements: ['id' => '\d+'],
  44.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT')"
  45.         ),
  46.         // new Put(
  47.         //     uriTemplate: '/reminders/{id}', requirements: ['id' => '\d+'],
  48.         //     security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT')"
  49.         // ),
  50.         new Post(
  51.             uriTemplate'/reminders',
  52.             security"is_granted('ROLE_ADMIN')"
  53.         ),
  54.         new Delete(
  55.             uriTemplate'/reminders/{id}'requirements: ['id' => '\d+'],
  56.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT')"
  57.         ),
  58.         new GetCollection(
  59.             uriTemplate'/reminders',
  60.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_READONLY')"
  61.         ),
  62.     ],
  63.     shortName'OSCPV_Reminders'
  64. )]
  65. #[ApiFilter(SearchFilter::class, properties: [
  66.     'id' => 'exact'
  67.     'externalCode' => 'exact'
  68.     'client' => 'exact',
  69.     'car' => 'exact',
  70.     'client.name' => 'partial'
  71.     'client.lastName' => 'partial'
  72.     'client.patronymic' => 'partial'
  73.     'client.externalCode' => 'partial'
  74.     'car.carNumber' => 'exact'
  75.     'car.carVIN' => 'exact'
  76. ])]
  77. #[ApiFilter(NumericFilter::class, properties: ['id'])]
  78. #[ApiFilter(RangeFilter::class, properties: ['id'])]
  79. #[ApiFilter(DateFilter::class, properties: ['endDate''createdAt''updatedAt'])]
  80. #[ApiFilter(OrderFilter::class)]
  81. #[ApiFilter(filterClassSimpleSearchFilter::class, properties: ['externalCode'])]
  82. #[ORM\Entity(repositoryClassReminderRepository::class)]
  83. #[ORM\Table(name'`oscpv_reminders`')]
  84. class ReminderEntity
  85. {   
  86.     #[ORM\Id]
  87.     #[ORM\GeneratedValue]
  88.     #[ORM\Column(typeTypes::INTEGER)]
  89.     #[Groups(['read'])]
  90.     private ?int $id null;
  91.     #[ORM\Column(typeTypes::STRINGlength255nullabletrueuniquetrue)]
  92.     #[Groups(['read'])]
  93.     private ?string $externalCode null;
  94.     // Клиент
  95.     #[ORM\ManyToOne(targetEntityClientEntity::class)]
  96.     #[ORM\JoinColumn(name'client_id'referencedColumnName'id'nullablefalse)]
  97.     #[Groups(['read'])]
  98.     #[MaxDepth(2)]
  99.     private ClientEntity $client;
  100.     // Автомобиль
  101.     #[ORM\ManyToOne(targetEntityCarEntity::class)]
  102.     #[ORM\JoinColumn(name'car_id'referencedColumnName'id'nullablefalse)]
  103.     #[Groups(['read'])]
  104.     #[MaxDepth(2)]
  105.     private CarEntity $car;
  106.     // Дата окончания страховки
  107.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLEnullablefalse)]
  108.     #[Context(
  109.         normalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d'],
  110.         denormalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d']
  111.     )]
  112.     #[Groups(['read'])]
  113.     private \DateTimeInterface $endDate;
  114.     #[Gedmo\Timestampable(on'create')]
  115.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLE)]
  116.     #[Groups(['read'])]
  117.     protected $createdAt;
  118.     #[Gedmo\Timestampable(on'update')]
  119.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLE)]
  120.     #[Groups(['read'])]
  121.     protected $updatedAt;
  122.     public function getId(): ?int
  123.     {
  124.         return $this->id;
  125.     }
  126.     public function getExternalCode()
  127.     {
  128.         return $this->externalCode;
  129.     }
  130.  
  131.     public function setExternalCode($code)
  132.     {
  133.         $this->externalCode $code;
  134.         return $this;
  135.     }
  136.     public function getClient()
  137.     {
  138.         return $this->client;
  139.     }
  140.     public function setClient($client)
  141.     {
  142.         $this->client $client;
  143.         return $this;
  144.     }
  145.     public function getCar()
  146.     {
  147.         return $this->car;
  148.     }
  149.     public function setCar($car)
  150.     {
  151.         $this->car $car;
  152.         return $this;
  153.     }
  154.     public function setEndDate(\DateTimeImmutable|null $date)
  155.     {
  156.         $this->endDate $date;
  157.         return $this;
  158.     }
  159.     public function getEndDate()
  160.     {
  161.         return $this->endDate;
  162.     }
  163.     public function getCreatedAt()
  164.     {
  165.         return $this->createdAt;
  166.     }
  167.     public function getUpdatedAt()
  168.     {
  169.         return $this->updatedAt;
  170.     }
  171. }