src/Entity/Service.php line 39

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\Repository\ServiceRepository;
  11. use Doctrine\Common\Collections\ArrayCollection;
  12. use Doctrine\Common\Collections\Collection;
  13. use Doctrine\ORM\Mapping as ORM;
  14. use Doctrine\ORM\Mapping\Column;
  15. use Doctrine\ORM\Mapping\Id;
  16. use Ramsey\Uuid\Doctrine\UuidGenerator;
  17. use Ramsey\Uuid\UuidInterface;
  18. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  19. use Symfony\Component\Serializer\Annotation\Groups;
  20. #[ORM\Entity(repositoryClassServiceRepository::class)]
  21. #[ORM\Table]
  22. #[UniqueEntity(fields: ['url'], message'Url musi być unikalny')]
  23. #[ApiResource(
  24.     operations: [
  25.         new Get(normalizationContextself::CONTEXT_ITEM_READname'getServiceItem'),
  26.         new GetCollection(name'getServiceCollection'),
  27.     ],
  28.     normalizationContextself::CONTEXT_READ,
  29.     denormalizationContextself::CONTEXT_WRITE
  30. )]
  31. #[ApiFilter(filterClassSearchFilter::class, properties: [
  32.     'name' => 'ipartial',
  33.     'url' => 'ipartial',
  34. ])]
  35. #[ApiFilter(filterClassBooleanFilter::class, properties: ['isCaseRelated'])]
  36. class Service
  37. {
  38.     public const GROUP_ALL       'service:all';
  39.     public const GROUP_READ      'service:read';
  40.     public const GROUP_WRITE     'service:write';
  41.     public const GROUP_ITEM_READ 'service:item_read';
  42.     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>';
  43.     public const CONTEXT_READ = [
  44.         'groups'                  => [BaseContext::GROUP_ALLBaseContext::GROUP_READself::GROUP_ALLself::GROUP_READ],
  45.         'swagger_definition_name' => self::class . 'Read',
  46.         'openapi_definition_name' => self::class . 'Read',
  47.     ];
  48.     public const CONTEXT_WRITE = [
  49.         'groups'                  => [BaseContext::GROUP_ALLBaseContext::GROUP_WRITEself::GROUP_ALLself::GROUP_WRITE],
  50.         'swagger_definition_name' => self::class . 'Write',
  51.         'openapi_definition_name' => self::class . 'Write',
  52.     ];
  53.     public const CONTEXT_ITEM_READ = [
  54.         'groups'                  => [BaseContext::GROUP_ALLBaseContext::GROUP_READself::GROUP_ALLself::GROUP_READself::GROUP_ITEM_READ],
  55.         'swagger_definition_name' => self::class . 'ItemRead',
  56.         'openapi_definition_name' => self::class . 'ItemRead',
  57.     ];
  58.     #[Id]
  59.     #[Column(type'uuid'nullablefalse)]
  60.     #[ORM\GeneratedValue(strategy'CUSTOM')]
  61.     #[ORM\CustomIdGenerator(class: UuidGenerator::class)]
  62.     #[Groups([self::GROUP_READBaseContext::GROUP_READ])]
  63.     protected UuidInterface $id;
  64.     #[Groups([self::GROUP_READBaseContext::GROUP_READ])]
  65.     #[ORM\Column(type'string'length4000)]
  66.     public ?string $name null;
  67.     #[Groups([self::GROUP_READBaseContext::GROUP_READ])]
  68.     #[ORM\Column(type'string'length255)]
  69.     public ?string $icon null;
  70.     #[Groups([self::GROUP_READBaseContext::GROUP_READ])]
  71.     #[ORM\Column(type'string'length4000uniquetrue)]
  72.     public ?string $url null;
  73.     #[Groups([self::GROUP_READBaseContext::GROUP_READ])]
  74.     #[ORM\Column(type'string'length255nullabletrue)]
  75.     public ?string $code null;
  76.     #[ORM\Column(type'integer')]
  77.     public ?int $position null;
  78.     #[Groups([self::GROUP_READBaseContext::GROUP_READ])]
  79.     #[ORM\Column(type'text',nullabletrue)]
  80.     public ?string $description null;
  81.     #[Groups([self::GROUP_READself::GROUP_ITEM_READBaseContext::GROUP_READ])]
  82.     #[ORM\Column(type'text'nullabletrue)]
  83.     public ?string $content null;
  84.     #[Groups([self::GROUP_READBaseContext::GROUP_READ])]
  85.     #[ORM\Column(type'boolean')]
  86.     public bool $isActive true;
  87.     #[Groups([self::GROUP_READBaseContext::GROUP_READ])]
  88.     #[ORM\Column(type'boolean')]
  89.     public bool $isCaseRelated false;
  90.     #[ORM\ManyToOne]
  91.     public ?DocumentTemplate $documentTemplate null;
  92.     #[Groups([self::GROUP_READApplication::GROUP_READ])]
  93.     #[ORM\OneToMany(mappedBy'service'targetEntityServiceAttachmentPosition::class, orphanRemovaltrue,cascade: ['persist''remove'])]
  94.     private Collection $serviceAttachmentPositions;
  95.     #[Groups([self::GROUP_READself::GROUP_ITEM_READBaseContext::GROUP_READ])]
  96.     #[ORM\Column(type'text'nullabletrue)]
  97.     public ?string $gdpr null;
  98.     #[Groups([self::GROUP_READBaseContext::GROUP_READ])]
  99.     #[ORM\Column(type'text'nullabletrue)]
  100.     public ?string $editorFooterContent null;
  101.     public function __construct()
  102.     {
  103.         $this->serviceAttachmentPositions = new ArrayCollection();
  104.         $this->editorFooterContent self::DEFAULT_FOOTER_CONTENT;
  105.     }
  106.     public function getId(): UuidInterface
  107.     {
  108.         return $this->id;
  109.     }
  110.     #[Groups([self::GROUP_READ])]
  111.     public function getUuid(): UuidInterface
  112.     {
  113.         return $this->id;
  114.     }
  115.     /**
  116.      * @return Collection<int, ServiceAttachmentPosition>
  117.      */
  118.     public function getServiceAttachmentPositions(): Collection
  119.     {
  120.         return $this->serviceAttachmentPositions;
  121.     }
  122.     public function addServiceAttachmentPosition(ServiceAttachmentPosition $serviceAttachmentPosition): self
  123.     {
  124.         if (!$this->serviceAttachmentPositions->contains($serviceAttachmentPosition)) {
  125.             $this->serviceAttachmentPositions->add($serviceAttachmentPosition);
  126.             $serviceAttachmentPosition->setService($this);
  127.         }
  128.         return $this;
  129.     }
  130.     public function removeServiceAttachmentPosition(ServiceAttachmentPosition $serviceAttachmentPosition): self
  131.     {
  132.         if ($this->serviceAttachmentPositions->removeElement($serviceAttachmentPosition)) {
  133.             // set the owning side to null (unless already changed)
  134.             if ($serviceAttachmentPosition->getService() === $this) {
  135.                 $serviceAttachmentPosition->setService(null);
  136.             }
  137.         }
  138.         return $this;
  139.     }
  140. }