Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 23 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| Log | |
0.00% |
0 / 23 |
|
0.00% |
0 / 3 |
210 | |
0.00% |
0 / 1 |
| actionLabelFromCode | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
12 | |||
| formatDisplayFields | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
72 | |||
| formatAppointmentAtDisplay | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace BO\Zmsentities; |
| 4 | |
| 5 | class Log extends Schema\Entity |
| 6 | { |
| 7 | public const PRIMARY = 'reference'; |
| 8 | |
| 9 | public const ACTION_MAIL_SUCCESS = 'E-Mail-Versand erfolgreich'; |
| 10 | public const ACTION_MAIL_FAIL = 'E-Mail-Versand ist fehlgeschlagen'; |
| 11 | public const ACTION_STATUS_CHANGE = 'Terminstatus wurde geändert'; |
| 12 | public const ACTION_SEND_REMINDER = 'Erinnerungsmail wurde gesendet'; |
| 13 | public const ACTION_REMOVED = 'Termin aus der Warteschlange entfernt'; |
| 14 | public const ACTION_CALLED = 'Termin wurde aufgerufen'; |
| 15 | public const ACTION_ARCHIVED = 'Termin wurde archiviert'; |
| 16 | public const ACTION_EDITED = 'Termin wurde geändert'; |
| 17 | public const ACTION_REDIRECTED = 'Termin wurde weitergeleitet'; |
| 18 | public const ACTION_NEW = 'Neuer Termin wurde erstellt'; |
| 19 | public const ACTION_DELETED = 'Termin wurde gelöscht'; |
| 20 | public const ACTION_CANCELED = 'Termin wurde abgesagt'; |
| 21 | |
| 22 | private const ACTION_CODE_TO_LABEL = [ |
| 23 | 'mail_success' => self::ACTION_MAIL_SUCCESS, |
| 24 | 'mail_fail' => self::ACTION_MAIL_FAIL, |
| 25 | 'status_changed' => self::ACTION_STATUS_CHANGE, |
| 26 | 'reminder_sent' => self::ACTION_SEND_REMINDER, |
| 27 | 'removed_from_queue' => self::ACTION_REMOVED, |
| 28 | 'called' => self::ACTION_CALLED, |
| 29 | 'archived' => self::ACTION_ARCHIVED, |
| 30 | 'edited' => self::ACTION_EDITED, |
| 31 | 'redirected' => self::ACTION_REDIRECTED, |
| 32 | 'created' => self::ACTION_NEW, |
| 33 | 'deleted' => self::ACTION_DELETED, |
| 34 | 'canceled' => self::ACTION_CANCELED, |
| 35 | ]; |
| 36 | |
| 37 | private const DISPLAY_TEXT_FIELDS = [ |
| 38 | 'user_id' => 'Sachbearbeiter*in', |
| 39 | 'display_number' => 'Terminnummer', |
| 40 | 'citizen_name' => 'Bürger*in', |
| 41 | 'services' => 'Dienstleistungen', |
| 42 | 'process_amendment' => 'Anmerkung', |
| 43 | 'scope_name' => 'Standort', |
| 44 | 'citizen_email' => 'E-Mail', |
| 45 | 'citizen_phone' => 'Telefon', |
| 46 | 'process_status' => 'Status', |
| 47 | 'db_status' => 'DB Status', |
| 48 | ]; |
| 49 | |
| 50 | private const DISPLAY_OPTIONAL_NUMBER_FIELDS = [ |
| 51 | 'queue_number' => 'Wartenummer', |
| 52 | 'slot_count' => 'Slots', |
| 53 | ]; |
| 54 | |
| 55 | public static $schema = "log.json"; |
| 56 | |
| 57 | public static function actionLabelFromCode(?string $code): ?string |
| 58 | { |
| 59 | if ($code === null || $code === '') { |
| 60 | return null; |
| 61 | } |
| 62 | |
| 63 | return self::ACTION_CODE_TO_LABEL[$code] ?? null; |
| 64 | } |
| 65 | |
| 66 | public static function formatDisplayFields(array $log): array |
| 67 | { |
| 68 | $display = []; |
| 69 | $actionLabel = self::actionLabelFromCode($log['action'] ?? null); |
| 70 | if ($actionLabel !== null) { |
| 71 | $display['Aktion'] = $actionLabel; |
| 72 | } |
| 73 | |
| 74 | foreach (self::DISPLAY_TEXT_FIELDS as $column => $label) { |
| 75 | if (!empty($log[$column])) { |
| 76 | $display[$label] = $log[$column]; |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | foreach (self::DISPLAY_OPTIONAL_NUMBER_FIELDS as $column => $label) { |
| 81 | if (isset($log[$column]) && $log[$column] !== '') { |
| 82 | $display[$label] = $log[$column]; |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | $appointmentAt = self::formatAppointmentAtDisplay($log['appointment_at'] ?? null); |
| 87 | if ($appointmentAt !== null) { |
| 88 | $display['Terminzeit'] = $appointmentAt; |
| 89 | } |
| 90 | |
| 91 | return $display; |
| 92 | } |
| 93 | |
| 94 | private static function formatAppointmentAtDisplay($appointmentAt): ?string |
| 95 | { |
| 96 | if (empty($appointmentAt)) { |
| 97 | return null; |
| 98 | } |
| 99 | |
| 100 | $parsed = \DateTimeImmutable::createFromFormat('Y-m-d H:i:s', (string) $appointmentAt); |
| 101 | if (!$parsed instanceof \DateTimeImmutable) { |
| 102 | return null; |
| 103 | } |
| 104 | |
| 105 | return $parsed->format('d.m.Y H:i:s'); |
| 106 | } |
| 107 | } |