src/Entity/ItemDocument.php line 45

  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use ApiPlatform\Core\Annotation\ApiSubresource;
  6. use App\Controller\Api\Action\ItemDocument\ItemDocumentGetAction;
  7. use App\Controller\Api\Action\ItemDocument\ItemDocumentPostAction;
  8. use App\Entity\Mapped\Entity;
  9. use App\Repository\ItemDocumentRepository;
  10. use Doctrine\Common\Collections\ArrayCollection;
  11. use Doctrine\ORM\Mapping as ORM;
  12. use Symfony\Component\Serializer\Annotation\Groups;
  13. use Symfony\Component\Validator\Constraints as Assert;
  14. #[ORM\Entity(
  15.     repositoryClassItemDocumentRepository::class
  16. )]
  17. #[ORM\Table(
  18.     name'item_document'
  19. )]
  20. #[ApiResource(
  21.     collectionOperations: [
  22.         'post' => [
  23.             'controller' => ItemDocumentPostAction::class
  24.         ],
  25.         'get_list' => [
  26.             'controller' => ItemDocumentGetAction::class,
  27.             'method' => 'GET',
  28.             'path' => '/item/{id}/documents'
  29.         ],
  30.     ],
  31.     itemOperations: [
  32.         'get',
  33.         'delete'
  34.     ],
  35.     denormalizationContext: [
  36.         'groups' => [
  37.             'create'
  38.         ]
  39.     ]
  40. )]
  41. class ItemDocument extends Entity implements DocumentInterface
  42. {
  43.     #[ORM\Column(
  44.         name'name',
  45.         type'string',
  46.         length191,
  47.         nullabletrue
  48.     )]
  49.     #[Assert\NotBlank(
  50.         groups: ['create']
  51.     )]
  52.     #[Groups(['create'])]
  53.     private ?string $name null;
  54.     #[ORM\Column(
  55.         name'original_name',
  56.         type'string',
  57.         length191,
  58.         nullabletrue
  59.     )]
  60.     private ?string $originalName null;
  61.     #[ORM\Column(
  62.         name'full_document_path',
  63.         type'string',
  64.         nullabletrue
  65.     )]
  66.     private ?string $fullDocumentPath null;
  67.     #[ORM\Column(
  68.         name'sequence',
  69.         type'integer',
  70.         nullabletrue
  71.     )]
  72.     private ?int $sequence null;
  73.     #[ORM\ManyToOne(
  74.         targetEntityItem::class,
  75.         cascade: ['persist'],
  76.         inversedBy'document'
  77.     )]
  78.     #[ORM\JoinColumn(
  79.         name'item',
  80.         onDelete'CASCADE'
  81.     )]
  82.     #[Assert\NotBlank(
  83.         groups: ['create']
  84.     )]
  85.     #[Groups(['create'])]
  86.     #[ApiSubresource]
  87.     private ?Item $item null;
  88.     #[Assert\NotBlank(
  89.         groups: ['create']
  90.     )]
  91.     #[Groups(['create'])]
  92.     private ?string $file null;
  93.     #[ORM\OneToMany(
  94.         mappedBy'itemDocument',
  95.         targetEntityItemDocumentReport::class,
  96.         cascade: ['persist''remove'],
  97.         fetch'EXTRA_LAZY',
  98.         orphanRemovaltrue
  99.     )]
  100.     #[Groups(['create'])]
  101.     private ?iterable $reports;
  102.     #[ORM\OneToMany(
  103.         mappedBy'itemDocument',
  104.         targetEntityItemDocumentIndicator::class,
  105.         cascade: ['persist'],
  106.         fetch'EXTRA_LAZY',
  107.         orphanRemovaltrue
  108.     )]
  109.     private iterable $documentIndicators;
  110.     public function __construct()
  111.     {
  112.         $this->reports = new ArrayCollection();
  113.         $this->documentIndicators = new ArrayCollection();
  114.     }
  115.     public function getOriginalName(): ?string
  116.     {
  117.         return $this->originalName;
  118.     }
  119.     public function setOriginalName(?string $originalName): self
  120.     {
  121.         $this->originalName $originalName;
  122.         return $this;
  123.     }
  124.     public function getFullDocumentPath(): ?string
  125.     {
  126.         return $this->fullDocumentPath;
  127.     }
  128.     public function setFullDocumentPath(?string $fullDocumentPath): self
  129.     {
  130.         $this->fullDocumentPath $fullDocumentPath;
  131.         return $this;
  132.     }
  133.     public function getSequence(): ?int
  134.     {
  135.         return $this->sequence;
  136.     }
  137.     public function setSequence(?int $sequence): self
  138.     {
  139.         $this->sequence $sequence;
  140.         return $this;
  141.     }
  142.     public function getItem(): ?Item
  143.     {
  144.         return $this->item;
  145.     }
  146.     public function setItem(?Item $item): self
  147.     {
  148.         $this->item $item;
  149.         return $this;
  150.     }
  151.     public function getName(): ?string
  152.     {
  153.         return $this->name;
  154.     }
  155.     public function setName(?string $name): self
  156.     {
  157.         $this->name $name;
  158.         return $this;
  159.     }
  160.     public function getFile(): ?string
  161.     {
  162.         return $this->file;
  163.     }
  164.     public function setFile(?string $file): self
  165.     {
  166.         $this->file $file;
  167.         return $this;
  168.     }
  169.     public function getReports(): ?iterable
  170.     {
  171.         return $this->reports;
  172.     }
  173.     public function addReport(ItemDocumentReport $itemDocumentReport): void
  174.     {
  175.         if ($this->reports->contains($itemDocumentReport)) {
  176.             return;
  177.         }
  178.         $this->reports[] = $itemDocumentReport;
  179.         $itemDocumentReport->setItemDocument($this);
  180.     }
  181.     public function removeReport(ItemDocumentReport $itemDocumentReport): void
  182.     {
  183.         if (!$this->reports->contains($itemDocumentReport)) {
  184.             return;
  185.         }
  186.         $this->reports->removeElement($itemDocumentReport);
  187.         $itemDocumentReport->setItemDocument(null);
  188.     }
  189.     public function getDocumentIndicators(): iterable
  190.     {
  191.         return $this->documentIndicators;
  192.     }
  193.     public function addDocumentIndicator(ItemDocumentIndicator $itemDocumentIndicator): void
  194.     {
  195.         if ($this->documentIndicators->contains($itemDocumentIndicator)) {
  196.             return;
  197.         }
  198.         $this->documentIndicators[] = $itemDocumentIndicator;
  199.         $itemDocumentIndicator->setItemDocument($this);
  200.     }
  201.     public function removeDocumentIndicator(ItemDocumentIndicator $itemDocumentIndicator): void
  202.     {
  203.         if (!$this->documentIndicators->contains($itemDocumentIndicator)) {
  204.             return;
  205.         }
  206.         $this->documentIndicators->removeElement($itemDocumentIndicator);
  207.         $itemDocumentIndicator->setItemDocument(null);
  208.     }
  209. }