LuminaWebsite/professions.php
Maaxxs ee7a3a2e8e Professions: members enter their characters' professions, a new page shows who can craft what
Asked for in Discord: profession management within the legion for a good balance. Aion 2 has five
crafting professions (Blacksmithing, Armorsmithing, Handicrafting, Alchemy, Cooking) with the stages
Beginner, Expert and Master; gathering is one shared skill for six raw materials that players
specialize in with points. Professions belong to characters, so they are entered per character.

- includes/professions.php: PROFESSIONS (German name, client name, icon, products, weapon classes),
  PROFESSION_STAGES, GATHERING_MATERIALS, loading/saving, counts per member, targets and "wanted".
  German names are not confirmed by the German client yet; only keys are stored.
- New table character_professions (stage, optional level, main profession - at most one per
  character) and member_characters.gathering (schema version 57, also in sql/schema.sql).
- Profile editor: per character a professions fieldset (stage, level, main-profession tick - a
  single profession becomes the main one) and the gathering specialization; saved with the
  character (member_action.php), invalid levels are rejected.
- Profile page shows them per character; the member list shows icons on the cards (main
  profession with a gold ring), gets a "Beruf" filter and finds professions in the search.
- New page professions.php ("Berufe" in the menu, members.view): per profession how many members
  have it as main profession and at all, characters per stage, which classes' weapons it makes and
  how many members play them, everyone with stage; below the gathering specializations.
- New permission professions.manage (initially for groups with roles.manage): targets per
  profession (professions_action.php, setting profession_targets, audit log). Professions below
  their target show as "Gerade gesucht" on the page and in the profile editor.
- Hammer icon; live updates for the new page, the member list and profile pages; the data export
  includes professions per character; privacy policy (as of 26.09.), patch notes and README.

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

198 lines
11 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* Berufe der Legion (includes/professions.php): je Handwerksberuf, wer ihn ausuebt (Stufe, Hauptberuf), fuer welche
* Klassen er die Waffen baut und - von der Leitung festgelegt (professions.manage) - wie viele ihn als Hauptberuf
* haben sollten; darunter die Sammel-Spezialisierungen. Eingetragen wird bei den Charakteren auf der eigenen
* Profilseite (member_edit.php).
*/
require_once __DIR__ . '/includes/bootstrap.php';
require_once __DIR__ . '/includes/professions.php';
require_permission('members.view');
$canManage = user_has_permission('professions.manage');
$rows = professions_all_rows();
$counts = profession_member_counts($rows);
$targets = profession_targets();
$wanted = professions_wanted($counts);
// Je Beruf die Charaktere: Hauptberufe zuerst, sonst wie geladen (Stufe, Level, Name)
$byProfession = array_fill_keys(array_keys(PROFESSIONS), []);
$stageCounts = array_fill_keys(array_keys(PROFESSIONS), array_fill_keys(array_keys(PROFESSION_STAGES), 0));
foreach ($rows as $row) {
$byProfession[$row['profession']][] = $row;
$stageCounts[$row['profession']][max(1, min(3, (int) $row['stage']))]++;
}
foreach ($byProfession as &$list) {
usort($list, static fn (array $a, array $b): int => (int) $b['is_main'] <=> (int) $a['is_main']);
}
unset($list);
// Main-Klassen der aktiven Mitglieder - fuer "Waffen fuer …: so viele spielen sie"
$classCounts = db()->query(
"SELECT class_name, COUNT(*) FROM users WHERE status = 'active' AND class_name IS NOT NULL AND class_name <> '' GROUP BY class_name"
)->fetchAll(PDO::FETCH_KEY_PAIR);
// Sammeln: Charaktere je Rohstoff
$byMaterial = array_fill_keys(array_keys(GATHERING_MATERIALS), []);
try {
$gatherRows = db()->query(
"SELECT c.name AS character_name, c.gathering, u.id AS user_id, u.username, u.display_name, u.avatar_filename
FROM member_characters c JOIN users u ON u.id = c.user_id
WHERE u.status = 'active' AND c.gathering IS NOT NULL AND c.gathering <> ''
ORDER BY COALESCE(NULLIF(u.display_name, ''), u.username), c.name"
)->fetchAll();
} catch (PDOException $e) {
$gatherRows = []; // Spalte entsteht erst beim naechsten Schema-Abgleich
}
foreach ($gatherRows as $row) {
foreach (gathering_parse($row['gathering']) as $material) {
$byMaterial[$material][] = $row;
}
}
$memberName = static fn (array $row): string => $row['display_name'] !== '' ? (string) $row['display_name'] : (string) $row['username'];
$pageTitle = 'Berufe';
include __DIR__ . '/includes/header.php';
?>
<div class="panel">
<div class="raid-header">
<h1>Berufe</h1>
<a class="button button-secondary" href="/member_edit.php#charaktere"><?= icon('edit') ?> Meine Berufe eintragen</a>
</div>
<p class="text-muted">
Wer in der Legion was herstellen kann. Eingetragen wird bei den Charakteren auf der eigenen Profilseite: Beruf, Stufe und
welcher der Hauptberuf ist – also der, auf den sich ein Charakter konzentriert. Gezählt werden Mitglieder; hat jemand
denselben Beruf auf mehreren Charakteren, zählt er einmal.
</p>
<?= professions_wanted_html($wanted) ?>
</div>
<div class="profession-grid">
<?php foreach (PROFESSIONS as $key => $profession): ?>
<?php
$list = $byProfession[$key];
$target = $targets[$key];
$count = $counts[$key];
$players = array_sum(array_map(static fn (string $class): int => (int) ($classCounts[$class] ?? 0), $profession['classes']));
?>
<section class="panel profession-card<?= isset($wanted[$key]) ? ' is-wanted' : '' ?>" id="beruf-<?= e($key) ?>">
<header class="profession-card-head">
<span class="profession-card-icon" aria-hidden="true"><?= $profession['icon'] ?></span>
<div class="profession-card-title">
<h2><?= e($profession['label']) ?> <span class="profession-card-en"><?= e($profession['en']) ?></span></h2>
<p class="text-muted"><?= e($profession['makes']) ?></p>
</div>
<?php if (isset($wanted[$key])): ?><span class="badge profession-wanted-badge">Gesucht</span><?php endif; ?>
</header>
<div class="profession-card-stats">
<div class="profession-stat">
<strong><?= $count['main'] ?><?= $target > 0 ? '<span class="profession-stat-target"> / ' . $target . '</span>' : '' ?></strong>
<span>als Hauptberuf<?= $target > 0 ? ' (Ziel ' . $target . ')' : '' ?></span>
</div>
<div class="profession-stat">
<strong><?= $count['any'] ?></strong>
<span>üben ihn aus</span>
</div>
<div class="profession-stat profession-stat-stages">
<?php foreach (array_reverse(PROFESSION_STAGES, true) as $stage => $stageLabel): ?>
<span class="profession-stage-count profession-stage-<?= $stage ?>" title="Charaktere mit Stufe <?= e($stageLabel) ?>"><?= e($stageLabel) ?> <strong><?= $stageCounts[$key][$stage] ?></strong></span>
<?php endforeach; ?>
</div>
</div>
<?php if ($target > 0): ?>
<div class="profession-progress" role="img" aria-label="<?= $count['main'] ?> von <?= $target ?> als Hauptberuf">
<span style="width: <?= min(100, (int) round($count['main'] / $target * 100)) ?>%"></span>
</div>
<?php endif; ?>
<?php if ($profession['classes']): ?>
<p class="profession-card-need">
Waffen für
<?php foreach ($profession['classes'] as $class): ?><span class="profession-class" title="<?= e($class) ?>"><?= class_badge_html($class, 18) ?><?= e($class) ?></span><?php endforeach; ?>
<span class="text-muted">– <?= $players ?> <?= $players === 1 ? 'Mitglied spielt' : 'Mitglieder spielen' ?> sie als Main-Klasse</span>
</p>
<?php endif; ?>
<?php if ($list): ?>
<ul class="profession-people">
<?php foreach ($list as $row): ?>
<?php $name = $memberName($row); ?>
<li class="<?= (int) $row['is_main'] === 1 ? 'is-main' : '' ?>">
<a href="/member.php?id=<?= (int) $row['user_id'] ?>">
<?= avatar_html(['id' => $row['user_id'], 'username' => $row['username'], 'display_name' => $row['display_name'], 'avatar_filename' => $row['avatar_filename']], 26) ?>
<span class="profession-person">
<span class="profession-person-name"><?= e($name) ?></span>
<?php if (mb_strtolower((string) $row['character_name']) !== mb_strtolower($name)): ?>
<span class="profession-person-character"><?= class_badge_html($row['character_class'], 14) ?><?= e((string) $row['character_name']) ?></span>
<?php endif; ?>
</span>
</a>
<span class="profession-person-stage profession-stage-<?= (int) $row['stage'] ?>">
<?= e(profession_stage_text((int) $row['stage'], $row['level'] !== null ? (int) $row['level'] : null)) ?>
<?php if ((int) $row['is_main'] === 1): ?><span class="profession-main-star" title="Hauptberuf">★</span><?php endif; ?>
</span>
</li>
<?php endforeach; ?>
</ul>
<?php else: ?>
<p class="text-muted profession-empty">Noch niemand eingetragen.</p>
<?php endif; ?>
</section>
<?php endforeach; ?>
</div>
<div class="panel" id="sammeln">
<h2>Sammeln</h2>
<p class="text-muted">
Sammeln ist in Aion 2 kein eigener Beruf, sondern eine gemeinsame Fertigkeit für alle Rohstoffe. Mit ihren Punkten
spezialisiert man sich auf einzelne – für alle reichen sie nicht. Hier steht, wer sich worauf spezialisiert hat.
</p>
<div class="gathering-grid">
<?php foreach (GATHERING_MATERIALS as $material => $info): ?>
<?php $list = $byMaterial[$material]; ?>
<div class="gathering-card">
<div class="gathering-card-head">
<span class="gathering-card-icon" aria-hidden="true"><?= $info['icon'] ?></span>
<strong><?= e($info['label']) ?></strong>
<span class="badge"><?= count($list) ?></span>
</div>
<?php if ($list): ?>
<ul class="gathering-people">
<?php foreach ($list as $row): ?>
<?php $name = $memberName($row); ?>
<li>
<a href="/member.php?id=<?= (int) $row['user_id'] ?>"><?= e($name) ?></a>
<?php if (mb_strtolower((string) $row['character_name']) !== mb_strtolower($name)): ?><span class="text-muted">· <?= e((string) $row['character_name']) ?></span><?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
<?php else: ?>
<p class="text-muted">Noch niemand.</p>
<?php endif; ?>
</div>
<?php endforeach; ?>
</div>
</div>
<?php if ($canManage): ?>
<div class="panel" id="ziele">
<h2>Zielzahlen</h2>
<p class="text-muted">
Wie viele Mitglieder den Beruf als Hauptberuf haben sollten. Liegt ein Beruf darunter, steht er oben und beim Eintragen der
Berufe im Profil als „Gerade gesucht“ – zugeteilt wird dadurch niemandem etwas. 0 = kein Ziel.
</p>
<form method="post" action="/professions_action.php" class="profession-targets">
<?= csrf_field() ?>
<input type="hidden" name="action" value="targets">
<div class="profession-targets-grid">
<?php foreach (PROFESSIONS as $key => $profession): ?>
<label class="profession-target">
<span><span aria-hidden="true"><?= $profession['icon'] ?></span> <?= e($profession['label']) ?></span>
<input type="number" name="target[<?= e($key) ?>]" min="0" max="<?= PROFESSION_TARGET_MAX ?>" value="<?= $targets[$key] ?>" inputmode="numeric">
</label>
<?php endforeach; ?>
</div>
<div class="actions"><button type="submit">Zielzahlen speichern</button></div>
</form>
</div>
<?php endif; ?>
<?php include __DIR__ . '/includes/footer.php'; ?>