src/Entity/JournalIndicator.php line 47

  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM,
  4.     Doctrine\DBAL\Types\Types;
  5. use Symfony\Component\Serializer\Annotation\Groups,
  6.     Symfony\Component\Validator\Constraints as Assert;
  7. use ApiPlatform\Metadata\ApiResource,
  8.     ApiPlatform\Metadata\ApiProperty,
  9.     ApiPlatform\Metadata\Get,
  10.     ApiPlatform\Metadata\GetCollection,
  11.     ApiPlatform\Metadata\Post,
  12.     ApiPlatform\Metadata\Put,
  13.     ApiPlatform\Metadata\Delete,
  14.     ApiPlatform\Metadata\ApiFilter,
  15.     ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
  16. use App\Entity\Trait\IdTrait,
  17.     App\Entity\Trait\UuidTrait,
  18.     App\Entity\Trait\OrdStatTrait,
  19.     App\Entity\Trait\TimestampableTrait,
  20.     App\Entity\Interface\OrdStatableInterface,
  21.     App\Repository\JournalIndicatorRepository;
  22. use App\Filter\IriFilter;
  23. #[ApiResource(
  24.     description'Journal indicators',
  25.     normalizationContext: ['groups' => ['read''read:' self::class]],
  26.     denormalizationContext: ['groups' => ['write']],
  27.     security'is_granted("' Journal::class . '")',
  28.     order: ['ord' => 'desc'],
  29.     operations: [
  30.         new GetCollection(),
  31.         new Post(denormalizationContext: ['groups' => ['write',  'post']]),
  32.         new Get(),
  33.         new Put(),
  34.         new Delete(),
  35.     ],
  36.     extraProperties: ['standard_put' => false],
  37. )]
  38. #[ApiFilter(IriFilter::class, properties: ['parent'])]
  39. #[ApiFilter(OrderFilter::class, properties: ['ord'])]
  40. #[ORM\Entity(repositoryClassJournalIndicatorRepository::class)]
  41. class JournalIndicator implements OrdStatableInterface
  42. {
  43.     use IdTrait,
  44.         UuidTrait,
  45.         OrdStatTrait,
  46.         TimestampableTrait;
  47.     #[ApiProperty(description'Parent'readableLinkfalsewritableLinkfalse)]
  48.     #[Groups(['read''post'])]
  49.     #[Assert\NotNull]
  50.     #[ORM\ManyToOne(targetEntityJournal::class, inversedBy'indicators')]
  51.     #[ORM\JoinColumn(onDelete'cascade'nullablefalse)]
  52.     private Journal $parent;
  53.     #[ApiProperty(description'Type'writableLinkfalse)]
  54.     #[Groups(['read''write'])]
  55.     #[Assert\NotNull]
  56.     #[ORM\ManyToOne(targetEntityIndicatorType::class)]
  57.     #[ORM\JoinColumn(onDelete'cascade'nullablefalse)]
  58.     private IndicatorType $type;
  59.     #[ApiProperty(description'Year')]
  60.     #[Groups(['read:' self::class, 'write'])]
  61.     #[Assert\Range(min1900)]
  62.     #[ORM\Column(typeTypes::INTEGERnullabletrue)]
  63.     private ?int $year null;
  64.     #[ApiProperty(description'Value')]
  65.     #[Groups(['read:' self::class, 'write'])]
  66.     #[ORM\Column(typeTypes::STRINGnullabletrue)]
  67.     private ?string $value null;
  68.     #[ApiProperty(description'Description')]
  69.     #[Groups(['read:' self::class, 'write'])]
  70.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  71.     private ?string $description null;
  72.     public function __construct(Journal $parentIndicatorType $type)
  73.     {
  74.         $this->setUuid();
  75.         $this->parent $parent;
  76.         $this->type $type;
  77.         $this->createdAt = new \DateTimeImmutable();
  78.         $this->updatedAt = new \DateTimeImmutable();
  79.         $parent->addIndicator($this);
  80.     }
  81.     public function getParent(): Journal
  82.     {
  83.         return $this->parent;
  84.     }
  85.     public function getType(): IndicatorType
  86.     {
  87.         return $this->type;
  88.     }
  89.     public function setType(IndicatorType $type): self
  90.     {
  91.         $this->type $type;
  92.         return $this;
  93.     }
  94.     public function getYear(): ?int
  95.     {
  96.         return $this->year;
  97.     }
  98.     public function setYear(?int $year): self
  99.     {
  100.         $this->year $year;
  101.         return $this;
  102.     }
  103.     public function getValue(): ?string
  104.     {
  105.         return $this->value;
  106.     }
  107.     public function setValue(?string $value): self
  108.     {
  109.         $this->value $value;
  110.         return $this;
  111.     }
  112.     public function getDescription(): ?string
  113.     {
  114.         return $this->description;
  115.     }
  116.     public function setDescription(?string $description): self
  117.     {
  118.         $this->description $description;
  119.         return $this;
  120.     }
  121. }