<?php
namespace App\Entity;
use App\Repository\AgendaReminderRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: AgendaReminderRepository::class)]
#[ORM\Table(
name: 'agenda_reminder',
uniqueConstraints: [
new ORM\UniqueConstraint(
name: 'UNIQ_AGENDA_REMINDER_SIGNATURE',
columns: ['user_id', 'source_type', 'source_id', 'remind_at', 'channel']
),
],
indexes: [
new ORM\Index(name: 'IDX_AGENDA_REMINDER_DUE', columns: ['status', 'remind_at']),
new ORM\Index(name: 'IDX_AGENDA_REMINDER_USER_STATUS', columns: ['user_id', 'status']),
]
)]
class AgendaReminder
{
public const STATUS_PENDING = 'pending';
public const STATUS_SENT = 'sent';
public const STATUS_CANCELED = 'canceled';
public const SOURCE_INTEREST_ACTIVITY = 'interest_activity';
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\ManyToOne]
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
private ?User $user = null;
#[ORM\Column(length: 40)]
private string $sourceType = self::SOURCE_INTEREST_ACTIVITY;
#[ORM\Column]
private int $sourceId = 0;
#[ORM\Column(length: 180)]
private string $title = '';
#[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
private ?\DateTimeImmutable $scheduledAt = null;
#[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
private ?\DateTimeImmutable $remindAt = null;
#[ORM\Column(length: 64)]
private string $timezone = 'Europe/Paris';
#[ORM\Column(length: 20)]
private string $channel = 'in_app';
#[ORM\Column(length: 20)]
private string $status = self::STATUS_PENDING;
#[ORM\Column(length: 255, nullable: true)]
private ?string $actionUrl = null;
#[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
private \DateTimeImmutable $createdAt;
#[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
private \DateTimeImmutable $updatedAt;
#[ORM\Column(type: Types::DATETIME_IMMUTABLE, nullable: true)]
private ?\DateTimeImmutable $sentAt = null;
public function __construct()
{
$now = new \DateTimeImmutable();
$this->createdAt = $now;
$this->updatedAt = $now;
}
public function getId(): ?int
{
return $this->id;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
public function getSourceType(): string
{
return $this->sourceType;
}
public function setSourceType(string $sourceType): self
{
$this->sourceType = mb_substr(trim($sourceType), 0, 40);
return $this;
}
public function getSourceId(): int
{
return $this->sourceId;
}
public function setSourceId(int $sourceId): self
{
$this->sourceId = max(0, $sourceId);
return $this;
}
public function getTitle(): string
{
return $this->title;
}
public function setTitle(string $title): self
{
$this->title = mb_substr(trim($title), 0, 180);
return $this;
}
public function getScheduledAt(): ?\DateTimeImmutable
{
return $this->scheduledAt;
}
public function setScheduledAt(?\DateTimeImmutable $scheduledAt): self
{
$this->scheduledAt = $scheduledAt;
return $this;
}
public function getRemindAt(): ?\DateTimeImmutable
{
return $this->remindAt;
}
public function setRemindAt(?\DateTimeImmutable $remindAt): self
{
$this->remindAt = $remindAt;
return $this;
}
public function getTimezone(): string
{
return $this->timezone;
}
public function setTimezone(string $timezone): self
{
$this->timezone = mb_substr(trim($timezone), 0, 64);
return $this;
}
public function getChannel(): string
{
return $this->channel;
}
public function setChannel(string $channel): self
{
$this->channel = mb_substr(trim($channel), 0, 20);
return $this;
}
public function getStatus(): string
{
return $this->status;
}
public function setStatus(string $status): self
{
$this->status = mb_substr(trim($status), 0, 20);
$this->touch();
return $this;
}
public function getActionUrl(): ?string
{
return $this->actionUrl;
}
public function setActionUrl(?string $actionUrl): self
{
$value = trim((string) ($actionUrl ?? ''));
$this->actionUrl = $value === '' ? null : mb_substr($value, 0, 255);
return $this;
}
public function getCreatedAt(): \DateTimeImmutable
{
return $this->createdAt;
}
public function getUpdatedAt(): \DateTimeImmutable
{
return $this->updatedAt;
}
public function touch(): self
{
$this->updatedAt = new \DateTimeImmutable();
return $this;
}
public function getSentAt(): ?\DateTimeImmutable
{
return $this->sentAt;
}
public function setSentAt(?\DateTimeImmutable $sentAt): self
{
$this->sentAt = $sentAt;
$this->touch();
return $this;
}
}