feat: door access codes display and admin crud
This commit is contained in:
1 parent
91419294b8
commit
afa3f17d77
20 files changed
+1428
No files matched your search
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Enum\CodeVisibility;
|
||||
use App\Repository\AccessCodeRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
/**
|
||||
* A code that opens something in the building: a door, the lift, the barrier.
|
||||
*
|
||||
* Stored in plain text, and that is the feature -- a code nobody can read opens nothing. What
|
||||
* protects it is the firewall in front of the page and `visibility`, not the storage.
|
||||
*
|
||||
* Who a code is for is `visibility` and nothing else: it is the access decision and the caption
|
||||
* at once. Anything about the audience that the two cases do not cover -- "nur donnerstags",
|
||||
* "Reinigungsfirma" -- belongs in the description, which is prose and claims nothing.
|
||||
*
|
||||
* Nothing here is unique. The same door legitimately appears more than once, because rotating a
|
||||
* code means adding the new one with a later `validFrom` while the old row is still the one that
|
||||
* works; which of them is current is a question about today's date, answered when the list is
|
||||
* built rather than by a flag somebody has to remember to clear.
|
||||
*/
|
||||
#[ORM\Entity(repositoryClass: AccessCodeRepository::class)]
|
||||
#[ORM\Index(name: 'idx_access_code_valid_from', columns: ['valid_from'])]
|
||||
class AccessCode
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column(length: 50)]
|
||||
#[Assert\NotBlank]
|
||||
#[Assert\Length(max: 50)]
|
||||
private string $label;
|
||||
|
||||
#[ORM\Column(length: 32)]
|
||||
#[Assert\NotBlank]
|
||||
#[Assert\Length(max: 32)]
|
||||
private string $code;
|
||||
|
||||
#[ORM\Column(type: 'date_immutable')]
|
||||
#[Assert\NotNull]
|
||||
private \DateTimeImmutable $validFrom;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
#[Assert\Length(max: 255)]
|
||||
private ?string $description = null;
|
||||
|
||||
#[ORM\Column(length: 20, enumType: CodeVisibility::class)]
|
||||
private CodeVisibility $visibility = CodeVisibility::EVERYONE;
|
||||
|
||||
public function __construct(
|
||||
string $label,
|
||||
string $code,
|
||||
\DateTimeImmutable $validFrom,
|
||||
?string $description = null,
|
||||
CodeVisibility $visibility = CodeVisibility::EVERYONE,
|
||||
) {
|
||||
$this->label = $label;
|
||||
$this->code = $code;
|
||||
$this->validFrom = $validFrom;
|
||||
$this->description = $description;
|
||||
$this->visibility = $visibility;
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getLabel(): string
|
||||
{
|
||||
return $this->label;
|
||||
}
|
||||
|
||||
public function setLabel(string $label): void
|
||||
{
|
||||
$this->label = $label;
|
||||
}
|
||||
|
||||
public function getCode(): string
|
||||
{
|
||||
return $this->code;
|
||||
}
|
||||
|
||||
public function setCode(string $code): void
|
||||
{
|
||||
$this->code = $code;
|
||||
}
|
||||
|
||||
public function getValidFrom(): \DateTimeImmutable
|
||||
{
|
||||
return $this->validFrom;
|
||||
}
|
||||
|
||||
public function setValidFrom(\DateTimeImmutable $validFrom): void
|
||||
{
|
||||
$this->validFrom = $validFrom;
|
||||
}
|
||||
|
||||
public function getDescription(): ?string
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
public function setDescription(?string $description): void
|
||||
{
|
||||
$this->description = $description;
|
||||
}
|
||||
|
||||
public function getVisibility(): CodeVisibility
|
||||
{
|
||||
return $this->visibility;
|
||||
}
|
||||
|
||||
public function setVisibility(CodeVisibility $visibility): void
|
||||
{
|
||||
$this->visibility = $visibility;
|
||||
}
|
||||
|
||||
/** Not yet in force: it is listed so nobody is surprised on the day it takes over. */
|
||||
public function isUpcoming(\DateTimeImmutable $on): bool
|
||||
{
|
||||
return $this->validFrom > $on;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user