44 lines
2.6 KiB
C#
44 lines
2.6 KiB
C#
using LehrerApp.Core.Models;
|
|
using LehrerApp.Templating;
|
|
|
|
namespace LehrerApp.Desktop.Services;
|
|
|
|
/// <summary>
|
|
/// Baut die Standard-Platzhalterwerte für Elternbrief-Vorlagen (Datum, Anrede, Kontaktadresse,
|
|
/// Schülerdaten, Brieftext, ...). Ursprünglich Teil von
|
|
/// <see cref="ViewModels.Students.CreateLetterDialogViewModel"/>, hierher extrahiert, damit
|
|
/// <c>LetterTemplateTools</c> (MCP, siehe Planungsdokument) dieselbe Logik nutzt statt sie zu
|
|
/// duplizieren — beide Aufrufer müssen exakt dieselben Platzhalternamen befüllen, sonst driften
|
|
/// Dialog-generierte und KI-generierte Briefe unbemerkt auseinander.
|
|
/// </summary>
|
|
public static class LetterPlaceholderBuilder
|
|
{
|
|
public static Dictionary<string, PlaceholderValue> BuildStandardValues(
|
|
Student student, Contact? contact, LearningGroup? group, DateOnly date,
|
|
string letterText, string teacherName, DrawingValue? attendanceCalendar = null)
|
|
{
|
|
var cityLine = string.Join(" ", new[] { contact?.PostalCode, contact?.City }.Where(x => !string.IsNullOrWhiteSpace(x)));
|
|
var address = string.Join(Environment.NewLine, new[] { contact?.Name, contact?.Street, cityLine }.Where(x => !string.IsNullOrWhiteSpace(x)));
|
|
return new Dictionary<string, PlaceholderValue>(StringComparer.Ordinal)
|
|
{
|
|
["Datum"] = new DateValue(date), ["CurrentDate"] = new DateValue(date),
|
|
["Empfaenger"] = new TextValue(contact?.Name ?? ""), ["Anrede"] = new TextValue(contact?.LetterSalutation ?? ""),
|
|
["Brieftext"] = new MultilineValue(letterText), ["LehrerName"] = new TextValue(teacherName),
|
|
["Student.FirstName"] = new TextValue(student.FirstName), ["Student.LastName"] = new TextValue(student.LastName),
|
|
["Contact.Name"] = new TextValue(contact?.Name ?? ""), ["Contact.Address"] = new MultilineValue(address),
|
|
["Contact.Street"] = new TextValue(contact?.Street ?? ""), ["Contact.PostalCode"] = new TextValue(contact?.PostalCode ?? ""),
|
|
["Contact.City"] = new TextValue(contact?.City ?? ""), ["Letter.Salutation"] = new TextValue(contact?.LetterSalutation ?? ""),
|
|
["Group.Name"] = new TextValue(group?.Name ?? ""), ["SchoolYear"] = new TextValue(group?.SchoolYear ?? ""),
|
|
[StudentAttendanceCalendarDrawingBuilder.PlaceholderName] = attendanceCalendar ?? new DrawingValue([], 0),
|
|
};
|
|
}
|
|
|
|
public static bool IsEmpty(PlaceholderValue value) => value switch
|
|
{
|
|
TextValue x => string.IsNullOrWhiteSpace(x.Value),
|
|
MultilineValue x => string.IsNullOrWhiteSpace(x.Value),
|
|
DrawingValue x => x.ContentHeight <= 0 || x.Commands.Count == 0,
|
|
_ => false,
|
|
};
|
|
}
|