IT-Service: Baumstruktur, HTML-Antworten, Fehlermeldungen, geschlossene Tickets, Meine IT im Profilkasten
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 3m31s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 3m39s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 3m57s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 3m46s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 5m9s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 5m13s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 4m30s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 4m27s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m7s
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 3m31s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 3m39s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 3m57s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 3m46s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 5m9s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 5m13s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 4m30s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 4m27s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m7s
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
ab35a67406
commit
50ee85c06b
119 changed files with 611 additions and 463 deletions
|
|
@ -3,6 +3,7 @@
|
|||
namespace Inhaus\Plugins\ItService;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Support\RichText;
|
||||
use Illuminate\Http\Client\Response;
|
||||
use Illuminate\Support\Arr;
|
||||
use Inhaus\Plugins\ItService\OpenNit\Client;
|
||||
|
|
@ -15,6 +16,8 @@ use Inhaus\Plugins\ItService\OpenNit\Settings;
|
|||
*/
|
||||
class ItService
|
||||
{
|
||||
public const CLOSED_STATUSES = ['closed', 'resolved', 'solved', 'done', 'geschlossen', 'erledigt', 'geloest', 'gelöst', 'cancelled', 'canceled'];
|
||||
|
||||
public const OPEN_STATUSES = ['open', 'new', 'pending', 'in_progress', 'waiting', 'reopened', 'offen', 'neu', 'in_bearbeitung', 'wartend'];
|
||||
|
||||
public function __construct(private readonly Client $client, private readonly Settings $settings) {}
|
||||
|
|
@ -65,12 +68,12 @@ class ItService
|
|||
|
||||
return [
|
||||
...self::ticketSummary($ticket),
|
||||
'description' => self::text($ticket, ['description', 'body', 'message', 'text']),
|
||||
'description' => self::html(self::text($ticket, ['description', 'body', 'message', 'text'])),
|
||||
'category' => self::text($ticket, ['category', 'category_name']),
|
||||
'location' => self::text($ticket, ['location', 'location_name']),
|
||||
'asset' => self::text($ticket, ['asset', 'asset_name']),
|
||||
'replies' => array_map(fn ($reply) => [
|
||||
'message' => is_array($reply) ? (string) (self::text($reply, ['message', 'body', 'text', 'content']) ?? '') : (string) $reply,
|
||||
'message' => self::html(is_array($reply) ? self::text($reply, ['message', 'body', 'text', 'content']) : (string) $reply),
|
||||
'author' => is_array($reply) ? self::text($reply, ['author', 'from_name', 'name', 'user', 'author_name']) : null,
|
||||
'from_staff' => is_array($reply) && (bool) ($reply['is_staff'] ?? $reply['internal_user'] ?? $reply['from_staff'] ?? (isset($reply['from_email']) && mb_strtolower((string) $reply['from_email']) !== mb_strtolower($user->email))),
|
||||
'created_at' => is_array($reply) ? self::text($reply, ['created_at', 'date', 'created']) : null,
|
||||
|
|
@ -220,7 +223,7 @@ class ItService
|
|||
|
||||
public static function isOpen(string $status): bool
|
||||
{
|
||||
return ! in_array(mb_strtolower($status), ['closed', 'resolved', 'done', 'geschlossen', 'erledigt', 'geloest', 'gelöst', 'cancelled'], true);
|
||||
return ! in_array(mb_strtolower($status), self::CLOSED_STATUSES, true);
|
||||
}
|
||||
|
||||
public static function ticketStatus(string $status): string
|
||||
|
|
@ -230,9 +233,9 @@ class ItService
|
|||
'in_progress', 'in_bearbeitung', 'assigned' => 'In Bearbeitung',
|
||||
'pending', 'waiting', 'wartend', 'on_hold' => 'Wartet auf Rückmeldung',
|
||||
'reopened' => 'Wieder geöffnet',
|
||||
'resolved', 'geloest', 'gelöst', 'done', 'erledigt' => 'Gelöst',
|
||||
'resolved', 'solved', 'geloest', 'gelöst', 'done', 'erledigt' => 'Gelöst',
|
||||
'closed', 'geschlossen' => 'Geschlossen',
|
||||
'cancelled' => 'Storniert',
|
||||
'cancelled', 'canceled' => 'Storniert',
|
||||
default => $status !== '' ? ucfirst(str_replace('_', ' ', $status)) : 'Offen',
|
||||
};
|
||||
}
|
||||
|
|
@ -270,26 +273,57 @@ class ItService
|
|||
*/
|
||||
private static function tree(array $items): array
|
||||
{
|
||||
$byId = [];
|
||||
$children = [];
|
||||
|
||||
foreach ($items as $item) {
|
||||
if (is_array($item) && isset($item['id'])) {
|
||||
$children[$item['parent_id'] ?? 0][] = $item;
|
||||
$byId[$item['id']] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($byId as $item) {
|
||||
// Eltern, die in der Liste fehlen, machen den Eintrag zur obersten Ebene
|
||||
$parent = $item['parent_id'] ?? null;
|
||||
$children[$parent !== null && isset($byId[$parent]) ? $parent : 0][] = $item;
|
||||
}
|
||||
|
||||
$result = [];
|
||||
$walk = function ($parent, int $depth) use (&$walk, &$children, &$result) {
|
||||
$walk = function ($parent, int $depth, array $path) use (&$walk, &$children, &$result) {
|
||||
foreach ($children[$parent] ?? [] as $item) {
|
||||
$result[] = ['value' => (int) $item['id'], 'label' => str_repeat('– ', $depth).($item['name'] ?? '')];
|
||||
$walk($item['id'], $depth + 1);
|
||||
$name = trim((string) ($item['name'] ?? ''));
|
||||
// Einrückung mit geschützten Leerzeichen – Auswahllisten verschlucken normale
|
||||
$result[] = [
|
||||
'value' => (int) $item['id'],
|
||||
'label' => ($depth > 0 ? str_repeat("\u{00A0}\u{00A0}\u{00A0}\u{00A0}", $depth - 1)."\u{00A0}\u{00A0}└\u{00A0}" : '').$name,
|
||||
'path' => implode(' › ', [...$path, $name]),
|
||||
'depth' => $depth,
|
||||
];
|
||||
$walk($item['id'], $depth + 1, [...$path, $name]);
|
||||
}
|
||||
};
|
||||
$walk(0, 0);
|
||||
$walk(0, 0, []);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Texte aus OpenNIT können HTML enthalten (<br>, <p> …): bereinigt ausgeben,
|
||||
* reinen Text mit Zeilenumbrüchen übernehmen.
|
||||
*/
|
||||
private static function html(?string $text): ?string
|
||||
{
|
||||
if ($text === null || trim($text) === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($text === strip_tags($text)) {
|
||||
return nl2br(e($text), false);
|
||||
}
|
||||
|
||||
return app(RichText::class)->sanitize($text);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
* @param list<string> $keys
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue