<?php
namespace App\Entity;
use App\Controller\Action\BlockContentCreateOrUpdateActionController;
use App\Controller\Action\BlockContentGetActionController;
use App\Repository\BlockContentRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\Put;
use phpDocumentor\Reflection\Types\Boolean;
use Symfony\Component\Serializer\Annotation\Groups;
#[ORM\Table(name: 'BLOCK_CONTENT')]
#[ORM\Entity(repositoryClass: BlockContentRepository::class)]
#[ApiResource(
operations: [
new Get(
name: 'block_content_item',
uriTemplate: '/block_contents/{name}',
controller: BlockContentGetActionController::class,
uriVariables: [
'name' => ['from_class' => BlockContent::class, 'from_property' => 'name']
],
write: false,
read: false
),
new Put(
name: 'block_content_create_or_update',
uriTemplate: '/block_contents/{name}',
controller: BlockContentCreateOrUpdateActionController::class,
uriVariables: [
'name' => ['from_class' => BlockContent::class, 'from_property' => 'name']
],
read: false,
write: false,
)
]
)]
class BlockContent
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
#[Groups(['block_content.list', 'block_content.get'])]
private ?int $id = null;
#[ORM\Column(length: 255, unique: true)]
#[Groups(['block_content.list', 'block_content.get', 'block_content.create', 'block_content.update'])]
private ?string $name = null;
#[ORM\Column(type: Types::TEXT)]
#[Groups(['block_content.get', 'block_content.create', 'block_content.update'])]
private ?string $content = null;
#[ORM\Column(length: 255)]
#[Groups(['block_content.list', 'block_content.get', 'block_content.create', 'block_content.update'])]
private ?string $type = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups(['block_content.list', 'block_content.get', 'block_content.create', 'block_content.update'])]
private ?string $color = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups(['block_content.list', 'block_content.get', 'block_content.create', 'block_content.update'])]
private ?string $icon = null;
#[ORM\Column(type: Types::BOOLEAN)]
#[Groups(['block_content.list', 'block_content.get', 'block_content.update'])]
private bool $isActive = true;
#[ORM\Column(type: Types::DATETIME_MUTABLE)]
#[Groups(['block_content.list', 'block_content.get'])]
private ?\DateTimeInterface $createdAt = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
#[Groups(['block_content.list', 'block_content.get'])]
private ?\DateTimeInterface $updatedAt = null;
public function __construct()
{
$this->createdAt = new \DateTime();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): static
{
$this->name = $name;
return $this;
}
public function getContent(): ?string
{
return $this->content;
}
public function setContent(string $content): static
{
$this->content = $content;
return $this;
}
public function getType(): ?string
{
return $this->type;
}
public function setType(string $type): static
{
$this->type = $type;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeInterface $createdAt): static
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
public function setUpdatedAt(?\DateTimeInterface $updatedAt): static
{
$this->updatedAt = $updatedAt;
return $this;
}
public function getColor(): ?string
{
return $this->color;
}
public function setColor(?string $color): static
{
$this->color = $color;
return $this;
}
public function getIcon(): ?string
{
return $this->icon;
}
public function setIcon(?string $icon): static
{
$this->icon = $icon;
return $this;
}
public function isActive(): bool
{
return $this->isActive;
}
public function getIsActive(): bool
{
return $this->isActive;
}
public function setIsActive(bool $isActive): static
{
$this->isActive = $isActive;
return $this;
}
#[ORM\PreUpdate]
public function setUpdatedAtValue(): void
{
$this->updatedAt = new \DateTime();
}
}