src/Entity/Service.php line 40

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
  4. use ApiPlatform\Doctrine\Orm\Filter\BooleanFilter;
  5. use ApiPlatform\Metadata\ApiFilter;
  6. use ApiPlatform\Metadata\ApiResource;
  7. use ApiPlatform\Metadata\Get;
  8. use ApiPlatform\Metadata\GetCollection;
  9. use App\BaseContext;
  10. use App\Entity\Dictionary\RoadOccupationPurpose;
  11. use App\Repository\ServiceRepository;
  12. use Doctrine\Common\Collections\ArrayCollection;
  13. use Doctrine\Common\Collections\Collection;
  14. use Doctrine\ORM\Mapping as ORM;
  15. use Doctrine\ORM\Mapping\Column;
  16. use Doctrine\ORM\Mapping\Id;
  17. use Ramsey\Uuid\Doctrine\UuidGenerator;
  18. use Ramsey\Uuid\UuidInterface;
  19. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  20. use Symfony\Component\Serializer\Annotation\Groups;
  21. #[ORM\Entity(repositoryClass: ServiceRepository::class)]
  22. #[ORM\Table]
  23. #[UniqueEntity(fields: ['url'], message: 'Url musi być unikalny')]
  24. #[ApiResource(
  25.     operations: [
  26.         new Get(normalizationContext: self::CONTEXT_ITEM_READ, name: 'getServiceItem'),
  27.         new GetCollection(name: 'getServiceCollection'),
  28.     ],
  29.     normalizationContext: self::CONTEXT_READ,
  30.     denormalizationContext: self::CONTEXT_WRITE
  31. )]
  32. #[ApiFilter(filterClass: SearchFilter::class, properties: [
  33.     'name' => 'ipartial',
  34.     'url' => 'ipartial',
  35. ])]
  36. #[ApiFilter(filterClass: BooleanFilter::class, properties: ['isCaseRelated'])]
  37. class Service
  38. {
  39.     public const GROUP_ALL       = 'service:all';
  40.     public const GROUP_READ      = 'service:read';
  41.     public const GROUP_WRITE     = 'service:write';
  42.     public const GROUP_ITEM_READ = 'service:item_read';
  43.     public const DEFAULT_FOOTER_CONTENT = '<p><small> Szczegółowe informacje na temat realizacji procesu uzyskać można pod nr telefonu <a href="tel:74 66 55 121">74 66 55 121</a></small></p>';
  44.     public const CONTEXT_READ = [
  45.         'groups'                  => [BaseContext::GROUP_ALL, BaseContext::GROUP_READ, self::GROUP_ALL, self::GROUP_READ],
  46.         'swagger_definition_name' => self::class . 'Read',
  47.         'openapi_definition_name' => self::class . 'Read',
  48.     ];
  49.     public const CONTEXT_WRITE = [
  50.         'groups'                  => [BaseContext::GROUP_ALL, BaseContext::GROUP_WRITE, self::GROUP_ALL, self::GROUP_WRITE],
  51.         'swagger_definition_name' => self::class . 'Write',
  52.         'openapi_definition_name' => self::class . 'Write',
  53.     ];
  54.     public const CONTEXT_ITEM_READ = [
  55.         'groups'                  => [BaseContext::GROUP_ALL, BaseContext::GROUP_READ, self::GROUP_ALL, self::GROUP_READ, self::GROUP_ITEM_READ],
  56.         'swagger_definition_name' => self::class . 'ItemRead',
  57.         'openapi_definition_name' => self::class . 'ItemRead',
  58.     ];
  59.     #[Id]
  60.     #[Column(type: 'uuid', nullable: false)]
  61.     #[ORM\GeneratedValue(strategy: 'CUSTOM')]
  62.     #[ORM\CustomIdGenerator(class: UuidGenerator::class)]
  63.     #[Groups([self::GROUP_READ, BaseContext::GROUP_READ])]
  64.     protected UuidInterface $id;
  65.     #[Groups([self::GROUP_READ, BaseContext::GROUP_READ])]
  66.     #[ORM\Column(type: 'string', length: 4000)]
  67.     public ?string $name = null;
  68.     #[Groups([self::GROUP_READ, BaseContext::GROUP_READ])]
  69.     #[ORM\Column(type: 'string', length: 255)]
  70.     public ?string $icon = null;
  71.     #[Groups([self::GROUP_READ, BaseContext::GROUP_READ])]
  72.     #[ORM\Column(type: 'string', length: 4000, unique: true)]
  73.     public ?string $url = null;
  74.     #[Groups([self::GROUP_READ, BaseContext::GROUP_READ])]
  75.     #[ORM\Column(type: 'string', length: 255, nullable: true)]
  76.     public ?string $code = null;
  77.     #[ORM\Column(type: 'integer')]
  78.     public ?int $position = null;
  79.     #[Groups([self::GROUP_READ, BaseContext::GROUP_READ])]
  80.     #[ORM\Column(type: 'text',nullable: true)]
  81.     public ?string $description = null;
  82.     #[Groups([self::GROUP_READ, self::GROUP_ITEM_READ, BaseContext::GROUP_READ])]
  83.     #[ORM\Column(type: 'text', nullable: true)]
  84.     public ?string $content = null;
  85.     #[Groups([self::GROUP_READ, BaseContext::GROUP_READ])]
  86.     #[ORM\Column(type: 'boolean')]
  87.     public bool $isActive = true;
  88.     #[Groups([self::GROUP_READ, BaseContext::GROUP_READ])]
  89.     #[ORM\Column(type: 'boolean')]
  90.     public bool $isCaseRelated = false;
  91.     #[ORM\ManyToOne]
  92.     public ?DocumentTemplate $documentTemplate = null;
  93.     #[Groups([self::GROUP_READ, Application::GROUP_READ])]
  94.     #[ORM\OneToMany(mappedBy: 'service', targetEntity: ServiceAttachmentPosition::class, orphanRemoval: true,cascade: ['persist', 'remove'])]
  95.     private Collection $serviceAttachmentPositions;
  96.     #[Groups([self::GROUP_READ, self::GROUP_ITEM_READ, BaseContext::GROUP_READ])]
  97.     #[ORM\Column(type: 'text', nullable: true)]
  98.     public ?string $gdpr = null;
  99.     #[Groups([self::GROUP_READ, BaseContext::GROUP_READ])]
  100.     #[ORM\Column(type: 'text', nullable: true)]
  101.     public ?string $editorFooterContent = null;
  102.     /**
  103.      * @var Collection<int, RoadOccupationPurpose> Cele zajetosci pasa drogowego przypisane do e-uslugi
  104.      */
  105.     #[Groups([self::GROUP_READ, self::GROUP_ITEM_READ, Application::GROUP_READ])]
  106.     #[ORM\OneToMany(mappedBy: 'service', targetEntity: RoadOccupationPurpose::class)]
  107.     private Collection $roadOccupationPurposes;
  108.     public function __construct()
  109.     {
  110.         $this->serviceAttachmentPositions = new ArrayCollection();
  111.         $this->roadOccupationPurposes     = new ArrayCollection();
  112.         $this->editorFooterContent = self::DEFAULT_FOOTER_CONTENT;
  113.     }
  114.     public function getId(): UuidInterface
  115.     {
  116.         return $this->id;
  117.     }
  118.     #[Groups([self::GROUP_READ])]
  119.     public function getUuid(): UuidInterface
  120.     {
  121.         return $this->id;
  122.     }
  123.     /**
  124.      * @return Collection<int, ServiceAttachmentPosition>
  125.      */
  126.     public function getServiceAttachmentPositions(): Collection
  127.     {
  128.         return $this->serviceAttachmentPositions;
  129.     }
  130.     public function addServiceAttachmentPosition(ServiceAttachmentPosition $serviceAttachmentPosition): self
  131.     {
  132.         if (!$this->serviceAttachmentPositions->contains($serviceAttachmentPosition)) {
  133.             $this->serviceAttachmentPositions->add($serviceAttachmentPosition);
  134.             $serviceAttachmentPosition->setService($this);
  135.         }
  136.         return $this;
  137.     }
  138.     public function removeServiceAttachmentPosition(ServiceAttachmentPosition $serviceAttachmentPosition): self
  139.     {
  140.         if ($this->serviceAttachmentPositions->removeElement($serviceAttachmentPosition)) {
  141.             // set the owning side to null (unless already changed)
  142.             if ($serviceAttachmentPosition->getService() === $this) {
  143.                 $serviceAttachmentPosition->setService(null);
  144.             }
  145.         }
  146.         return $this;
  147.     }
  148.     /**
  149.      * @return Collection<int, RoadOccupationPurpose>
  150.      */
  151.     public function getRoadOccupationPurposes(): Collection
  152.     {
  153.         return $this->roadOccupationPurposes;
  154.     }
  155.     public function addRoadOccupationPurpose(RoadOccupationPurpose $roadOccupationPurpose): self
  156.     {
  157.         if (!$this->roadOccupationPurposes->contains($roadOccupationPurpose)) {
  158.             $this->roadOccupationPurposes->add($roadOccupationPurpose);
  159.             $roadOccupationPurpose->service = $this;
  160.         }
  161.         return $this;
  162.     }
  163.     public function removeRoadOccupationPurpose(RoadOccupationPurpose $roadOccupationPurpose): self
  164.     {
  165.         if ($this->roadOccupationPurposes->removeElement($roadOccupationPurpose)) {
  166.             if ($roadOccupationPurpose->service === $this) {
  167.                 $roadOccupationPurpose->service = null;
  168.             }
  169.         }
  170.         return $this;
  171.     }
  172. }