90 lines
2.6 KiB
PHP
90 lines
2.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Entity;
|
|
|
|
use App\Enum\ResourceType;
|
|
use App\Repository\ResourceTypeSettingsRepository;
|
|
use Doctrine\DBAL\Types\Types;
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
use Symfony\Component\Validator\Constraints as Assert;
|
|
|
|
/**
|
|
* What an administrator has configured for a whole kind of resource, as opposed to for one
|
|
* resource or one group.
|
|
*
|
|
* ResourceType is an enum and has no row of its own, so settings that belong to a kind need
|
|
* somewhere to live. A row exists only once something has actually been configured for that
|
|
* kind: adding a case to the enum therefore still needs nothing but the case, and a kind nobody
|
|
* has touched is simply absent here rather than a row full of defaults.
|
|
*
|
|
* Today the only setting is who is told about new bookings. Anything else that turns out to be
|
|
* per-kind rather than per-resource belongs here too.
|
|
*/
|
|
#[ORM\Entity(repositoryClass: ResourceTypeSettingsRepository::class)]
|
|
#[ORM\UniqueConstraint(name: 'uniq_resource_type_settings_type', columns: ['type'])]
|
|
class ResourceTypeSettings
|
|
{
|
|
#[ORM\Id]
|
|
#[ORM\GeneratedValue]
|
|
#[ORM\Column]
|
|
private ?int $id = null;
|
|
|
|
#[ORM\Column(enumType: ResourceType::class)]
|
|
private ResourceType $type;
|
|
|
|
/**
|
|
* Who receives a mail when something of this kind is booked. Empty means nobody, which is
|
|
* the state every kind starts in.
|
|
*
|
|
* A JSON list rather than a table of its own: nothing ever queries by recipient -- the list
|
|
* is only ever read through the kind it belongs to -- and a recipient carries no data beyond
|
|
* the address itself.
|
|
*
|
|
* @var list<string>
|
|
*/
|
|
#[ORM\Column(type: Types::JSON)]
|
|
#[Assert\All([
|
|
new Assert\Email(message: '"{{ value }}" ist keine gültige E-Mail-Adresse.'),
|
|
new Assert\Length(max: 180),
|
|
])]
|
|
private array $notificationRecipients = [];
|
|
|
|
public function __construct(ResourceType $type)
|
|
{
|
|
$this->type = $type;
|
|
}
|
|
|
|
public function getId(): ?int
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
public function getType(): ResourceType
|
|
{
|
|
return $this->type;
|
|
}
|
|
|
|
/**
|
|
* @return list<string>
|
|
*/
|
|
public function getNotificationRecipients(): array
|
|
{
|
|
return $this->notificationRecipients;
|
|
}
|
|
|
|
/**
|
|
* @param list<string> $recipients
|
|
*/
|
|
public function setNotificationRecipients(array $recipients): void
|
|
{
|
|
$this->notificationRecipients = array_values($recipients);
|
|
}
|
|
|
|
public function hasNotificationRecipients(): bool
|
|
{
|
|
return [] !== $this->notificationRecipients;
|
|
}
|
|
}
|