<?php
namespace JanusHercules\TodosDemo\Domain\Entity;
use App\Entity\User;
use App\Utility\DatabaseIdGenerator;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity]
#[ORM\Table(name: 'todo_items')]
class TodoItem
{
public function __construct(
User $user,
string $text
) {
$this->user = $user;
$this->text = $text;
$this->isDone = false;
}
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[ORM\CustomIdGenerator(class: DatabaseIdGenerator::class)]
#[ORM\Column(
type: Types::GUID,
unique: true
)]
private ?string $id = null;
public function getId(): ?string
{
return $this->id;
}
#[ORM\ManyToOne(
targetEntity: User::class,
cascade: ['persist']
)]
#[ORM\JoinColumn(
name: 'users_id',
referencedColumnName: 'id',
nullable: true,
onDelete: 'CASCADE'
)]
private User $user;
public function getUser(): User
{
return $this->user;
}
#[ORM\Column(
type: Types::STRING,
length: 1024,
nullable: false
)]
private string $text;
public function getText(): string
{
return $this->text;
}
#[ORM\Column(
type: Types::BOOLEAN,
nullable: false
)]
private bool $isDone;
public function isDone(): bool
{
return $this->isDone;
}
public function setIsDone(bool $isDone): void
{
$this->isDone = $isDone;
}
}