feat(mail) : TaskMailLink entity + repository
This commit is contained in:
88
src/Entity/TaskMailLink.php
Normal file
88
src/Entity/TaskMailLink.php
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Entity;
|
||||||
|
|
||||||
|
use App\Repository\TaskMailLinkRepository;
|
||||||
|
use DateTimeImmutable;
|
||||||
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
|
||||||
|
#[ORM\Entity(repositoryClass: TaskMailLinkRepository::class)]
|
||||||
|
#[ORM\Table(name: 'task_mail_link')]
|
||||||
|
#[ORM\UniqueConstraint(name: 'uq_task_mail_link', columns: ['task_id', 'mail_message_id'])]
|
||||||
|
class TaskMailLink
|
||||||
|
{
|
||||||
|
#[ORM\Id]
|
||||||
|
#[ORM\GeneratedValue]
|
||||||
|
#[ORM\Column]
|
||||||
|
private ?int $id = null;
|
||||||
|
|
||||||
|
#[ORM\ManyToOne(targetEntity: Task::class)]
|
||||||
|
#[ORM\JoinColumn(name: 'task_id', referencedColumnName: 'id', nullable: false, onDelete: 'CASCADE')]
|
||||||
|
private Task $task;
|
||||||
|
|
||||||
|
#[ORM\ManyToOne(targetEntity: MailMessage::class)]
|
||||||
|
#[ORM\JoinColumn(name: 'mail_message_id', referencedColumnName: 'id', nullable: false, onDelete: 'CASCADE')]
|
||||||
|
private MailMessage $mailMessage;
|
||||||
|
|
||||||
|
#[ORM\Column(type: 'datetimetz_immutable')]
|
||||||
|
private DateTimeImmutable $linkedAt;
|
||||||
|
|
||||||
|
#[ORM\ManyToOne(targetEntity: User::class)]
|
||||||
|
#[ORM\JoinColumn(name: 'linked_by_id', referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
|
||||||
|
private ?User $linkedBy = null;
|
||||||
|
|
||||||
|
public function getId(): ?int
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTask(): Task
|
||||||
|
{
|
||||||
|
return $this->task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setTask(Task $task): static
|
||||||
|
{
|
||||||
|
$this->task = $task;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMailMessage(): MailMessage
|
||||||
|
{
|
||||||
|
return $this->mailMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setMailMessage(MailMessage $mailMessage): static
|
||||||
|
{
|
||||||
|
$this->mailMessage = $mailMessage;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getLinkedAt(): DateTimeImmutable
|
||||||
|
{
|
||||||
|
return $this->linkedAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setLinkedAt(DateTimeImmutable $linkedAt): static
|
||||||
|
{
|
||||||
|
$this->linkedAt = $linkedAt;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getLinkedBy(): ?User
|
||||||
|
{
|
||||||
|
return $this->linkedBy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setLinkedBy(?User $linkedBy): static
|
||||||
|
{
|
||||||
|
$this->linkedBy = $linkedBy;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
||||||
46
src/Repository/TaskMailLinkRepository.php
Normal file
46
src/Repository/TaskMailLinkRepository.php
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Repository;
|
||||||
|
|
||||||
|
use App\Entity\MailMessage;
|
||||||
|
use App\Entity\Task;
|
||||||
|
use App\Entity\TaskMailLink;
|
||||||
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||||
|
use Doctrine\Persistence\ManagerRegistry;
|
||||||
|
|
||||||
|
class TaskMailLinkRepository extends ServiceEntityRepository
|
||||||
|
{
|
||||||
|
public function __construct(ManagerRegistry $registry)
|
||||||
|
{
|
||||||
|
parent::__construct($registry, TaskMailLink::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return list<TaskMailLink>
|
||||||
|
*/
|
||||||
|
public function findByTask(Task $task): array
|
||||||
|
{
|
||||||
|
return $this->createQueryBuilder('l')
|
||||||
|
->andWhere('l.task = :task')
|
||||||
|
->setParameter('task', $task)
|
||||||
|
->orderBy('l.linkedAt', 'DESC')
|
||||||
|
->getQuery()
|
||||||
|
->getResult()
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function findByTaskAndMessage(Task $task, MailMessage $message): ?TaskMailLink
|
||||||
|
{
|
||||||
|
return $this->findOneBy(['task' => $task, 'mailMessage' => $message]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return list<TaskMailLink>
|
||||||
|
*/
|
||||||
|
public function findByMessage(MailMessage $message): array
|
||||||
|
{
|
||||||
|
return $this->findBy(['mailMessage' => $message]);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user