src/Entity/CitationType.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\Put,
ApiPlatform\Metadata\ApiFilter,
ApiPlatform\Doctrine\Orm\Filter\SearchFilter,
ApiPlatform\Doctrine\Orm\Filter\BooleanFilter,
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\CitationTypeRepository;
use App\Attribute\Sanitizeable;
use App\Enum\PredefinedCitationType;
#[ApiResource(
description: 'Citation types',
normalizationContext: ['groups' => ['read', 'read:' . self::class]],
denormalizationContext: ['groups' => ['write']],
security: 'is_granted("' . self::class . '")',
order: ['ord' => 'desc'],
operations: [
new GetCollection(),
new Get(),
new Put(),
],
extraProperties: ['standard_put' => false],
)]
#[ApiFilter(SearchFilter::class, properties: ['title' => 'partial'])]
#[ApiFilter(BooleanFilter::class, properties: ['stat'])]
#[ApiFilter(OrderFilter::class, properties: ['ord'])]
#[ORM\Entity(repositoryClass: CitationTypeRepository::class)]
class CitationType implements OrdStatableInterface
{
use IdTrait,
UuidTrait,
OrdStatTrait,
TimestampableTrait;
#[ApiProperty(description: 'Title')]
#[Groups(['read', 'write'])]
#[Assert\NotBlank]
#[ORM\Column(type: Types::STRING, length: 255, unique: true)]
private string $title;
#[ApiProperty(description: 'Example')]
#[Sanitizeable]
#[Groups(['read:' . self::class, 'write'])]
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $example = null;
#[ApiProperty(description: 'Type')]
#[Groups(['read:' . self::class])]
#[ORM\Column(
type: Types::STRING,
enumType: PredefinedCitationType::class,
length: 255,
options: ['default' => PredefinedCitationType::APA],
unique: true
)]
private PredefinedCitationType $type = PredefinedCitationType::APA;
public function __construct(string $title, PredefinedCitationType $type)
{
$this->setUuid();
$this->title = $title;
$this->type = $type;
$this->createdAt = new \DateTimeImmutable();
$this->updatedAt = new \DateTimeImmutable();
}
public function getTitle(): string
{
return $this->title;
}
public function setTitle(string $title): self
{
$this->title = $title;
return $this;
}
public function getExample(): ?string
{
return $this->example;
}
public function setExample(?string $example): self
{
$this->example = $example;
return $this;
}
public function getType(): PredefinedCitationType
{
return $this->type;
}
}