src/Entity/ItemDocumentIndicator.php line 32

  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\Entity\Mapped\Entity;
  7. use App\Repository\ItemDocumentIndicatorRepository;
  8. use App\Validator\Constraint as CustomValidator;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Symfony\Component\Validator\Constraints as Assert;
  11. #[ORM\Entity(
  12.     repositoryClassItemDocumentIndicatorRepository::class
  13. )]
  14. #[ORM\Table(
  15.     name'item_document_indicator'
  16. )]
  17. #[ApiResource(
  18.     collectionOperations: [],
  19.     itemOperations: [
  20.         'get',
  21.         'patch' => [
  22.             'validation_groups' => [
  23.                 'update'
  24.             ]
  25.         ]
  26.     ]
  27. )]
  28. class ItemDocumentIndicator extends Entity
  29. {
  30.     #[ORM\Column(
  31.         name'value',
  32.         type'decimal',
  33.         precision20,
  34.         scale2,
  35.         nullabletrue
  36.     )]
  37.     #[Assert\NotBlank(
  38.         groups: ['update']
  39.     )]
  40.     #[CustomValidator\PriceFormat(
  41.         groups: ['update'],
  42.         message'item.invalidFormat'
  43.     )]
  44.     private ?string $value '0';
  45.     #[ORM\ManyToOne(
  46.         targetEntityItemIndicator::class,
  47.         cascade: ['persist'],
  48.         inversedBy'documentIndicators'
  49.     )]
  50.     #[ORM\JoinColumn(
  51.         name'item_indicator'
  52.     )]
  53.     #[Assert\NotBlank(
  54.         groups: ['create''update']
  55.     )]
  56.     #[ApiSubresource]
  57.     private ?ItemIndicator $itemIndicator null;
  58.     #[ORM\ManyToOne(
  59.         targetEntityItemDocument::class,
  60.         cascade: ['persist'],
  61.         inversedBy'documentIndicators'
  62.     )]
  63.     #[ORM\JoinColumn(
  64.         name'item_document'
  65.     )]
  66.     #[Assert\NotBlank(
  67.         groups: ['create''update']
  68.     )]
  69.     #[ApiSubresource]
  70.     private ?ItemDocument $itemDocument null;
  71.     public function getItemIndicator(): ?ItemIndicator
  72.     {
  73.         return $this->itemIndicator;
  74.     }
  75.     public function getValue(): ?string
  76.     {
  77.         if (
  78.             $this->value
  79.             &&
  80.             str_contains($this->value',')
  81.         ) {
  82.             return $this->value;
  83.         }
  84.         return $this->value number_format((float) $this->value2',''.') : null;
  85.     }
  86.     public function setValue(?string $value): self
  87.     {
  88.         $this->value $value;
  89.         return $this;
  90.     }
  91.     public function setItemIndicator(?ItemIndicator $itemIndicator): self
  92.     {
  93.         $this->itemIndicator $itemIndicator;
  94.         return $this;
  95.     }
  96.     public function getItemDocument(): ?ItemDocument
  97.     {
  98.         return $this->itemDocument;
  99.     }
  100.     public function setItemDocument(?ItemDocument $itemDocument): self
  101.     {
  102.         $this->itemDocument $itemDocument;
  103.         return $this;
  104.     }
  105. }