145 lines
3.6 KiB
PHP
145 lines
3.6 KiB
PHP
<?php
|
|
|
|
namespace App\Entity;
|
|
|
|
use App\Entity\Traits\BlameableEntity;
|
|
use App\Entity\Traits\SoftDeletableEntity;
|
|
use App\Entity\Traits\TimestampableEntity;
|
|
use App\Repository\MailingTemplateRepository;
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
use Doctrine\Common\Collections\Collection;
|
|
use Doctrine\DBAL\Types\Types;
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
use Symfony\Component\Uid\Uuid;
|
|
use Symfony\Component\Validator\Constraints as Assert;
|
|
|
|
/**
|
|
* A reusable starting point for an assignment mailing, shared by all managers and admins.
|
|
*
|
|
* Picking it fills subject and message of a mailing, which can then be changed for that one
|
|
* mailing without touching the template. Its attachments always go out with the mailing.
|
|
*/
|
|
#[ORM\Entity(repositoryClass: MailingTemplateRepository::class)]
|
|
class MailingTemplate implements BlameableEntityInterface, TimestampableEntityInterface, SoftDeletableEntityInterface
|
|
{
|
|
use BlameableEntity;
|
|
use TimestampableEntity;
|
|
use SoftDeletableEntity;
|
|
|
|
#[ORM\Id]
|
|
#[ORM\GeneratedValue]
|
|
#[ORM\Column]
|
|
private ?int $id = null;
|
|
|
|
#[ORM\Column(type: 'string', length: 36, unique: true)]
|
|
private string $uuid;
|
|
|
|
#[ORM\Column(length: 255)]
|
|
#[Assert\NotBlank(message: 'Bitte gib einen Namen an')]
|
|
private ?string $name = null;
|
|
|
|
#[ORM\Column(length: 255)]
|
|
#[Assert\NotBlank(message: 'Bitte gib einen Betreff an')]
|
|
private ?string $subject = null;
|
|
|
|
#[ORM\Column(type: Types::TEXT)]
|
|
#[Assert\NotBlank(message: 'Bitte gib eine Nachricht ein')]
|
|
private ?string $message = null;
|
|
|
|
/**
|
|
* @var Collection<int, Upload>
|
|
*/
|
|
#[ORM\OneToMany(targetEntity: Upload::class, mappedBy: 'mailingTemplate')]
|
|
#[ORM\OrderBy(['id' => \SortDirection::Ascending])]
|
|
private Collection $attachments;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->uuid = Uuid::v4();
|
|
$this->attachments = new ArrayCollection();
|
|
}
|
|
|
|
public function __toString(): string
|
|
{
|
|
return (string) $this->name;
|
|
}
|
|
|
|
public function getId(): ?int
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
public function getUuid(): string
|
|
{
|
|
return $this->uuid;
|
|
}
|
|
|
|
public function getName(): ?string
|
|
{
|
|
return $this->name;
|
|
}
|
|
|
|
public function setName(?string $name): static
|
|
{
|
|
$this->name = $name;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getSubject(): ?string
|
|
{
|
|
return $this->subject;
|
|
}
|
|
|
|
public function setSubject(?string $subject): static
|
|
{
|
|
$this->subject = $subject;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getMessage(): ?string
|
|
{
|
|
return $this->message;
|
|
}
|
|
|
|
public function setMessage(?string $message): static
|
|
{
|
|
$this->message = $message;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return Collection<int, Upload>
|
|
*/
|
|
public function getAttachments(): Collection
|
|
{
|
|
return $this->attachments;
|
|
}
|
|
|
|
public function addAttachment(Upload $attachment): static
|
|
{
|
|
if (!$this->attachments->contains($attachment)) {
|
|
$this->attachments->add($attachment);
|
|
$attachment->setMailingTemplate($this);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function removeAttachment(Upload $attachment): static
|
|
{
|
|
if ($this->attachments->removeElement($attachment) && $attachment->getMailingTemplate() === $this) {
|
|
$attachment->setMailingTemplate(null);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getAttachmentSize(): int
|
|
{
|
|
return array_sum($this->attachments->map(fn (Upload $upload) => (int) $upload->getSize())->toArray());
|
|
}
|
|
}
|