src/Entity/JournalIndicator.php line 47
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM,
Doctrine\DBAL\Types\Types;
use Symfony\Component\Serializer\Annotation\Groups,
Symfony\Component\Validator\Constraints as Assert;
use ApiPlatform\Metadata\ApiResource,
ApiPlatform\Metadata\ApiProperty,
ApiPlatform\Metadata\Get,
ApiPlatform\Metadata\GetCollection,
ApiPlatform\Metadata\Post,
ApiPlatform\Metadata\Put,
ApiPlatform\Metadata\Delete,
ApiPlatform\Metadata\ApiFilter,
ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
use App\Entity\Trait\IdTrait,
App\Entity\Trait\UuidTrait,
App\Entity\Trait\OrdStatTrait,
App\Entity\Trait\TimestampableTrait,
App\Entity\Interface\OrdStatableInterface,
App\Repository\JournalIndicatorRepository;
use App\Filter\IriFilter;
#[ApiResource(
description: 'Journal indicators',
normalizationContext: ['groups' => ['read', 'read:' . self::class]],
denormalizationContext: ['groups' => ['write']],
security: 'is_granted("' . Journal::class . '")',
order: ['ord' => 'desc'],
operations: [
new GetCollection(),
new Post(denormalizationContext: ['groups' => ['write', 'post']]),
new Get(),
new Put(),
new Delete(),
],
extraProperties: ['standard_put' => false],
)]
#[ApiFilter(IriFilter::class, properties: ['parent'])]
#[ApiFilter(OrderFilter::class, properties: ['ord'])]
#[ORM\Entity(repositoryClass: JournalIndicatorRepository::class)]
class JournalIndicator implements OrdStatableInterface
{
use IdTrait,
UuidTrait,
OrdStatTrait,
TimestampableTrait;
#[ApiProperty(description: 'Parent', readableLink: false, writableLink: false)]
#[Groups(['read', 'post'])]
#[Assert\NotNull]
#[ORM\ManyToOne(targetEntity: Journal::class, inversedBy: 'indicators')]
#[ORM\JoinColumn(onDelete: 'cascade', nullable: false)]
private Journal $parent;
#[ApiProperty(description: 'Type', writableLink: false)]
#[Groups(['read', 'write'])]
#[Assert\NotNull]
#[ORM\ManyToOne(targetEntity: IndicatorType::class)]
#[ORM\JoinColumn(onDelete: 'cascade', nullable: false)]
private IndicatorType $type;
#[ApiProperty(description: 'Year')]
#[Groups(['read:' . self::class, 'write'])]
#[Assert\Range(min: 1900)]
#[ORM\Column(type: Types::INTEGER, nullable: true)]
private ?int $year = null;
#[ApiProperty(description: 'Value')]
#[Groups(['read:' . self::class, 'write'])]
#[ORM\Column(type: Types::STRING, nullable: true)]
private ?string $value = null;
#[ApiProperty(description: 'Description')]
#[Groups(['read:' . self::class, 'write'])]
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $description = null;
public function __construct(Journal $parent, IndicatorType $type)
{
$this->setUuid();
$this->parent = $parent;
$this->type = $type;
$this->createdAt = new \DateTimeImmutable();
$this->updatedAt = new \DateTimeImmutable();
$parent->addIndicator($this);
}
public function getParent(): Journal
{
return $this->parent;
}
public function getType(): IndicatorType
{
return $this->type;
}
public function setType(IndicatorType $type): self
{
$this->type = $type;
return $this;
}
public function getYear(): ?int
{
return $this->year;
}
public function setYear(?int $year): self
{
$this->year = $year;
return $this;
}
public function getValue(): ?string
{
return $this->value;
}
public function setValue(?string $value): self
{
$this->value = $value;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
}