OpenNIT

Quelltext des aktuellen Standes

Fassung 1.1.1

_widget_tickets.php

5 KB
<?php
/**
 * Partial: Dashboard-Widget "Meine Tickets"
 *
 * Wird sowohl beim normalen Dashboard-Render als auch vom schlanken
 * Polling-Endpoint (/dashboard/tickets-widget) verwendet, damit der
 * 30s-Auto-Refresh nicht das komplette Dashboard neu berechnen muss.
 *
 * Erwartete Variablen: $my_tickets, $my_ticket_counts, $has_view_tickets, $icon_style
 */
$myTickets      = $my_tickets       ?? [];
$myTicketCounts = $my_ticket_counts ?? ['new' => 0, 'active' => 0];
$hasViewTickets = $has_view_tickets ?? false;
$_useFA         = ($icon_style ?? 'fontawesome') === 'fontawesome';
$ticketIcon     = $_useFA ? '<i class="fa-solid fa-ticket-alt"></i>' : '🎫';

if ($hasViewTickets):
?>
<section class="dashboard-card" data-widget="my_tickets" id="wMyTickets">
    <div class="card-header">
        <div style="display:flex;align-items:center;gap:0.5rem;">
            <span class="widget-drag-handle" title="<?= $this->te('Verschieben') ?>">&#8942;&#8942;</span>
            <h2><?= $ticketIcon ?> <?= $this->te('Meine Tickets') ?></h2>
        </div>
        <a href="/tickets?preset=mine" class="card-link"><?= $this->te('Alle &rarr;') ?></a>
    </div>
    <div class="card-body">
        <!-- KPI-Zeile -->
        <div style="display:flex;gap:0.5rem;margin-bottom:0.75rem;">
            <span style="display:flex;flex-direction:column;align-items:center;background:var(--color-primary-soft);color:var(--color-primary-strong);border-radius:0.25rem;padding:0.4rem 0.75rem;flex:1;border-top:3px solid var(--color-primary);">
                <span style="font-size:1.1rem;font-weight:800;line-height:1;"><?= $myTicketCounts['new'] ?></span>
                <span style="font-size:0.65rem;font-weight:600;margin-top:2px;text-transform:uppercase;letter-spacing:.04em;"><?= $this->te('Neu') ?></span>
            </span>
            <span style="display:flex;flex-direction:column;align-items:center;background:var(--emerald-100);color:var(--emerald-800);border-radius:0.25rem;padding:0.4rem 0.75rem;flex:1;border-top:3px solid var(--color-success);">
                <span style="font-size:1.1rem;font-weight:800;line-height:1;"><?= $myTicketCounts['active'] ?></span>
                <span style="font-size:0.65rem;font-weight:600;margin-top:2px;text-transform:uppercase;letter-spacing:.04em;"><?= $this->te('Meine') ?></span>
            </span>
        </div>

        <?php if (empty($myTickets)): ?>
            <p style="font-size:0.85rem;color:var(--gray-400);text-align:center;padding:0.75rem 0;"><?= $this->te('Keine offenen Tickets.') ?></p>
        <?php else: ?>
        <div style="display:flex;flex-direction:column;gap:0.35rem;">
            <?php
            $statusLabel = ['new'=>'Neu','open'=>'In Bearb.','waiting'=>'Warten'];
            $statusColor = ['new'=>['#d2e9f5','#2471a3'],'open'=>['#d1fae5','#065f46'],'waiting'=>['#fef3c7','#92400e']];
            $shown = 0;
            foreach ($myTickets as $t):
                if ($shown >= 8) break;
                $shown++;
                [$bg, $fg] = $statusColor[$t['status']] ?? ['#f3f4f6','#6b7280'];
                $lbl = $statusLabel[$t['status']] ?? $t['status'];
            ?>
            <a href="/tickets/<?= (int)$t['id'] ?>" style="display:flex;align-items:center;gap:0.6rem;padding:0.45rem 0.6rem;border-radius:0.4rem;background:var(--gray-50);text-decoration:none;border:1px solid var(--gray-100);">
                <span style="font-size:0.7rem;font-weight:700;color:var(--gray-400);min-width:2rem;">#<?= (int)$t['id'] ?></span>
                <span style="flex:1;font-size:0.82rem;font-weight:600;color:var(--gray-900);overflow:hidden;text-overflow:ellipsis;white-space:nowrap;"><?= $this->e($t['subject']) ?></span>
                <span style="font-size:0.68rem;font-weight:700;padding:0.15rem 0.5rem;border-radius:9999px;background:<?= $bg ?>;color:<?= $fg ?>;white-space:nowrap;"><?= $lbl ?></span>
            </a>
            <?php endforeach; ?>
            <?php if (count($myTickets) > 8): ?>
            <a href="/tickets?preset=mine" style="font-size:0.78rem;color:var(--gray-500);text-align:center;padding-top:0.25rem;">
                <?= $this->te('+ {anzahl} weitere &rarr;', ['anzahl' => count($myTickets) - 8]) ?>
            </a>
            <?php endif; ?>
        </div>
        <?php endif; ?>

        <?php if ($this->hasCapability('manage_tickets')): ?>
        <div style="margin-top:0.75rem;text-align:right;">
            <a href="/tickets/create" style="font-size:0.82rem;color:var(--color-primary);font-weight:600;"><?= $this->te('+ Ticket erstellen') ?></a>
        </div>
        <?php endif; ?>
    </div>
</section>
<?php endif; ?>