dsadsa
All checks were successful
Deploy / deploy (push) Successful in 54s

This commit is contained in:
2026-08-17 00:24:57 +02:00
parent 9d5bad8294
commit 0d384cee2d
10 changed files with 237 additions and 17 deletions

View File

@@ -707,6 +707,31 @@ final class AccountPages
}
$community->saveMembershipLevels($levels, $userId);
$info = 'Community-Level gelöscht.';
} elseif ($action === 'community_points_adjust') {
if (!$canManageProfileLevels || !$community) {
throw new \RuntimeException('Keine Berechtigung für Community-Punkte.');
}
$targetUserId = (int)($_POST['target_user_id'] ?? 0);
$amountRaw = trim((string)($_POST['points_amount'] ?? ''));
$reason = trim((string)($_POST['points_reason'] ?? ''));
if ($targetUserId <= 0) {
throw new \RuntimeException('Bitte wähle einen Benutzer aus.');
}
if ($amountRaw === '' || !is_numeric($amountRaw)) {
throw new \RuntimeException('Bitte gib eine gültige Punktzahl an.');
}
$amount = (float)$amountRaw;
if ($amount <= 0) {
throw new \RuntimeException('Es können hier nur zusätzliche Punkte vergeben werden.');
}
if ($reason === '') {
throw new \RuntimeException('Bitte gib eine Begründung für die Punktevergabe an.');
}
$community->adjustPoints($targetUserId, $amount, $reason, $userId);
$info = 'Community-Punkte wurden erhöht.';
}
} catch (\Throwable $e) {
$error = $e->getMessage();
@@ -913,6 +938,21 @@ final class AccountPages
$communityLevelRightDefinitions = Community::membershipRightDefinitions();
$communityRoles = $communityAccess ? $communityAccess->getUserRoles($userId) : [];
$systemRoleAssignments = $communityAccess && $canManageProfileLevels ? $communityAccess->listRoleAssignments() : [];
$profileLevelUserSearchQuery = '';
$profileLevelUserSearchResults = [];
if ($communityAccess && $community && $canManageProfileLevels) {
$profileLevelUserSearchQuery = trim((string)($_GET['profile_level_user_query'] ?? ''));
if ($profileLevelUserSearchQuery !== '') {
foreach ($communityAccess->searchUsers($profileLevelUserSearchQuery, 12) as $searchRow) {
$targetSearchUserId = (int)($searchRow['id'] ?? 0);
$targetPoints = $community->computePoints($targetSearchUserId);
$searchRow['community_points'] = $targetPoints;
$searchRow['community_level'] = $community->membershipLevel($targetPoints);
$searchRow['roles'] = $communityAccess->getUserRoles($targetSearchUserId);
$profileLevelUserSearchResults[] = $searchRow;
}
}
}
$communityApplication = $communityAccess ? $communityAccess->getLatestApplication($userId) : null;
$communityCanApply = $communityAccess ? $communityAccess->canApplyForForumAdmin($userId, $communityPoints) : false;
$communityRestrictions = $communityAccess ? $communityAccess->getRestrictionState($userId) : [
@@ -991,6 +1031,8 @@ final class AccountPages
'communityLevelRightDefinitions',
'communityRoles',
'systemRoleAssignments',
'profileLevelUserSearchQuery',
'profileLevelUserSearchResults',
'communityApplication',
'communityCanApply',
'communityRestrictions',

View File

@@ -417,6 +417,36 @@ final class Community
return $amount;
}
public function adjustPoints(int $userId, float $amount, string $reason = '', ?int $actingUserId = null): float
{
if ($userId <= 0) {
throw new \RuntimeException('Benutzer nicht gefunden.');
}
if ($amount == 0.0) {
throw new \RuntimeException('Bitte gib eine Punkteänderung ungleich 0 an.');
}
$meta = [
'reason' => trim($reason),
];
if ($actingUserId !== null && $actingUserId > 0) {
$meta['acting_user_id'] = $actingUserId;
}
$stmt = $this->pdo->prepare('INSERT INTO user_points (user_id, action, amount, meta) VALUES (:uid, :action, :amount, :meta)');
$stmt->execute([
':uid' => $userId,
':action' => 'manual.adjustment',
':amount' => $amount,
':meta' => json_encode($meta, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),
]);
$stmt = $this->pdo->prepare('INSERT INTO user_points_totals (user_id, total) VALUES (:uid, :amt) ON DUPLICATE KEY UPDATE total = total + VALUES(total)');
$stmt->execute([':uid' => $userId, ':amt' => $amount]);
return $amount;
}
public function membershipLevel(float $points): array
{
$level = $this->membershipLevelMeta($points);

View File

@@ -290,6 +290,53 @@ final class CommunityAccess
return $this->emailStore()->decryptRowEmails($stmt->fetchAll(\PDO::FETCH_ASSOC) ?: [], 'user_id');
}
public function searchUsers(string $query, int $limit = 12): array
{
$query = trim($query);
if ($query === '') {
return [];
}
$limit = max(1, min(50, $limit));
$tokens = array_values(array_filter(preg_split('/\s+/u', mb_strtolower($query)) ?: [], static fn(string $token): bool => $token !== ''));
if ($tokens === []) {
return [];
}
$conditions = [];
$params = [];
foreach ($tokens as $index => $token) {
$displayKey = ':display_' . $index;
$nameKey = ':name_' . $index;
$emailKey = ':email_' . $index;
$conditions[] = '(LOWER(COALESCE(up.display_name, "")) LIKE ' . $displayKey . ' OR LOWER(CONCAT_WS(" ", COALESCE(up.first_name, ""), COALESCE(up.last_name, ""))) LIKE ' . $nameKey . ' OR LOWER(COALESCE(u.email, "")) LIKE ' . $emailKey . ')';
$needle = '%' . $token . '%';
$params[$displayKey] = $needle;
$params[$nameKey] = $needle;
$params[$emailKey] = $needle;
}
$sql = '
SELECT u.id, u.email, u.status, up.display_name, up.first_name, up.last_name
FROM users u
LEFT JOIN user_profiles up ON up.user_id = u.id
WHERE ' . implode(' AND ', $conditions) . '
ORDER BY
CASE
WHEN LOWER(COALESCE(up.display_name, "")) = :exactQuery THEN 0
WHEN LOWER(COALESCE(u.email, "")) = :exactQuery THEN 1
ELSE 2
END,
COALESCE(up.display_name, ""),
u.id DESC
LIMIT ' . $limit;
$params[':exactQuery'] = mb_strtolower($query);
$stmt = $this->pdo->prepare($sql);
$stmt->execute($params);
return $this->emailStore()->decryptRowEmails($stmt->fetchAll(\PDO::FETCH_ASSOC) ?: [], 'id');
}
public function setRestriction(int $actingUserId, int $targetUserId, string $type, string $reason): void
{
if (!$this->canModerateForum($actingUserId)) {