feat(14-email-templates): CRUD szablonów e-mail z Quill.js + załączniki

Phase 14 complete (2 plans):
- 14-01: CRUD szablonów, Quill.js editor, system zmiennych {{grupa.pole}}, podgląd, toggle
- 14-02: Select "Załącznik nr 1" z mapą ATTACHMENT_TYPES, kolumna w liście, migracja attachment_1

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-16 23:59:25 +01:00
parent 4d091b2441
commit 2f73a940de
12 changed files with 479 additions and 25 deletions

View File

@@ -54,6 +54,10 @@ final class EmailTemplateController
],
];
private const ATTACHMENT_TYPES = [
'receipt' => 'Paragon',
];
private const SAMPLE_DATA = [
'zamowienie.numer' => 'OP000001234',
'zamowienie.numer_zewnetrzny' => 'ALG-98765432',
@@ -104,6 +108,7 @@ final class EmailTemplateController
'mailboxes' => $mailboxes,
'editTemplate' => $editTemplate,
'variableGroups' => self::VARIABLE_GROUPS,
'attachmentTypes' => self::ATTACHMENT_TYPES,
'successMessage' => Flash::get('settings.email_templates.success', ''),
'errorMessage' => Flash::get('settings.email_templates.error', ''),
], 'layouts/app');
@@ -127,6 +132,9 @@ final class EmailTemplateController
return Response::redirect('/settings/email-templates');
}
$attachment1Raw = trim((string) $request->input('attachment_1', ''));
$attachment1 = isset(self::ATTACHMENT_TYPES[$attachment1Raw]) ? $attachment1Raw : '';
try {
$this->repository->save([
'id' => $request->input('id', ''),
@@ -134,6 +142,7 @@ final class EmailTemplateController
'subject' => $subject,
'body_html' => $bodyHtml,
'mailbox_id' => $request->input('mailbox_id', ''),
'attachment_1' => $attachment1,
'is_active' => $request->input('is_active', null),
]);

View File

@@ -19,7 +19,7 @@ final class EmailTemplateRepository
public function listAll(): array
{
$statement = $this->pdo->prepare(
'SELECT t.id, t.name, t.subject, t.mailbox_id, t.is_active, t.created_at, t.updated_at,
'SELECT t.id, t.name, t.subject, t.mailbox_id, t.attachment_1, t.is_active, t.created_at, t.updated_at,
m.name AS mailbox_name
FROM email_templates t
LEFT JOIN email_mailboxes m ON m.id = t.mailbox_id
@@ -37,7 +37,7 @@ final class EmailTemplateRepository
public function findById(int $id): ?array
{
$statement = $this->pdo->prepare(
'SELECT id, name, subject, body_html, mailbox_id, is_active, created_at, updated_at
'SELECT id, name, subject, body_html, mailbox_id, attachment_1, is_active, created_at, updated_at
FROM email_templates
WHERE id = :id'
);
@@ -53,7 +53,7 @@ final class EmailTemplateRepository
public function listActive(): array
{
$statement = $this->pdo->prepare(
'SELECT id, name, subject, mailbox_id
'SELECT id, name, subject, mailbox_id, attachment_1
FROM email_templates
WHERE is_active = 1
ORDER BY name ASC'
@@ -75,11 +75,16 @@ final class EmailTemplateRepository
? (int) $data['mailbox_id']
: null;
$attachment1 = isset($data['attachment_1']) && $data['attachment_1'] !== ''
? (string) $data['attachment_1']
: null;
$params = [
'name' => trim((string) ($data['name'] ?? '')),
'subject' => trim((string) ($data['subject'] ?? '')),
'body_html' => (string) ($data['body_html'] ?? ''),
'mailbox_id' => $mailboxId,
'attachment_1' => $attachment1,
'is_active' => isset($data['is_active']) ? 1 : 0,
];
@@ -88,13 +93,13 @@ final class EmailTemplateRepository
$statement = $this->pdo->prepare(
'UPDATE email_templates
SET name = :name, subject = :subject, body_html = :body_html,
mailbox_id = :mailbox_id, is_active = :is_active
mailbox_id = :mailbox_id, attachment_1 = :attachment_1, is_active = :is_active
WHERE id = :id'
);
} else {
$statement = $this->pdo->prepare(
'INSERT INTO email_templates (name, subject, body_html, mailbox_id, is_active)
VALUES (:name, :subject, :body_html, :mailbox_id, :is_active)'
'INSERT INTO email_templates (name, subject, body_html, mailbox_id, attachment_1, is_active)
VALUES (:name, :subject, :body_html, :mailbox_id, :attachment_1, :is_active)'
);
}