Neues Modul: Qualitätsmanagement
All checks were successful
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 2m46s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 2m51s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 3m2s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 2m55s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 4m15s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 4m16s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 3m44s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 3m46s
CI / Build-Artefakte aktuell (pull_request) Successful in 52s

- Kategorien mit farbigen Ordnerkacheln; Farbe und Symbol je Ordner
  (Auswahl oder eigener Upload, SVG bereinigt), an Unterordner vererbt
- Ordnerseite: Einführungstext, Ansprechpartner (Profilfelder wählbar),
  Unterordner, Liste mit Dokument, Version, Stand, Größe, Aktion
- Einträge: Datei (Lesefassung + bearbeitbare Vorlage), Link,
  Online-Formular; neue Fassungen archivieren die bisherigen
- PDF-Betrachter im Portal (pdf.js)
- Eigene Volltextsuche (PDF, Word, Excel, PowerPoint, OpenDocument)
  mit Textausschnitt; optionale Texterkennung per Tesseract
- Rollen-Ausschluss für das ganze Modul, Pflegerecht qm.manage,
  Zielgruppen je Kategorie
- Vorbereitet: Wiedervorlage, Verantwortliche, Lesebestätigungen
- Abhängigkeit smalot/pdfparser

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Friederich Loheide 2026-09-26 15:50:23 +00:00
parent f78cc96be7
commit b3a057e27c
218 changed files with 13478 additions and 358 deletions

View file

@ -0,0 +1,159 @@
<?php
namespace Inhaus\Plugins\Qm;
use App\Models\User;
use App\Support\ProfileFields;
use App\Support\Settings;
use Inhaus\Plugins\Qm\Models\QmEntry;
/**
* Daten für das Portal: Ordnerkacheln, Einträge und Ansprechpartner.
*/
class Presenter
{
public const CONTACT_FIELDS = 'qm.contact_fields';
/** Kernfelder des Profils, die bei Ansprechpartnern erscheinen können. */
public const CORE_FIELDS = [
'job_title' => 'Funktion',
'department' => 'Abteilung',
'location' => 'Standort',
'phone' => 'Telefon',
'mobile' => 'Mobil',
'email' => 'E-Mail-Adresse',
];
public const DEFAULT_CONTACT_FIELDS = ['job_title', 'phone', 'email'];
public function __construct(private readonly QmTree $tree, private readonly Settings $settings, private readonly ProfileFields $profileFields) {}
/**
* @param array<int, int> $counts Ordner => Anzahl Einträge
* @return array<string, mixed>
*/
public function tile(int $id, array $counts = []): array
{
$folder = $this->tree->folder($id);
$children = count($this->tree->childIds($id));
return [
'id' => $id,
'name' => $folder['name'],
'color' => $folder['color'],
'icon' => $folder['icon'],
'folders' => $children,
'entries' => (int) ($counts[$id] ?? 0),
'url' => route('qm.folder', $id),
];
}
/**
* @return array<string, mixed>
*/
public function entry(QmEntry $entry, bool $withFolder = false): array
{
$reading = $entry->relationLoaded('readingFile') ? $entry->readingFile : null;
$editable = $entry->relationLoaded('editableFile') ? $entry->editableFile : null;
$main = $reading ?? $editable;
$open = match ($entry->type) {
QmEntry::LINK => ['url' => $entry->url, 'kind' => 'link'],
QmEntry::FORM => ['url' => $entry->form_id ? $this->formUrl($entry->form_id) : null, 'kind' => 'form'],
default => $main
? ($main->isViewable() ? ['url' => route('qm.view', $entry), 'kind' => 'view'] : ['url' => $main->url(), 'kind' => 'download'])
: ['url' => null, 'kind' => 'none'],
};
return [
'id' => $entry->id,
'type' => $entry->type,
'title' => $entry->title,
'description' => $entry->description,
'version' => $entry->version,
'valid_from' => $entry->valid_from?->toDateString(),
'size' => $main?->size,
'extension' => $main?->extension(),
'open_url' => $open['url'],
'open_kind' => $open['kind'],
'download_url' => $main?->url(),
'editable' => $editable ? ['name' => $editable->name, 'extension' => $editable->extension(), 'url' => $editable->url(), 'size' => $editable->size] : null,
'searchable' => $main ? in_array($main->text_status, ['ok', 'ocr'], true) : null,
'text_status' => $main?->text_status,
'url' => $entry->url,
'form_id' => $entry->form_id,
'folder' => $withFolder ? $this->folderLabel($entry->folder_id) : null,
];
}
/**
* @return array{id: int, path: string, color: string}
*/
public function folderLabel(int $id): array
{
return [
'id' => $id,
'path' => implode(' › ', array_column($this->tree->path($id), 'name')),
'color' => $this->tree->folder($id)['color'] ?? Colors::DEFAULT,
'url' => route('qm.folder', $id),
];
}
/**
* Ansprechpartner mit den im Admin gewählten Profilfeldern.
*
* @param iterable<User> $people
* @return list<array<string, mixed>>
*/
public function contacts(iterable $people, ?User $viewer): array
{
$fields = (array) $this->settings->get(self::CONTACT_FIELDS, self::DEFAULT_CONTACT_FIELDS);
$result = [];
foreach ($people as $person) {
if (! $person->is_active) {
continue;
}
$values = [];
$custom = collect($this->profileFields->visibleValues($person, $viewer))->keyBy('key');
foreach ($fields as $field) {
if (isset(self::CORE_FIELDS[$field])) {
$value = $person->{$field};
if (filled($value)) {
$values[] = ['key' => $field, 'label' => self::CORE_FIELDS[$field], 'value' => $value, 'type' => in_array($field, ['phone', 'mobile'], true) ? 'phone' : ($field === 'email' ? 'email' : 'text')];
}
} elseif (str_starts_with($field, 'custom.') && ($item = $custom->get(substr($field, 7)))) {
$values[] = ['key' => $field, 'label' => $item['label'], 'value' => $item['value'], 'type' => $item['type'] ?? 'text'];
}
}
$result[] = [
'id' => $person->id,
'name' => $person->name,
'initials' => $person->initials,
'avatar_url' => $person->avatarUrl(160),
'fields' => $values,
];
}
return $result;
}
/**
* @return array<string, string> auswählbare Felder für die Einstellungen
*/
public function contactFieldOptions(): array
{
return self::CORE_FIELDS + collect($this->profileFields->options())->mapWithKeys(fn ($label, $key) => ['custom.'.$key => $label.' (Profilfeld)'])->all();
}
private function formUrl(int $id): ?string
{
$class = 'Inhaus\\Plugins\\Forms\\Models\\Form';
return class_exists($class) ? $class::query()->find($id)?->url() : null;
}
}