src/Entity/ItemIndicator.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\ItemIndicator\ItemIndicatorGetAction;
  7. use App\Entity\Mapped\Entity;
  8. use App\Repository\ItemIndicatorRepository;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. use Doctrine\ORM\Mapping as ORM;
  11. use Symfony\Component\Validator\Constraints as Assert;
  12. #[ORM\Entity(
  13.     repositoryClassItemIndicatorRepository::class
  14. )]
  15. #[ORM\Table(
  16.     name'item_indicator'
  17. )]
  18. #[ApiResource(
  19.     collectionOperations: [
  20.         'post' => [
  21.             'validation_groups' => [
  22.                 'create'
  23.             ]
  24.         ],
  25.         'get_list' => [
  26.             'controller' => ItemIndicatorGetAction::class,
  27.             'method' => 'GET',
  28.             'path' => '/item/{id}/indicators'
  29.         ]
  30.     ],
  31.     itemOperations: [
  32.         'get',
  33.         'delete',
  34.         'put' => [
  35.             'validation_groups' => [
  36.                 'update'
  37.             ]
  38.         ]
  39.     ]
  40. )]
  41. class ItemIndicator extends Entity
  42. {
  43.     #[ORM\ManyToOne(
  44.         targetEntityItem::class,
  45.         cascade: ['persist'],
  46.         inversedBy'indicators'
  47.     )]
  48.     #[ORM\JoinColumn(
  49.         name'item'
  50.     )]
  51.     #[Assert\NotBlank(
  52.         groups: ['create''update']
  53.     )]
  54.     #[ApiSubresource]
  55.     private ?Item $item null;
  56.     #[ORM\ManyToOne(
  57.         targetEntityIndicator::class,
  58.         cascade: ['persist']
  59.     )]
  60.     #[ORM\JoinColumn(
  61.         name'indicator'
  62.     )]
  63.     #[Assert\NotBlank(
  64.         groups: ['create''update']
  65.     )]
  66.     #[ApiSubresource]
  67.     private ?Indicator $indicator null;
  68.     #[ORM\OneToMany(
  69.         mappedBy'itemIndicator',
  70.         targetEntityItemDocumentIndicator::class,
  71.         cascade: ['persist'],
  72.         fetch'EXTRA_LAZY',
  73.         orphanRemovaltrue
  74.     )]
  75.     private iterable $documentIndicators;
  76.     public function __construct()
  77.     {
  78.         $this->documentIndicators = new ArrayCollection();
  79.     }
  80.     public function getItem(): ?Item
  81.     {
  82.         return $this->item;
  83.     }
  84.     public function setItem(?Item $item): self
  85.     {
  86.         $this->item $item;
  87.         return $this;
  88.     }
  89.     public function getIndicator(): ?Indicator
  90.     {
  91.         return $this->indicator;
  92.     }
  93.     public function setIndicator(?Indicator $indicator): self
  94.     {
  95.         $this->indicator $indicator;
  96.         return $this;
  97.     }
  98.     public function getDocumentIndicators(): iterable
  99.     {
  100.         return $this->documentIndicators;
  101.     }
  102.     public function addDocumentIndicator(ItemDocumentIndicator $itemDocumentIndicator): void
  103.     {
  104.         if ($this->documentIndicators->contains($itemDocumentIndicator)) {
  105.             return;
  106.         }
  107.         $this->documentIndicators[] = $itemDocumentIndicator;
  108.         $itemDocumentIndicator->setItemIndicator($this);
  109.     }
  110.     public function removeDocumentIndicator(ItemDocumentIndicator $itemDocumentIndicator): void
  111.     {
  112.         if (!$this->documentIndicators->contains($itemDocumentIndicator)) {
  113.             return;
  114.         }
  115.         $this->documentIndicators->removeElement($itemDocumentIndicator);
  116.         $itemDocumentIndicator->setItemIndicator(null);
  117.     }
  118. }