LuminaWebsite/includes/item_tooltip.php
Maaxxs 6f8040c397 Menu counts for open reports and moderation, item tooltips in warehouse and Lumishop
- Reports: the menu item shows how many reports are still open (not archived), for everyone with
  reports.view. The reports live in the bot, so the count sits in settings.reports_nav_cache and is
  fetched at most every 2 minutes with a short timeout (reports_nav_open()); the reports page
  refreshes it right away, also after archiving. reports_api_request() takes a timeout.
- Moderation: the menu count now matches the "Freigabe" tab - waiting items plus reported items that
  are still visible (moderation_open_counts(), internal calendar entries only for
  calendar.leadership), with a title like "2 warten auf Freigabe, 1 gemeldet".
- Warehouse and Lumishop cards get an info bubble on mouse hover or keyboard focus (not on touch):
  large image, category, stock, Lumishop price and the last movement in the warehouse; price,
  availability, amount in open requests and whether the own Lumipunkte suffice in the shop. Weapons
  and armour with the same name in the gear catalogue also show grade, level and base stats.
  Content is rendered as a <template> per card (includes/item_tooltip.php), shown and placed by
  assets/js/item-tooltip.js; the old native title on warehouse cards is gone.
- Patch notes and README updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-25 01:48:08 +02:00

95 lines
4 KiB
PHP

<?php
declare(strict_types=1);
/**
* Info-Blase zu Gegenstaenden im Lagerhaus und im Lumishop: gross das Bild, Name und Art - und fuer
* Waffen und Ruestungen, die es auch im Gear-Katalog gibt (gear_items, gleicher Name), Seltenheit,
* Stufe und Grundwerte wie im Spiel. Die Seiten geben den Inhalt als <template> in der Karte aus,
* assets/js/item-tooltip.js zeigt ihn beim Draufzeigen (Maus) bzw. Ansteuern (Tastatur) an.
*/
require_once __DIR__ . '/gear.php';
/**
* Gegenstaende aus dem Gear-Katalog mit diesen Namen (Gross-/Kleinschreibung egal). Gibt es einen
* Namen mehrfach, gilt der mit der hoechsten Gegenstandsstufe.
*
* @param array<int, string> $names
* @return array<string, array<string, mixed>> klein geschriebener Name => Gegenstand (gear_item_decode)
*/
function item_tip_gear(array $names): array
{
$names = array_values(array_unique(array_filter(array_map('trim', $names), static fn (string $name): bool => $name !== '')));
if (empty($names)) {
return [];
}
try {
$stmt = db()->prepare(
'SELECT * FROM gear_items WHERE name IN (' . implode(',', array_fill(0, count($names), '?')) . ') ORDER BY item_level, id'
);
$stmt->execute($names);
} catch (PDOException $e) {
return []; // Gear-Planer noch nicht eingerichtet
}
$items = [];
foreach ($stmt->fetchAll() as $row) {
$items[mb_strtolower((string) $row['name'])] = gear_item_decode($row);
}
return $items;
}
/**
* Inhalt der Info-Blase als <template> (fuer assets/js/item-tooltip.js).
*
* @param array{name: string, icon_html: string, subtitle?: string, gear?: ?array<string, mixed>, text?: string,
* lines?: array<int, array{0: string, 1: string}>, hint?: string} $tip
* lines: [Beschriftung, Wert als fertiges HTML]; text: Beschreibung (Klartext, Zeilenumbrueche bleiben)
*/
function item_tip_template(array $tip): string
{
$gear = $tip['gear'] ?? null;
$sub = [];
$type = '';
if ($gear) {
$type = $gear['item_type'] !== '' && $gear['item_type'] !== $gear['slot'] ? gear_type_label((string) $gear['item_type']) : '';
$sub[] = ($type !== '' ? $type . ' · ' : '') . $gear['grade'] . ' · Stufe ' . (int) $gear['item_level'];
}
// Die Kategorie nur, wenn sie nicht schon als Art dasteht ("Bogen · Epic · Stufe 45" statt noch mal "Bogen")
if (($tip['subtitle'] ?? '') !== '' && $tip['subtitle'] !== $type) {
$sub[] = (string) $tip['subtitle'];
}
// Das Bild steht in der Karte schon geladen - in der Blase nicht erst "lazy" nachladen
$html = '<template class="item-tip-template"><div class="item-tip-head">' . str_replace(' loading="lazy"', '', $tip['icon_html'])
. '<div class="item-tip-title"><strong' . ($gear ? ' class="' . e(gear_grade_class((string) $gear['grade'])) . '"' : '') . '>'
. e($tip['name']) . '</strong>';
foreach ($sub as $line) {
$html .= '<span class="item-tip-sub">' . e($line) . '</span>';
}
$html .= '</div></div>';
// Grundwerte aus dem Gear-Katalog - wie auf der Gegenstands-Karte im Gear-Planer
$stats = $gear ? array_slice((array) $gear['stats'], 0, 10) : [];
if ($stats) {
$html .= '<ul class="item-tip-stats">';
foreach ($stats as $stat) {
$html .= '<li><span>' . e((string) $stat[0]) . '</span><span class="item-tip-value">'
. e(gear_format_value((float) $stat[1], (string) ($stat[2] ?? ''))) . '</span></li>';
}
$html .= '</ul>';
}
if (($tip['text'] ?? '') !== '') {
$html .= '<p class="item-tip-text">' . nl2br(e((string) $tip['text'])) . '</p>';
}
if (!empty($tip['lines'])) {
$html .= '<dl class="item-tip-lines">';
foreach ($tip['lines'] as [$label, $value]) {
$html .= '<div><dt>' . e($label) . '</dt><dd>' . $value . '</dd></div>';
}
$html .= '</dl>';
}
if (($tip['hint'] ?? '') !== '') {
$html .= '<div class="item-tip-hint">' . e((string) $tip['hint']) . '</div>';
}
return $html . '</template>';
}